Skip to content

[release/2.6] Fix dtype before comparing torch and numpy tensors#2340

Merged
pruthvistony merged 1 commit intorelease/2.6from
fix_dtype_comparsion_test_binary_ufuncs_rel2.6
Jul 14, 2025
Merged

[release/2.6] Fix dtype before comparing torch and numpy tensors#2340
pruthvistony merged 1 commit intorelease/2.6from
fix_dtype_comparsion_test_binary_ufuncs_rel2.6

Conversation

@dnikolaev-amd
Copy link
Copy Markdown

@dnikolaev-amd dnikolaev-amd commented Jul 9, 2025

Cast numpy dtype result to torch dtype result before compare

Numpy returns np.power(float32, int64) => float64 Promotion rules for Python scalars
Pytorch returns torch.pow(float32, int64) => float32

Reverts #2287 and fixes tests in a different way

Fixes:

  • SWDEV-538110 - 'dtype' do not match: torch.float32 != torch.float64
  • test_binary_ufuncs.py::TestBinaryUfuncsCUDA::test_cuda_tensor_pow_scalar_tensor_cuda
  • SWDEV-539171 - AttributeError: 'float' object has no attribute 'dtype
  • test_binary_ufuncs.py::TestBinaryUfuncsCUDA::test_long_tensor_pow_floats_cuda
  • test_binary_ufuncs.py::TestBinaryUfuncsCUDA::test_complex_scalar_pow_tensor_cuda_*
  • test_binary_ufuncs.py::TestBinaryUfuncsCUDA::test_float_scalar_pow_float_tensor_cuda_*

Cherry-picked to release/2.7 branch via #2362

Cherry-picked to rocm7.0_internal_testing branch via #2363

Copy link
Copy Markdown

@ethanwee1 ethanwee1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@rocm-repo-management-api
Copy link
Copy Markdown

Jenkins build for ec94658d7c893ed63d2a9628615d0b179640540f commit is in progress
Links: Blue Ocean view / Build artifacts

@jithunnair-amd
Copy link
Copy Markdown
Collaborator

@dnikolaev-amd Does this PR fix any more tests with the proposed changes as compared to #2287?

@ethanwee1
Copy link
Copy Markdown

@dnikolaev-amd Does this PR fix any more tests with the proposed changes as compared to #2287?

These tests started failing after we introduced #2287 @jithunnair-amd

@pruthvistony pruthvistony merged commit 84e9867 into release/2.6 Jul 14, 2025
0 of 2 checks passed
@pruthvistony pruthvistony deleted the fix_dtype_comparsion_test_binary_ufuncs_rel2.6 branch July 14, 2025 16:58
@ethanwee1
Copy link
Copy Markdown

! cherry-pick --onto release/2.7

@ethanwee1
Copy link
Copy Markdown

! cherry-pick --onto rocm7.0_internal_testing

okakarpa pushed a commit that referenced this pull request Jul 14, 2025
Cast numpy dtype result to torch dtype result before compare

Numpy returns `np.power(float32, int64) => float64` [Promotion rules for
Python scalars](https://numpy.org/neps/nep-0050-scalar-promotion.html)
Pytorch returns `torch.pow(float32, int64) => float32`

Reverts #2287 and fixes tests in a
different way

Fixes:
- SWDEV-538110 - `'dtype' do not match: torch.float32 != torch.float64`
> -
test_binary_ufuncs.py::TestBinaryUfuncsCUDA::test_cuda_tensor_pow_scalar_tensor_cuda
- SWDEV-539171 - `AttributeError: 'float' object has no attribute
'dtype`
> -
test_binary_ufuncs.py::TestBinaryUfuncsCUDA::test_long_tensor_pow_floats_cuda
> -
test_binary_ufuncs.py::TestBinaryUfuncsCUDA::test_complex_scalar_pow_tensor_cuda_*
> -
test_binary_ufuncs.py::TestBinaryUfuncsCUDA::test_float_scalar_pow_float_tensor_cuda_*
@okakarpa
Copy link
Copy Markdown
Collaborator

Created branch autogenerated/release/2.7_cherry-pick_pr-2340 and #2362

okakarpa pushed a commit that referenced this pull request Jul 14, 2025
Cast numpy dtype result to torch dtype result before compare

Numpy returns `np.power(float32, int64) => float64` [Promotion rules for
Python scalars](https://numpy.org/neps/nep-0050-scalar-promotion.html)
Pytorch returns `torch.pow(float32, int64) => float32`

Reverts #2287 and fixes tests in a
different way

Fixes:
- SWDEV-538110 - `'dtype' do not match: torch.float32 != torch.float64`
> -
test_binary_ufuncs.py::TestBinaryUfuncsCUDA::test_cuda_tensor_pow_scalar_tensor_cuda
- SWDEV-539171 - `AttributeError: 'float' object has no attribute
'dtype`
> -
test_binary_ufuncs.py::TestBinaryUfuncsCUDA::test_long_tensor_pow_floats_cuda
> -
test_binary_ufuncs.py::TestBinaryUfuncsCUDA::test_complex_scalar_pow_tensor_cuda_*
> -
test_binary_ufuncs.py::TestBinaryUfuncsCUDA::test_float_scalar_pow_float_tensor_cuda_*
@okakarpa
Copy link
Copy Markdown
Collaborator

pruthvistony pushed a commit that referenced this pull request Jul 15, 2025
…g torch and numpy tensors (#2362)

Cherry-pick of #2340

Co-authored-by: Dmitry Nikolaev <139769634+dnikolaev-amd@users.noreply.github.com>
pruthvistony pushed a commit that referenced this pull request Jul 15, 2025
…fore comparing torch and numpy tensors (#2363)

Cherry-pick of #2340

Co-authored-by: Dmitry Nikolaev <139769634+dnikolaev-amd@users.noreply.github.com>
pragupta pushed a commit that referenced this pull request Jul 21, 2025
…g torch and numpy tensors (#2362)

Cherry-pick of #2340

Co-authored-by: Dmitry Nikolaev <139769634+dnikolaev-amd@users.noreply.github.com>
(cherry picked from commit 22c98ea)
pragupta pushed a commit to pragupta/pytorch that referenced this pull request Jul 21, 2025
…g torch and numpy tensors (ROCm#2362)

Cherry-pick of ROCm#2340

Co-authored-by: Dmitry Nikolaev <139769634+dnikolaev-amd@users.noreply.github.com>
(cherry picked from commit 22c98ea)
pragupta pushed a commit that referenced this pull request Jul 22, 2025
…g torch and numpy tensors (#2362)

Cherry-pick of #2340

Co-authored-by: Dmitry Nikolaev <139769634+dnikolaev-amd@users.noreply.github.com>
(cherry picked from commit 22c98ea)
jithunnair-amd pushed a commit that referenced this pull request Jul 22, 2025
…g torch and numpy tensors (#2362)

Cherry-pick of #2340

Co-authored-by: Dmitry Nikolaev <139769634+dnikolaev-amd@users.noreply.github.com>
(cherry picked from commit 22c98ea)
pragupta pushed a commit that referenced this pull request Jul 29, 2025
…g torch and numpy tensors (#2362)

Cherry-pick of #2340

Co-authored-by: Dmitry Nikolaev <139769634+dnikolaev-amd@users.noreply.github.com>
(cherry picked from commit 22c98ea)
pragupta pushed a commit that referenced this pull request Oct 8, 2025
…g torch and numpy tensors (#2362)

Cherry-pick of #2340

Co-authored-by: Dmitry Nikolaev <139769634+dnikolaev-amd@users.noreply.github.com>
(cherry picked from commit 22c98ea)
(cherry picked from commit 2d72fcd)
jithunnair-amd pushed a commit that referenced this pull request Oct 10, 2025
…g torch and numpy tensors (#2362)

Cherry-pick of #2340

Co-authored-by: Dmitry Nikolaev <139769634+dnikolaev-amd@users.noreply.github.com>
(cherry picked from commit 22c98ea)
(cherry picked from commit 2d72fcd)
jeffdaily pushed a commit that referenced this pull request Nov 17, 2025
…g torch and numpy tensors (#2362)

Cherry-pick of #2340

Co-authored-by: Dmitry Nikolaev <139769634+dnikolaev-amd@users.noreply.github.com>
(cherry picked from commit 22c98ea)
(cherry picked from commit 2d72fcd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants