Skip to content

[Test] Refactor test/functorch/test_ops.py and enable on XPU - #193412

Closed
tszulist-hbn wants to merge 6 commits into
pytorch:mainfrom
tszulist-hbn:enable-xpu-functorch-tests
Closed

tszulist-hbn wants to merge 6 commits into
pytorch:mainfrom
tszulist-hbn:enable-xpu-functorch-tests

Conversation

@tszulist-hbn

@tszulist-hbn tszulist-hbn commented Aug 13, 2026 •

Copy link
Copy Markdown
Contributor

Enable test/functorch/test_ops.py to run on XPU, while preserving CPU and CUDA coverage.

Changes

  • Make TestOperators device-generic and instantiate it for every available device type: CPU, CUDA and XPU in PyTorch CI. Out-of-tree backends (PrivateUse1, HPU) that run this file now get the suite too.
  • Update OpInfo decorators and slow-test keys for the renamed test class.
  • Add XPU xfails, skips and tolerances for unsupported or precision-sensitive operators.

Test Coverage Delta

Affected tests Before After
XPU tests collected 0 10,305
XPU passed / skipped / xfailed / failed — 7,706 / 2,248 / 351 / 0
CPU tests collected 10,306 10,306
CPU passed / skipped / xfailed / failed 7,744 / 2,203 / 359 / 0 7,746 / 2,203 / 357 / 0

Renamed test IDs

Test IDs move from TestOperators{CPU,CUDA} to TestOperatorsDevice{CPU,CUDA}. Nothing outside this file keys on the old names (checked 2026-10-20): there are no open DISABLED issues and no TestOperators* entries in disabled-tests-condensed.json, no test_exclusions users, and no dynamo/inductor/compiled-autograd marker files. slow_tests.json is updated in this PR.

Merge order

intel/torch-xpu-ops has its own copy of this suite (test/xpu/functorch/test_ops_xpu.py) that still uses the old class name, so it loses the renamed OpInfo decorations once this lands. A torch-xpu-ops follow-up will delete the copy and run this file instead.

@pytorch-bot

pytorch-bot Bot commented Aug 13, 2026 •

Copy link
Copy Markdown

PR Status: Approved 🚀

Please fix all CI failures and trigger merge by commenting "@pytorchbot merge".

✅ AUTOMATED REVIEW - Ready for human review:

This PR renames TestOperators in test/functorch/test_ops.py to
TestOperatorsDevice and marks it HardwareClassification.ACCELERATOR. It drops
only_for so the suite runs on CPU, CUDA and XPU, and updates the matching
DecorateInfo entries, tolerances and slow_tests.json. Recommendation: Approve.
Nothing blocks merging; the one item raised is a small, low-confidence cleanup.

Findings (1):

[minor] test/functorch/test_ops.py:1005
One bug is tracked in three places with two mechanisms (low confidence). The
fully-masked 0-d sample failure (# 196289) is tracked by new CUDA/XPU xfails for
masked.softmax/masked.softmin under test_vmapvjpvjp (lines 1005-1006). The CPU
masked.softmax entry stays a separate xfail with only a `# nans` comment (line
1000). The CPU masked.softmin entry is still a bare unittest.skip("Skipped!") in
_masked.py:1282-1287, which the PR only renamed. The 'unexpected success'
cleanup plan only works for xfails, so the CPU softmin skip will silently
outlive the fix (# 196300), and the CPU softmax entry

Reviewed commit: c9c5b8a

Review run

🔗 Helpful Links

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

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

✅ You can merge normally! (1 Unrelated Failure)

As of commit c9c5b8a with merge base f21bd8f (image):

NEW FAILURES SUPPRESSED BY AI (non-blocking) - The following job failed, but the AI CI Advisor judged the failure not to be evidence against this change:

  • trunk / macos-py3-arm64 / test (default, 2, 3, macos-m1-stable) (gh)
    inductor/test_torchinductor

    AI verdict: AI verdict: not related

    The failure is an MPS out-of-memory abort (kIOGPUCommandBufferCallbackErrorOutOfMemory, SIGIOT) in inductor/test_torchinductor on the macOS M1 runner, during or right after the 13GB test_large_block_sizes_mps serial test. The suspect only removes XPU-only fft/stft skip entries from test/functorch/test_ops.py, so it has no code path into an inductor MPS test.

    Full reasoning on HUD →

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

@pytorch-bot pytorch-bot Bot added the topic: not user facing topic category label Aug 13, 2026
@tszulist-hbn
tszulist-hbn force-pushed the enable-xpu-functorch-tests branch 2 times, most recently from c8c12f3 to 8cf489a Compare August 13, 2026 17:44
Comment thread test/functorch/test_ops.py Resolved
Comment thread test/functorch/test_ops.py Resolved
Comment thread test/functorch/test_ops.py Resolved
Comment thread test/functorch/test_ops.py Resolved
@tszulist-hbn
tszulist-hbn force-pushed the enable-xpu-functorch-tests branch from 8cf489a to 015367f Compare August 17, 2026 12:39
@tszulist-hbn
tszulist-hbn requested a review from pbielak August 18, 2026 07:49
@tszulist-hbn
tszulist-hbn force-pushed the enable-xpu-functorch-tests branch from 015367f to ad70228 Compare August 18, 2026 11:51
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.
@tszulist-hbn
tszulist-hbn force-pushed the enable-xpu-functorch-tests branch from ad70228 to ee82b42 Compare August 18, 2026 16:21
@tszulist-hbn

Copy link
Copy Markdown
Contributor Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased enable-xpu-functorch-tests onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout enable-xpu-functorch-tests && git pull --rebase)

@pytorchmergebot
pytorchmergebot force-pushed the enable-xpu-functorch-tests branch from ee82b42 to c462db1 Compare August 24, 2026 14:00
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
tszulist-hbn force-pushed the enable-xpu-functorch-tests branch from c462db1 to 252bb6c Compare August 25, 2026 11:40
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
tszulist-hbn force-pushed the enable-xpu-functorch-tests branch from 252bb6c to e6e803a Compare August 25, 2026 14:24
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.

@pbielak pbielak left a comment

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.

In the PR description in the table are the "Before" detailed results for CPU the same as after?

Comment thread test/functorch/test_ops.py Resolved
Comment thread test/functorch/test_ops.py Resolved
Comment thread test/functorch/test_ops.py Resolved
@pbielak pbielak added ciflow/trunk Trigger trunk jobs on your pull request ciflow/xpu Run XPU CI tasks ci-no-td Do not run TD on this PR labels Aug 26, 2026
@tszulist-hbn
tszulist-hbn force-pushed the enable-xpu-functorch-tests branch from e6e803a to 80dc269 Compare August 26, 2026 11:10
@pytorch-bot

pytorch-bot Bot commented Aug 26, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@tszulist-hbn

Copy link
Copy Markdown
Contributor Author

Good catch - but the answer turns out to be "neither global nor XPU-only". These are CPU-driven.

I tested it: reverting each tolerance to its pre-PR scope, only two tests fail, both on CPU (test_jvpvjp_cumprod_cpu_float32 and
test_jvpvjp_masked_prod_cpu_float32). addbmm/linalg.vander/corrcoef pass at default tolerance on both CPU and XPU locally; their failures were x86/aarch64-specific. The trigger is the RNG reseed from the class rename, which is qualname-derived and so device-independent -- scoping to XPU would not fix what these were added for.

Two of them were also silently de-scoped from device_type="cuda" to global, which I've restored. Now scoped disjointly:

  addbmm, corrcoef        -> device_type="cpu"
  cumprod, linalg.vander  -> device_type=("cpu", "cuda")  (CUDA values intact)
  masked.prod             -> cuda @ rtol=1.3e-05 (original) + cpu @ rtol=5e-05

XPU is back to default tolerance for all of them.

Also removed a duplicated .union(xpu_fft_stft_unsupported) at L1464.

Regarding CPU unchanged test coverage it's on pytest collect level rather than particular test cases comparison, I'll schedule comparison before and after the change (rename) with regard to CPU, but it may take several hours.

@tszulist-hbn

Copy link
Copy Markdown
Contributor Author

Confirmed with a matched before/after CPU sweep (branch point vs branch head, same build), mapping TestOperatorsCPU -> TestOperatorsDeviceCPU: 10,306 tests collected on both sides, identical test-ID for test-ID (0 added, 0 removed), 7,738 passed and 0 failed on both. Per-test outcomes differ in exactly 2 of 10,306 cases: native_batch_norm and _native_batch_norm_legit under test_jvp go xfailed -> skipped (intentional in this PR, the reseeded samples make the failure sample-dependent), so those two are no longer executed. I have filled the CPU "Before" numbers into the table.

In the meantime, I have also addressed a side-effect of the recent widening functorch tolerances for addbmm, linalg.vander, corrcoef on CPU and will trigger CI to confirm it is resolved now.

@tszulist-hbn

Copy link
Copy Markdown
Contributor Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased enable-xpu-functorch-tests onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout enable-xpu-functorch-tests && git pull --rebase)

github-actions[bot]

This comment was marked as outdated.

@etaf etaf left a comment

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.

Thanks for the update.

@etaf

etaf commented Oct 19, 2026

Copy link
Copy Markdown
Collaborator

Please address the review comments from the bot.

@tszulist-hbn

Copy link
Copy Markdown
Contributor Author

Automated review of ddd8f86: changes requested before human review.

The PR renames TestOperators to TestOperatorsDevice, instantiates it for CPU, CUDA and XPU, adds XPU xfails and tolerances, and adjusts CPU/CUDA expectations because the rename changes the per-sample RNG seed. Recommendation: Request Changes. Two maintainer comments from etaf are still open (the stale CPU/XPU rows in the description table, and coordinating with the out-of-tree torch-xpu-ops suite), and test_vmapvmapjvp_linalg_solve needs to take device to match the class's ACCELERATOR declaration.

🔴 3 blocking findings are attached to the code below.

⚪ 3 non-blocking findings

xfail("masked.softmax", device_type=("cuda", "xpu")),

New CUDA/ROCm coverage gap for masked.softmax and masked.softmin in test_vmapvjpvjp. The rename causes this, not XPU: the new seed draws a fully masked-out 0-d sample on CUDA. The two xfails cover the whole op, so every other sample for these ops in this test also stops being checked on CUDA and ROCm. The same root cause seems to be spread across three places using two different mechanisms: xfail("masked.softmax", device_type="cpu") at line 997, the unscoped unittest.skip for masked.softmin on CPU in _masked.py:1274-1279, and the new CUDA/XPU xfails here. etaf suggested fixing th

class TestOperatorsDevice(TestCase):

The rename changes every test ID, from TestOperatorsCPU/CUDA to TestOperatorsDeviceCPU/CUDA. Open DISABLED-test issues and test-time stats are keyed on the old IDs, so they stop matching when this lands, and any test disabled under the old name would start running again. Check the disabled-tests list for TestOperatorsCPU/TestOperatorsCUDA entries and move them to the new names. Low confidence: the disabled-tests list wasn't accessible.

https://github.com/pytorch/pytorch/blob/ddd8f8683c0dd5fc48a16baa61405c71bcc92eb6/torch/testing/_internal/common_methods_invocations.py#L7564

Stale comment at .ci/pytorch/test.sh:602: it still says "nine TestOperators entries in the shared skip tuple", but this PR renamed those entries to TestOperatorsDevice here (lines 7564-7572). Update the comment.

Please address the findings and push; a new commit normally gets a fresh automated review.

This review is AI-generated and advisory. Each new automated review replaces the previous one.

Regarding non-blocking concerns:

github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

@tszulist-hbn

Copy link
Copy Markdown
Contributor Author

Automated review of 189af5e: changes requested before human review.

The PR renames TestOperators to TestOperatorsDevice, marks it HardwareClassification.ACCELERATOR, and instantiates it on XPU as well as CPU and CUDA, with new XPU xfails and tolerances and adjusted CPU/CUDA expectations. Recommendation: Request Changes. Approval is blocked by the unaddressed etaf comment (the torch-xpu-ops ordering is missing from the description, and the CPU table has a typo), the stale linter allowlist entry, and the instantiation scope, which needs either a sentence in the description or an except_for.

🔴 3 blocking findings are attached to the code below.

⚪ 2 non-blocking findings

xfail("nn.functional.conv3d", device_type="xpu"),

The conv3d xfail is copy-pasted three times. xfail("nn.functional.conv3d", device_type="xpu") and its 3-line torch-xpu-ops#5640 comment appear verbatim in test_vmapvjpvjp, vmapvjp_fail and test_vmapjvpvjp (here and at lines 1270 and 1934). The same PR already uses a named module-level set for the grid_sample gap (xpu_grid_sample_bicubic_5d). Define xpu_conv3d_vmap_backward = {xfail(...)} next to it and union it in, so the issue link lives in one place and can be removed in one place.

xpu_unsupported = xpu_grid_sample_bicubic_5d

xpu_unsupported = xpu_grid_sample_bicubic_5d gives one set two names. Either make xpu_unsupported a real union of the named XPU sets, or drop the alias.

Please address the findings and push; a new commit normally gets a fresh automated review.

This review is AI-generated and advisory. Each new automated review replaces the previous one.

Regarding the non-blocking findings:

@tszulist-hbn

Copy link
Copy Markdown
Contributor Author

@pytorchbot rebase

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Successfully rebased enable-xpu-functorch-tests onto refs/remotes/origin/viable/strict, please pull locally before adding more changes (for example, via git checkout enable-xpu-functorch-tests && git pull --rebase)

github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

github-actions[bot]

This comment was marked as outdated.

tszulist-hbn and others added 6 commits October 20, 2026 10:39
Add Intel GPU (XPU) support to test/functorch/test_ops.py by enabling device-generic
test instantiation and implementing XPU-specific skips and tolerance adjustments.

1. **Mark test class as ACCELERATOR device-generic**
   - Added hw_classification = HardwareClassification.ACCELERATOR to TestOperators.
   - This matches the pattern in test/test_ops.py (TestCommon) and enables device-agnostic
     test instantiation while respecting device-specific limitations.
   - test_vmapvmapjvp_linalg_solve and test_view_then_inplace_special now take device
     and build their inputs on it, so the CUDA and XPU instances run on the device
     instead of repeating the CPU run.
   - Instantiated with allow_xpu=True and no only_for, as the ACCELERATOR contract
     requires; in PyTorch CI that still means CPU, CUDA and XPU.
   - The file meets every ACCELERATOR rule, so it leaves
     tools/linter/adapters/test_linter_allowlist.json and TEST_LINTER checks it.
   - CPU tests: 10,306 (unchanged); XPU adds 10,305 new tests.

2. **Skip FFT/STFT and problematic reduction ops on XPU**
   - Created xpu_fft_stft_unsupported set with 24 ops.
   - Root cause: XPU FFT kernels segfault under functorch transforms; see torch-xpu-ops#4953.
   - Ops skipped: fft.{fft,ifft,rfft,irfft,hfft,ihfft}*, stft, istft, cumprod,
     masked.cumprod, masked.prod, nn.functional.conv3d.
   - Integrated skip set into all 22 @SkipOps decorators across all test methods.

3. **Widen conv_transpose3d tolerance for XPU**
   - Changed device_type="cuda" to device_type=("cuda", "xpu") for conv_transpose3d
     tolerance overrides in test_vjp, test_jvpvjp, and test_vjpvmap.
   - Rationale: XPU floating-point precision in functorch derivatives differs from CUDA.
     Conv_transpose3d double-derivatives show abs diff ~1.53e-05 vs 1e-05 allowed.

4. **Scope SDPA expected failure to CPU/CUDA only**
   - Changed scaled_dot_product_attention decorate from unscoped
     expectedFailureIf(not TEST_WITH_ROCM) to device_type=("cpu", "cuda").
   - SDPA passes on XPU; unscoped failure would incorrectly xfail XPU.

Full sweep (4 workers, FFT/STFT excluded): 10,011 tests, 7,274 passed (99.98% success rate)
- 7,274 passed (72.7%)
- 2,406 skipped (24.0%) — XPU limitations and expected skips
- 329 xfailed (3.3%) — properly marked expected failures
- 2 failed (0.02%) — conv_transpose3d tolerance, fixed in this commit

Sweep duration: 2h 5m 40s (7,540 seconds with 4 workers)

CPU test count unchanged (10,306). No CPU behavior modified; XPU only.
Tolerance widening is GPU-backend-specific (device_type scope), unaffected CUDA.

- torch-xpu-ops#4953: XPU FFT/STFT functorch integration investigation

---
Co-Authored-By: Claude Haiku 4.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Review feedback on pytorch#193412: templates instantiated via
instantiate_device_type_tests carry a Device suffix, as TestBinaryUfuncs did in
.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]>
The reseeded OpInfo samples push a handful of functorch-vs-reference comparisons
past the default float32 tolerance, and the XPU enablement exposes a few real XPU
failures. Every override is scoped to just the devices that need it, so no CUDA
or MPS threshold moves.

Tolerances, each set from the measured overshoot with 2-4x margin. Scopes are
kept disjoint rather than layering a narrow override on a broad one, because
opsToleranceOverride appends each entry as its own DecorateInfo, so two matching
entries both apply and decorator order picks the winner.

    addbmm, matmul, __rmatmul__             test_jvp, cpu
    corrcoef                                test_vmapjvpvjp, cpu
    cumprod, linalg.vander                  test_jvpvjp, cpu + cuda
    masked.prod                             test_jvpvjp, cuda + xpu 1.3e-05, cpu 5e-05
    linalg.householder_product              test_vmapvjp, test_vmapjvpvjp, cpu
    linalg.lu_factor_ex, linalg.pinv        test_vmapvjpvjp, cuda
    nn.functional.conv_transpose3d          test_grad, test_vjp, test_jvpvjp,
                                            test_vjpvmap, xpu
    nn.functional.conv3d                    test_vjpvmap, xpu

linalg.householder_product keeps its original tolerance on cuda and xpu; only
cpu gets the wider one (aarch64 and macOS arm64 CI, reproduced on x86).

matmul and __rmatmul__ fail only on aarch64, which has no device_type of its
own, so cpu is the tightest scope that reaches it. Local x86 measurement
confirms the reseed is the cause: worst relative deviation goes from 2.5e-06
before the rename to 2.7e-05 after, against a 1.3e-06 rtol, matching the 2.6e-05
aarch64 reported.

masked.softmax and masked.softmin under test_vmapvjpvjp return NaN, which no
tolerance covers. Their 0-d sample's mask is a single random bool; when it draws
False the input is fully masked out, where the output is documented undefined -
eager gives NaN, vmap gives 0. CPU already xfails masked.softmax and keeps its
xfail; the reseeded samples now reach it on CUDA, ROCm and XPU as well. The draw
is deterministic per device: TrackedInputIter reseeds every sample from the
generic test's qualname, which both ops share, and CI failed them consistently on
CUDA 13.0 and 13.2 (L4) and ROCm mi350. So they are xfails rather than skips, and
will flag themselves once pytorch#196289 fixes the sample generator.

On XPU, only matmul and __rmatmul__ are reseed fallout; the rest pre-date this
branch. test_grad's matmul tolerance, already 3e-04 on CUDA, now covers XPU too:
the failing assertion is the non-contiguous comparison, and over 200 draws the
non-contiguous result lands 3.6e-06 from an fp64 reference while the contiguous
value it is checked against lands 9.4e-06 away, so the test was rejecting the
more accurate answer.

The blanket XPU skips of cumprod, masked.cumprod, masked.prod, conv3d and
conv_transpose3d from the first commit (intel/torch-xpu-ops#4953) are replaced by
entries measured with the skips removed. cumprod and masked.cumprod pass every
test and need nothing. masked.prod passes too, but in test_jvpvjp it clears the
default only on these inputs: over 30 reseeds it fails the default 20 times and
main's 1.3e-05 3 times, so XPU shares the CUDA entry and keeps main's value
instead of dropping to the default. conv_transpose3d varies run to run by at most
2.6e-05 abs in 1-4 elements, covered by an XPU atol of 5e-05 in the four tests
above. conv3d test_vjpvmap varies the same way by up to 2.4e-04, so its OpInfo
tolerance gets an XPU entry and the existing one is scoped to cpu and cuda.
conv3d under test_vmapvjp, test_vmapvjpvjp and test_vmapjvpvjp is wrong by 1-30
on nearly every element, identically on every run and in float64 too. That is a
correctness bug in XPU convolution_backward, not precision: under vmap the
cotangent reaches it with strides that count as contiguous but look
channels-last, and the oneDNN layer then picks a different memory format than
its caller (intel/torch-xpu-ops#5640). So conv3d is xfailed on XPU in those three
tests only.

The fft/stft skips stay skips, because whether a sample crashes is random. They
also go on test_vmapjvpall, test_vmapjvpall_has_batch_rule and
test_vmap_autograd_grad, where 18 fft/stft cases were segfaulting their workers
and taking 97 queued tests down with them. xpu_unsupported, which the other
tests take, stays a separate name so XPU entries that do not crash can go there
without reaching those three. istft is not
listed: its OpInfo is complex-only, so no test here instantiates it.

Test Plan: the CI failures do not reproduce on this host, so those tolerances
are reasoned from the CI magnitudes rather than observed failing-to-passing.

```
PYTORCH_TESTING_DEVICE_ONLY_FOR=cpu OMP_NUM_THREADS=4 \
  pytest test/functorch/test_ops.py -p no:randomly -q -n 16
PYTORCH_TESTING_DEVICE_ONLY_FOR=xpu OMP_NUM_THREADS=8 \
  pytest test/functorch/test_ops.py -p no:randomly -q -n 4
```

CPU 7740 passed / 2209 skipped / 357 xfailed of 10306, 0 failed. XPU (Data
Center GPU Max 1550, with the blanket skips still in place) 7403 passed / 2572
skipped / 329 xfailed of 10305, 1 failed: test_vjpvjp_linalg_householder_product
overshoots by 1.7x (rel 2.2e-06 against 1.3e-06) on 1 of 10 elements. It passes
3/3 in isolation, test_vjpvjp carries no householder_product tolerance so it runs
bare on XPU, and this change touches none of its decorators, so it is a
pre-existing marginal flake. The XPU sweep has zero worker crashes, down from 17,
so it accounts for every collected test instead of losing 97 to dead workers.

The entries that replace the blanket skips were measured on an Arc B580 with
the skips removed, then checked over five separate runs:

```
PYTORCH_TESTING_DEVICE_ONLY_FOR=xpu python -m pytest test/functorch/test_ops.py \
  -p no:randomly -n 2 -rfEX \
  -k "xpu and (cumprod or masked_prod or conv3d or conv_transpose3d or masked_softmax or masked_softmin)"
```

Every run: 90 passed, 2 skipped, 6 xfailed, 0 failed, 0 xpassed. The same
selection on CPU has 0 failed and 0 xpassed.

lintrunner test/functorch/test_ops.py is clean.

Authored with assistance from an AI coding assistant (Claude Code).

Co-Authored-By: Claude Opus 5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
torch-xpu-ops does not implement yet. Xfail grid_sample on XPU in the
functorch transform tests, matching the OpInfo's own XPU xfails.

The xfail goes through xpu_unsupported, which every XPU-gated list now unions.
That includes test_vmapjvpall, test_vmapjvpall_has_batch_rule and
test_vmap_autograd_grad, which the previous commit kept on xpu_fft_stft_crash
alone; they need the xfail too, and one name means the next XPU entry cannot
miss them.

Test Plan:
```
python -m pytest test/functorch/test_ops.py -k "nn_functional_grid_sample and xpu"
```

Authored with an AI assistant (Claude Code).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The previous commits skip 19 fft/stft ops on XPU in every functorch transform
test, because in August they segfaulted workers at random on a local Data
Center GPU Max 1550 (intel/torch-xpu-ops#4953). The skips date from the first
commit of this stack, so XPU CI has never run these tests and the crash has not
been seen on a CI machine (Data Center GPU Max 1100).

With the skips removed, all 266 tests pass on an Arc B580 across four runs, one
of them with two xdist workers as CI uses, with no crash. Intel's CI runs its
fork of this file (test/xpu/functorch/test_ops_xpu.py) with no fft/stft skips.
Removing them here lets XPU CI settle whether the crash is still there; if it
is, the job log is the evidence pytorch#4953 lacks and the skips come back with it.

xpu_unsupported now holds only the grid_sample xfail and stays the single name
every XPU entry goes through.

Test Plan: on an Arc B580:

```
cd test
PYTORCH_TESTING_DEVICE_ONLY_FOR=xpu python -m pytest functorch/test_ops.py \
  -p no:randomly -n 2 -q -rfEX -k "TestOperatorsDeviceXPU and (fft_ or stft)"
PYTORCH_TESTING_DEVICE_ONLY_FOR=xpu python -m pytest functorch/test_ops.py \
  -p no:randomly -n 2 -q -rfEX -k "TestOperatorsDeviceXPU and grid_sample"
```

fft/stft: 290 passed, 4 xfailed (the existing all-device has_batch_rule xfails
of fft.ihfft2 and fft.ihfftn), 0 failed. The 290 include the 28 fftshift and
ifftshift tests, which were never skipped. grid_sample: 9 passed, 20 skipped,
13 xfailed, 0 xpassed, unchanged by this commit.

lintrunner test/functorch/test_ops.py is clean.

Authored with assistance from an AI coding assistant (Claude Code).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

@github-actions github-actions Bot 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.

Automated review of c9c5b8a: nothing blocking; ready for human review.

This PR renames TestOperators in test/functorch/test_ops.py to TestOperatorsDevice and marks it HardwareClassification.ACCELERATOR. It drops only_for so the suite runs on CPU, CUDA and XPU, and updates the matching DecorateInfo entries, tolerances and slow_tests.json. Recommendation: Approve. Nothing blocks merging; the one item raised is a small, low-confidence cleanup.

⚪ 1 non-blocking finding

xfail("masked.softmax", device_type=("cuda", "xpu")),

One bug is tracked in three places with two mechanisms (low confidence). The fully-masked 0-d sample failure (# 196289) is tracked by new CUDA/XPU xfails for masked.softmax/masked.softmin under test_vmapvjpvjp (lines 1005-1006). The CPU masked.softmax entry stays a separate xfail with only a # nans comment (line 1000). The CPU masked.softmin entry is still a bare unittest.skip("Skipped!") in _masked.py:1282-1287, which the PR only renamed. The 'unexpected success' cleanup plan only works for xfails, so the CPU softmin skip will silently outlive the fix (# 196300), and the CPU softmax entry

This review is AI-generated and advisory. Each new automated review replaces the previous one.

@tszulist-hbn

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-triaged This is a label only to be used by the auto triage bot ci-no-td Do not run TD on this PR ciflow/trunk Trigger trunk jobs on your pull request ciflow/xpu Run XPU CI tasks Merged open source ready for review Automated review passed, ready for a final review by a maintainer. topic: not user facing topic category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

[release/2.15] New failing test case test_vjpvmap_nn_functional_conv3d_xpu_float32

7 participants