Repository navigation
[Test] Refactor test/functorch/test_ops.py and enable on XPU - #193412
tszulist-hbn wants to merge 6 commits into
Conversation
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". ✅ AUTOMATED REVIEW - Ready for human review:
Findings (1): Reviewed commit: 🔗 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 ( 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:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
c8c12f3 to
8cf489a
Compare
8cf489a to
015367f
Compare
015367f to
ad70228
Compare
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.
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.
ad70228 to
ee82b42
Compare
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
ee82b42 to
c462db1
Compare
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.
c462db1 to
252bb6c
Compare
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.
252bb6c to
e6e803a
Compare
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
left a comment
There was a problem hiding this comment.
In the PR description in the table are the "Before" detailed results for CPU the same as after?
e6e803a to
80dc269
Compare
|
|
|
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 Two of them were also silently de-scoped from device_type="cuda" to global, which I've restored. Now scoped disjointly: 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. |
|
Confirmed with a matched before/after CPU sweep (branch point vs branch head, same build), mapping 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. |
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
|
Please address the review comments from the bot. |
Regarding non-blocking concerns:
|
Regarding the non-blocking findings:
|
|
@pytorchbot rebase |
|
@pytorchbot started a rebase job onto refs/remotes/origin/viable/strict. Check the current status here |
|
Successfully rebased |
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]>
There was a problem hiding this comment.
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
pytorch/test/functorch/test_ops.py
Line 1005 in c9c5b8a
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.
|
@pytorchmergebot merge |
Merge startedYour 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 |
Enable
test/functorch/test_ops.pyto run on XPU, while preserving CPU and CUDA coverage.Changes
TestOperatorsdevice-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.Test Coverage Delta
Renamed test IDs
Test IDs move from
TestOperators{CPU,CUDA}toTestOperatorsDevice{CPU,CUDA}. Nothing outside this file keys on the old names (checked 2026-10-20): there are no open DISABLED issues and noTestOperators*entries indisabled-tests-condensed.json, notest_exclusionsusers, and no dynamo/inductor/compiled-autograd marker files.slow_tests.jsonis 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.