From a6df8f0e62f8b1970dae09bb9e0d50b8c9036167 Mon Sep 17 00:00:00 2001 From: skishore Date: Mon, 17 Nov 2025 17:33:02 +0000 Subject: [PATCH 1/3] Revert "[ROCm] Use a ROCm version string without hash. (#166336)" This reverts commit a77f5d9a005a789804fc4d5064036490db5f48fb. --- torch/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/torch/CMakeLists.txt b/torch/CMakeLists.txt index d92b9e19a76c5..866c40ad1c12e 100644 --- a/torch/CMakeLists.txt +++ b/torch/CMakeLists.txt @@ -490,7 +490,7 @@ add_custom_target( "${Python_EXECUTABLE}" "${TOOLS_PATH}/generate_torch_version.py" --is-debug=${TORCH_VERSION_DEBUG} --cuda-version=${CUDA_VERSION} - --hip-version=${ROCM_VERSION_DEV} + --hip-version=${HIP_VERSION} --xpu-version=${SYCL_COMPILER_VERSION} BYPRODUCTS ${TORCH_SRC_DIR}/version.py COMMENT "Regenerating version file..." From d0dbe05ff401466b5414eef23a21a1195a789ee6 Mon Sep 17 00:00:00 2001 From: skishore Date: Mon, 17 Nov 2025 20:23:01 +0000 Subject: [PATCH 2/3] This extra code removes the trailing hashcode from the HIP_VERSION variable so that the torch.version.hip is parsable by packaging version parse method. --- cmake/public/LoadHIP.cmake | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cmake/public/LoadHIP.cmake b/cmake/public/LoadHIP.cmake index 018bca837a5a8..6a5af5bc59ef8 100644 --- a/cmake/public/LoadHIP.cmake +++ b/cmake/public/LoadHIP.cmake @@ -84,6 +84,17 @@ if(HIP_FOUND) set(PYTORCH_FOUND_HIP TRUE) find_package_and_print_version(hip REQUIRED CONFIG) + if(HIP_VERSION) + # Check if HIP_VERSION contains a dash (e.g., "7.1.25421-32f9fa6ca5") + # and strip everything after it to get clean numeric version + string(FIND "${HIP_VERSION}" "-" DASH_POS) + if(NOT DASH_POS EQUAL -1) + string(SUBSTRING "${HIP_VERSION}" 0 ${DASH_POS} HIP_VERSION_CLEAN) + set(HIP_VERSION "${HIP_VERSION_CLEAN}") + endif() + message("HIP version: ${HIP_VERSION}") + endif() + # The rocm-core package was only introduced in ROCm 6.4, so we make it optional. find_package(rocm-core CONFIG) From d2170fdd152ef799a9623ae12314211235d2b44b Mon Sep 17 00:00:00 2001 From: skishore Date: Tue, 18 Nov 2025 08:09:40 +0000 Subject: [PATCH 3/3] create torch.version.rocm variable to store rocm version --- tools/generate_torch_version.py | 5 ++++- torch/CMakeLists.txt | 1 + torch/version.py.tpl | 1 + 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/generate_torch_version.py b/tools/generate_torch_version.py index ec16bbf4546e2..25ba0f1633b19 100644 --- a/tools/generate_torch_version.py +++ b/tools/generate_torch_version.py @@ -119,6 +119,7 @@ def get_torch_version(sha: str | None = None) -> str: ) parser.add_argument("--cuda-version", "--cuda_version", type=str) parser.add_argument("--hip-version", "--hip_version", type=str) + parser.add_argument("--rocm-version", "--rocm_version", type=str) parser.add_argument("--xpu-version", "--xpu_version", type=str) args = parser.parse_args() @@ -126,6 +127,7 @@ def get_torch_version(sha: str | None = None) -> str: assert args.is_debug is not None args.cuda_version = None if args.cuda_version == "" else args.cuda_version args.hip_version = None if args.hip_version == "" else args.hip_version + args.rocm_version = None if args.rocm_version == "" else args.rocm_version args.xpu_version = None if args.xpu_version == "" else args.xpu_version pytorch_root = Path(__file__).parent.parent @@ -141,7 +143,7 @@ def get_torch_version(sha: str | None = None) -> str: with open(version_path, "w") as f: f.write("from typing import Optional\n\n") f.write( - "__all__ = ['__version__', 'debug', 'cuda', 'git_version', 'hip', 'xpu']\n" + "__all__ = ['__version__', 'debug', 'cuda', 'git_version', 'hip', 'rocm', 'xpu']\n" ) f.write(f"__version__ = '{version}'\n") # NB: This is not 100% accurate, because you could have built the @@ -151,4 +153,5 @@ def get_torch_version(sha: str | None = None) -> str: f.write(f"cuda: Optional[str] = {repr(args.cuda_version)}\n") f.write(f"git_version = {repr(sha)}\n") f.write(f"hip: Optional[str] = {repr(args.hip_version)}\n") + f.write(f"rocm: Optional[str] = {repr(args.rocm_version)}\n") f.write(f"xpu: Optional[str] = {repr(args.xpu_version)}\n") diff --git a/torch/CMakeLists.txt b/torch/CMakeLists.txt index 866c40ad1c12e..523e9e0002ace 100644 --- a/torch/CMakeLists.txt +++ b/torch/CMakeLists.txt @@ -491,6 +491,7 @@ add_custom_target( --is-debug=${TORCH_VERSION_DEBUG} --cuda-version=${CUDA_VERSION} --hip-version=${HIP_VERSION} + --rocm-version=${ROCM_VERSION_DEV} --xpu-version=${SYCL_COMPILER_VERSION} BYPRODUCTS ${TORCH_SRC_DIR}/version.py COMMENT "Regenerating version file..." diff --git a/torch/version.py.tpl b/torch/version.py.tpl index 1b7eab07ac949..ee37a91b7ffdc 100644 --- a/torch/version.py.tpl +++ b/torch/version.py.tpl @@ -4,6 +4,7 @@ cuda = '{{CUDA_VERSION}}' # TODO: use workspace status to stamp the correct version git_version = "" hip = None +rocm = None # This is a gross monkey-patch hack that depends on the order of imports # in torch/__init__.py