Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: judge an HSA_OVERRIDE_GFX_VERSION GPU by its override in the cold engine status (#16670)

Daniel Hanc9f786f2c9f3
diff --git a/studio/backend/core/inference/engine_install.py b/studio/backend/core/inference/engine_install.py
index 443591f89b4..6119260b3b0 100644
--- a/studio/backend/core/inference/engine_install.py
+++ b/studio/backend/core/inference/engine_install.py
@@ -847,7 +847,11 @@ def _rocm_reason(
return "Requires ROCm {}.{} or a newer {}.x release installed in /opt/rocm".format(
*wanted["rocm"], wanted["rocm"][0]
) + (" (found {}.{}).".format(*found) if found else ".")
- from utils.hardware.amd import _a_bare_soname_resolves, amd_kfd_gpu_gfx_targets
+ from utils.hardware.amd import (
+ _a_bare_soname_resolves,
+ amd_kfd_gpu_gfx_targets,
+ hsa_override_gfx_target,
+ )
missing = [soname for soname in ROCM_LIBRARIES if not (ROCM_HOME / "lib" / soname).exists()]
if missing:
@@ -881,16 +885,16 @@ def _rocm_reason(
# Each GPU's target as the engine sees it (HSA_OVERRIDE_GFX_VERSION included), else the kernel's.
arches = _known_rocm_gpu_arches(wait = wait)
- if (
- not arches
- and _rocm_arches is None
- and (
- os.environ.get("HSA_OVERRIDE_GFX_VERSION", "").strip()
- or amd_kfd_gpu_gfx_targets() is None
- )
- ):
- # The kernel's target ignores the override, or is unreadable; stay provisional until torch reports one.
- return "Checking for a supported AMD GPU."
+ if not arches and _rocm_arches is None:
+ kernel = amd_kfd_gpu_gfx_targets()
+ if os.environ.get("HSA_OVERRIDE_GFX_VERSION", "").strip():
+ # ROCr presents a readable global override for every GPU KFD lists; the kernel's target ignores it.
+ override = hsa_override_gfx_target()
+ if override is None or not kernel:
+ return "Checking for a supported AMD GPU."
+ arches = dict.fromkeys(range(len(kernel)), override)
+ elif kernel is None:
+ return "Checking for a supported AMD GPU."
if gpu_id is None:
selected = list(arches.values()) or amd_kfd_gpu_gfx_targets() or []
elif gpu_id in arches:
diff --git a/studio/backend/tests/test_managed_engines_rocm.py b/studio/backend/tests/test_managed_engines_rocm.py
index 4527fbd95da..c23395ea2b3 100644
--- a/studio/backend/tests/test_managed_engines_rocm.py
+++ b/studio/backend/tests/test_managed_engines_rocm.py
@@ -287,13 +287,64 @@ def test_cold_status_does_not_judge_an_overridden_gpu_by_its_kernel_target(amd_h
monkeypatch.setenv("HSA_OVERRIDE_GFX_VERSION", "11.0.0")
monkeypatch.setattr(install, "_rocm_arches", None)
monkeypatch.delitem(install.sys.modules, "torch", raising = False)
- assert install.support_reason("vllm", wait = False) == "Checking for a supported AMD GPU."
+ assert install.support_reason("vllm", wait = False) is None
monkeypatch.delenv("HSA_OVERRIDE_GFX_VERSION")
assert install.support_reason("vllm", wait = False).startswith("Requires an AMD Instinct")
amd_host.targets["value"] = None
assert install.support_reason("vllm", wait = False) == "Checking for a supported AMD GPU."
[email protected]("gpu_id", [None, 0, 1])
+def test_cold_status_judges_an_overridden_gpu_by_the_override_without_torch(
+ amd_host, monkeypatch, gpu_id
+):
+ def no_torch():
+ raise AssertionError("an idle status poll probed torch")
+
+ amd_host.targets["value"] = ["gfx1102", "gfx1102"]
+ monkeypatch.setattr(install, "_rocm_gpu_arches", no_torch)
+ monkeypatch.setattr(install, "_rocm_arches", None)
+ monkeypatch.delitem(install.sys.modules, "torch", raising = False)
+ monkeypatch.setenv("HSA_OVERRIDE_GFX_VERSION", "11.0.0")
+ assert install.support_reason("vllm", gpu_id, wait = False) is None
+ monkeypatch.setenv("HSA_OVERRIDE_GFX_VERSION", "10.3.0")
+ assert install.support_reason("vllm", gpu_id, wait = False) == (
+ install._unsupported_amd_gpu(["gfx1030"] if gpu_id is not None else ["gfx1030", "gfx1030"])
+ )
+ monkeypatch.setenv("HSA_OVERRIDE_GFX_VERSION", "11")
+ assert install.support_reason("vllm", gpu_id, wait = False) == "Checking for a supported AMD GPU."
+ monkeypatch.setenv("HSA_OVERRIDE_GFX_VERSION", "11.0.0")
+ monkeypatch.setenv("HSA_OVERRIDE_GFX_VERSION_0", "10.3.0")
+ assert install.support_reason("vllm", gpu_id, wait = False) == "Checking for a supported AMD GPU."
+ monkeypatch.delenv("HSA_OVERRIDE_GFX_VERSION_0")
+ amd_host.targets["value"] = None
+ assert install.support_reason("vllm", gpu_id, wait = False) == "Checking for a supported AMD GPU."
+ assert "torch" not in install.sys.modules
+
+
+ "value, target",
+ [
+ ("11.0.0", "gfx1100"),
+ (" 9.0.10", "gfx90a"),
+ ("11.0.0 ", None),
+ ("64.0.0", None),
+ ("11.5.1", "gfx1151"),
+ ("10.3.0", "gfx1030"),
+ ("", None),
+ ("11", None),
+ ("11.0.16", None),
+ ("11.10.0", None),
+ ("0.0.0", None),
+ ("1x.0.0", None),
+ ],
+)
+def test_hsa_override_gfx_target(monkeypatch, value, target):
+ from utils.hardware import amd
+ monkeypatch.setenv("HSA_OVERRIDE_GFX_VERSION", value)
+ assert amd.hsa_override_gfx_target() == target
+
+
def test_sglang_on_amd_points_to_vllm(amd_host):
assert install.support_reason("sglang", wait = False) == (
"SGLang requires an NVIDIA GPU. Use vLLM on AMD GPUs."
diff --git a/studio/backend/utils/hardware/amd.py b/studio/backend/utils/hardware/amd.py
index 2f407b1753b..97ce17700cf 100644
--- a/studio/backend/utils/hardware/amd.py
+++ b/studio/backend/utils/hardware/amd.py
@@ -655,6 +655,20 @@ def amd_kfd_gpu_gfx_targets(
return targets
+def hsa_override_gfx_target() -> Optional[str]:
+ """Target ROCr presents for every GPU (11.0.0 -> gfx1100, 9.0.10 -> gfx90a), else None: unset,
+ per-node _<n> set, rejected by libhsakmt (sscanf "%u.%u.%u%c", major <= 63), or no one-digit name."""
+ if any(key.startswith("HSA_OVERRIDE_GFX_VERSION_") for key in os.environ):
+ return None
+ value = os.environ.get("HSA_OVERRIDE_GFX_VERSION", "").lstrip()
+ if not re.fullmatch(r"[0-9]+\.[0-9]+\.[0-9]+", value):
+ return None
+ major, minor, step = (int(part) for part in value.split("."))
+ if not 0 < major <= 63 or minor > 9 or step > 15:
+ return None
+ return f"gfx{major}{minor}{step:x}"
+
+
def _amd_render_node_exists() -> bool:
"""Presence, not openability: /dev/kfd without /dev/dri passes every probe yet initialises nothing."""
_unreadable = False