Skip to content

[CUDA][cuBLAS][Inductor] Don't get bfx9 from the legacy precision getter - #196860

Closed
eqy wants to merge 1 commit into
pytorch:mainfrom
eqy:bfx9legacy
Closed

eqy wants to merge 1 commit into
pytorch:mainfrom
eqy:bfx9legacy

Conversation

@eqy

@eqy eqy commented Sep 12, 2026 •

Copy link
Copy Markdown
Collaborator

If the mode is bfx9 we should avoid try trying to get it from the legacy getter which doesn't know about it

authored with codex

cc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo

@pytorch-bot

pytorch-bot Bot commented Sep 12, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

⏳ No Failures, 1 Pending

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

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

@eqy eqy added the topic: not user facing topic category label Sep 12, 2026
@eqy

eqy commented Sep 12, 2026

Copy link
Copy Markdown
Collaborator Author

@pytorchmergebot merge

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

jeffdaily added a commit that referenced this pull request Sep 18, 2026
Resolves conflicts with #196860, which added a narrower workaround at the two
autotune cache-key sites this PR migrates: read the new-style per-backend
value and only consult the legacy getter when it is not "bfx9". This PR's
fp32_matmul_precision_key() supersedes that, since it never consults the
legacy getter and so covers bfx9 along with every other mixed-API state.

Updates test_precompile_cache_key_handles_bfx9 for the pair-format key and
tightens it to assert the legacy getter is never called for any precision.
pytorchmergebot pushed a commit that referenced this pull request Sep 18, 2026
)

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests ciflow/trunk Trigger trunk jobs on your pull request Merged module: inductor open source topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants