From f036ee0022a02d5d794b53bc25907caf0d61620e Mon Sep 17 00:00:00 2001 From: LeoBorcherding Date: Wed, 6 May 2026 20:14:14 -0500 Subject: [PATCH] fix: detect AMD SDK ROCm torch via __version__ when torch.version.hip is unset AMD's repo.radeon.com wheels (e.g. 2.9.0+rocmsdk20251116) do not set torch.version.hip, leaving it None. All three probes that relied solely on torch.version.hip now also check for 'rocm' in torch.__version__.lower(): - hardware.py detect_hardware(): IS_ROCM was never set, causing the studio to report 'Hardware detected: CPU' even after AMD wheels were installed and HIP DLLs were on PATH. - install_python_stack.py _ensure_rocm_torch(): skip-if-already-installed probe would always reinstall on subsequent runs. - install_python_stack.py Windows AMD warning: suppression check always failed, so the 'must be installed manually' note kept appearing after a successful AMD wheel install. --- studio/backend/utils/hardware/hardware.py | 8 ++++++-- studio/install_python_stack.py | 25 +++++++++++++++++------ 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/studio/backend/utils/hardware/hardware.py b/studio/backend/utils/hardware/hardware.py index 3b1c2a54dc..c4d6584e2b 100644 --- a/studio/backend/utils/hardware/hardware.py +++ b/studio/backend/utils/hardware/hardware.py @@ -120,10 +120,14 @@ def detect_hardware() -> DeviceType: # Distinguish AMD ROCm (HIP) from NVIDIA CUDA for display purposes. # DeviceType stays CUDA since torch.cuda.* works on ROCm via HIP. - if getattr(torch.version, "hip", None) is not None: + # AMD's repo.radeon.com SDK wheels (e.g. 2.9.0+rocmsdk20251116) do + # not set torch.version.hip, so fall back to checking __version__. + _hip_ver = getattr(torch.version, "hip", None) + if _hip_ver is not None or "rocm" in torch.__version__.lower(): IS_ROCM = True + _hip_label = _hip_ver or torch.__version__ print( - f"Hardware detected: ROCm (HIP {torch.version.hip}) -- {device_name}" + f"Hardware detected: ROCm (HIP {_hip_label}) -- {device_name}" ) else: print(f"Hardware detected: CUDA -- {device_name}") diff --git a/studio/install_python_stack.py b/studio/install_python_stack.py index d580a163e4..29fe70cdbb 100644 --- a/studio/install_python_stack.py +++ b/studio/install_python_stack.py @@ -299,13 +299,18 @@ def _ensure_rocm_torch() -> None: [ sys.executable, "-c", - "import torch; print(getattr(torch.version,'hip','') or '')", + ( + "import torch; " + "hip=getattr(torch.version,'hip','') or ''; " + "ver=torch.__version__; " + "print('yes' if hip or 'rocm' in ver.lower() else '')" + ), ], stdout = subprocess.PIPE, stderr = subprocess.DEVNULL, timeout = 30, ) - if probe.returncode == 0 and probe.stdout.decode().strip(): + if probe.returncode == 0 and probe.stdout.decode().strip() == "yes": return # already ROCm torch except (OSError, subprocess.TimeoutExpired): pass @@ -1175,20 +1180,28 @@ def install_python_stack() -> int: _win_amd_gpu = True break if _win_amd_gpu: - # Only warn if torch doesn't already have ROCm (HIP) support + # Only warn if torch doesn't already have ROCm (HIP) support. + # AMD SDK wheels (e.g. 2.9.0+rocmsdk20251116) don't set + # torch.version.hip, so also check for "rocm" in __version__. try: - _hip_ver = subprocess.run( + _rocm_probe = subprocess.run( [ sys.executable, "-c", - "import torch; print(getattr(torch.version,'hip','') or '')", + ( + "import torch; " + "hip=getattr(torch.version,'hip','') or ''; " + "ver=torch.__version__; " + "print('yes' if hip or 'rocm' in ver.lower() else '')" + ), ], stdout = subprocess.PIPE, stderr = subprocess.DEVNULL, timeout = 20, ) _has_rocm_torch = ( - _hip_ver.returncode == 0 and _hip_ver.stdout.decode().strip() != "" + _rocm_probe.returncode == 0 + and _rocm_probe.stdout.decode().strip() == "yes" ) except Exception: _has_rocm_torch = False