Repository navigation
[release/2.12] derive ROCM_VERSION from torch.version.rocm (#194985) - #3751
Merged
Merged
Conversation
…ytorch#194985) Summary: Relands pytorch#188184 with the import-time failure fixed. `torch.version.rocm` rather than `torch.version.hip`, so extensions can compare against the ROCm release version rather than the HIP runtime version. It was reverted out of Meta's internal monorepo because it raised at module import. `torch.version.rocm` was added by pytorch#168097, which wired it through `tools/generate_torch_version.py` and CMake only. A build that produces `torch/version.py` some other way -- Meta's Buck build substitutes a hand-written module -- leaves `rocm` absent or None while `torch.version.hip` is set. pytorch#188184 raised `AssertionError` in that state; where the attribute was absent entirely it raised `AttributeError` instead, because `if torch.version.rocm is None:` dereferences the very attribute whose absence it reports, so the assertion message was unreachable. Either way, `torch/testing/_internal/common_utils.py` imports `cpp_extension` at module scope, so this took down test collection rather than a single test. Read `torch/utils/cpp_extension.py` first. `_derive_rocm_version()` prefers `torch.version.rocm` and falls back to the HIP version with a warning instead of raising, which keeps `ROCM_VERSION` set whenever `torch.version.hip` is -- `_get_hipcc_path` compares it with no None guard. That function also moves to the newly added `HIP_VERSION`: it selects between `hipcc.exe` and `hipcc.bat`, which is a HIP SDK layout property, and pytorch#188184 left it reading `ROCM_VERSION` after repointing that name at a different quantity. The remaining files put the other readers of the ROCm release version on the same footing. `common_cuda.ROCM_VERSION`, `common_cuda._get_torch_rocm_version()` and the `skip_if_rocm_ver_*` decorators in `common_distributed.py` all derived it from HIP even though their thresholds mirror the C++ `ROCM_VERSION` macro. `blaslt_supported_device()` now uses the shared `common_cuda.ROCM_VERSION` instead of recomputing the same tuple, and keeps its `torch.version.hip` guard; switching that guard, as the original did, makes a build with a falsy `rocm` fall through to `return True` and report hipBLASLt support on every AMD GPU without checking `gcnArchName`. `torch/_inductor/heuristics/template/triton.py` reads the attribute through `getattr`, since its `torch.version.rocm is not None` test is itself an attribute access and raised at import on any build lacking the attribute, CUDA builds included. On shipped ROCm the HIP and ROCm major and minor components agree, so this is behaviour-preserving there. It changes results only on builds where the two diverge, which is what the original change was for. Test Plan: Internal context: D116640565 was the import of pytorch#188184 and was backed out by D117079854 after S699381. The internal producer that defines `rocm` in `caffe2/fb/version.py` is already on trunk via D117070955, so this diff needs no `caffe2/fb/**` change -- the consumer-side fallback makes a None `rocm` harmless, which is also why the previously proposed `rocm = hip` producer fallback is not needed. Done locally: - `arc f` and `arc lint` clean. - fbcode and xplat copies verified byte-identical for all six files. - The derivation was exercised over every `(hip, rocm)` state: both set and equal, both set and different, `rocm` None, `rocm` attribute absent, `rocm` empty string, `hip` None, `hip` absent, and a `-rc1` third component. No state raises; a differing `rocm` is preserved rather than overwritten by `hip`. To run before landing (needs AMD hardware): - `buck2 test fbcode//caffe2/test/inductor:max_autotune_amd -- --list-only` - `buck2 test fbcode//deeplearning/aot_inductor/inductor_passes/post_grad/tests:test_move_cat_before_batch_expand_in_bmm_amd -- --list-only` - `buck2 test fbcode//mode/opt-amd-gpu fbcode//dper_lib/silvertorch/core/experimental/mrs_publish/utils/tests:li_utils_test` - the APS checkpoint-compatibility target, testx 844425290139603 - the owning targets for `caffe2/test/test_utils.py` and `caffe2/test/test_linalg.py` The first two are the land-blocking AMD test-listing signals that were red on D116640565 V1 and were landed through anyway. Differential Revision: D117630130 Pull Request resolved: pytorch#194985 Approved by: https://github.com/pytorchgreenlight, https://github.com/jeffdaily (cherry picked from commit aa627e6)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reland pytorch#188184: derive ROCM_VERSION from torch.version.rocm (pytorch#194985)
Summary:
Relands pytorch#188184 with the import-time failure fixed.
torch.version.rocmrather thantorch.version.hip, so extensions can compareagainst the ROCm release version rather than the HIP runtime version. It was
reverted out of Meta's internal monorepo because it raised at module import.
torch.version.rocmwas added by pytorch#168097, which wired it throughtools/generate_torch_version.pyand CMake only. A build that producestorch/version.pysome other way -- Meta's Buck build substitutes ahand-written module -- leaves
rocmabsent or None whiletorch.version.hipis set. pytorch#188184 raised
AssertionErrorin that state; where the attribute wasabsent entirely it raised
AttributeErrorinstead, becauseif torch.version.rocm is None:dereferences the very attribute whose absenceit reports, so the assertion message was unreachable. Either way,
torch/testing/_internal/common_utils.pyimportscpp_extensionat modulescope, so this took down test collection rather than a single test.
Read
torch/utils/cpp_extension.pyfirst._derive_rocm_version()preferstorch.version.rocmand falls back to the HIP version with a warning insteadof raising, which keeps
ROCM_VERSIONset whenevertorch.version.hipis --_get_hipcc_pathcompares it with no None guard. That function also moves tothe newly added
HIP_VERSION: it selects betweenhipcc.exeandhipcc.bat,which is a HIP SDK layout property, and pytorch#188184 left it reading
ROCM_VERSIONafter repointing that name at a different quantity.
The remaining files put the other readers of the ROCm release version on the
same footing.
common_cuda.ROCM_VERSION,common_cuda._get_torch_rocm_version()and the
skip_if_rocm_ver_*decorators incommon_distributed.pyall derivedit from HIP even though their thresholds mirror the C++
ROCM_VERSIONmacro.blaslt_supported_device()now uses the sharedcommon_cuda.ROCM_VERSIONinstead of recomputing the same tuple, and keeps its
torch.version.hipguard;switching that guard, as the original did, makes a build with a falsy
rocmfall through to
return Trueand report hipBLASLt support on every AMD GPUwithout checking
gcnArchName.torch/_inductor/heuristics/template/triton.pyreads the attribute through
getattr, since itstorch.version.rocm is not Nonetest is itself an attribute access and raised at import on any build lacking the
attribute, CUDA builds included.
On shipped ROCm the HIP and ROCm major and minor components agree, so this is
behaviour-preserving there. It changes results only on builds where the two
diverge, which is what the original change was for.
Test Plan:
Internal context: D116640565 was the import of pytorch#188184 and was backed out by
D117079854 after S699381. The internal producer that defines
rocmincaffe2/fb/version.pyis already on trunk via D117070955, so this diff needs nocaffe2/fb/**change -- the consumer-side fallback makes a Nonerocmharmless, which is also why the previously proposed
rocm = hipproducerfallback is not needed.
Done locally:
arc fandarc lintclean.(hip, rocm)state: both set andequal, both set and different,
rocmNone,rocmattribute absent,rocmempty string,
hipNone,hipabsent, and a-rc1third component. No stateraises; a differing
rocmis preserved rather than overwritten byhip.To run before landing (needs AMD hardware):
buck2 test fbcode//caffe2/test/inductor:max_autotune_amd -- --list-onlybuck2 test fbcode//deeplearning/aot_inductor/inductor_passes/post_grad/tests:test_move_cat_before_batch_expand_in_bmm_amd -- --list-onlybuck2 test fbcode//mode/opt-amd-gpu fbcode//dper_lib/silvertorch/core/experimental/mrs_publish/utils/tests:li_utils_testcaffe2/test/test_utils.pyandcaffe2/test/test_linalg.pyThe first two are the land-blocking AMD test-listing signals that were red on
D116640565 V1 and were landed through anyway.
Differential Revision: D117630130
Pull Request resolved: pytorch#194985
Approved by: https://github.com/pytorchgreenlight, https://github.com/jeffdaily
(cherry picked from commit aa627e6)
🤖 Generated with Claude Code