Repository navigation
[Inductor] Key autotune cache on per-backend fp32_precision - #196737
indrajeetapache wants to merge 2 commits into
Conversation
PersistentCache.lookup and create_precompile_key called torch.get_float32_matmul_precision(), which raises after the new per-backend API is used (e.g. fp32_precision="bfx9"). Read torch.backends.cuda.matmul.fp32_precision instead, falling back to the legacy getter only when it reports "none". Fixes pytorch#196728 Test Plan: - test/inductor/test_codecache.py -k TestAutotuneCacheFp32Precision - CI inductor coverage for flex_attention / autotune paths
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/196737
Note: Links to docs will display an error until the docs builds have been completed.
|
This PR needs a
|
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
1 similar comment
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
| def get_autotune_cache_fp32_precision() -> str: | ||
| """Precision string for Inductor autotune / PersistentCache keys. | ||
|
|
||
| Prefer the per-backend CUDA matmul API. Calling the legacy | ||
| ``torch.get_float32_matmul_precision()`` after the new API has been used | ||
| (e.g. ``fp32_precision="bfx9"`` or ``"tf32"``) raises a mixed-API error — | ||
| see #196728. Fall back to the legacy getter only when the new API reports | ||
| ``"none"``. | ||
| """ | ||
| precision = torch.backends.cuda.matmul.fp32_precision | ||
| if precision != "none": | ||
| return precision | ||
| return torch.get_float32_matmul_precision() |
There was a problem hiding this comment.
| def get_autotune_cache_fp32_precision() -> str: | |
| """Precision string for Inductor autotune / PersistentCache keys. | |
| Prefer the per-backend CUDA matmul API. Calling the legacy | |
| ``torch.get_float32_matmul_precision()`` after the new API has been used | |
| (e.g. ``fp32_precision="bfx9"`` or ``"tf32"``) raises a mixed-API error — | |
| see #196728. Fall back to the legacy getter only when the new API reports | |
| ``"none"``. | |
| """ | |
| precision = torch.backends.cuda.matmul.fp32_precision | |
| if precision != "none": | |
| return precision | |
| return torch.get_float32_matmul_precision() | |
| def get_autotune_cache_fp32_precision() -> str: | |
| """Return a cache key for CUDA and MKLDNN matmul precision.""" | |
| cuda_precision = torch.backends.cuda.matmul.fp32_precision | |
| cpu_precision = torch.backends.mkldnn.matmul.fp32_precision | |
| if cuda_precision == "none" and cpu_precision == "none": | |
| return torch.get_float32_matmul_precision() | |
| return f"cuda={cuda_precision};mkldnn={cpu_precision}" |
|
Thanks for picking up #196728. I found that the older #189955 already fixes the same two call sites— There is also an edge case in the helper introduced here: when CUDA precision is |
Address review on pytorch#196737: the CUDA-only helper still fell back to the legacy getter when cuda was unset but mkldnn used the new API, and it collapsed legacy high (tf32/tf32) vs medium (tf32/bf16). Use the resolved per-backend pair via _get_fp32_precision_getter, matching the approach in pytorch#189955 for the overlapping cache-key sites. Test Plan: - test/inductor/test_codecache.py::TestAutotuneCacheFp32Precision Authored with an AI assistant.
|
Addressed the review feedback in the latest commit:
@drisspg @janbernloehr — this aligns with the cache-key approach in #189955 for the two overlapping inductor sites. #189955 is older/broader (also covers flex attention, ROCm CK, benchmark util) and already approved; happy to close this as a duplicate once that lands, or keep this as a narrower #196728-focused path if maintainers prefer. Please advise. cc @zasdfgbnm @ptrblck @drisspg @janbernloehr @coconutruben @jataylo |
|
Thanks for working on this fix. The underlying issue has since been resolved in main by 7949d704 from #196860. Since the fix is now in main, this PR appears to be superseded and can be closed. Thanks again for investigating and preparing the patch. |
|
We should wait for jeffs pr to land if it hasnt |
Summary
Fixes #196728.
Setting
torch.backends.cuda.matmul.fp32_precision = "bfx9"(TorchTitan on Blackwell) makes Inductor's autotune cache raise:Root cause: after #195301, several Inductor sites moved to the per-backend API, but these two still call the legacy getter:
PersistentCache.lookupintorch/_inductor/codecache.py(raising frame from the issue)create_precompile_keyintorch/_inductor/select_algorithm.pyThe cache lookup is unconditional, so even bf16 FlexAttention fails.
Fix: add
get_autotune_cache_fp32_precision()that:torch.backends.cuda.matmul.fp32_precisiontorch.get_float32_matmul_precision()only when the new API is"none"This matches the pattern already used in FlexAttention / other #195301 call sites, keeps legacy-only IEEE/TF32 cache keys working when the new API is unset, and makes
bfx9a distinct autotune key (correct, since GEMM arithmetic differs).Test plan
test/inductor/test_codecache.py::TestAutotuneCacheFp32Precisionhighestthenfp32_precision="tf32") must not raise in helper /create_precompile_key/PersistentCache.lookup"ieee"via the helpercc @voznesenskym @penguinwu @EikanWang @jgong5 @Guobing-Chen @XiaobingSuper @zhuhaozhe @blzheng @wenzhe-nrv @jiayisunx @ipiszy @kadeng @muchulee8 @amjames @chauhang @aakhundov @coconutruben @jataylo @zasdfgbnm @ptrblck @janbernloehr @Chillee @drisspg