Skip to content

[ROCm] add torch.version.rocm, distinct from torch.version.hip#168097

Closed
amd-sriram wants to merge 3 commits intopytorch:mainfrom
amd-sriram:Fix_RocmHipVersion
Closed

[ROCm] add torch.version.rocm, distinct from torch.version.hip#168097
amd-sriram wants to merge 3 commits intopytorch:mainfrom
amd-sriram:Fix_RocmHipVersion

Conversation

@amd-sriram
Copy link
Contributor

@amd-sriram amd-sriram commented Nov 18, 2025

Historically, HIP and ROCm versions were interchangeable, but moving forward these versions are allowed to diverge. ROCm version represents the full ROCm software stack, while HIP is a component of the ROCm stack.

Issue #166068 was fixed by switching from using HIP_VERSION to ROCM_VERSION_DEV. However, this broke the build of ROCm apex because the hip version from hipcc --version no longer matched torch.version.hip. This highlights the need for both versions to be exposed.

Bitsandbytes has also been impacted by the change in behavior of torch.version.hip: bitsandbytes-foundation/bitsandbytes#1799 (comment)

The solution is to fix the torch.version.hip so that it uses the hipcc header values and removes the trailing hash code. In addition, torch.version.rocm variable is created to store the ROCm version.

Technical Details

Fix torch.version.hip

HIP_VERSION variable is computed in https://github.com/ROCm/hip/blob/develop/cmake/FindHIP.cmake. This runs hipcc –version and extracts the output of HIP version line, e.g.,

hipcc --version 
HIP version: 7.1.25421-32f9fa6ca5 

The HIP_VERSION variable may contain a hash code at the end. This trailing hashcode is removed from the HIP_VERSION variable so that the torch.version.hip can be parsed by packaging version parse method, e.g.,

import torch  
from packaging import version  
print(version.parse(torch.version.hip)) 

Add torch.version.rocm

Code changes:

  • Add rocm variable to torch/version.py.tpl
  • Add code to write rocm variable in tools/generate_torch_version.py
  • Write rocm version in installation process - torch/CMakeLists.txt

Testing

Tested on a preview of ROCm 7.2. Successfully built pytorch and apex. Tested above parsing torch.version.hip code.

>>> import torch
>>> torch.version.hip
'7.1.25421'
>>> torch.version.rocm
'7.2.0'

cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @dllehr-amd @jataylo @hongxiayang @naromero77amd

@pytorch-bot
Copy link

pytorch-bot bot commented Nov 18, 2025

🔗 Helpful Links

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

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

✅ You can merge normally! (2 Unrelated Failures)

As of commit da35bf3 with merge base ee5610f (image):

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

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

@amd-sriram amd-sriram changed the title Fix torch.version.hip issue containing trailing hash code [ROCm] Fix torch.version.hip issue containing trailing hash code Nov 18, 2025
@pytorch-bot pytorch-bot bot added the module: rocm AMD GPU support for Pytorch label Nov 18, 2025
@amd-sriram
Copy link
Contributor Author

@pytorchbot label "release notes: rocm"

@pytorch-bot pytorch-bot bot added the release notes: rocm mandatorylabel label Nov 18, 2025
…riable so that the torch.version.hip is parsable by packaging version parse method. created torch.version.rocm variable to store rocm version
@jeffdaily jeffdaily changed the title [ROCm] Fix torch.version.hip issue containing trailing hash code [ROCm] add torch.version.rocm, distinct from torch.version.hip Nov 18, 2025
@pytorch-bot pytorch-bot bot added the ciflow/rocm Trigger "default" config CI on ROCm label Nov 19, 2025
@jithunnair-amd jithunnair-amd added keep-going Don't stop on first failure, keep running tests until the end ci-no-td Do not run TD on this PR labels Nov 19, 2025
@jeffdaily jeffdaily added the ciflow/trunk Trigger trunk jobs on your pull request label Nov 19, 2025
@jithunnair-amd
Copy link
Collaborator

@pytorchbot merge

@pytorchmergebot
Copy link
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

JacobSzwejbka pushed a commit that referenced this pull request Dec 8, 2025
)

Historically, HIP and ROCm versions were interchangeable, but moving forward these versions are allowed to diverge.  ROCm version represents the full ROCm software stack, while HIP is a component of the ROCm stack.

Issue #166068 was fixed by [switching from using HIP_VERSION to ROCM_VERSION_DEV](#166336).  However, this broke the build of ROCm apex because the hip version from `hipcc --version` no longer matched `torch.version.hip`.  This highlights the need for both versions to be exposed.

Bitsandbytes has also been impacted by the change in behavior of `torch.version.hip`: bitsandbytes-foundation/bitsandbytes#1799 (comment)

The solution is to fix the `torch.version.hip` so that it uses the hipcc header values and removes the trailing hash code. In addition, `torch.version.rocm` variable is created to store the ROCm version.

## Technical Details

### Fix torch.version.hip

HIP_VERSION variable is computed in https://github.com/ROCm/hip/blob/develop/cmake/FindHIP.cmake. This runs hipcc –version and extracts the output of HIP version line, e.g.,
```
hipcc --version
HIP version: 7.1.25421-32f9fa6ca5
```

The HIP_VERSION variable may contain a hash code at the end.  This trailing hashcode is removed from the HIP_VERSION variable so that the torch.version.hip can be parsed by packaging version parse method, e.g.,
```
import torch
from packaging import version
print(version.parse(torch.version.hip))
```

### Add torch.version.rocm

Code changes:
- Add rocm variable to torch/version.py.tpl
- Add code to write rocm variable in tools/generate_torch_version.py
- Write rocm version in installation process - torch/CMakeLists.txt

## Testing

Tested on a preview of ROCm 7.2.  Successfully built pytorch and apex. Tested above parsing torch.version.hip code.

```
>>> import torch
>>> torch.version.hip
'7.1.25421'
>>> torch.version.rocm
'7.2.0'
```

Pull Request resolved: #168097
Approved by: https://github.com/jeffdaily

Co-authored-by: Jeff Daily <jeff.daily@amd.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-no-td Do not run TD on this PR ciflow/rocm Trigger "default" config CI on ROCm ciflow/trunk Trigger trunk jobs on your pull request keep-going Don't stop on first failure, keep running tests until the end Merged module: rocm AMD GPU support for Pytorch open source release notes: rocm mandatorylabel

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants