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.
Python agentaichatgptdeepseekfine-tuninggemmaimage-generationllamallmllmsopenaipythonqwenreinforcement-learningself-hostedstable-diffusiontext-to-speechttsuiunsloth
Installers (AMD, Linux): a Strix APU defers torch to a discrete card, and a lone gfx1153 warns instead of getting kernel-less wheels (#13931)
Daniel Han4a8b727dfd7b
diff --git a/install.sh b/install.shindex f375293e715..0532ecd307a 100755--- a/install.sh+++ b/install.sh@@ -4740,11 +4740,23 @@ _amd_gfx_is_shadowing_integrated() {# The card to install for when enumeration put an integrated GPU first (#7776): one arch picks# the wheel family, so letting the APU decide strands the discrete card. gfx906 is never a-# candidate, since naming it on a mixed host strands BOTH cards.+# candidate, since naming it on a mixed host strands BOTH cards. A third argument of "torch"+# also defers a Strix APU (gfx1150-gfx1152) to a routable discrete card: its per-arch wheels+# carry no other arch. Strix stays off the shadowing table, so llama.cpp and a lone Strix keep+# it. Mirrors _STRIX_APU_GFX in _runtime_gfx_target (install_python_stack.py)._amd_prefer_discrete_gfx() {_apdg_devs="$1"_apdg_sel="$2"- if ! _amd_gfx_is_shadowing_integrated "$_apdg_sel"; then+ _apdg_strix=""+ case "${3:-}:$_apdg_sel" in+ torch:gfx1150|torch:gfx1151|torch:gfx1152) _apdg_strix=1 ;;+ esac+ # A readable HSA override spoofs every agent, the dGPU included: keep the Strix wheels.+ if [ -n "$_apdg_strix" ] && [ -n "${HSA_OVERRIDE_GFX_VERSION:-}" ] && \+ [ -n "$(_hsa_override_gfx_arch "$HSA_OVERRIDE_GFX_VERSION" 2>/dev/null)" ]; then+ _apdg_strix=""+ fi+ if [ -z "$_apdg_strix" ] && ! _amd_gfx_is_shadowing_integrated "$_apdg_sel"; thenprintf '%s' "$_apdg_sel"return 0fi@@ -4756,6 +4768,11 @@ _amd_prefer_discrete_gfx() {_apdg_others=$(printf '%s\n' "$_apdg_devs" | awk 'NF' | while IFS= read -r _apdg_g; do_amd_gfx_is_shadowing_integrated "$_apdg_g" && continue[ "$_apdg_g" = gfx906 ] && continue+ # No `case` here: bash 3.2 (macOS /bin/sh) misparses its `)` inside `$(...)`.+ if [ -n "$_apdg_strix" ] && { [ "$_apdg_g" = gfx1150 ] || [ "$_apdg_g" = gfx1151 ] || \+ [ "$_apdg_g" = gfx1152 ]; }; then+ continue+ fiprintf '%s\n' "$_apdg_g"done)_apdg_pick=$(printf '%s\n' "$_apdg_others" | awk 'NF' | while IFS= read -r _apdg_g; do@@ -5326,6 +5343,8 @@ _infer_linux_amd_gfx_arch() {fi# On WSL /proc/cpuinfo and lspci still report the host APU, but without the ROCDXG bridge (librocdxg over /dev/dxg) the AMD wheels cannot reach the GPU; keep the CPU fallback there unless that runtime is present. The explicit override above still wins. Mirrors install_python_stack.py._gpu_evidence=""+ # Krackan Point 2 names overlap the gfx1152 patterns below, so both scans test them first (mirrors install_python_stack.py).+ _krackan2_ere='820M|Krackan ?(Point ?)?2|AI 5 (PRO )?330'if [ -e /dev/dxg ] || grep -qi microsoft /proc/version 2>/dev/null; thenfor _d in /opt/rocm/lib /opt/rocm/lib64 /opt/rocm-*/lib /opt/rocm-*/lib64; do{ [ -e "$_d/librocdxg.so" ] || [ -e "$_d/librocdxg.so.1" ]; } && _rocdxg=1 && break@@ -5345,7 +5364,12 @@ _infer_linux_amd_gfx_arch() {echo gfx1150return 0fi- if [ -n "$_gpu_evidence" ] && grep -qiE '860M|840M|Krackan|AI 7 35[05]|AI 5 34[05]|AI 7 PRO 35|AI 5 33' /proc/cpuinfo 2>/dev/null; then+ # Krackan Point 2 has no Linux torch wheel, so a discrete AMD card lspci names wins over it.+ _k2=""+ if [ -n "$_gpu_evidence" ] && grep -qiE "$_krackan2_ere" /proc/cpuinfo 2>/dev/null; then+ _k2=1+ fi+ if [ -z "$_k2" ] && [ -n "$_gpu_evidence" ] && grep -qiE '860M|840M|Krackan|AI 7 35[05]|AI 5 34[05]|AI 7 PRO 35|AI 5 33' /proc/cpuinfo 2>/dev/null; thenecho gfx1152return 0fi@@ -5354,7 +5378,16 @@ _infer_linux_amd_gfx_arch() {_amd_disp=$(lspci -nn 2>/dev/null | grep -E 'VGA compatible controller|3D controller|Display controller' | grep -E 'AMD|ATI' || true)while IFS= read -r _ln; do[ -n "$_ln" ] || continue+ # A Krackan Point 2 line is only the fallback: a covered adapter later still answers.+ if printf '%s\n' "$_ln" | grep -Eqi "$_krackan2_ere"; then+ _k2=1+ continue+ fiif _gfx=$(_infer_amd_gfx_arch_from_gpu_name "$_ln"); then+ # With the Krackan Point 2 CPU, its own iGPU line (Krackan names) is not a peer.+ if [ -n "${_k2:-}" ] && { [ "$_gfx" = gfx1152 ] || [ "$_gfx" = gfx1153 ]; }; then+ continue+ fiecho "$_gfx"return 0fi@@ -5362,6 +5395,10 @@ _infer_linux_amd_gfx_arch() {$_amd_dispEOFfi+ if [ -n "${_k2:-}" ]; then+ echo gfx1153+ return 0+ fireturn 1}@@ -5881,12 +5918,18 @@ get_torch_index_url() {echo "$_base/cpu"; returnfi# Repairing rocminfo cannot help here: the arch would read fine and still have no wheels (#8529). Advice only, same CPU index either way.- if _amd_unsup_gfx=$(_infer_linux_unsupported_amd_gfx_arch 2>/dev/null); then+ # gfx1153 is inferred above (no index family), so it gets this warning without a name match.+ if { [ "${_amd_inferred_gfx:-}" = gfx1153 ] && _amd_unsup_gfx=gfx1153; } || \+ _amd_unsup_gfx=$(_infer_linux_unsupported_amd_gfx_arch 2>/dev/null); then# Scoped to the card named, never to the host: a second AMD GPU here may well have wheels, and nothing has looked at it yet.echo "[WARN] AMD GPU detected ($_amd_unsup_gfx) -- Unsloth has no ROCm PyTorch wheels for that arch, installing CPU PyTorch." >&2echo "[WARN] This is expected on this GPU; repairing rocminfo/amd-smi or setting UNSLOTH_ROCM_GFX_ARCH will not give it ROCm PyTorch." >&2# Torch ends here, llama.cpp does not. `export` is load-bearing: a bare assignment never reaches the re-run (the #8458 mistake).- echo "[INFO] GGUF chat can still use this GPU through Vulkan: export UNSLOTH_LLAMA_CPP_BACKEND=vulkan and re-run this installer (it selects the llama.cpp bundle at install time)." >&2+ if [ "$_amd_unsup_gfx" = gfx1153 ]; then+ echo "[INFO] GGUF chat keeps the llama.cpp HIP build on this GPU (gfx1153 has one); no Vulkan switch is needed." >&2+ else+ echo "[INFO] GGUF chat can still use this GPU through Vulkan: export UNSLOTH_LLAMA_CPP_BACKEND=vulkan and re-run this installer (it selects the llama.cpp bundle at install time)." >&2+ fi# Only arches TheRock actually builds, so Polaris is never pointed at# wheels that do not exist. Untested: nothing routes here on its own.if _amd_therock_extra=$(_therock_device_extra_for_gfx "$_amd_unsup_gfx" 2>/dev/null); then@@ -5938,8 +5981,8 @@ get_torch_index_url() {fi# end of the miscomputing-arch gate -- tests/sh/test_rocm_bad_arch_gate.sh lifts# the block between the header comment above and this line, so keep both exact.- # RDNA 1 / Polaris read fine and still have no wheels: no pytorch.org tag and no AMD- # per-arch index carries their kernels, so the generic tag below installed a multi-GB+ # RDNA 1 / Polaris / gfx1153 read fine and still have no wheels: no pytorch.org tag and no+ # AMD per-arch index carries their kernels (only the opt-in multi-arch index does), so the generic tag below installed a multi-GB# torch that faults on its first GPU op (#8529). Only when EVERY probed arch is one, so# a covered peer keeps its wheels. A readable HSA_OVERRIDE_GFX_VERSION is the arch the# runtime runs, whatever amd-smi reads, so it alone is judged unless an arch is declared.@@ -5947,12 +5990,16 @@ get_torch_index_url() {_amd_hsa_gfx=$(_hsa_override_gfx_arch "${HSA_OVERRIDE_GFX_VERSION:-}" 2>/dev/null) || _amd_hsa_gfx=""[ -n "$_amd_hsa_gfx" ] && [ -z "${UNSLOTH_ROCM_GFX_ARCH:-}" ] && _amd_unsup_src="$_amd_hsa_gfx"_amd_unsup_all=$(printf '%s\n' "$_amd_unsup_src" | sed 's/:.*$//' | tr '[:upper:]' '[:lower:]' \- | awk 'NF { if ($1 !~ /^gfx(1010|1011|1012|803)$/) bad = 1; else if (!seen[$1]++) l = l (l ? ", " : "") $1 }+ | awk 'NF { if ($1 !~ /^gfx(1010|1011|1012|1153|803)$/) bad = 1; else if (!seen[$1]++) l = l (l ? ", " : "") $1 }END { if (!bad && l != "") print l }')if [ -n "$_amd_unsup_all" ]; thenecho "[WARN] AMD GPU detected ($_amd_unsup_all) -- Unsloth has no ROCm PyTorch wheels for that arch, installing CPU PyTorch." >&2echo "[WARN] The ROCm PyTorch wheels carry no kernels for it: they would install, then fail on the first GPU operation." >&2- echo "[INFO] GGUF chat can still use this GPU through Vulkan: export UNSLOTH_LLAMA_CPP_BACKEND=vulkan and re-run this installer (it selects the llama.cpp bundle at install time)." >&2+ if [ "$_amd_unsup_all" = gfx1153 ]; then+ echo "[INFO] GGUF chat keeps the llama.cpp HIP build on this GPU (gfx1153 has one); no Vulkan switch is needed." >&2+ else+ echo "[INFO] GGUF chat can still use this GPU through Vulkan: export UNSLOTH_LLAMA_CPP_BACKEND=vulkan and re-run this installer (it selects the llama.cpp bundle at install time)." >&2+ fiecho "[INFO] If you run this GPU with HSA_OVERRIDE_GFX_VERSION, export it and re-run this installer to keep ROCm PyTorch." >&2if _amd_therock_extra=$(_therock_device_extra_for_gfx "${_amd_unsup_all%%,*}" 2>/dev/null); thenecho "[INFO] Untested: AMD's TheRock publishes nightly ${_amd_unsup_all%%,*} wheels. To try them, export both and re-run:" >&2@@ -6285,7 +6332,7 @@ THEROCK_MIRROR="${UNSLOTH_THEROCK_MIRROR:-https://rocm.nightlies.amd.com/whl-mul# absent because TheRock has no Polaris target._therock_device_extra_for_gfx() {case "$1" in- gfx1010|gfx1011|gfx1012) echo "device-$1" ;;+ gfx1010|gfx1011|gfx1012|gfx1153) echo "device-$1" ;;*) return 1 ;;esac}@@ -7157,7 +7204,23 @@ case "$_torch_index_leaf" in_runtime_gfx=""elif [ "$_gfx_space" = hip ] && [ -z "${UNSLOTH_ROCM_GFX_ARCH:-}" ] && [ -n "$_runtime_gfx" ]; then# Unmasked iGPU listed first: install for the discrete card (#7776), as setup.sh does.- _runtime_gfx=$(_amd_prefer_discrete_gfx "$_gfx_all" "$_runtime_gfx")+ # Strix too: its per-arch wheels would strand a discrete card beside it.+ _gfx_igpu="$_runtime_gfx"+ _runtime_gfx=$(_amd_prefer_discrete_gfx "$_gfx_all" "$_runtime_gfx" torch)+ case "$_gfx_igpu" in+ gfx1150|gfx1151|gfx1152)+ if [ "$_runtime_gfx" != "$_gfx_igpu" ]; then+ # Set by the Strix's own Radeon name; the generic index picked above decides.+ _amd_gpu_radeon=false+ echo "" >&2+ echo " [WARN] Multiple AMD GPUs detected; installing torch for $_runtime_gfx instead of the" >&2+ echo " [WARN] integrated $_gfx_igpu, whose arch-specific wheels carry no $_runtime_gfx kernels." >&2+ echo " [WARN] Set HIP_VISIBLE_DEVICES (or UNSLOTH_ROCM_GFX_ARCH=$_gfx_igpu) and re-run to" >&2+ echo " [WARN] install for the integrated GPU instead." >&2+ echo "" >&2+ fi+ ;;+ esacfifi# An explicit UNSLOTH_ROCM_GFX_ARCH=gfx906 pins the runtime target to the MI50 / Radeon VII path and must win over Strix probe-order detection on a mixed Strix + MI50 host, so the Strix reroute is suppressed when it is set. Normalize a copied HIP gcnArchName (gfx906:sramecc-:xnack- to gfx906) and trim whitespace so the suffix or a stray newline does not defeat the exact gfx906 comparisons below.@@ -7445,7 +7508,7 @@ elif _torch_index_url_is_rocm "$TORCH_INDEX_URL"; then# Only when the routing block ran: a pinned index installs what it names, not the dGPU.if [ "$_torch_index_pinned" = false ] && [ -z "${UNSLOTH_ROCM_GFX_ARCH:-}" ] && [ -n "$_gpu_disp_gfx" ]; then_gpu_disp_pref=$(_amd_prefer_discrete_gfx \- "$(printf '%s\n' "$_gpu_disp_records" | awk -F'|' '$1 != "" { print $1 }')" "$_gpu_disp_gfx")+ "$(printf '%s\n' "$_gpu_disp_records" | awk -F'|' '$1 != "" { print $1 }')" "$_gpu_disp_gfx" torch)if [ -n "$_gpu_disp_pref" ] && [ "$_gpu_disp_pref" != "$_gpu_disp_gfx" ]; thensubstep "Integrated $_gpu_disp_gfx enumerated first; installing for discrete $_gpu_disp_pref"substep "Set UNSLOTH_ROCM_GFX_ARCH=$_gpu_disp_gfx to target the integrated GPU instead."@@ -7524,10 +7587,15 @@ elif _has_amd_rocm_gpu; then_amd_unsup_read=""if [ "$_torch_index_pinned" != true ]; then_amd_unsup_read=$(_probe_amd_gfx_arch 2>/dev/null) || _amd_unsup_read=""+ # Runtime-less gfx1153 is only inferable, as in get_torch_index_url's CPU warning.+ if [ -z "$_amd_unsup_read" ] && \+ [ "$(_infer_linux_amd_gfx_arch 2>/dev/null || true)" = gfx1153 ]; then+ _amd_unsup_read=gfx1153+ fi_amd_hsa_gfx=$(_hsa_override_gfx_arch "${HSA_OVERRIDE_GFX_VERSION:-}" 2>/dev/null) || _amd_hsa_gfx=""[ -n "$_amd_hsa_gfx" ] && [ -z "${UNSLOTH_ROCM_GFX_ARCH:-}" ] && _amd_unsup_read="$_amd_hsa_gfx"_amd_unsup_read=$(printf '%s\n' "$_amd_unsup_read" | sed 's/:.*$//' | tr '[:upper:]' '[:lower:]' \- | awk 'NF { if ($1 !~ /^gfx(1010|1011|1012|803)$/) bad = 1; else if (!seen[$1]++) l = l (l ? ", " : "") $1 }+ | awk 'NF { if ($1 !~ /^gfx(1010|1011|1012|1153|803)$/) bad = 1; else if (!seen[$1]++) l = l (l ? ", " : "") $1 }END { if (!bad && l != "") print l }') || _amd_unsup_read=""fiif [ "$_torch_index_pinned" = true ]; then@@ -7569,8 +7637,12 @@ case "$TORCH_INDEX_URL" in# Scoped to the card, as above: the SDK may still help another one.substep "AMD GPU detected ($_unsup_disp_gfx) -- Unsloth has no ROCm PyTorch wheels for that arch, installing CPU PyTorch." "$C_WARN"substep "Installing the ROCm/HIP SDK will not give this GPU ROCm PyTorch." "$C_WARN"- substep "GGUF chat can still use this GPU through Vulkan: export UNSLOTH_LLAMA_CPP_BACKEND=vulkan and re-run this installer." "$C_WARN"- substep "That variable selects the llama.cpp bundle at install time, so setting it afterwards has no effect until you install or update again." "$C_WARN"+ if [ "$_unsup_disp_gfx" = gfx1153 ]; then+ substep "GGUF chat keeps the llama.cpp HIP build on this GPU (gfx1153 has one); no Vulkan switch is needed."+ else+ substep "GGUF chat can still use this GPU through Vulkan: export UNSLOTH_LLAMA_CPP_BACKEND=vulkan and re-run this installer." "$C_WARN"+ substep "That variable selects the llama.cpp bundle at install time, so setting it afterwards has no effect until you install or update again." "$C_WARN"+ fielsesubstep "AMD GPU detected, but no usable ROCm/HIP install -- installing CPU-only PyTorch." "$C_WARN"substep "Install the ROCm/HIP SDK and re-run this installer for GPU PyTorch." "$C_WARN"diff --git a/studio/backend/tests/test_install_resolve_prebuilt.py b/studio/backend/tests/test_install_resolve_prebuilt.pyindex 6e6af601d88..1f9e69160fe 100644--- a/studio/backend/tests/test_install_resolve_prebuilt.py+++ b/studio/backend/tests/test_install_resolve_prebuilt.py@@ -4078,5 +4078,6 @@ def test_linux_rdna2_plan_keeps_its_rocm_bundle(linux_no_rocm_env):def test_linux_no_rocm_set_matches_the_torch_installer():# Duplicated because this module is vendored standalone; keep the two in step.+ # gfx1153 is torch-only: no torch wheel, but the llama.cpp HIP route is left alone.ips = importlib.import_module("install_python_stack")- assert ilp.LINUX_NO_ROCM_GFX_TARGETS == ips._LINUX_UNCOVERED_AMD_GFX+ assert ilp.LINUX_NO_ROCM_GFX_TARGETS == ips._LINUX_UNCOVERED_AMD_GFX - {"gfx1153"}diff --git a/studio/backend/tests/test_krackan2_health_gate.py b/studio/backend/tests/test_krackan2_health_gate.pynew file mode 100644index 00000000000..636a89cec29--- /dev/null+++ b/studio/backend/tests/test_krackan2_health_gate.py@@ -0,0 +1,27 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""A lone Linux Krackan Point 2 (gfx1153) gets CPU torch on purpose, so the health gate must not+read it as a gfx1152 the installers would have served and prompt for a repair."""++from __future__ import annotations++import pytest++import utils.hardware.hardware as hw+++ "system,name,expected",+ [+ ("Linux", "AMD Radeon 820M", False),+ ("Linux", "AMD Ryzen AI 5 330 w/ Radeon Graphics", False),+ ("Linux", "AMD Radeon 860M", True),+ ("Windows", "AMD Radeon 820M", True),+ ],+)+def test_a_linux_krackan_point_2_cannot_establish_a_mismatch(monkeypatch, system, name, expected):+ # Windows routing is unchanged: the multi-arch route serves gfx1153 there.+ monkeypatch.setattr(hw.platform, "system", lambda: system)+ monkeypatch.setattr(hw, "_linux_kfd_reports_an_amd_gpu", lambda: True)+ assert hw._amd_device_can_establish_a_mismatch({"name": name}) is expecteddiff --git a/studio/backend/utils/hardware/hardware.py b/studio/backend/utils/hardware/hardware.pyindex 1d8ef1dc89e..e485dc2c488 100644--- a/studio/backend/utils/hardware/hardware.py+++ b/studio/backend/utils/hardware/hardware.py@@ -1042,6 +1042,10 @@ _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"})+# 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"+def _rocm_supported_gfx_here() -> "frozenset[str]":"""The arches the installers ship a ROCm wheel for on THIS platform."""@@ -1071,6 +1075,11 @@ def _amd_device_can_establish_a_mismatch(device: Dict[str, Any]) -> bool:if gfx]if not candidates:+ # A lone Linux gfx1153 is declined by the installers, so its CPU wheel is no fault.+ if platform.system() != "Windows" and re.search(+ _LINUX_KRACKAN2_NAME_RE, device.get("name") or "", re.IGNORECASE+ ):+ return False# The DirectX registry publishes AdapterFamily only when the driver wrote one, so a supported Windows card can arrive with no arch. setup.ps1 answers that from the marketing name; the probe below can only speak for Linux._named = _rocm_supported_gfx_from_gpu_name(device.get("name") or "")if _named:diff --git a/studio/install_python_stack.py b/studio/install_python_stack.pyindex bd3b1c96305..e12f388a496 100644--- a/studio/install_python_stack.py+++ b/studio/install_python_stack.py@@ -2432,6 +2432,11 @@ def _unsupported_gfx_arch_from_gpu_name(name: str) -> "str | None":return None+# Krackan Point 2 names overlap the Krackan patterns of the shared name table (gfx1152);+# the Linux runtime-less paths test them first so the uncovered-arch fallback sees gfx1153.+_LINUX_KRACKAN2_NAME_RE = r"820M|Krackan ?(?:Point ?)?2|AI 5 (?:PRO )?330"++def _linux_amd_gfx_from_cpuinfo() -> "str | None":"""Infer gfx arch from /proc/cpuinfo on integrated AMD APUs (Strix Halo/Point)."""try:@@ -2442,6 +2447,8 @@ def _linux_amd_gfx_from_cpuinfo() -> "str | None":return "gfx1151"if re.search(r"890M|880M|Strix Point|HX 37[05]|AI 9 HX|AI 9 36[05]", text, re.IGNORECASE):return "gfx1150"+ if re.search(_LINUX_KRACKAN2_NAME_RE, text, re.IGNORECASE):+ return "gfx1153"if re.search(r"860M|840M|Krackan|AI 7 35[05]|AI 5 34[05]|AI 7 PRO 35|AI 5 33", text, re.IGNORECASE):@@ -2449,12 +2456,13 @@ def _linux_amd_gfx_from_cpuinfo() -> "str | None":return None-def _linux_amd_gfx_from_lspci() -> "str | None":+def _linux_amd_gfx_from_lspci(beside_krackan2: bool = False) -> "str | None":"""First AMD display-class lspci line mapping to a known gfx arch. A non-AMDcontroller can enumerate first (Intel/ASPEED before an AMD dGPU), so scanthem all. The vendor guard is case-SENSITIVE: a -i "ATI" would match"CorporATIon" on every Intel/NVIDIA line. Whole-line matching also survives- the 0000: PCI domain prefix."""+ the 0000: PCI domain prefix. beside_krackan2 skips that APU's own iGPU line, so only a+ discrete peer answers."""lspci = shutil.which("lspci")if not lspci:return None@@ -2472,15 +2480,21 @@ def _linux_amd_gfx_from_lspci() -> "str | None":return Noneif result.returncode != 0:return None+ # A Krackan Point 2 line (gfx1153, no Linux torch wheel) is only the fallback: a covered+ # adapter later in the list still answers, as for the CPU-name case.+ krackan2 = beside_krackan2for line in result.stdout.splitlines():if not re.search(r"VGA compatible controller|3D controller|Display controller", line, re.I):continueif not re.search(r"AMD|ATI", line):continue+ if re.search(_LINUX_KRACKAN2_NAME_RE, line, re.IGNORECASE):+ krackan2 = True+ continuearch = _gfx_arch_from_gpu_name(line)- if arch:+ if arch and not (krackan2 and arch in ("gfx1152", "gfx1153")):return arch- return None+ return "gfx1153" if krackan2 and not beside_krackan2 else Nonedef _is_wsl() -> bool:@@ -2545,6 +2559,9 @@ def _infer_linux_amd_gfx_arch() -> "str | None":# fallback reads the same PCI space and would find nothing here either.return Nonecpu_gfx = _linux_amd_gfx_from_cpuinfo()+ if cpu_gfx == "gfx1153":+ # Krackan Point 2 has no Linux torch wheel, so a discrete AMD card lspci names wins.+ return _linux_amd_gfx_from_lspci(beside_krackan2 = True) or cpu_gfxif cpu_gfx:return cpu_gfxreturn _linux_amd_gfx_from_lspci()@@ -3199,6 +3216,12 @@ _GENERIC_ROCM_WHEEL_GFX: frozenset[str] = frozenset()+# Strix APUs: listed first beside a discrete card, they defer to it for torch alone (their+# per-arch wheels carry no other arch). Not shadowing: llama.cpp and a lone Strix keep them.+# install.sh's _amd_prefer_discrete_gfx "torch" mode holds the same list.+_STRIX_APU_GFX: "frozenset[str]" = frozenset({"gfx1150", "gfx1151", "gfx1152"})++# Arches whose only wheel route is unreachable once a second GPU is present, so they must# never depose an integrated card. gfx906's rocm6.3 route is gated on it being the sole# detected arch (_runtime_target_is_gfx906), which no mixed host satisfies.@@ -3332,9 +3355,13 @@ def _gfx_has_a_wheel_route(gfx: "str | None") -> bool:return bool(gfx) and (gfx in _GENERIC_ROCM_WHEEL_GFX or gfx in _GFX_TO_AMD_INDEX_ARCH)-# RDNA 1 and Polaris: no Linux index this installer picks carries their kernels (#8529).+# RDNA 1, Polaris and gfx1153 (Krackan Point 2): no Linux index this installer picks carries+# their kernels (#8529, #11815); the generic wheel loads and faults on first use. gfx1153 is+# torch-only here: llama.cpp's LINUX_NO_ROCM_GFX_TARGETS keeps its HIP route.# install.sh's get_torch_index_url holds the same list.-_LINUX_UNCOVERED_AMD_GFX: "frozenset[str]" = frozenset({"gfx1010", "gfx1011", "gfx1012", "gfx803"})+_LINUX_UNCOVERED_AMD_GFX: "frozenset[str]" = frozenset(+ {"gfx1010", "gfx1011", "gfx1012", "gfx1153", "gfx803"}+)def _linux_host_only_uncovered_amd(*arch_lists: "list[str]") -> "str | None":@@ -3618,7 +3645,15 @@ def _runtime_gfx_target(if gfx_deviceselse None)- if runtime_gfx in _SHADOWING_INTEGRATED_GFX and not _visible_devices_pinned():+ # Strix defers only where the discrete card's wheel can be installed and will run: a readable+ # ROCm version (the versionless path has no generic tag for it) and no HSA override (which+ # spoofs every agent, the dGPU included). Otherwise it keeps its own per-arch index, as before.+ _strix_first = (+ runtime_gfx in _STRIX_APU_GFX+ and _detect_rocm_version() is not None+ and _hsa_override_gfx_arch(os.environ.get("HSA_OVERRIDE_GFX_VERSION")) is None+ )+ if (runtime_gfx in _SHADOWING_INTEGRATED_GFX or _strix_first) and not _visible_devices_pinned():# Unpinned mixed host: only enumeration order put the integrated GPU first, and the# wheel family is picked for ONE arch, so letting the APU decide strands the discrete# card. Same #7776 preference _detect_windows_gfx_arch applies, stopping at a set mask@@ -3629,7 +3664,9 @@ def _runtime_gfx_target(_others = [gfor g in gfx_devices- if g not in _SHADOWING_INTEGRATED_GFX and g not in _MIXED_HOST_UNROUTABLE+ if g not in _SHADOWING_INTEGRATED_GFX+ and g not in _MIXED_HOST_UNROUTABLE+ and not (_strix_first and g in _STRIX_APU_GFX)]# Prefer a discrete card the installer can serve: deposing a routable APU for one no# index carries (an RDNA 1 dGPU beside a gfx1103) trades a repairable GPU for nothing.@@ -6587,8 +6624,16 @@ def _ensure_rocm_torch() -> "bool | None":# This branch installs for the inferred arch without asking the mask layers, so an# ordinal the guess cannot account for reaches the wheel the preflight already# declines. An explicit arch is exempt above, and no ordinal contradicts it.- and (_gfx_override_env or _runtime_gfx_target(_inferred_linux_gfx)[0] is not None)+ and (+ _gfx_override_env+ or (_inferred_target := _runtime_gfx_target(_inferred_linux_gfx)[0]) is not 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:+ _inferred_linux_gfx = _inferred_targetindex_url = _amd_arch_index_url(_inferred_linux_gfx)if index_url is not None:# The bare arch _amd_arch_index_url resolved the URL from: stripping the suffix there is@@ -6670,8 +6715,8 @@ def _ensure_rocm_torch() -> "bool | None":_uncovered = _linux_host_only_uncovered_amd(gfx_codes, _host_codes)if _uncovered and not rocm_torch_ready:_safe_print(- f" AMD {_uncovered}: no ROCm PyTorch wheel carries kernels for this GPU -- "- f"not installing ROCm torch for it.\n"+ f" AMD {_uncovered}: no ROCm PyTorch wheel Unsloth installs carries kernels for "+ f"this GPU -- not installing ROCm torch for it.\n")return_strix_gfx = _AMD_ARCH_INDEX_FLOOR_GFX@@ -6716,8 +6761,12 @@ def _ensure_rocm_torch() -> "bool | None":_clear_confirmed_hsa_spoof(_selected_gfx)else:_gfx_str = ", ".join(sorted(_detected_strix))+ # Unpinned, the discrete-card preference in _runtime_gfx_target moved it.+ _selector = (+ "HIP_VISIBLE_DEVICES" if _visible_devices_pinned() else "the discrete GPU"+ )_safe_print(- f" AMD per-gfx GPU ({_gfx_str}) present but HIP_VISIBLE_DEVICES "+ f" AMD per-gfx GPU ({_gfx_str}) present but {_selector} "f"selects another runtime target ({_runtime_gfx});\n"f" skipping AMD per-gfx index override.\n")diff --git a/studio/setup.sh b/studio/setup.shindex c2b47685dec..14dde7493fc 100755--- a/studio/setup.sh+++ b/studio/setup.sh@@ -4450,6 +4450,26 @@ elif [ "$_setup_amd_detected" = true ]; then# Name-based arch inference when tools don't report gfx (mirrors setup.ps1 nameArchTable)elif [ -z "$_setup_gfx" ] && [ -n "$_setup_mkt" ]; then_setup_gfx=$(_setup_supported_gfx_from_name "$_setup_mkt") || _setup_gfx=""+ # Krackan Point 2 names overlap the table's gfx1152 patterns (install.sh tests them first).+ # amd-smi names only the first device, so a covered lspci peer (the same rule as+ # _setup_unsupported_gfx_any) keeps the table's answer, as before.+ _setup_k2_name_ere='820M|Krackan ?(Point ?)?2|AI 5 (PRO )?330'+ if printf '%s\n' "$_setup_mkt" | grep -Eqi "$_setup_k2_name_ere"; then+ _setup_k2_peer=""+ if command -v lspci >/dev/null 2>&1; 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+ _setup_k2_peer=1+ break+ fi+ done <<EOF+$(lspci -nn 2>/dev/null | grep -E 'VGA compatible controller|3D controller|Display controller' | grep -E 'AMD|ATI' || true)+EOF+ fi+ [ -n "$_setup_k2_peer" ] || _setup_gfx=gfx1153+ fiif [ -n "$_setup_gfx" ]; thensubstep "gfx arch inferred from GPU name: $_setup_gfx"substep "Tip: set UNSLOTH_ROCM_GFX_ARCH=$_setup_gfx to skip inference next time"@@ -4498,6 +4518,7 @@ elif [ "$_setup_amd_detected" = true ]; then# Deliberately NOT written back into _setup_mkt: the supported table keys on it and# would start feeding --rocm-gfx to the prebuilt and whisper commands on the KFD path._setup_unsupported_gfx_any() {+ _setup_k2_ere='820M|Krackan ?(Point ?)?2|AI 5 (PRO )?330' # install.sh's _krackan2_ere# Peer guard FIRST, so it covers the named hit too: amd-smi reports one market name,# the first device's, so where an RX 5700 precedes an RX 7900 the name IS the 5700.# Only when lspci can answer: with no adapter list there is no peer to find, and@@ -4507,6 +4528,8 @@ elif [ "$_setup_amd_detected" = true ]; then_setup_unsup_pci=$(lspci -nn 2>/dev/null | grep -E 'VGA compatible controller|3D controller|Display controller' | grep -E 'AMD|ATI' || true)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" && continueif _setup_supported_gfx_from_name "$_setup_unsup_ln" >/dev/null 2>&1; thenreturn 1fi@@ -4514,6 +4537,13 @@ elif [ "$_setup_amd_detected" = true ]; then$_setup_unsup_pciEOFfi+ # Krackan Point 2 (gfx1153) before the name tables, which map its names to gfx1152; the+ # CPU name counts only beside an AMD display adapter, as in install.sh.+ if printf '%s\n%s\n' "$1" "$_setup_unsup_pci" | grep -Eqi "$_setup_k2_ere" \+ || { [ -n "$_setup_unsup_pci" ] && grep -Eqi "$_setup_k2_ere" /proc/cpuinfo 2>/dev/null; }; then+ echo gfx1153+ return 0+ fi# Only on a HIT: a nonempty but unmapped name (a generic "AMD Radeon Graphics"# from rocminfo) used to end the lookup here, so the lspci scan below never ran# and the report fell through to the plain "AMD ROCm" line this change replaces.@@ -4569,7 +4599,7 @@ EOF{ [ -n "$_setup_unsup_hsa" ] || [ -n "${UNSLOTH_ROCM_GFX_ARCH:-}" ] || [ -z "${ROCR_VISIBLE_DEVICES:-}" ]; }; then_setup_unsup_gfx=$(printf '%s\n' "$_setup_unsup_cur" "$_setup_unsup_inv" | sed 's/:.*$//' \| tr '[:upper:]' '[:lower:]' \- | awk 'NF { if ($1 !~ /^gfx(1010|1011|1012|803)$/) bad = 1; else if (!seen[$1]++) l = l (l ? ", " : "") $1 }+ | awk 'NF { if ($1 !~ /^gfx(1010|1011|1012|1153|803)$/) bad = 1; else if (!seen[$1]++) l = l (l ? ", " : "") $1 }END { if (!bad && l != "") print l }')fiif [ -z "$_setup_unsup_gfx" ] && [ -n "$_setup_gfx" ] && [ -n "$_setup_mkt" ]; then@@ -4593,9 +4623,18 @@ EOFsubstep "torch stays CPU-only: Unsloth training and GPU inference are unavailable."substep "No HIP SDK install and no UNSLOTH_ROCM_GFX_ARCH value gives this GPU one."fi- substep "GGUF chat can still use this GPU through Vulkan: export UNSLOTH_LLAMA_CPP_BACKEND=vulkan,"- substep "then re-run the installer. It picks the llama.cpp bundle at install time, so setting"- substep "it afterwards has no effect until you install or update again."+ if [ "$_setup_unsup_gfx" = gfx1153 ]; then+ substep "GGUF chat keeps the llama.cpp HIP build on this GPU (gfx1153 has one); no Vulkan switch is needed."+ else+ substep "GGUF chat can still use this GPU through Vulkan: export UNSLOTH_LLAMA_CPP_BACKEND=vulkan,"+ substep "then re-run the installer. It picks the llama.cpp bundle at install time, so setting"+ substep "it afterwards has no effect until you install or update again."+ fi+ # gfx1153 keeps its llama.cpp HIP bundle: forward the arch, which a runtime-less probe+ # cannot read. RDNA 1 / Polaris have none, so they stay unforwarded.+ if [ "$_setup_unsup_gfx" = gfx1153 ] && [ -z "$_setup_gfx" ]; then+ _setup_gfx=gfx1153+ fielif [ -n "$_setup_mkt" ]; then# Name without an arch, as install.sh does. Deliberately BELOW the unsupported# arm above: a card with no ROCm wheels also reaches here with a name, anddiff --git a/tests/studio/install/test_linux_amd_strix_dgpu_gfx1153.py b/tests/studio/install/test_linux_amd_strix_dgpu_gfx1153.pynew file mode 100644index 00000000000..ff470a780fd--- /dev/null+++ b/tests/studio/install/test_linux_amd_strix_dgpu_gfx1153.py@@ -0,0 +1,656 @@+# SPDX-License-Identifier: AGPL-3.0-only+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0++"""Linux AMD torch routing for two host shapes no table handled.++Strix APU (gfx1150-gfx1152) listed ahead of a discrete RDNA card: the device-0 pick sent torch+to the Strix-only per-arch index, whose wheels carry no kernels for the discrete card. A lone+gfx1153 (Krackan Point 2) was in no Linux table, so it got the generic ROCm wheel (no gfx1153+kernels) with no warning (#11815, #9932).+"""++from __future__ import annotations++import os+import shutil+import subprocess+import sys+from pathlib import Path++import pytest++_HERE = Path(__file__).resolve().parent+PACKAGE_ROOT = _HERE.parents[2]+sys.path.insert(0, str(_HERE))+sys.path.insert(0, str(PACKAGE_ROOT / "tests" / "_shared"))++import test_missing_kernel_arch_routing_9396 as routing # noqa: E402+import test_rocm_support as rocm_support # noqa: E402+import test_unsupported_arch_routing_guards_8529 as guards # noqa: E402++stack_mod = routing.stack_mod+_INSTALL_SH = PACKAGE_ROOT / "install.sh"+_POSIX = pytest.mark.skipif(+ os.name == "nt" or shutil.which("bash") is None, reason = "POSIX shell only"+)+_STRIX_INDEX = "repo.amd.com/rocm/whl/gfx1151"++[email protected](autouse = True)+def _reset_probe(monkeypatch):+ for name in (+ "HSA_OVERRIDE_GFX_VERSION",+ "ROCR_VISIBLE_DEVICES",+ "HIP_VISIBLE_DEVICES",+ "CUDA_VISIBLE_DEVICES",+ "UNSLOTH_ROCM_GFX_ARCH",+ ):+ monkeypatch.delenv(name, raising = False)+ stack_mod._invalidate_torch_runtime_probe()+ yield+ stack_mod._invalidate_torch_runtime_probe()+++def _sh_routing_leaf(arches, env = ""):+ """install.sh's routing block on a rocminfo stub; the index leaf it leaves selected."""+ source = _INSTALL_SH.read_text(encoding = "utf-8")+ start = source.find('case "$_torch_index_leaf" in\n rocm[0-9]*)')+ end = source.find("\nfi # _torch_index_pinned guard", start)+ assert start >= 0 and end >= 0+ script = (+ "set -euo pipefail\n"+ + rocm_support._extract_sh_function_body(source, "_rocm_leaf_below")+ + "\n"+ + rocm_support._gpu_record_helpers(source)+ + "\n"+ + 'TORCH_INDEX_URL="https://download.pytorch.org/whl/rocm7.1"\n'+ + '_torch_index_leaf="rocm7.1"\n'+ + "_torch_index_pinned=false\nSKIP_TORCH=false\n_amd_gpu_radeon=false\n"+ + "_gfx_rocm64_target=false\n"+ + "unset HSA_OVERRIDE_GFX_VERSION HIP_VISIBLE_DEVICES ROCR_VISIBLE_DEVICES\n"+ + "unset CUDA_VISIBLE_DEVICES UNSLOTH_ROCM_GFX_ARCH UNSLOTH_PYTORCH_MIRROR\n"+ + "unset UNSLOTH_AMD_ROCM_MIRROR\n"+ + "rocminfo() { printf '"+ + "".join(f"Name: {a}\\n" for a in arches)+ + "'; }\n"+ + "".join(f"export {a}\n" for a in env.split())+ + source[start:end]+ + '\nprintf "URL:%s\\n" "$TORCH_INDEX_URL"\n'+ )+ out = subprocess.run(["bash", "-c", script], capture_output = True, text = True, timeout = 60)+ assert out.returncode == 0, out.stderr+ url = out.stdout.strip().rsplit("URL:", 1)[-1].rstrip("/")+ return url.rsplit("/", 1)[-1].lower()+++# ── Strix APU + discrete card ───────────────────────────────────────────────+++ "devices,expected",+ [+ (("gfx1151", "gfx1100"), "gfx1100"),+ (("gfx1151", "gfx1201"), "gfx1201"),+ (("gfx1150", "gfx1101"), "gfx1101"),+ ],+)+def test_python_target_skips_a_leading_strix_apu(devices, expected):+ calls = routing._run_install(gfx_devices = devices, rocm_version = (7, 1))+ assert _STRIX_INDEX not in calls and "whl/gfx1150" not in calls, calls+ assert f"installing for {expected}" in routing._run_install.printed+++def test_python_strix_plus_rdna3_installs_the_generic_wheel():+ calls = routing._run_install(gfx_devices = ("gfx1151", "gfx1100"), rocm_version = (7, 1))+ assert "download.pytorch.org/whl/rocm7.1" in calls, calls+++def test_python_strix_plus_rdna4_installs_the_rdna4_family():+ calls = routing._run_install(gfx_devices = ("gfx1151", "gfx1201"), rocm_version = (7, 1))+ assert "repo.amd.com/rocm/whl/gfx120X-all" in calls, calls+++ "devices,env",+ [+ (("gfx1151",), {}),+ (("gfx1151", "gfx1100"), {"HIP_VISIBLE_DEVICES": "0"}),+ (("gfx1151", "gfx1100"), {"UNSLOTH_ROCM_GFX_ARCH": "gfx1151"}),+ ],+)+def test_python_lone_or_selected_strix_keeps_its_index(devices, env):+ calls = routing._run_install(gfx_devices = devices, rocm_version = (7, 1), env = env)+ assert _STRIX_INDEX in calls, calls+++@_POSIX+ "arches,env,expected",+ [+ (("gfx1151", "gfx1100"), "", "rocm7.1"),+ (("gfx1151", "gfx1201"), "", "gfx120x-all"),+ (("gfx1152", "gfx1102"), "", "rocm7.1"),+ ],+)+def test_install_sh_skips_a_leading_strix_apu(arches, env, expected):+ assert _sh_routing_leaf(arches, env) == expected+++@_POSIX+ "arches,env",+ [+ (("gfx1151",), ""),+ (("gfx1151", "gfx1100"), "HIP_VISIBLE_DEVICES=0"),+ (("gfx1151", "gfx1100"), "CUDA_VISIBLE_DEVICES=0"),+ (("gfx1151", "gfx1100"), "UNSLOTH_ROCM_GFX_ARCH=gfx1151"),+ ],+)+def test_install_sh_lone_or_selected_strix_keeps_its_index(arches, env):+ assert _sh_routing_leaf(arches, env) == "gfx1151"+++@_POSIX+def test_install_sh_strix_reroute_names_the_discrete_choice():+ source = _INSTALL_SH.read_text(encoding = "utf-8")+ assert '"$_runtime_gfx" torch)' in source+ assert '"$_gpu_disp_gfx" torch)' in source+++# ── lone gfx1153 ────────────────────────────────────────────────────────────++[email protected]("ver", [(6, 4), (7, 2)])+def test_python_lone_gfx1153_gets_no_kernel_less_rocm_torch(ver):+ calls = routing._run_install(gfx_devices = ("gfx1153",), rocm_version = ver)+ assert "download.pytorch.org" not in calls and "repo.amd.com" not in calls, calls+ assert "AMD gfx1153: no ROCm PyTorch wheel" in routing._run_install.printed+++def test_python_gfx1153_beside_a_dgpu_keeps_the_dgpu_route():+ calls = routing._run_install(gfx_devices = ("gfx1153", "gfx1100"), rocm_version = (7, 2))+ assert "download.pytorch.org/whl/rocm7.2" in calls, calls+++def test_python_gfx1153_spoofed_to_a_covered_arch_keeps_rocm():+ calls = routing._run_install(+ gfx_devices = ("gfx1153",),+ rocm_version = (7, 2),+ env = {"HSA_OVERRIDE_GFX_VERSION": "11.0.0"},+ )+ assert "download.pytorch.org/whl/rocm7.2" in calls, calls+++@_POSIX[email protected]("tag", ["rocm7.2", "rocm6.4", ""])+def test_install_sh_lone_gfx1153_warns_and_takes_cpu(tag):+ url, err = guards._run_sh_get_torch_index_url("gfx1153", rocm_tag = tag)+ assert url.endswith("/cpu"), (url, err)+ assert "AMD GPU detected (gfx1153) -- Unsloth has no ROCm PyTorch wheels" in err, err+++@_POSIX+def test_install_sh_gfx1153_beside_a_dgpu_keeps_the_generic_tag():+ url, err = guards._run_sh_get_torch_index_url("gfx1153\ngfx1100", rocm_tag = "rocm7.2")+ assert url.endswith("/rocm7.2"), (url, err)+++@_POSIX+def test_install_sh_names_the_multiarch_device_extra_for_gfx1153():+ body = rocm_support._extract_sh_function_body(+ _INSTALL_SH.read_text(encoding = "utf-8"), "_therock_device_extra_for_gfx"+ )+ out = subprocess.run(+ ["bash", "-c", body + "\n_therock_device_extra_for_gfx gfx1153 || echo none"],+ capture_output = True,+ text = True,+ timeout = 30,+ )+ assert out.stdout.strip() == "device-gfx1153", out+++# ── gfx1153 inferred without a runtime ──────────────────────────────────────++# Krackan Point 2 names the broader Krackan patterns also match; gfx1152 hosts stay gfx1152.+_KRACKAN2_TEXT = [+ "model name : AMD Ryzen AI 5 330 w/ Radeon 820M\n",+ "Advanced Micro Devices, Inc. [AMD/ATI] Krackan Point 2 [Radeon Graphics]\n",+]+_KRACKAN_TEXT = "model name : AMD Ryzen AI 7 350 w/ Radeon 860M\n"++[email protected]("text", _KRACKAN2_TEXT)+def test_python_cpuinfo_names_gfx1153_before_gfx1152(text, monkeypatch):+ monkeypatch.setattr(Path, "read_text", lambda *a, **k: text)+ assert stack_mod._linux_amd_gfx_from_cpuinfo() == "gfx1153"+ monkeypatch.setattr(Path, "read_text", lambda *a, **k: _KRACKAN_TEXT)+ assert stack_mod._linux_amd_gfx_from_cpuinfo() == "gfx1152"+++def test_python_lspci_names_gfx1153_before_gfx1152(monkeypatch):+ line = "c4:00.0 VGA compatible controller [0300]: " + _KRACKAN2_TEXT[1]+ monkeypatch.setattr(stack_mod.shutil, "which", lambda _n: "/usr/bin/lspci")+ monkeypatch.setattr(+ stack_mod.subprocess, "run", lambda *a, **k: subprocess.CompletedProcess(a, 0, line, "")+ )+ assert stack_mod._linux_amd_gfx_from_lspci() == "gfx1153"+++def _sh_infer(+ tmp_path,+ cpuinfo,+ lspci = "",+):+ """install.sh _infer_linux_amd_gfx_arch on a stub cpuinfo, PCI evidence and lspci."""+ source = _INSTALL_SH.read_text(encoding = "utf-8")+ body = rocm_support._extract_sh_function_body(source, "_infer_linux_amd_gfx_arch")+ (tmp_path / "cpuinfo").write_text(cpuinfo, encoding = "utf-8")+ body = body.replace("/proc/cpuinfo", str(tmp_path / "cpuinfo"))+ body = body.replace("/proc/version", "/dev/null")+ script = (+ "_amd_gpu_present_via_pci() { return 0; }\n"+ + rocm_support._extract_sh_function_body(source, "_infer_amd_gfx_arch_from_gpu_name")+ + "\n"+ + f"lspci() {{ printf '%s\\n' '{lspci}'; }}\n"+ + "unset UNSLOTH_ROCM_GFX_ARCH\n"+ + body+ + "\n_infer_linux_amd_gfx_arch || echo none\n"+ )+ out = subprocess.run(["bash", "-c", script], capture_output = True, text = True, timeout = 30)+ return out.stdout.strip().splitlines()[-1], out.stderr+++@_POSIX+def test_install_sh_cpuinfo_names_gfx1153_before_gfx1152(tmp_path):+ assert _sh_infer(tmp_path, _KRACKAN2_TEXT[0])[0] == "gfx1153"+ assert _sh_infer(tmp_path, _KRACKAN_TEXT)[0] == "gfx1152"+++@_POSIX+def test_install_sh_lspci_names_gfx1153_before_gfx1152(tmp_path):+ line = "c4:00.0 VGA compatible controller [0300]: " + _KRACKAN2_TEXT[1].strip()+ assert _sh_infer(tmp_path, "model name : AMD\n", lspci = line)[0] == "gfx1153"+++@_POSIX+def test_install_sh_inferred_gfx1153_warns_and_takes_cpu(monkeypatch):+ # No rocminfo/amd-smi reading: the arch comes only from _infer_linux_amd_gfx_arch.+ stubs = guards._INDEX_URL_STUBS+ probe = next(ln for ln in stubs.splitlines() if ln.startswith("_probe_amd_gfx_arch()"))+ monkeypatch.setattr(+ guards, "_INDEX_URL_STUBS", stubs.replace(probe, "_probe_amd_gfx_arch() { :; }")+ )+ url, err = guards._run_sh_get_torch_index_url("gfx1153")+ assert url.endswith("/cpu"), (url, err)+ assert "AMD GPU detected (gfx1153) -- Unsloth has no ROCm PyTorch wheels" in err, err+++# ── Strix deferral only where the discrete wheel installs and runs ─────────+++def test_python_strix_keeps_its_index_when_the_rocm_version_is_unreadable():+ # Versionless: no generic tag can serve the dGPU, so the Strix route main installed stays.+ calls = routing._run_install(gfx_devices = ("gfx1151", "gfx1100"), rocm_version = None)+ assert _STRIX_INDEX in calls, calls++[email protected]("devices", [("gfx1151", "gfx1100"), ("gfx1151", "gfx1201")])+def test_python_strix_keeps_its_index_under_an_hsa_override(devices):+ # The override spoofs every agent, the dGPU included, so dGPU wheels would never load.+ calls = routing._run_install(+ gfx_devices = devices, rocm_version = (7, 1), env = {"HSA_OVERRIDE_GFX_VERSION": "11.5.1"}+ )+ assert "gfx120X-all" not in calls and "whl/rocm7.1" not in calls, calls+++def test_python_inferred_install_uses_the_deferred_discrete_card():+ calls = routing._run_install(+ gfx_devices = ("gfx1151", "gfx1201"),+ inferred = "gfx1151",+ rocm_version = (7, 1),+ rocm_gpu_visible = False,+ )+ assert "repo.amd.com/rocm/whl/gfx120X-all" in calls and _STRIX_INDEX not in calls, calls+++@_POSIX[email protected]("hsa,expected", [("", "gfx1201"), ("11.5.1", "gfx1151")])+def test_install_sh_strix_keeps_its_index_under_an_hsa_override(hsa, expected):+ source = _INSTALL_SH.read_text(encoding = "utf-8")+ script = (+ rocm_support._gpu_record_helpers(source)+ + "\nunset HIP_VISIBLE_DEVICES ROCR_VISIBLE_DEVICES CUDA_VISIBLE_DEVICES\n"+ + (+ f"export HSA_OVERRIDE_GFX_VERSION={hsa}\n"+ if hsa+ else "unset HSA_OVERRIDE_GFX_VERSION\n"+ )+ + "_amd_prefer_discrete_gfx \"$(printf 'gfx1151\\ngfx1201')\" gfx1151 torch\n"+ )+ out = subprocess.run(["bash", "-c", script], capture_output = True, text = True, timeout = 60)+ assert out.stdout.strip() == expected, out+++@_POSIX+def test_install_sh_strix_handoff_clears_the_radeon_downloader():+ # rocminfo's "Radeon 8060S" set the flag; the dGPU's generic index must not be overridden.+ source = _INSTALL_SH.read_text(encoding = "utf-8")+ start = source.find('case "$_torch_index_leaf" in\n rocm[0-9]*)')+ end = source.find("\nfi # _torch_index_pinned guard", start)+ script = (+ "set -euo pipefail\n"+ + rocm_support._extract_sh_function_body(source, "_rocm_leaf_below")+ + "\n"+ + rocm_support._gpu_record_helpers(source)+ + "\n"+ + 'TORCH_INDEX_URL="https://download.pytorch.org/whl/rocm7.1"\n'+ + '_torch_index_leaf="rocm7.1"\n'+ + "_torch_index_pinned=false\nSKIP_TORCH=false\n_amd_gpu_radeon=true\n"+ + "_gfx_rocm64_target=false\n"+ + "unset HSA_OVERRIDE_GFX_VERSION HIP_VISIBLE_DEVICES ROCR_VISIBLE_DEVICES\n"+ + "unset CUDA_VISIBLE_DEVICES UNSLOTH_ROCM_GFX_ARCH UNSLOTH_PYTORCH_MIRROR\n"+ + "unset UNSLOTH_AMD_ROCM_MIRROR\n"+ + "rocminfo() { printf 'Name: gfx1151\\nName: gfx1030\\n'; }\n"+ + source[start:end]+ + '\nprintf "RADEON:%s\\n" "$_amd_gpu_radeon"\n'+ )+ out = subprocess.run(["bash", "-c", script], capture_output = True, text = True, timeout = 60)+ assert out.returncode == 0, out.stderr+ assert out.stdout.strip().rsplit("RADEON:", 1)[-1] == "false", out.stdout+++@_POSIX+def test_install_sh_final_summary_keeps_the_inferred_gfx1153():+ source = _INSTALL_SH.read_text(encoding = "utf-8")+ start = source.find("elif _has_amd_rocm_gpu; then\n # The arch read fine")+ end = source.find('elif [ "$_torch_index_leaf" = xpu ]; then', start)+ assert start >= 0 and end >= 0+ script = (+ rocm_support._extract_sh_function_body(source, "_hsa_override_gfx_arch")+ + "\nstep() { printf 'STEP:%s\\n' \"$2\"; }\n"+ + "_has_amd_rocm_gpu() { return 0; }\n_probe_amd_gfx_arch() { :; }\n"+ + "_infer_linux_amd_gfx_arch() { echo gfx1153; }\n"+ + "_torch_index_pinned=false\nunset HSA_OVERRIDE_GFX_VERSION UNSLOTH_ROCM_GFX_ARCH\n"+ + "if false; then :\n"+ + source[start:end]+ + "fi\n"+ )+ out = subprocess.run(["bash", "-c", script], capture_output = True, text = True, timeout = 60)+ assert "AMD GPU (gfx1153, no ROCm PyTorch wheels -- CPU fallback)" in out.stdout, out+++# ── Codex round: generic-only dGPU, Krackan Point 2 peer, HIP guidance ──────++_RX7900 = "03:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] Navi 31 [Radeon RX 7900 XTX]"+++def test_python_inferred_strix_defers_to_a_generic_only_dgpu():+ # gfx942 has no AMD per-arch index: the generic route installs for it, not the Strix wheel.+ calls = routing._run_install(+ gfx_devices = ("gfx1151", "gfx942"),+ inferred = "gfx1151",+ rocm_version = (7, 1),+ rocm_gpu_visible = False,+ )+ assert "download.pytorch.org/whl/rocm7.1" in calls and _STRIX_INDEX not in calls, calls+++ "lspci,expected", [(_RX7900, "gfx1100"), (_KRACKAN2_TEXT[1].strip(), "gfx1153")]+)+def test_python_krackan2_cpu_defers_to_a_discrete_peer(lspci, expected, monkeypatch):+ monkeypatch.setattr(stack_mod, "_is_wsl", lambda: False)+ monkeypatch.setattr(stack_mod, "_linux_amd_display_device_present", lambda: True)+ monkeypatch.setattr(Path, "read_text", lambda *a, **k: _KRACKAN2_TEXT[0])+ monkeypatch.setattr(stack_mod.shutil, "which", lambda _n: "/usr/bin/lspci")+ line = lspci if lspci.startswith("0") else "c4:00.0 VGA compatible controller [0300]: " + lspci+ monkeypatch.setattr(+ stack_mod.subprocess, "run", lambda *a, **k: subprocess.CompletedProcess(a, 0, line, "")+ )+ assert stack_mod._infer_linux_amd_gfx_arch() == expected+++@_POSIX+ "lspci,expected",+ [+ (_RX7900, "gfx1100"),+ ("c4:00.0 VGA compatible controller [0300]: " + _KRACKAN2_TEXT[1].strip(), "gfx1153"),+ ("", "gfx1153"),+ ],+)+def test_install_sh_krackan2_cpu_defers_to_a_discrete_peer(tmp_path, lspci, expected):+ assert _sh_infer(tmp_path, _KRACKAN2_TEXT[0], lspci = lspci)[0] == expected+++@_POSIX+ "arches,vulkan", [("gfx1153", False), ("gfx1010", True), ("gfx1010\ngfx1153", True)]+)+def test_install_sh_gfx1153_keeps_its_hip_guidance(arches, vulkan):+ url, err = guards._run_sh_get_torch_index_url(arches, rocm_tag = "rocm7.2")+ assert url.endswith("/cpu"), (url, err)+ assert ("UNSLOTH_LLAMA_CPP_BACKEND=vulkan" in err) is vulkan, err+ assert ("llama.cpp HIP build" in err) is (not vulkan), err+++def test_setup_sh_gfx1153_keeps_its_hip_guidance():+ source = (PACKAGE_ROOT / "studio" / "setup.sh").read_text(encoding = "utf-8")+ block = source[source.index('step "gpu" "AMD GPU detected ($_setup_unsup_gfx)') :]+ block = block[: block.index('elif [ -n "$_setup_mkt" ]')]+ assert 'if [ "$_setup_unsup_gfx" = gfx1153 ]' in block and "llama.cpp HIP build" in block+++def _setup_unsupported_lookup(gpu_name, lspci_lines, tmp_path):+ """setup.sh's runtime-less unsupported lookup, with its covered-peer guard and a scripted lspci."""+ import os+ import shutil+ import subprocess++ from test_rdna1_unsupported_message_8529 import _SETUP_SH, _sh_function_body++ src = _SETUP_SH.read_text(encoding = "utf-8")+ body = "\n".join(+ _sh_function_body(src, name)+ for name in (+ "_setup_supported_gfx_from_name",+ "_setup_unsupported_gfx_from_name",+ "_setup_unsupported_gfx_any",+ )+ )+ bin_dir = tmp_path / "bin"+ bin_dir.mkdir()+ for tool in ("sh", "grep", "cat", "sed", "tr", "awk", "printf"):+ found = shutil.which(tool)+ if found:+ (bin_dir / tool).symlink_to(found)+ if lspci_lines is not None:+ fake = bin_dir / "lspci"+ printed = "\n".join(lspci_lines)+ fake.write_text(f'#!/bin/sh\ncat <<"LSPCI_EOF"\n{printed}\nLSPCI_EOF\n', encoding = "utf-8")+ fake.chmod(0o755)+ out = subprocess.run(+ ["sh", "-c", f'{body}\n_setup_unsupported_gfx_any "$1" || true\n', "sh", gpu_name],+ stdout = subprocess.PIPE,+ stderr = subprocess.DEVNULL,+ text = True,+ timeout = 30,+ env = dict(os.environ, PATH = str(bin_dir)),+ )+ return out.stdout.strip()+++_K2_LINE = "c5:00.0 Display controller [0380]: Advanced Micro Devices, Inc. [AMD/ATI] Krackan Point 2 [1002:1114]"+_NAVI31_LINE = (+ "03:00.0 VGA compatible controller [0300]: Advanced Micro Devices, Inc. [AMD/ATI] "+ "Navi 31 [Radeon RX 7900 XTX] [1002:744c]"+)+++ "gpu_name,lspci,expected",+ [+ ("", [_K2_LINE], "gfx1153"),+ ("AMD Radeon 820M", None, "gfx1153"),+ ("", [_K2_LINE, _NAVI31_LINE], ""),+ ],+)+@_POSIX+def test_setup_sh_runtime_less_summary_names_gfx1153(gpu_name, lspci, expected, tmp_path):+ # No rocminfo / amd-smi: the summary still warns for a lone Krackan Point 2, never beside a covered peer.+ assert _setup_unsupported_lookup(gpu_name, lspci, tmp_path) == expected+++# ── Codex round 2: lspci gfx1153 is a fallback; setup.sh forwards gfx1153 ───+++def _python_lspci(lines, monkeypatch):+ monkeypatch.setattr(stack_mod.shutil, "which", lambda _n: "/usr/bin/lspci")+ out = "\n".join(lines)+ monkeypatch.setattr(+ stack_mod.subprocess, "run", lambda *a, **k: subprocess.CompletedProcess(a, 0, out, "")+ )+ return stack_mod._linux_amd_gfx_from_lspci()+++ "lines,expected",+ [+ ([_K2_LINE, _NAVI31_LINE], "gfx1100"),+ ([_NAVI31_LINE, _K2_LINE], "gfx1100"),+ ([_K2_LINE], "gfx1153"),+ ],+)+def test_python_lspci_gfx1153_is_only_the_fallback(lines, expected, monkeypatch):+ assert _python_lspci(lines, monkeypatch) == expected+++@_POSIX+ "lines,expected",+ [+ ([_K2_LINE, _NAVI31_LINE], "gfx1100"),+ ([_NAVI31_LINE, _K2_LINE], "gfx1100"),+ ([_K2_LINE], "gfx1153"),+ ],+)+def test_install_sh_lspci_gfx1153_is_only_the_fallback(tmp_path, lines, expected):+ # Generic CPU name: only lspci can answer.+ assert _sh_infer(tmp_path, "model name : AMD EPYC\n", lspci = "\n".join(lines))[0] == expected+++@_POSIX+ "unsup,setup_gfx,expected",+ [+ ("gfx1153", "", "gfx1153"),+ ("gfx1010", "", ""),+ ("gfx1010, gfx1153", "", ""),+ ("gfx1153", "gfx1153", "gfx1153"),+ ],+)+def test_setup_sh_forwards_an_inferred_gfx1153_to_llama_cpp(unsup, setup_gfx, expected):+ # The forwarding below the summary passes _setup_gfx as --rocm-gfx; gfx1153 keeps a HIP bundle.+ source = (PACKAGE_ROOT / "studio" / "setup.sh").read_text(encoding = "utf-8")+ start = source.index(" # gfx1153 keeps its llama.cpp HIP bundle")+ end = source.index(" fi\n", start) + len(" fi\n")+ script = (+ "step() { :; }\n"+ + f"_setup_unsup_gfx='{unsup}'\n_setup_gfx='{setup_gfx}'\n"+ + source[start:end]+ + '\nprintf "GFX:%s\\n" "$_setup_gfx"\n'+ )+ out = subprocess.run(["bash", "-c", script], capture_output = True, text = True, timeout = 30)+ assert out.stdout.strip().rsplit("GFX:", 1)[-1] == expected, out+ # That value is what reaches the prebuilt installer (--rocm-gfx implies --has-rocm there).+ assert (+ ' if [ -n "${_setup_gfx:-}" ]; then\n _PREBUILT_CMD+=(--rocm-gfx "$_setup_gfx")'+ in source+ )+++@_POSIX+ "name,expected",+ [+ ("AMD Ryzen AI 5 330 w/ Radeon 820M", "gfx1153"),+ ("Krackan Point 2", "gfx1153"),+ ("AMD Radeon 860M", "gfx1152"),+ ],+)+def test_setup_sh_name_inference_reads_krackan_point_2_first(name, expected):+ # An older rocminfo / amd-smi gives only a marketing name; the gfx1152 table must not claim Krackan Point 2.+ import subprocess++ from test_rdna1_unsupported_message_8529 import _SETUP_SH, _sh_function_body++ src = _SETUP_SH.read_text(encoding = "utf-8")+ start = src.index(' elif [ -z "$_setup_gfx" ] && [ -n "$_setup_mkt" ]; then')+ end = src.index(+ "\n fi\n", src.index('_setup_supported_gfx_from_name "$_setup_mkt"', start)+ ) + len("\n fi\n")+ block = "if false; then :\n" + src[start:end]+ script = "\n".join(+ [+ _sh_function_body(src, "_setup_supported_gfx_from_name"),+ "substep() { :; }",+ '_setup_gfx=""; _setup_mkt="$1"',+ block,+ 'printf "%s" "$_setup_gfx"',+ ]+ )+ out = subprocess.run(+ ["bash", "-c", script, "bash", name], capture_output = True, text = True, timeout = 30+ )+ assert out.stdout.strip() == expected, out.stderr+++# ── Codex round 3: setup.sh name inference keeps the covered-peer guard ─────+++@_POSIX+ "mkt,lspci,expected",+ [+ ("AMD Radeon 820M", [_K2_LINE], "gfx1153"),+ ("AMD Radeon 820M", None, "gfx1153"),+ # A covered peer keeps the table's answer, as main: none for 820M, gfx1152 for "Krackan".+ ("AMD Radeon 820M", [_K2_LINE, _NAVI31_LINE], ""),+ ("AMD Krackan Point 2", [_K2_LINE, _NAVI31_LINE], "gfx1152"),+ ("AMD Radeon 860M", [_K2_LINE], "gfx1152"),+ ],+)+def test_setup_sh_name_inference_keeps_the_covered_peer_guard(mkt, lspci, expected, tmp_path):+ from test_rdna1_unsupported_message_8529 import _SETUP_SH, _sh_function_body++ src = _SETUP_SH.read_text(encoding = "utf-8")+ start = src.index(+ ' _setup_gfx=$(_setup_supported_gfx_from_name "$_setup_mkt") || _setup_gfx=""'+ )+ end_marker = ' [ -n "$_setup_k2_peer" ] || _setup_gfx=gfx1153\n fi\n'+ end = src.index(end_marker, start) + len(end_marker)+ bin_dir = tmp_path / "bin"+ bin_dir.mkdir()+ for tool in ("sh", "bash", "grep", "cat", "sed", "tr", "awk", "printf"):+ found = shutil.which(tool)+ if found:+ (bin_dir / tool).symlink_to(found)+ if lspci is not None:+ fake = bin_dir / "lspci"+ printed = "\n".join(lspci)+ fake.write_text(f'#!/bin/sh\ncat <<"LSPCI_EOF"\n{printed}\nLSPCI_EOF\n', encoding = "utf-8")+ fake.chmod(0o755)+ script = (+ _sh_function_body(src, "_setup_supported_gfx_from_name")+ + f"\n_setup_mkt='{mkt}'\n_setup_gfx=''\n"+ + src[start:end]+ + 'printf "GFX:%s\\n" "$_setup_gfx"\n'+ )+ out = subprocess.run(+ [str(bin_dir / "bash"), "-c", script],+ capture_output = True,+ text = True,+ timeout = 30,+ env = dict(os.environ, PATH = str(bin_dir)),+ )+ assert out.stdout.strip().rsplit("GFX:", 1)[-1] == expected, outdiff --git a/tests/studio/install/test_rocm_support.py b/tests/studio/install/test_rocm_support.pyindex 52aa3ca5b33..1160e600b4d 100644--- a/tests/studio/install/test_rocm_support.py+++ b/tests/studio/install/test_rocm_support.py@@ -98,6 +98,7 @@ def _gpu_record_helpers(source: str) -> str:"_gfx_arch_slots","_amd_smi_hip_order","_amd_prefer_discrete_gfx",+ "_hsa_override_gfx_arch","_amd_gfx_is_shadowing_integrated","_amd_gfx_has_wheel_route","_amd_arch_index_family_for_gfx",@@ -6440,7 +6441,9 @@ class TestStrixRocm71Override:r"^_infer_amd_gfx_arch_from_gpu_name\(\) \{\n.*?\n\}\n", source, re.S | re.M)scan = re.search(- r"^ if command -v lspci[^\n]*\n.*?\nEOF\n fi\n return 1\n", source, re.S | re.M+ r"^ if command -v lspci[^\n]*\n.*?\nEOF\n fi\n.*? return 1\n",+ source,+ re.S | re.M,)assert name_fn and scan, "could not extract the lspci scan block"cases = (diff --git a/tests/studio/install/test_uncovered_amd_read_arch_linux_8529.py b/tests/studio/install/test_uncovered_amd_read_arch_linux_8529.pyindex b1e7fed9a98..e4091dbb247 100644--- a/tests/studio/install/test_uncovered_amd_read_arch_linux_8529.py+++ b/tests/studio/install/test_uncovered_amd_read_arch_linux_8529.py@@ -34,7 +34,7 @@ stack_mod = routing.stack_mod_INSTALL_SH = PACKAGE_ROOT / "install.sh"_SETUP_SH = PACKAGE_ROOT / "studio" / "setup.sh"-_UNCOVERED = ("gfx1010", "gfx1011", "gfx1012", "gfx803")+_UNCOVERED = ("gfx1010", "gfx1011", "gfx1012", "gfx1153", "gfx803")_POSIX = pytest.mark.skipif(os.name == "nt" or shutil.which("bash") is None, reason = "POSIX shell only")