Skip to content

[release/2.14] derive ROCM_VERSION from torch.version.rocm (#194985) - #3750

Merged
pragupta merged 1 commit into
release/2.14from
zjliu-amd/rocm-version-cp
Oct 6, 2026
Merged

pragupta merged 1 commit into
release/2.14from
zjliu-amd/rocm-version-cp

Conversation

@zjliu-amd

Copy link
Copy Markdown

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)

…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)
@zjliu-amd
zjliu-amd force-pushed the zjliu-amd/rocm-version-cp branch from ea2cf35 to c5b4d50 Compare October 1, 2026 23:15
@pragupta
pragupta merged commit d70fd61 into release/2.14 Oct 6, 2026
@pragupta
pragupta deleted the zjliu-amd/rocm-version-cp branch October 6, 2026 15:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants