Repository navigation
Conversation
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.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/185236
Note: Links to docs will display an error until the docs builds have been completed. ❗ 1 Active SEVsThere are 1 currently active SEVs. If your PR is affected, please view them below: ❌ 1 New Failure, 6 Unclassified FailuresAs of commit 5dd1a53 with merge base d55bda7 ( NEW FAILURE - The following job has failed:
UNCLASSIFIED FAILURES - DrCI could not classify the following jobs because the workflow did not run on the merge base. The failures may be pre-existing on trunk or introduced by this PR:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
The four distributed setUpModule/tearDownModule fixtures saved and restored the legacy allow_tf32 bool. Because writing allow_tf32 = False maps fp32_precision to "ieee" rather than the pristine "none" default, the bool round-trip left fp32_precision at "ieee" instead of its original value. Snapshot and restore fp32_precision directly, matching the TestLinalg and TestMatmulCuda fixtures in this PR; the flag is still turned off via the legacy allow_tf32 = False to preserve the original intent. Authored by Claude.
|
For reference, the audit inventory mentioned above was produced by a throwaway AST script (not part of this PR): https://gist.github.com/jeffdaily/c30ed8a1c68703f74ea143e1301f2194 It scans |
…ion-audit # Conflicts: # test/inductor/test_mix_order_reduction.py
|
@claude explain those CI failures, check if they are related, and review the changes in this PR |
|
Claude finished @jansel's task in 4m 49s —— View job CI Failure Analysis and PR Review
CI Failure AnalysisAll 4 new failures are ROCm-only and share the same root cause. The failing tests are:
Root cause: The
The state changed from Fix needed: The Unclassified failures: The Code ReviewCore Mechanism (
|
| Aspect | Assessment |
|---|---|
| Core detection mechanism | Sound |
| Offender fixes (setUpModule pattern) | Correct |
with_ieee_matmul_precision removal |
Correct (once leaks are all fixed) |
| CI failures | Real bug — tf32_off()/tf32_on() in common_cuda.py need the same fp32_precision save/restore pattern |
| Unclassified failures | Mix of the same tf32_off bug + unrelated trunk flakes |
Recommendation: Fix tf32_off() and tf32_on() in torch/testing/_internal/common_cuda.py to save/restore fp32_precision instead of allow_tf32 for the matmul flag. This will resolve all 4 new CI failures and likely the test_recompile_on_global_state_change failures too (if that test uses those helpers). The dynamo test may also need a @recover_orig_fp32_precision decorator if it intentionally mutates precision state.
The TestCase precision-leak detector added in this PR exposed a latent
round-trip bug. tf32_off/tf32_on/tf32_enabled in common_cuda.py, and a few
tests that roll their own restore, saved and restored the legacy allow_tf32
bool. On ROCm the default cuda.matmul fp32_precision is "none", and writing
allow_tf32 back yields "ieee" instead of "none", which the detector correctly
flagged. ("none" and "ieee" are not equivalent: "none" defers to the global
set_float32_matmul_precision, "ieee" forces full FP32.) On CUDA the default
round-trips cleanly, so the failures were ROCm-only.
Fix the three CUDA helpers to snapshot and restore fp32_precision directly,
matching the rest of this PR. Tests that manage the bool themselves are fixed
too: test_cublas_allow_tf32_get_set and test_float32_matmul_precision_get_set
(test_cuda.py) and test_recompile_on_global_state_change (dynamo) get
@recover_orig_fp32_precision; the two CUTLASS sparse tests snapshot
fp32_precision.
Test Plan:
HIP_VISIBLE_DEVICES=7 python test/test_nn.py TestNN.test_AdaptiveLogSoftmax_cuda_fp32
HIP_VISIBLE_DEVICES=7 python test/inductor/test_torchinductor.py GPUTests.test_alexnet_prefix_cuda
HIP_VISIBLE_DEVICES=7 python test/test_cuda.py TestCuda.test_cublas_allow_tf32_get_set TestCuda.test_float32_matmul_precision_get_set
HIP_VISIBLE_DEVICES=7 python test/dynamo/test_misc.py -k test_recompile_on_global_state_change
All pass; tf32_off/tf32_enabled now round-trip fp32_precision none->none.
The CUTLASS sparse tests are skipped on ROCm so were verified by analogy with
the test_cuda fix (same pattern, same mechanism).
Authored by Claude.
|
Fixed in 3361376. The analysis was correct: the leak detector exposed that I also swept for tests that manage the bool themselves instead of going through the helpers, since they hit the same issue: Verified on MI300: |
This dynamo test toggles torch.backends.cuda.matmul.allow_tf32 via create_toggle_fns and resets the saved bool. On platforms where the default cuda.matmul fp32_precision is "none" (ROCm and CPU builds), resetting the bool leaves it at "ieee", which the new TestCase precision-leak detector flags. Wrap the test with @recover_orig_fp32_precision so the ambient precision is restored exactly, regardless of the bool round-trip; the test's intentional toggling (which exercises dynamo recompilation on global-state change) is unchanged. Dr.CI classified this failure as unrelated, but it reproduces locally as a leak-detector AssertionError and is fixed by this change. The two remaining CI failures (conv2d_backward on B200, addmm_persistent_tma on H100) contain no "leak detected" in their logs and are unrelated. Test Plan: python test/dynamo/test_graph_region_tracker.py GraphRegionTrackerTests.test_mismatched_global_state Authored by Claude.
|
@claude Analyze CI failures |
|
Claude finished @jeffdaily's task in 2m 50s —— View job CI Failure Analysis
SummaryThere are 3 failed workflow runs containing 6 failed jobs (each run has a regular test + OSDC test variant). All failures fall into 2 distinct categories, and neither is caused by this PR. Failure 1:
|
| Failure | Hardware | Related to PR? | Category |
|---|---|---|---|
test_max_autotune_addmm_persistent_tma (Unregistered range symbol: yindex) |
H100 | No | Pre-existing inductor codegen bug in persistent TMA + dynamic shapes |
test_conv2d_backward_parametrized (CUDA illegal memory access) |
B200 | No | Pre-existing B200 Triton kernel crash (sticky CUDA error) |
Both failures are unrelated to the fp32 precision flag changes in this PR. They are pre-existing issues that happen to be surfaced in these CI runs. The DrCI bot has already classified them as "UNSTABLE" (trunk flakes), which confirms they are known issues.
|
@pytorchbot merge -i Remaining red is unrelated: the macos-m2-15 mps job fails identically on trunk (test_simple_add_bfloat16_float32 conformance, broken on main), and the rocm-mi300 jobs were queue-cancelled on all three attempts without executing tests; mi300 was green on the previous reland CI and the only changes since are two test-side leak fixes validated on the L4 full-test-set (ci-no-td) run. |
Merge startedYour change will be merged while ignoring the following 7 checks: trunk / macos-py3-arm64 / test (mps, 1, 1, macos-m2-15), rocm-mi300 / linux-noble-rocm-py3.12-mi300 / test (default, 3, 6, linux.rocm.gpu.gfx942.1), rocm-mi300 / linux-noble-rocm-py3.12-mi300 / test (default, 5, 6, linux.rocm.gpu.gfx942.1), rocm-mi300 / linux-noble-rocm-py3.12-mi300 / test (default, 1, 6, linux.rocm.gpu.gfx942.1), rocm-mi300 / linux-noble-rocm-py3.12-mi300 / test (default, 4, 6, linux.rocm.gpu.gfx942.1), rocm-mi300 / linux-noble-rocm-py3.12-mi300 / test (default, 6, 6, linux.rocm.gpu.gfx942.1), rocm-mi300 / linux-noble-rocm-py3.12-mi300 / test (default, 2, 6, linux.rocm.gpu.gfx942.1) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
…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
pytorch#185236)" This reverts commit 85ac0b1. Reverted pytorch#185236 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#185236 (comment)))
…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
pytorch#185236)" This reverts commit 1344b3c. Reverted pytorch#185236 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#185236 (comment)))
…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
…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
…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
pytorch#185236)" This reverts commit 85ac0b1. Reverted pytorch#185236 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#185236 (comment)))
…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
pytorch#185236)" This reverts commit 1344b3c. Reverted pytorch#185236 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#185236 (comment)))
…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
…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
pytorch#185236)" This reverts commit 1344b3c. Reverted pytorch#185236 on behalf of https://github.com/pytorch-auto-revert due to Reverted automatically by pytorch's autorevert, to avoid this behaviour add the tag autorevert: disable ([comment](pytorch#185236 (comment)))
…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
Fixes issues reported in: #4438 Test cases fixed: ``` dynamo.test_misc_xpu.MiscTests,test_recompile_on_global_state_change dynamo.test_regional_inductor_xpu.RegionalInductorInvokeSubgraphTests,test_max_autotune_no_cudagraphs_serialize_False dynamo.test_regional_inductor_xpu.RegionalInductorInvokeSubgraphTests,test_invalid_inductor_config ``` `test_misc_xpu` changed upstream in pytorch/pytorch#185236 `test_regional_inductor_xpu` changed upstream in pytorch/pytorch#190068
Reading torch.get_float32_matmul_precision() or torch.backends.cuda.matmul.allow_tf32 raises a mixed-API TORCH_CHECK error whenever fp32 precision was last written through the new per-backend torch.backends.cuda.matmul.fp32_precision API, because the new-style setter intentionally does not update the legacy global enum. Several framework-internal hot paths still read through the legacy getters, so a single new-style write poisons inductor compilation (cache keys in codecache and select_algorithm), dynamo region tracking, TunableOp type naming, and ROCm CK instance gating. This blocks migrating tests and user code to the new API, as suggested by review on #185236. This PR converts those framework-internal readers to the resolved per-backend getters (torch._C._get_fp32_precision_getter in Python, Context::float32Precision in C++), which never throw and are the same source of truth the aten matmul paths already consult. The two inductor cache keys now key on the (cuda, mkldnn) matmul precision pair via a shared fp32_matmul_precision_key() helper; the pair carries exactly the information of the legacy string ("highest" -> ieee/ieee, "high" -> tf32/tf32, "medium" -> tf32/bf16). torch/utils/benchmark/utils/compile.py previously called the legacy getter at import time; the snapshot is now taken lazily and only when the util actually changes the precision. The legacy API surface itself (the bindings behind get_float32_matmul_precision and allow_tf32) keeps its consistency check by design, and legacy writers are untouched since the legacy setters keep both representations in sync. An alternative was to relax the TORCH_CHECK in Context::allowTF32CuBLAS() and Context::float32MatmulPrecision(), but that check is the only guard alerting users to genuinely inconsistent mixed usage, so migrating the internal readers is strictly safer. Test Plan: Verified the failure mode and the fix on a ROCm host (gfx90a). Before this change, importing the benchmark util or reading the legacy getters after a new-style write raises; after it, all converted readers work under both APIs: ``` python -c " import torch torch.backends.cuda.matmul.fp32_precision = 'tf32' print(torch._C._get_fp32_precision_getter('cuda', 'matmul'))" ``` Exercised the modified benchmark util end to end (enable sets high, disable restores highest, idempotent, and no throw under mixed state). Verified getter equivalences under the legacy setter: highest -> ieee/ieee, high -> tf32/tf32, medium -> tf32/bf16 for (cuda, mkldnn). ``` python -m py_compile torch/_inductor/utils.py torch/_inductor/codecache.py torch/_inductor/select_algorithm.py torch/_inductor/codegen/rocm/ck_template.py torch/_dynamo/graph_region_tracker.py torch/utils/benchmark/utils/compile.py uv run --script tools/linter/adapters/flake8_linter.py -- <changed py files> uv run --script tools/linter/adapters/ruff_linter.py --config=pyproject.toml --show-disable -- <changed py files> g++ -fsyntax-only -std=c++17 (snippet using Context::float32Precision with Float32Backend::CUDA / Float32Op::MATMUL) ``` Authored with Claude Code (Claude).
Reading torch.get_float32_matmul_precision() or torch.backends.cuda.matmul.allow_tf32 raises a mixed-API TORCH_CHECK error whenever fp32 precision was last written through the new per-backend torch.backends.cuda.matmul.fp32_precision API, because the new-style setter intentionally does not update the legacy global enum. Several framework-internal hot paths still read through the legacy getters, so a single new-style write poisons inductor compilation (cache keys in codecache and select_algorithm), ROCm CK instance gating, and the benchmark compile util. This blocks migrating tests and user code to the new API, as suggested by review on #185236. This PR converts those framework-internal readers to the resolved per-backend getter (torch._C._get_fp32_precision_getter), which never throws and is the same source of truth the aten matmul paths already consult. The two inductor cache keys now key on the (cuda, mkldnn) matmul precision pair via a shared fp32_matmul_precision_key() helper; the pair carries exactly the information of the legacy string ("highest" -> ieee/ieee, "high" -> tf32/tf32, "medium" -> tf32/bf16). torch/utils/benchmark/utils/compile.py previously called the legacy getter at import time; the snapshot is now taken lazily and only when the util actually changes the precision. The legacy API surface itself (the bindings behind get_float32_matmul_precision and allow_tf32) keeps its consistency check by design, and legacy writers are untouched since the legacy setters keep both representations in sync. The TunableOp TypeName and dynamo graph_region_tracker readers this PR originally also migrated were converted upstream in the meantime by #195301, so they dropped out of the diff when rebasing onto viable/strict. An alternative was to relax the TORCH_CHECK in Context::allowTF32CuBLAS() and Context::float32MatmulPrecision(), but that check is the only guard alerting users to genuinely inconsistent mixed usage, so migrating the internal readers is strictly safer. Test Plan: Verified the failure mode and the fix on a ROCm host (gfx90a). Before this change, importing the benchmark util or reading the legacy getters after a new-style write raises; after it, all converted readers work under both APIs: ``` python -c " import torch torch.backends.cuda.matmul.fp32_precision = 'tf32' print(torch._C._get_fp32_precision_getter('cuda', 'matmul'))" ``` Exercised the modified benchmark util end to end (enable sets high, disable restores highest, idempotent, and no throw under mixed state). Verified getter equivalences under the legacy setter: highest -> ieee/ieee, high -> tf32/tf32, medium -> tf32/bf16 for (cuda, mkldnn). ``` python -m py_compile torch/_inductor/utils.py torch/_inductor/codecache.py torch/_inductor/select_algorithm.py torch/_inductor/codegen/rocm/ck_template.py torch/utils/benchmark/utils/compile.py lintrunner --skip PYREFLY <changed py files> ``` Authored with Claude Code (Claude).
Fixes issues reported in: intel#4438 Test cases fixed: ``` dynamo.test_misc_xpu.MiscTests,test_recompile_on_global_state_change dynamo.test_regional_inductor_xpu.RegionalInductorInvokeSubgraphTests,test_max_autotune_no_cudagraphs_serialize_False dynamo.test_regional_inductor_xpu.RegionalInductorInvokeSubgraphTests,test_invalid_inductor_config ``` `test_misc_xpu` changed upstream in pytorch/pytorch#185236 `test_regional_inductor_xpu` changed upstream in pytorch/pytorch#190068
) Reading `torch.get_float32_matmul_precision()` or `torch.backends.cuda.matmul.allow_tf32` raises a mixed-API TORCH_CHECK error whenever fp32 precision was last written through the new per-backend `torch.backends.cuda.matmul.fp32_precision` API, because the new-style setter intentionally does not update the legacy global enum. Several framework-internal hot paths still read through the legacy getters, so a single new-style write poisons inductor compilation (cache keys in codecache and select_algorithm), ROCm CK instance gating, flex attention precision selection, and the benchmark compile util. This blocks migrating tests and user code to the new API, as suggested in review on #185236. This PR converts those framework-internal readers to the resolved per-backend getter (`torch._C._get_fp32_precision_getter`), which never throws and is the same source of truth the aten matmul paths already consult. The converted readers are the two inductor cache keys (now keyed on the (cuda, mkldnn) matmul precision pair via a shared `fp32_matmul_precision_key()` helper; the pair carries exactly the information of the legacy string: "highest" -> ieee/ieee, "high" -> tf32/tf32, "medium" -> tf32/bf16), ROCm CK instance gating, flex attention's `set_float32_precision()` (its legacy fallback for the unset "none" state still threw on new-style writes to other backends; a resolved "none" means unset at every level of the per-backend hierarchy, which is exactly the legacy default "highest", so the fallback collapses to "ieee"), and `torch/utils/benchmark/utils/compile.py`, which previously called the legacy getter at import time and now snapshots lazily. The legacy API surface itself keeps its consistency check by design, and legacy writers are untouched since the legacy setters keep both representations in sync. A regression test (`test_fp32_precision_new_api_internal_readers` in test_cuda.py) exercises the converted readers under the mixed state that makes the legacy getters raise. The TunableOp TypeName and dynamo `get_global_state_key()` readers this PR originally also migrated were converted upstream in the meantime by #195301, so they dropped out of the diff when rebasing. #196860 landed a narrower workaround at the two autotune cache-key sites this PR migrates: it reads the new-style per-backend value and only falls back to the legacy getter when that value is not `bfx9`. That dodges the throw for `bfx9` specifically, but the legacy getter still throws for every other precision written through the new API. `fp32_matmul_precision_key()` supersedes it, because it never consults the legacy getter at all and so covers `bfx9` along with the rest; merging main therefore drops that workaround. `test_precompile_cache_key_handles_bfx9` is updated for the pair-format key and tightened to assert the legacy getter is never called for any precision. Compatibility note: the autotune/precompile cache-key component changes format (e.g. "high" becomes "cuda:tf32,mkldnn:tf32"), which invalidates existing on-disk autotune caches once on upgrade; this causes a one-time re-benchmark and has no correctness impact. An alternative was to relax the TORCH_CHECK in `Context::allowTF32CuBLAS()` / `Context::float32MatmulPrecision()`, but that check is the only guard alerting users to genuinely inconsistent mixed usage, so migrating the internal readers is strictly safer. A follow-up will migrate the module-level precision setup in the test suite to the per-backend API (the follow-up promised in the #185236 review thread). Authored with an AI assistant (Claude Code). Pull Request resolved: #189955 Approved by: https://github.com/drisspg
Follow-up to #180926. In review there, @albanD asked that we not spread defensive
with_ieee_matmul_precisiondecorators 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 baseTestCasenot catching such leaks.This makes any test running under
torch.testing._internal.common_utils.TestCasestart from a known precision baseline, and turns a leak into a loud failure intearDownrather 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.setUpsnapshots them andtearDowncompares, restores, and raisesAssertionErrornaming the leaked flag.recover_orig_fp32_precisionis refactored to reuse the same snapshot/restore. An opt-out env varPYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1exists 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/tearDownModulewith save/restore, so importing the module no longer poisons precision for everything imported after it; distributed suites that setallow_tf32 = Falseat import time get the same treatment. Thetest_linalg.pytunableop tests replace a hardcodedfinally: allow_tf32 = Falsewithtf32_enabled(), andTestLinalg/TestMatmulCudasetUp/tearDownsnapshot the realfp32_precisioninstead 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_precisiondecorator 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.
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._internalis private API, and the removedwith_ieee_matmul_precisionwas only added recently in #180926. The newtearDownassertion can surface pre-existing precision-flag leaks in out-of-tree test suites built on ourTestCase;PYTORCH_DISABLE_FP32_PRECISION_LEAK_CHECK=1disables it if needed.Authored by Claude.
cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo @azahed98