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.
This commit is contained in:
LeoBorcherding 2026-05-06 20:14:14 -05:00
commit f036ee0022
2 changed files with 25 additions and 8 deletions

View file

@ -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}")

View file

@ -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