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.

AMD install follow-ups: installable inferred target, gfx1153 lspci peer, override health hint (#14117)

Daniel Han6069a27a0bc3
diff --git a/studio/backend/tests/test_krackan2_health_gate_hsa_override.py b/studio/backend/tests/test_krackan2_health_gate_hsa_override.py
new file mode 100644
index 00000000000..f045e09bfa1
--- /dev/null
+++ b/studio/backend/tests/test_krackan2_health_gate_hsa_override.py
@@ -0,0 +1,101 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""lone Linux gfx1153 (Krackan Point 2), nameless DRM record, no rocminfo/amd-smi,
+CPU torch. With HSA_OVERRIDE_GFX_VERSION=11.0.0 the installers judge gfx1100 (covered) and
+install generic ROCm torch (install_python_stack._linux_host_only_uncovered_amd), so the
+health gate must keep the adapter eligible for a torch_cpu_build mismatch. Without the
+override the gfx1153 exemption (#13931/#14022) must still apply.
+
+"""
+
+import os
+import sys
+import tempfile
+from pathlib import Path
+from unittest.mock import patch
+
+import pytest
+
+ROOT = Path(__file__).resolve().parents[3]
+sys.path.insert(0, str(ROOT / "studio" / "backend"))
+import utils.hardware.amd as amd # noqa: E402
+import utils.hardware.hardware as hw # noqa: E402
+import utils.hardware.nvidia as nvidia # noqa: E402
+
+
+def _kfd_dir(versions):
+ d = Path(tempfile.mkdtemp(dir = os.environ.get("TMPDIR")))
+ for i, v in enumerate(("0", *versions)):
+ n = d / str(i)
+ n.mkdir()
+ (n / "properties").write_text(
+ f"simd_count {0 if i == 0 else 16}\nvendor_id {0 if i == 0 else 4098}\n"
+ f"gfx_target_version {v}\n"
+ )
+ return d
+
+
+def _eligible(hsa):
+ d = _kfd_dir(["110503"]) # gfx1153
+ real = amd.amd_kfd_gpu_gfx_targets
+ rec = {"vendor": "amd", "index": 0, "name": None, "memory_total_gb": None}
+ env = {
+ k: v
+ for k, v in os.environ.items()
+ if k not in ("HSA_OVERRIDE_GFX_VERSION", "UNSLOTH_ROCM_GFX_ARCH")
+ }
+ if hsa:
+ env["HSA_OVERRIDE_GFX_VERSION"] = hsa
+ with (
+ patch.dict(os.environ, env, clear = True),
+ patch.object(amd, "amd_kfd_gpu_gfx_targets", lambda real = real: real(str(d))),
+ patch.object(hw.platform, "system", lambda: "Linux"),
+ patch.object(nvidia, "get_physical_gpu_inventory", lambda: {"devices": [], "absent": True}),
+ patch.object(hw, "_linux_drm_sysfs_records", lambda **_: [dict(rec)], create = True),
+ patch.object(hw, "_linux_amd_gfx_candidates", lambda: [], create = True),
+ patch.object(hw, "_linux_kfd_reports_an_amd_gpu", lambda: True, create = True),
+ ):
+ devs = [
+ x for x in hw._probe_physical_gpu_inventory()["devices"] if x.get("vendor") == "amd"
+ ]
+ assert len(devs) == 1
+ return hw._amd_device_can_establish_a_mismatch(devs[0]), devs[0].get("gfx_candidates")
+
+
+def test_hsa_override_to_covered_arch_keeps_mismatch_eligible():
+ ok, cand = _eligible("11.0.0")
+ print("override 11.0.0 ->", ok, cand)
+ assert (
+ ok
+ ), f"gfx1153 under HSA_OVERRIDE_GFX_VERSION=11.0.0 hidden from health (candidates={cand})"
+
+
+def test_plain_gfx1153_still_exempt():
+ ok, cand = _eligible(None)
+ print("no override ->", ok, cand)
+ assert not ok, f"plain gfx1153 should be exempt (candidates={cand})"
+
+
[email protected]("bad", ["", "garbage", "11.0"])
+def test_unreadable_override_keeps_exemption(bad):
+ ok, cand = _eligible(bad)
+ assert not ok, f"unreadable override {bad!r} must not lift the exemption (candidates={cand})"
+
+
[email protected]("uncovered", ["10.1.0", "8.0.3", "11.5.3"])
+def test_override_to_an_uncovered_arch_keeps_exemption(uncovered):
+ ok, cand = _eligible(uncovered)
+ assert not ok, f"override {uncovered} stays on CPU torch on purpose (candidates={cand})"
+
+
[email protected]("generic_only", ["9.4.2", "9.5.0"])
+def test_override_to_a_generic_only_arch_keeps_mismatch_eligible(generic_only):
+ ok, cand = _eligible(generic_only)
+ assert ok, f"override {generic_only} gets generic ROCm torch, so CPU torch is a mismatch (candidates={cand})"
+
+
+def test_uncovered_set_matches_the_installer():
+ sys.path.insert(0, str(ROOT / "studio"))
+ import install_python_stack as ips
+ assert hw._LINUX_UNCOVERED_AMD_GFX == ips._LINUX_UNCOVERED_AMD_GFX
diff --git a/studio/backend/utils/hardware/hardware.py b/studio/backend/utils/hardware/hardware.py
index 1602478c11c..64ae53db46d 100644
--- a/studio/backend/utils/hardware/hardware.py
+++ b/studio/backend/utils/hardware/hardware.py
@@ -383,7 +383,25 @@ def _linux_kfd_gfx1153_candidates() -> list[str]:
logger.debug("KFD gfx target probe failed: %s", e)
return []
found = sorted({gfx for gfx in targets if gfx})
- return found if "gfx1153" in found else []
+ if "gfx1153" not in found:
+ return []
+ # KFD reads the silicon, immune to HSA_OVERRIDE_GFX_VERSION; the installers judge a readable
+ # override instead (install_python_stack._linux_host_only_uncovered_amd): any arch outside
+ # their uncovered set (per-arch or generic-only, e.g. gfx942) gets a ROCm wheel, so keep the
+ # conservative no-candidates answer; an uncovered one stays on CPU torch on purpose.
+ _hsa = (os.environ.get("HSA_OVERRIDE_GFX_VERSION") or "").strip()
+ if not (os.environ.get("UNSLOTH_ROCM_GFX_ARCH") or "").strip() and re.fullmatch(
+ r"[0-9]+\.[0-9]+\.[0-9]+", _hsa
+ ):
+ _maj, _min, _step = (int(p) for p in _hsa.split("."))
+ if (
+ _maj > 0
+ and _min <= 9
+ and _step <= 15
+ and f"gfx{_maj}{_min}{_step:x}" not in _LINUX_UNCOVERED_AMD_GFX
+ ):
+ return []
+ return found
def _linux_amd_gfx_candidates() -> list[str]:
@@ -1062,6 +1080,9 @@ _GPU_NAME_GFX_TABLE: "list[tuple[str, str]]" = [
# Only the Windows multi-arch route ships these (#11755, #11815); Linux installers decline them.
_ROCM_SUPPORTED_GFX_WINDOWS_ONLY = frozenset({"gfx1010", "gfx1011", "gfx1012", "gfx1153"})
+# install_python_stack._LINUX_UNCOVERED_AMD_GFX: the arches the Linux installers leave on CPU torch.
+_LINUX_UNCOVERED_AMD_GFX = _ROCM_SUPPORTED_GFX_WINDOWS_ONLY | {"gfx803"}
+
# Krackan Point 2 (gfx1153) names overlap the table's gfx1152 row; the Linux installers read them
# first and leave CPU torch on purpose (install_python_stack._LINUX_KRACKAN2_NAME_RE).
_LINUX_KRACKAN2_NAME_RE = r"820M|Krackan ?(?:Point ?)?2|AI 5 (?:PRO )?330"
diff --git a/studio/install_python_stack.py b/studio/install_python_stack.py
index 6f10d933245..18bcf926963 100644
--- a/studio/install_python_stack.py
+++ b/studio/install_python_stack.py
@@ -6627,7 +6627,21 @@ def _ensure_rocm_torch() -> "bool | None":
# The discrete card a leading Strix deferred to. One served only by the generic index
# (gfx942) skips this per-arch install: the generic route below installs for it, since
# the deferral already required a readable ROCm version.
- if not _gfx_override_env and _inferred_target != _inferred_linux_gfx:
+ # Only to a card something installs for (a per-arch index, a generic tag, or a known
+ # minimum generic tag the fallback below picks without a version, e.g. gfx950): a target
+ # moved by KFD order on a versionless host with none of these would leave CPU torch.
+ if (
+ not _gfx_override_env
+ and _inferred_target != _inferred_linux_gfx
+ and (
+ _amd_arch_index_url(_inferred_target) is not None
+ or _inferred_target in _GENERIC_WHEEL_GFX_MIN_ROCM
+ or (
+ (_target_rocm := _detect_rocm_version()) is not None
+ and _generic_pytorch_rocm_tag(_target_rocm) is not None
+ )
+ )
+ ):
_inferred_linux_gfx = _inferred_target
index_url = _amd_arch_index_url(_inferred_linux_gfx)
if index_url is not None:
diff --git a/studio/setup.sh b/studio/setup.sh
index 14dde7493fc..7b42d50288e 100755
--- a/studio/setup.sh
+++ b/studio/setup.sh
@@ -4460,7 +4460,9 @@ elif [ "$_setup_amd_detected" = true ]; then
while IFS= read -r _setup_k2_ln; do
[ -n "$_setup_k2_ln" ] || continue
printf '%s\n' "$_setup_k2_ln" | grep -Eqi "$_setup_k2_name_ere" && continue
- if _setup_supported_gfx_from_name "$_setup_k2_ln" >/dev/null 2>&1; then
+ if _setup_k2_peer_gfx=$(_setup_supported_gfx_from_name "$_setup_k2_ln" 2>/dev/null); then
+ # The APU's own line can carry the Krackan die name it shares with gfx1152 (install.sh skips it too).
+ [ "$_setup_k2_peer_gfx" = gfx1152 ] && continue
_setup_k2_peer=1
break
fi
@@ -4526,11 +4528,19 @@ EOF
_setup_unsup_pci=""
if command -v lspci >/dev/null 2>&1; then
_setup_unsup_pci=$(lspci -nn 2>/dev/null | grep -E 'VGA compatible controller|3D controller|Display controller' | grep -E 'AMD|ATI' || true)
+ # Beside a Krackan Point 2 CPU the APU's own line may carry the Krackan die name it
+ # shares with gfx1152 (1002:1114), so a gfx1152 answer there is not a peer (install.sh).
+ _setup_unsup_k2cpu=""
+ if printf '%s\n' "$1" | grep -Eqi "$_setup_k2_ere" \
+ || grep -Eqi "$_setup_k2_ere" /proc/cpuinfo 2>/dev/null; then
+ _setup_unsup_k2cpu=1
+ fi
while IFS= read -r _setup_unsup_ln; do
[ -n "$_setup_unsup_ln" ] || continue
# A Krackan Point 2 APU's own line is not a covered peer (its names overlap gfx1152's).
printf '%s\n' "$_setup_unsup_ln" | grep -Eqi "$_setup_k2_ere" && continue
- if _setup_supported_gfx_from_name "$_setup_unsup_ln" >/dev/null 2>&1; then
+ if _setup_unsup_peer=$(_setup_supported_gfx_from_name "$_setup_unsup_ln" 2>/dev/null); then
+ [ -n "$_setup_unsup_k2cpu" ] && [ "$_setup_unsup_peer" = gfx1152 ] && continue
return 1
fi
done <<EOF
diff --git a/tests/studio/install/test_linux_amd_strix_dgpu_gfx1153.py b/tests/studio/install/test_linux_amd_strix_dgpu_gfx1153.py
index dca44fe5bb0..dbff1f9da36 100644
--- a/tests/studio/install/test_linux_amd_strix_dgpu_gfx1153.py
+++ b/tests/studio/install/test_linux_amd_strix_dgpu_gfx1153.py
@@ -321,6 +321,33 @@ def test_python_inferred_install_uses_the_deferred_discrete_card():
assert "repo.amd.com/rocm/whl/gfx120X-all" in calls and _STRIX_INDEX not in calls, calls
+ "devices,inferred,expected",
+ [
+ (("gfx942", "gfx1151"), "gfx1151", _STRIX_INDEX),
+ (("gfx1103", "gfx942"), "gfx1103", "repo.amd.com/rocm/whl/gfx110X-all"),
+ (("gfx942", "gfx1103"), "gfx1103", "repo.amd.com/rocm/whl/gfx110X-all"),
+ ],
+)
+def test_python_versionless_inferred_install_keeps_an_installable_arch(devices, inferred, expected):
+ # No ROCm version and no per-arch index for the KFD pick: switching to it installed nothing.
+ calls = routing._run_install(
+ gfx_devices = devices, inferred = inferred, rocm_version = None, rocm_gpu_visible = False
+ )
+ assert expected in calls, calls
+
+
+def test_python_versionless_gfx950_ahead_of_an_apu_keeps_the_generic_fallback():
+ # gfx950 has no per-arch index, but a known minimum generic tag the versionless fallback picks.
+ calls = routing._run_install(
+ gfx_devices = ("gfx950", "gfx1151"),
+ inferred = "gfx1151",
+ rocm_version = None,
+ rocm_gpu_visible = False,
+ )
+ assert _STRIX_INDEX not in calls and "download.pytorch.org/whl/rocm" in calls, calls
+
+
@_POSIX
@pytest.mark.parametrize("hsa,expected", [("", "gfx1201"), ("11.5.1", "gfx1151")])
def test_install_sh_strix_keeps_its_index_under_an_hsa_override(hsa, expected):
diff --git a/tests/studio/install/test_setup_sh_gfx1153_lspci_peer.py b/tests/studio/install/test_setup_sh_gfx1153_lspci_peer.py
new file mode 100644
index 00000000000..c90b4a29379
--- /dev/null
+++ b/tests/studio/install/test_setup_sh_gfx1153_lspci_peer.py
@@ -0,0 +1,148 @@
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+
+"""studio/setup.sh treats a Krackan Point 2 APU's OWN lspci line as a covered gfx1152
+peer when lspci prints the Krackan die name shared with Krackan Point ("Krackan [Radeon 840M /
+860M Graphics]"), so a runtime-less lone gfx1153 host gets no "gfx1153" from
+_setup_unsupported_gfx_any and setup.sh forwards no --rocm-gfx gfx1153 to
+install_llama_prebuilt.py (whose gfx1153 HIP bundle exists). install.sh (_infer_linux_amd_gfx_arch)
+and install_python_stack.py both skip that line beside a Krackan Point 2 CPU; setup.sh must too.
+Same gap in the marketing-name block (_setup_mkt names the K2, lspci Krackan line = "peer").
+
+Each case runs in its own bash subprocess with lspci stubbed and /proc/cpuinfo redirected.
+"""
+
+import os
+import re
+import subprocess
+import tempfile
+from pathlib import Path
+
+import pytest
+
+# setup.sh is Linux/macOS only; Windows "bash" may be the WSL launcher with no distro.
+pytestmark = pytest.mark.skipif(os.name == "nt", reason = "runs setup.sh functions in bash")
+
+ROOT = Path(__file__).resolve().parents[3]
+SRC = (ROOT / "studio" / "setup.sh").read_text(encoding = "utf-8")
+
+
+def _func(name):
+ m = re.search(rf"^[ \t]*{re.escape(name)}\(\) \{{", SRC, re.M)
+ if not m:
+ return ""
+ i, depth = SRC.index("{", m.start()), 0
+ while i < len(SRC):
+ c = SRC[i]
+ if c == "{":
+ depth += 1
+ elif c == "}":
+ depth -= 1
+ if depth == 0:
+ return SRC[m.start() : i + 1]
+ i += 1
+ raise AssertionError(name)
+
+
+def _mkt_block():
+ lines = SRC.split("\n")
+ s = next(i for i, l in enumerate(lines) if "_setup_k2_name_ere=" in l)
+ e = next(
+ i
+ for i, l in enumerate(lines)
+ if i > s and "_setup_gfx=gfx1153" in l and "_setup_k2_peer" in l
+ )
+ assert lines[e + 1].strip() == "fi"
+ return "\n".join(lines[s : e + 2])
+
+
+K2_CPU = "model name : AMD Ryzen AI 5 330 w/ Radeon 820M\n"
+KP_CPU = "model name : AMD Ryzen AI 7 350 w/ Radeon 860M\n"
+SHARED = "c4:00.0 Display controller [0380]: Advanced Micro Devices, Inc. [AMD/ATI] Krackan [Radeon 840M / 860M Graphics] [1002:1114]"
+K2NAME = "c4:00.0 Display controller [0380]: Advanced Micro Devices, Inc. [AMD/ATI] Krackan Point 2 [1002:1114]"
+RX7900 = "03:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 31 [Radeon RX 7900 XTX] [1002:744c]"
+
+
+def _run(snippet, cpu, lspci_lines):
+ d = Path(tempfile.mkdtemp(dir = os.environ.get("TMPDIR")))
+ (d / "cpuinfo").write_text(cpu)
+ (d / "lspci.txt").write_text("\n".join(lspci_lines) + "\n")
+ funcs = "\n".join(
+ _func(n)
+ for n in (
+ "_setup_supported_gfx_from_name",
+ "_setup_unsupported_gfx_from_name",
+ "_setup_unsupported_gfx_any",
+ )
+ ).replace("/proc/cpuinfo", '"$STUB_CPUINFO"')
+ if not _func("_setup_unsupported_gfx_any"):
+ pytest.skip("tree has no _setup_unsupported_gfx_any (no gfx1153 handling)")
+ script = f'lspci() {{ cat "$STUB_LSPCI"; }}\n{funcs}\n{snippet}\n'
+ r = subprocess.run(
+ ["bash", "-c", script],
+ capture_output = True,
+ text = True,
+ timeout = 30,
+ env = {
+ "PATH": os.environ["PATH"],
+ "STUB_CPUINFO": str(d / "cpuinfo"),
+ "STUB_LSPCI": str(d / "lspci.txt"),
+ },
+ )
+ return r.stdout.strip()
+
+
+ANY = 'out=$(_setup_unsupported_gfx_any "$MKT") && echo "HIT:$out" || echo "MISS"'
+
+
+ "case,cpu,lspci,mkt,want",
+ [
+ ("lone K2, shared Krackan lspci name", K2_CPU, [SHARED], "", "HIT:gfx1153"),
+ (
+ "lone K2, amd-smi says 820M, shared lspci",
+ K2_CPU,
+ [SHARED],
+ "AMD Radeon 820M",
+ "HIT:gfx1153",
+ ),
+ ("lone K2, K2-named lspci (already fine)", K2_CPU, [K2NAME], "", "HIT:gfx1153"),
+ ("K2 + RX 7900 peer keeps covered route", K2_CPU, [SHARED, RX7900], "", "MISS"),
+ ("lone Krackan Point gfx1152 is supported", KP_CPU, [SHARED], "", "MISS"),
+ ],
+)
+def test_unsupported_any(case, cpu, lspci, mkt, want):
+ got = _run(f"MKT='{mkt}'\n{ANY}", cpu, lspci)
+ print(case, "->", got)
+ assert got == want, case
+
+
+ "case,cpu,lspci,mkt,want",
+ [
+ (
+ "mkt names K2 CPU, shared lspci line only",
+ K2_CPU,
+ [SHARED],
+ "AMD Ryzen AI 5 330 w/ Radeon 820M",
+ "gfx1153",
+ ),
+ (
+ "mkt names K2 CPU, real RX 7900 peer",
+ K2_CPU,
+ [SHARED, RX7900],
+ "AMD Ryzen AI 5 330 w/ Radeon 820M",
+ "gfx1152",
+ ),
+ ],
+)
+def test_marketing_name_block(case, cpu, lspci, mkt, want):
+ snippet = (
+ f"_setup_mkt='{mkt}'\n"
+ '_setup_gfx=$(_setup_supported_gfx_from_name "$_setup_mkt") || _setup_gfx=""\n'
+ f"{_mkt_block()}\n"
+ 'echo "$_setup_gfx"'
+ )
+ got = _run(snippet, cpu, lspci)
+ print(case, "->", got)
+ assert got == want, case