Skip to content

[Test] Refactor test/test_binary_ufuncs.py - #185699

Closed
KarhouTam wants to merge 5 commits into
gh/KarhouTam/8/basefrom
gh/KarhouTam/8/head
Closed

KarhouTam wants to merge 5 commits into
gh/KarhouTam/8/basefrom
gh/KarhouTam/8/head

Conversation

@KarhouTam

@KarhouTam KarhouTam commented May 30, 2026 •

Copy link
Copy Markdown
Collaborator

[ghstack-poisoned]
@KarhouTam
KarhouTam requested a review from mruberry as a code owner May 30, 2026 09:09
@pytorch-bot

pytorch-bot Bot commented May 30, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/185699

Note: Links to docs will display an error until the docs builds have been completed.

✅ No Failures

As of commit 4f0e718 with merge base 3d10a8a (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@KarhouTam
KarhouTam marked this pull request as draft May 30, 2026 09:10
@KarhouTam KarhouTam added module: tests Issues related to tests (not the torch.testing module) topic: not user facing topic category labels May 30, 2026
[ghstack-poisoned]
KarhouTam added a commit that referenced this pull request Jun 1, 2026
@KarhouTam
KarhouTam marked this pull request as ready for review June 1, 2026 08:11
[ghstack-poisoned]

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors the binary ufunc test suite by separating CPU-only tests from device-template tests and updating OpInfo decorators to target the renamed device-template test class.

Changes:

  • Split a set of CPU-only tests into a standalone parametrized TestBinaryUfuncs class.
  • Rename/retarget the device-template suite to TestBinaryUfuncsDevice and adjust instantiation accordingly.
  • Update DecorateInfo(..., cls_name=...) entries in OpInfos to match the new device-template class name.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
test/test_binary_ufuncs.py Splits CPU-only tests into a parametrized class, renames/adjusts device-template tests and instantiation settings.
torch/testing/_internal/common_methods_invocations.py Updates OpInfo DecorateInfo class-name filters from TestBinaryUfuncs to TestBinaryUfuncsDevice.
Comments suppressed due to low confidence (3)

test/test_binary_ufuncs.py:1842

  • This test is still CUDA-specific (name/body variables like cuda_out) and uses torch.complex128, which is not supported on all non-CPU backends (notably MPS). Since TestBinaryUfuncsDevice is now instantiated for additional device types, this test needs to be restricted again (or split) to avoid running on backends that can’t create complex128 tensors.
    @dtypes(torch.complex64, torch.complex128)
    def test_pow_cuda_complex_extremal_passing(self, device, dtype):
        t = torch.tensor(complex(-1.0, float("inf")), dtype=dtype, device=device)
        cuda_out = t.pow(2)

test/test_binary_ufuncs.py:1842

  • This test is still CUDA-specific (name/body variables like cuda_out) and uses torch.complex128, which is not supported on all non-CPU backends (notably MPS). Since TestBinaryUfuncsDevice is now instantiated for additional device types, this test needs to be restricted again (or split) to avoid running on backends that can’t create complex128 tensors.
    @dtypes(torch.complex64, torch.complex128)
    def test_pow_cuda_complex_extremal_passing(self, device, dtype):
        t = torch.tensor(complex(-1.0, float("inf")), dtype=dtype, device=device)
        cuda_out = t.pow(2)

test/test_binary_ufuncs.py:1842

  • This test is still CUDA-specific (name/body variables like cuda_out) and uses torch.complex128, which is not supported on all non-CPU backends (notably MPS). Since TestBinaryUfuncsDevice is now instantiated for additional device types, this test needs to be restricted again (or split) to avoid running on backends that can’t create complex128 tensors.
    @dtypes(torch.complex64, torch.complex128)
    def test_pow_cuda_complex_extremal_passing(self, device, dtype):
        t = torch.tensor(complex(-1.0, float("inf")), dtype=dtype, device=device)
        cuda_out = t.pow(2)

Comment on lines +4710 to +4712
instantiate_device_type_tests(
TestBinaryUfuncsDevice, globals(), allow_mps=True, allow_xpu=True, except_for="cpu"
)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Actually good point here on the MPS backend.

@KarhouTam KarhouTam Jun 2, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Sure. But if MPS doesn't support those dtypes indeed, why the CI didn't go red? 🤨 Just curious. Will remove it for now.

Comment thread test/test_binary_ufuncs.py Resolved
Comment thread test/test_binary_ufuncs.py Resolved
Comment thread test/test_binary_ufuncs.py Resolved
Comment thread test/test_binary_ufuncs.py Resolved
Comment thread test/test_binary_ufuncs.py Resolved
@Skylion007
Skylion007 self-requested a review June 1, 2026 16:25
[ghstack-poisoned]
@KarhouTam KarhouTam added the ciflow/trunk Trigger trunk jobs on your pull request label Jun 2, 2026
[ghstack-poisoned]
@KarhouTam

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

@KarhouTam KarhouTam added the module: tests/core This label covers all test cases within the Core and Tensor sheets. label Jun 5, 2026
pbielak added a commit to intel/torch-xpu-ops that referenced this pull request Jun 10, 2026
In PR [1], the upstream file `test_binary_ufuncs.py` was refactored and
the `TestBinaryUfuncs` class was renamed to `TestBinaryUfuncsDevice`.
The previous name is still used for CPU only tests, but it is directly
wrapped in `instantiate_parametrized_tests`, so when imported on XPU
side, it was already overwritten to `None`. This commit updates the
imported class name on XPU side.

[1] pytorch/pytorch#185699
pbielak added a commit to intel/torch-xpu-ops that referenced this pull request Jun 11, 2026
In PR [1], the upstream file `test_binary_ufuncs.py` was refactored and
the `TestBinaryUfuncs` class was renamed to `TestBinaryUfuncsDevice`.
The previous name is still used for CPU only tests, but it is directly
wrapped in `instantiate_parametrized_tests`, so when imported on XPU
side, it was already overwritten to `None`. This commit updates the
imported class name on XPU side.

[1] pytorch/pytorch#185699
pponikox pushed a commit to pponikox/torch-xpu-ops that referenced this pull request Jun 12, 2026
In PR [1], the upstream file `test_binary_ufuncs.py` was refactored and
the `TestBinaryUfuncs` class was renamed to `TestBinaryUfuncsDevice`.
The previous name is still used for CPU only tests, but it is directly
wrapped in `instantiate_parametrized_tests`, so when imported on XPU
side, it was already overwritten to `None`. This commit updates the
imported class name on XPU side.

[1] pytorch/pytorch#185699
daisyden pushed a commit to daisyden/torch-xpu-ops that referenced this pull request Jun 18, 2026
In PR [1], the upstream file `test_binary_ufuncs.py` was refactored and
the `TestBinaryUfuncs` class was renamed to `TestBinaryUfuncsDevice`.
The previous name is still used for CPU only tests, but it is directly
wrapped in `instantiate_parametrized_tests`, so when imported on XPU
side, it was already overwritten to `None`. This commit updates the
imported class name on XPU side.

[1] pytorch/pytorch#185699
@github-actions
github-actions Bot deleted the gh/KarhouTam/8/head branch July 6, 2026 02:25
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
tszulist-hbn added a commit to tszulist-hbn/pytorch that referenced this pull request Aug 18, 2026
Review feedback on pytorch#193412: device-generic test templates instantiated via
instantiate_device_type_tests carry a Device suffix, as done for
TestBinaryUfuncs -> TestBinaryUfuncsDevice in pytorch#185699. Renaming the class
means renaming every OpInfo DecorateInfo cls_name that targets it, since
DecorateInfo.is_active compares cls_name to the generic class name by exact
string and a mismatch silently deactivates the decoration.

test/test_maskedtensor.py also defines a class named TestOperators, so the
three 'TestOperators' entries whose test_name is test_reduction_all belong to
that class and are deliberately left untouched; every other entry keys off a
functorch test name.

The rename is not behaviour-preserving. common_utils seeds the RNG for each
OpInfo sample with sha256(test_fn.__qualname__), and the qualname contains the
class name, so renaming reshuffles the random inputs of all ~10k tests in the
class. That is the root cause of the four CPU tests that flipped: cumprod and
masked.prod test_jvpvjp drew samples that land just outside their tolerances
(relative error 6.7e-05 vs 1.3e-06 allowed, and 3.4e-05 vs 1.3e-05 allowed),
so both tolerances are widened, cumprod's for all devices rather than CUDA
only. native_batch_norm and _native_batch_norm_legit test_jvp on CPU stopped
failing and turned into unexpected successes; since whether they fail depends
on which samples are drawn, the xfails become skips rather than being deleted.

Authored with the assistance of Claude Code.
tszulist-hbn added a commit to tszulist-hbn/pytorch that referenced this pull request Aug 18, 2026
Review feedback on pytorch#193412: device-generic test templates instantiated via
instantiate_device_type_tests carry a Device suffix, as done for
TestBinaryUfuncs -> TestBinaryUfuncsDevice in pytorch#185699. Renaming the class
means renaming every OpInfo DecorateInfo cls_name that targets it, since
DecorateInfo.is_active compares cls_name to the generic class name by exact
string and a mismatch silently deactivates the decoration.

test/test_maskedtensor.py also defines a class named TestOperators, so the
three 'TestOperators' entries whose test_name is test_reduction_all belong to
that class and are deliberately left untouched; every other entry keys off a
functorch test name.

The rename is not behaviour-preserving. common_utils seeds the RNG for each
OpInfo sample with sha256(test_fn.__qualname__), and the qualname contains the
class name, so renaming reshuffles the random inputs of all ~10k tests in the
class. That is the root cause of the four CPU tests that flipped: cumprod and
masked.prod test_jvpvjp drew samples that land just outside their tolerances
(relative error 6.7e-05 vs 1.3e-06 allowed, and 3.4e-05 vs 1.3e-05 allowed),
so both tolerances are widened, cumprod's for all devices rather than CUDA
only. native_batch_norm and _native_batch_norm_legit test_jvp on CPU stopped
failing and turned into unexpected successes; since whether they fail depends
on which samples are drawn, the xfails become skips rather than being deleted.

Authored with the assistance of Claude Code.
pytorchmergebot pushed a commit to tszulist-hbn/pytorch that referenced this pull request Aug 24, 2026
Review feedback on pytorch#193412: device-generic test templates instantiated via
instantiate_device_type_tests carry a Device suffix, as done for
TestBinaryUfuncs -> TestBinaryUfuncsDevice in pytorch#185699. Renaming the class
means renaming every OpInfo DecorateInfo cls_name that targets it, since
DecorateInfo.is_active compares cls_name to the generic class name by exact
string and a mismatch silently deactivates the decoration.

test/test_maskedtensor.py also defines a class named TestOperators, so the
three 'TestOperators' entries whose test_name is test_reduction_all belong to
that class and are deliberately left untouched; every other entry keys off a
functorch test name.

The rename is not behaviour-preserving. common_utils seeds the RNG for each
OpInfo sample with sha256(test_fn.__qualname__), and the qualname contains the
class name, so renaming reshuffles the random inputs of all ~10k tests in the
class. That is the root cause of the four CPU tests that flipped: cumprod and
masked.prod test_jvpvjp drew samples that land just outside their tolerances
(relative error 6.7e-05 vs 1.3e-06 allowed, and 3.4e-05 vs 1.3e-05 allowed),
so both tolerances are widened, cumprod's for all devices rather than CUDA
only. native_batch_norm and _native_batch_norm_legit test_jvp on CPU stopped
failing and turned into unexpected successes; since whether they fail depends
on which samples are drawn, the xfails become skips rather than being deleted.

Authored with the assistance of Claude Code.
tszulist-hbn added a commit to tszulist-hbn/pytorch that referenced this pull request Aug 25, 2026
Review feedback on pytorch#193412: device-generic test templates instantiated via
instantiate_device_type_tests carry a Device suffix, as done for
TestBinaryUfuncs -> TestBinaryUfuncsDevice in pytorch#185699. Renaming the class
means renaming every OpInfo DecorateInfo cls_name that targets it, since
DecorateInfo.is_active compares cls_name to the generic class name by exact
string and a mismatch silently deactivates the decoration.

test/test_maskedtensor.py also defines a class named TestOperators, so the
three 'TestOperators' entries whose test_name is test_reduction_all belong to
that class and are deliberately left untouched; every other entry keys off a
functorch test name.

The rename is not behaviour-preserving. common_utils seeds the RNG for each
OpInfo sample with sha256(test_fn.__qualname__), and the qualname contains the
class name, so renaming reshuffles the random inputs of all ~10k tests in the
class. That is the root cause of the four CPU tests that flipped: cumprod and
masked.prod test_jvpvjp drew samples that land just outside their tolerances
(relative error 6.7e-05 vs 1.3e-06 allowed, and 3.4e-05 vs 1.3e-05 allowed),
so both tolerances are widened, cumprod's for all devices rather than CUDA
only. native_batch_norm and _native_batch_norm_legit test_jvp on CPU stopped
failing and turned into unexpected successes; since whether they fail depends
on which samples are drawn, the xfails become skips rather than being deleted.

Authored with the assistance of Claude Code.
tszulist-hbn added a commit to tszulist-hbn/pytorch that referenced this pull request Aug 25, 2026
Review feedback on pytorch#193412: device-generic test templates instantiated via
instantiate_device_type_tests carry a Device suffix, as done for
TestBinaryUfuncs -> TestBinaryUfuncsDevice in pytorch#185699. Renaming the class
means renaming every OpInfo DecorateInfo cls_name that targets it, since
DecorateInfo.is_active compares cls_name to the generic class name by exact
string and a mismatch silently deactivates the decoration.

test/test_maskedtensor.py also defines a class named TestOperators, so the
three 'TestOperators' entries whose test_name is test_reduction_all belong to
that class and are deliberately left untouched; every other entry keys off a
functorch test name.

The rename is not behaviour-preserving. common_utils seeds the RNG for each
OpInfo sample with sha256(test_fn.__qualname__), and the qualname contains the
class name, so renaming reshuffles the random inputs of all ~10k tests in the
class. That is the root cause of the four CPU tests that flipped: cumprod and
masked.prod test_jvpvjp drew samples that land just outside their tolerances
(relative error 6.7e-05 vs 1.3e-06 allowed, and 3.4e-05 vs 1.3e-05 allowed),
so both tolerances are widened, cumprod's for all devices rather than CUDA
only. native_batch_norm and _native_batch_norm_legit test_jvp on CPU stopped
failing and turned into unexpected successes; since whether they fail depends
on which samples are drawn, the xfails become skips rather than being deleted.

Authored with the assistance of Claude Code.
tszulist-hbn added a commit to tszulist-hbn/pytorch that referenced this pull request Sep 8, 2026
Review feedback on pytorch#193412: templates instantiated via
instantiate_device_type_tests carry a Device suffix, as TestBinaryUfuncs did in
pytorch#185699. Every OpInfo DecorateInfo cls_name targeting the class has to be
renamed with it, since DecorateInfo.is_active compares cls_name by exact string
and a mismatch silently deactivates the decoration. The three entries whose
test_name is test_reduction_all belong to test_maskedtensor.py's own
TestOperators and are left alone.

The rename is not behaviour-preserving: common_utils seeds each OpInfo sample
from sha256(test_fn.__qualname__), so the inputs of all ~10k tests in the class
are reshuffled. Four CPU tests flipped. cumprod and masked.prod test_jvpvjp now
land just outside their tolerances (6.7e-05 vs 1.3e-06 allowed, 3.4e-05 vs
1.3e-05), so both are widened. native_batch_norm and _native_batch_norm_legit
test_jvp stopped failing, so their xfails are dropped rather than turned into
skips; the reshuffled samples sit at abs 3.8e-06 against a 1e-05 atol, down from
2.1e-05.

Authored with the assistance of Claude Code.
pytorchmergebot pushed a commit to tszulist-hbn/pytorch that referenced this pull request Sep 8, 2026
Review feedback on pytorch#193412: templates instantiated via
instantiate_device_type_tests carry a Device suffix, as TestBinaryUfuncs did in
pytorch#185699. Every OpInfo DecorateInfo cls_name targeting the class has to be
renamed with it, since DecorateInfo.is_active compares cls_name by exact string
and a mismatch silently deactivates the decoration. The three entries whose
test_name is test_reduction_all belong to test_maskedtensor.py's own
TestOperators and are left alone.

The rename is not behaviour-preserving: common_utils seeds each OpInfo sample
from sha256(test_fn.__qualname__), so the inputs of all ~10k tests in the class
are reshuffled. Four CPU tests flipped. cumprod and masked.prod test_jvpvjp now
land just outside their tolerances (6.7e-05 vs 1.3e-06 allowed, 3.4e-05 vs
1.3e-05), so both are widened. native_batch_norm and _native_batch_norm_legit
test_jvp stopped failing, so their xfails are dropped rather than turned into
skips; the reshuffled samples sit at abs 3.8e-06 against a 1e-05 atol, down from
2.1e-05.

Authored with the assistance of Claude Code.
pytorchmergebot pushed a commit to tszulist-hbn/pytorch that referenced this pull request Sep 11, 2026
Review feedback on pytorch#193412: templates instantiated via
instantiate_device_type_tests carry a Device suffix, as TestBinaryUfuncs did in
pytorch#185699. Every OpInfo DecorateInfo cls_name targeting the class has to be
renamed with it, since DecorateInfo.is_active compares cls_name by exact string
and a mismatch silently deactivates the decoration. The three entries whose
test_name is test_reduction_all belong to test_maskedtensor.py's own
TestOperators and are left alone.

The rename is not behaviour-preserving: common_utils seeds each OpInfo sample
from sha256(test_fn.__qualname__), so the inputs of all ~10k tests in the class
are reshuffled. Four CPU tests flipped. cumprod and masked.prod test_jvpvjp now
land just outside their tolerances (6.7e-05 vs 1.3e-06 allowed, 3.4e-05 vs
1.3e-05), so both are widened. native_batch_norm and _native_batch_norm_legit
test_jvp stopped failing, so their xfails are dropped rather than turned into
skips; the reshuffled samples sit at abs 3.8e-06 against a 1e-05 atol, down from
2.1e-05.

Authored with the assistance of Claude Code.
minmingzhu pushed a commit to minmingzhu/torch-xpu-ops that referenced this pull request Sep 15, 2026
In PR [1], the upstream file `test_binary_ufuncs.py` was refactored and
the `TestBinaryUfuncs` class was renamed to `TestBinaryUfuncsDevice`.
The previous name is still used for CPU only tests, but it is directly
wrapped in `instantiate_parametrized_tests`, so when imported on XPU
side, it was already overwritten to `None`. This commit updates the
imported class name on XPU side.

[1] pytorch/pytorch#185699
tszulist-hbn added a commit to tszulist-hbn/pytorch that referenced this pull request Oct 19, 2026
Review feedback on pytorch#193412: templates instantiated via
instantiate_device_type_tests carry a Device suffix, as TestBinaryUfuncs did in
pytorch#185699. Every OpInfo DecorateInfo that targets the class, and the
.ci/pytorch/test.sh comment that counts the shared ones, is renamed with it,
since DecorateInfo.is_active compares cls_name by exact string and a mismatch
silently deactivates the decoration. The three entries whose
test_name is test_reduction_all belong to test_maskedtensor.py's own
TestOperators and are left alone.

The rename is not behaviour-preserving: common_utils seeds each OpInfo sample
from sha256(test_fn.__qualname__), so the inputs of all ~10k tests in the class
are reshuffled. Four CPU tests flipped. cumprod and masked.prod test_jvpvjp now
land just outside their tolerances (6.7e-05 vs 1.3e-06 allowed, 3.4e-05 vs
1.3e-05), so both are widened. native_batch_norm and _native_batch_norm_legit
test_jvp stopped failing, so their xfails are dropped rather than turned into
skips; the reshuffled samples sit at abs 3.8e-06 against a 1e-05 atol, down from
2.1e-05.

Authored with the assistance of Claude Code.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/trunk Trigger trunk jobs on your pull request Merged module: tests/core This label covers all test cases within the Core and Tensor sheets. module: tests Issues related to tests (not the torch.testing module) open source topic: not user facing topic category

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

5 participants