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 installer (AMD, Linux): no generic ROCm torch for RDNA 1 / Polaris when the arch is readable (#13419)

Daniel Han53199eaa1bed
diff --git a/install.sh b/install.sh
index 97527d82b66..53b57d6ece2 100755
--- a/install.sh
+++ b/install.sh
@@ -5938,6 +5938,29 @@ 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
+ # 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.
+ _amd_unsup_src="$_amd_gfx_probe"
+ _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 }
+ END { if (!bad && l != "") print l }')
+ if [ -n "$_amd_unsup_all" ]; then
+ echo "[WARN] AMD GPU detected ($_amd_unsup_all) -- Unsloth has no ROCm PyTorch wheels for that arch, installing CPU PyTorch." >&2
+ echo "[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
+ echo "[INFO] If you run this GPU with HSA_OVERRIDE_GFX_VERSION, export it and re-run this installer to keep ROCm PyTorch." >&2
+ if _amd_therock_extra=$(_therock_device_extra_for_gfx "${_amd_unsup_all%%,*}" 2>/dev/null); then
+ echo "[INFO] Untested: AMD's TheRock publishes nightly ${_amd_unsup_all%%,*} wheels. To try them, export both and re-run:" >&2
+ echo "[INFO] export UNSLOTH_TORCH_INDEX_URL='$THEROCK_MIRROR'" >&2
+ echo "[INFO] export UNSLOTH_TORCH_EXTRA=$_amd_therock_extra" >&2
+ fi
+ echo "$_base/cpu"; return
+ fi
_rocm_tag=""
_rocm_tag=$(_detect_rocm_version_tag) || _rocm_tag=""
# The `||` guard is belt and braces on the set -e contract the helpers hold, so a fresh AMD host with no version source at all still reaches the actionable no-version WARN below. stderr is deliberately not redirected: each source already silences its own noise, leaving only the sources-disagree breadcrumb, which belongs in the install log. The shape gate on "rocmX.Y" with major >= 1 is kept, though _highest_rocm_tag enforces it too, so a future source cannot leak garbage into the cases below.
@@ -7496,9 +7519,22 @@ elif [ "$OS" = "macos" ] && [ "$_ARCH" = "arm64" ]; then
# Apple Silicon: PyTorch gets Metal (MPS) acceleration over unified memory, so not CPU-only.
step "gpu" "Apple Silicon (Metal, unified memory)"
elif _has_amd_rocm_gpu; then
+ # The arch read fine and get_torch_index_url sent it to CPU for having no wheels (#8529),
+ # so "no usable ROCm" would blame a working install. Same filter as that function.
+ _amd_unsup_read=""
+ if [ "$_torch_index_pinned" != true ]; then
+ _amd_unsup_read=$(_probe_amd_gfx_arch 2>/dev/null) || _amd_unsup_read=""
+ _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 }
+ END { if (!bad && l != "") print l }') || _amd_unsup_read=""
+ fi
if [ "$_torch_index_pinned" = true ]; then
# An explicit UNSLOTH_TORCH_INDEX_URL/_FAMILY pin skipped all probing; do not claim ROCm is unusable when a CPU or other index was requested.
step "gpu" "AMD GPU (torch index pinned: $_torch_index_leaf)" "$C_WARN"
+ elif [ -n "$_amd_unsup_read" ]; then
+ step "gpu" "AMD GPU ($_amd_unsup_read, no ROCm PyTorch wheels -- CPU fallback)" "$C_WARN"
else
# AMD GPU visible to the kernel but the torch index stayed CPU: no usable ROCm userspace to pick a wheel. "none" would repeat the false diagnosis this installer used to give.
step "gpu" "AMD GPU (no usable ROCm -- CPU fallback)" "$C_WARN"
@@ -7528,6 +7564,7 @@ case "$TORCH_INDEX_URL" in
else
_unsup_disp_gfx=$(_infer_linux_unsupported_amd_gfx_arch 2>/dev/null) || _unsup_disp_gfx=""
fi
+ [ -n "$_unsup_disp_gfx" ] || _unsup_disp_gfx="${_amd_unsup_read:-}"
if [ -n "$_unsup_disp_gfx" ]; then
# 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"
diff --git a/studio/install_python_stack.py b/studio/install_python_stack.py
index a07e14d403d..b1c80bc8f56 100644
--- a/studio/install_python_stack.py
+++ b/studio/install_python_stack.py
@@ -3336,6 +3336,32 @@ 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).
+# install.sh's get_torch_index_url holds the same list.
+_LINUX_UNCOVERED_AMD_GFX: "frozenset[str]" = frozenset({"gfx1010", "gfx1011", "gfx1012", "gfx803"})
+
+
+def _linux_host_only_uncovered_amd(*arch_lists: "list[str]") -> "str | None":
+ """The uncovered arches, comma-joined, when every probed arch is one; else None.
+
+ A generic ROCm wheel installed there loads, then faults on its first GPU op. A covered
+ peer anywhere in the lists keeps the normal route. A readable HSA_OVERRIDE_GFX_VERSION is
+ the arch the runtime runs, whatever amd-smi and KFD read, so it alone is judged.
+ """
+ _spoof = _hsa_override_gfx_arch(os.environ.get("HSA_OVERRIDE_GFX_VERSION"))
+ if _spoof and not (os.environ.get("UNSLOTH_ROCM_GFX_ARCH") or "").strip():
+ arch_lists = ([_spoof],)
+ _archs = list(
+ dict.fromkeys(
+ (g or "").strip().lower().split(":", 1)[0] for _l in arch_lists for g in (_l or [])
+ )
+ )
+ _archs = [g for g in _archs if g]
+ if not _archs or any(g not in _LINUX_UNCOVERED_AMD_GFX for g in _archs):
+ return None
+ return ", ".join(_archs)
+
+
# _GENERIC_ROCM_WHEEL_GFX was measured on the tags the pins resolve (rocm7.0 and up), but
# _ROCM_TORCH_INDEX also maps ROCm 6.0-6.4, whose wheels predate some of these arches. A host
# can resolve an old tag while the KERNEL names a new card (a current amdgpu beside a stale
@@ -6062,7 +6088,9 @@ def _amd_torch_needs_dependency_pass() -> bool:
# returns no target ONLY when the selection is genuinely unreadable, so gate on its
# answer, not the shape of the host: a mixed box with HIP_VISIBLE_DEVICES naming a
# card is not ambiguous, and its generic wheel can still lack kernels for it.
- _selected_gfx, _, _selected_spoof, _selected_host = _runtime_gfx_target(_inferred_gfx)
+ _selected_gfx, _selected_codes, _selected_spoof, _selected_host = _runtime_gfx_target(
+ _inferred_gfx
+ )
if _selected_gfx is None:
return False
# Every arm below is about the wheel. A corroborated spoof is not: the family can be
@@ -6072,6 +6100,13 @@ def _amd_torch_needs_dependency_pass() -> bool:
return True
_pre_ran, _pre_imp, _pre_ver, _pre_hip, _pre_cuda = _probe_torch_runtime()
_pre_torch = (_pre_ver or "").lower() if (_pre_ran and _pre_imp) else ""
+ # The repair declines a ROCm install for these GPUs, so forcing its pass only repeats.
+ if (
+ _pre_torch
+ and not (_pre_hip or "rocm" in _pre_torch)
+ and _linux_host_only_uncovered_amd(_selected_codes, _selected_host)
+ ):
+ return False
# The compatibility reroutes have no version floor either, so a host whose ROCm
# version will not read must not be turned away before they are asked. Only with a
# torch that reads back: an unreadable one is not evidence its wheels are wrong.
@@ -6635,6 +6670,14 @@ def _ensure_rocm_torch() -> "bool | None":
f"(studio/ROCM_RDNA2_APU.md) -- not installing ROCm torch for it.\n"
)
return
+ # Keeps an existing ROCm build: only the install onto CPU/CUDA torch is declined.
+ _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"
+ )
+ return
_strix_gfx = _AMD_ARCH_INDEX_FLOOR_GFX
_detected_strix = (
_strix_gfx.intersection(gfx_codes) if _strix_needs_amd_arch_index(ver) else set()
diff --git a/studio/setup.sh b/studio/setup.sh
index 1a4332d43f0..76a922557f9 100755
--- a/studio/setup.sh
+++ b/studio/setup.sh
@@ -4346,11 +4346,48 @@ EOF
}
# $_setup_mkt is the marketing name of the SAME record the arch came from, paired
# per GPU agent by _rocminfo_gpu_records and ordered by _amd_smi_hip_order.
- if [ -n "$_setup_gfx" ] && [ -n "$_setup_mkt" ]; then
+ # An arch READ as uncovered on every probed GPU gets the warning too, not only a missing
+ # one: a host with ROCm installed reads gfx1010 fine and still has no wheels (#8529).
+ # install.sh's get_torch_index_url holds the same list. A declared arch is all the
+ # installers route on, so the physical inventory is not consulted beside it. The
+ # installers probe with ROCR_VISIBLE_DEVICES stripped, rocminfo here does not, so a mask
+ # could hide the covered peer. A readable HSA_OVERRIDE_GFX_VERSION is the arch the runtime
+ # runs, so it alone is judged (same triple parse as install.sh's _hsa_override_gfx_arch).
+ _setup_unsup_cur="$_setup_gfx"
+ _setup_unsup_inv="$_setup_gfx_all"
+ [ -n "${UNSLOTH_ROCM_GFX_ARCH:-}" ] && _setup_unsup_inv=""
+ _setup_unsup_hsa=$(printf '%s' "${HSA_OVERRIDE_GFX_VERSION:-}" | awk '
+ { gsub(/^[[:space:]]+|[[:space:]]+$/, "")
+ if ($0 !~ /^[0-9]+\.[0-9]+\.[0-9]+$/) exit
+ split($0, p, "."); maj = p[1] + 0; min = p[2] + 0; step = p[3] + 0
+ if (maj <= 0 || min > 9 || step > 15) exit
+ printf "gfx%d%d%x", maj, min, step }')
+ if [ -n "$_setup_unsup_hsa" ] && [ -z "${UNSLOTH_ROCM_GFX_ARCH:-}" ]; then
+ _setup_unsup_cur="$_setup_unsup_hsa"
+ _setup_unsup_inv=""
+ fi
+ # A ROCm torch already in the venv is kept by the update (a TheRock or hand-installed build
+ # may run here), so only a non-ROCm one is reported as CPU-only. Read off disk, no import.
+ _setup_unsup_torch_rocm=false
+ for _setup_unsup_tv in "$VENV_DIR"/lib/python*/site-packages/torch/version.py; do
+ [ -f "$_setup_unsup_tv" ] || continue
+ grep -qE "^hip(: [^=]*)? = '|^__version__ = '[^']*\+rocm" "$_setup_unsup_tv" 2>/dev/null \
+ && _setup_unsup_torch_rocm=true
+ break
+ done
+ _setup_unsup_gfx=""
+ if [ "$_setup_unsup_torch_rocm" = false ] && \
+ { [ -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 }
+ END { if (!bad && l != "") print l }')
+ fi
+ if [ -z "$_setup_unsup_gfx" ] && [ -n "$_setup_gfx" ] && [ -n "$_setup_mkt" ]; then
step "gpu" "$_setup_mkt ($_setup_gfx)"
- elif [ -n "$_setup_gfx" ]; then
+ elif [ -z "$_setup_unsup_gfx" ] && [ -n "$_setup_gfx" ]; then
step "gpu" "AMD ROCm ($_setup_gfx)"
- elif _setup_unsup_gfx=$(_setup_unsupported_gfx_any "$_setup_mkt"); then
+ elif [ -n "$_setup_unsup_gfx" ] || _setup_unsup_gfx=$(_setup_unsupported_gfx_any "$_setup_mkt"); then
step "gpu" "AMD GPU detected ($_setup_unsup_gfx) -- no ROCm PyTorch wheels Unsloth installs"
# Not "training runs on CPU": with no CUDA/XPU visible, unsloth raises
# NotImplementedError at import (unsloth/device_type.py).
diff --git a/tests/sh/test_get_torch_index_url.sh b/tests/sh/test_get_torch_index_url.sh
index 615d0f8c32d..75bcd8ba758 100755
--- a/tests/sh/test_get_torch_index_url.sh
+++ b/tests/sh/test_get_torch_index_url.sh
@@ -53,6 +53,8 @@ _FAKE_ROCM_DIR=$(mktemp -d)
echo
sed -n '/^_amd_sole_index_arch()/,/^}/p' "$INSTALL_SH"
echo ""
+ sed -n '/^_hsa_override_gfx_arch()/,/^}/p' "$INSTALL_SH"
+ echo ""
sed -n '/^_trim_index_path_slashes()/,/^}/p' "$INSTALL_SH"
echo ""
sed -n '/^_nvidia_library_inventory()/,/^}/p' "$INSTALL_SH"
@@ -528,6 +530,29 @@ _result=$(run_func "$_dir")
assert_eq "gfx1100 via rocminfo still floors to rocm6.4" "https://download.pytorch.org/whl/rocm6.4" "$_result"
rm -rf "$_dir"
+# RDNA 1 / Polaris read fine through a real ROCm install and still have no wheels (#8529):
+# every generic tag lacks their kernels, so the readable arch must not pick one.
+_dir=$(make_mock_rocminfo "6.4" "gfx1010" 1)
+_result=$(run_func "$_dir")
+assert_eq "gfx1010 via rocminfo with ROCm 6.4 takes the CPU index" "https://download.pytorch.org/whl/cpu" "$_result"
+rm -rf "$_dir"
+
+_dir=$(make_mock_rocminfo "7.1" "gfx1012" 2)
+_result=$(run_func "$_dir")
+assert_eq "two gfx1012 agents with ROCm 7.1 take the CPU index" "https://download.pytorch.org/whl/cpu" "$_result"
+rm -rf "$_dir"
+
+_dir=$(make_mock_rocminfo "6.4" "gfx803" 1)
+_result=$(run_func "$_dir")
+assert_eq "gfx803 via rocminfo with ROCm 6.4 takes the CPU index" "https://download.pytorch.org/whl/cpu" "$_result"
+rm -rf "$_dir"
+
+# A covered card beside it still gets the generic wheels it can run.
+_dir=$(make_mock_rocminfo_multi "6.4" "gfx1010 gfx1100")
+_result=$(run_func "$_dir")
+assert_eq "gfx1010 beside gfx1100 keeps rocm6.4" "https://download.pytorch.org/whl/rocm6.4" "$_result"
+rm -rf "$_dir"
+
# A mixed host is not a sole gfx906 target, so it keeps the generic floor.
_dir=$(make_mock_rocminfo_multi "6.1" "gfx906 gfx1100")
_result=$(run_func "$_dir")
diff --git a/tests/studio/install/test_rdna1_unsupported_message_8529.py b/tests/studio/install/test_rdna1_unsupported_message_8529.py
index bfe03568888..ed5f66c825a 100644
--- a/tests/studio/install/test_rdna1_unsupported_message_8529.py
+++ b/tests/studio/install/test_rdna1_unsupported_message_8529.py
@@ -833,7 +833,8 @@ class TestSetupShKfdOnlyHost:
def test_the_report_site_uses_the_lspci_aware_lookup(self):
src = _normalised(_SETUP_SH)
assert (
- 'elif _setup_unsup_gfx=$(_setup_unsupported_gfx_any "$_setup_mkt"); then' in src
+ 'elif [ -n "$_setup_unsup_gfx" ] || _setup_unsup_gfx=$(_setup_unsupported_gfx_any "$_setup_mkt"); then'
+ in src
), "studio/setup.sh: the gpu report no longer goes through the lspci-aware lookup"
def test_the_lspci_name_never_reaches_the_routing_table(self):
@@ -1185,7 +1186,7 @@ class TestVulkanAdvice:
# install.ps1's second anchor names $ROCmUnsupportedGfxArch deliberately: the same sentence four lines earlier is
# for a supported card.
_ADVICE_SITES = [
- (_INSTALL_SH, "Unsloth has no ROCm PyTorch wheels for that arch", 2),
+ (_INSTALL_SH, "Unsloth has no ROCm PyTorch wheels for that arch", 3),
(_INSTALL_PS1, "Unsloth installs no ROCm PyTorch wheels for $ROCmUnsupportedGfxArch", 1),
(
_INSTALL_PS1,
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.py
new file mode 100644
index 00000000000..b1e7fed9a98
--- /dev/null
+++ b/tests/studio/install/test_uncovered_amd_read_arch_linux_8529.py
@@ -0,0 +1,426 @@
+# 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 RDNA 1 / Polaris with a READABLE arch and ROCm version (#8529).
+
+With ROCm installed, rocminfo reports gfx1010 and every installer used to pick the generic
+pytorch.org ROCm tag for it, a multi-GB torch with no gfx1010 kernels. Only the unreadable-arch
+path reached the "no ROCm PyTorch wheels" message.
+"""
+
+from __future__ import annotations
+
+import os
+import re
+import shutil
+import subprocess
+import sys
+import tempfile
+from pathlib import Path
+
+import pytest
+from unittest.mock import patch
+
+_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_amd_fastpath_probe as fastpath # noqa: E402
+import test_missing_kernel_arch_routing_9396 as routing # noqa: E402
+import test_unsupported_arch_routing_guards_8529 as guards # noqa: E402
+
+stack_mod = routing.stack_mod
+_INSTALL_SH = PACKAGE_ROOT / "install.sh"
+_SETUP_SH = PACKAGE_ROOT / "studio" / "setup.sh"
+
+_UNCOVERED = ("gfx1010", "gfx1011", "gfx1012", "gfx803")
+_POSIX = pytest.mark.skipif(
+ os.name == "nt" or shutil.which("bash") is None, reason = "POSIX shell only"
+)
+
+
[email protected](autouse = True)
+def _reset_probe(monkeypatch):
+ # The shell harnesses inherit os.environ; a test sets these itself.
+ for name in ("HSA_OVERRIDE_GFX_VERSION", "ROCR_VISIBLE_DEVICES", "UNSLOTH_ROCM_GFX_ARCH"):
+ monkeypatch.delenv(name, raising = False)
+ stack_mod._invalidate_torch_runtime_probe()
+ yield
+ stack_mod._invalidate_torch_runtime_probe()
+
+
+# ── the list ────────────────────────────────────────────────────────────────
+
+
+def test_no_uncovered_arch_has_a_wheel_route():
+ assert set(_UNCOVERED) == set(stack_mod._LINUX_UNCOVERED_AMD_GFX)
+ for gfx in _UNCOVERED:
+ assert not stack_mod._gfx_has_a_wheel_route(gfx), gfx
+ with patch.object(stack_mod, "IS_WINDOWS", False):
+ assert stack_mod._amd_arch_index_url(gfx) is None, gfx
+
+
+def test_the_shell_copies_name_the_same_arches():
+ want = "gfx(" + "|".join(sorted(g[3:] for g in _UNCOVERED)) + ")"
+ for path in (_INSTALL_SH, _SETUP_SH):
+ found = re.findall(r"\$1 !~ /\^(gfx\([0-9|]+\))\$/", path.read_text(encoding = "utf-8"))
+ assert found, f"{path.name}: uncovered-arch filter not found"
+ for f in found:
+ got = "gfx(" + "|".join(sorted(f[4:-1].split("|"))) + ")"
+ assert got == want, f"{path.name} names {f}, python names {sorted(_UNCOVERED)}"
+
+
+ "lists,expected",
+ [
+ ((["gfx1010"],), "gfx1010"),
+ ((["gfx1010:xnack-", "GFX1010"], ["gfx1010"]), "gfx1010"),
+ ((["gfx1010", "gfx803"],), "gfx1010, gfx803"),
+ ((["gfx1010", "gfx1100"],), None),
+ ((["gfx1010"], ["gfx1030"]), None),
+ ((["gfx1030"],), None),
+ (([],), None),
+ ((["", None],), None),
+ ],
+)
+def test_only_an_all_uncovered_host_answers(lists, expected):
+ assert stack_mod._linux_host_only_uncovered_amd(*lists) == expected
+
+
+# ── install_python_stack._ensure_rocm_torch ─────────────────────────────────
+
+
[email protected]("gfx", _UNCOVERED)
[email protected]("ver", [(6, 4), (7, 1)])
+def test_a_lone_uncovered_card_gets_no_rocm_torch(gfx, ver):
+ calls = routing._run_install(gfx_devices = (gfx,), rocm_version = ver)
+ assert "download.pytorch.org" not in calls and "repo.amd.com" not in calls, calls
+ assert "bitsandbytes" not in calls, calls
+ assert f"AMD {gfx}: no ROCm PyTorch wheel" in routing._run_install.printed
+
+
[email protected]("peer", ["gfx1100", "gfx1030"])
+def test_a_covered_peer_keeps_the_generic_install(peer):
+ calls = routing._run_install(gfx_devices = ("gfx1010", peer), rocm_version = (6, 4))
+ assert "download.pytorch.org/whl/rocm6.4" in calls, calls
+
+
+def test_a_covered_card_alone_is_unchanged():
+ calls = routing._run_install(gfx_devices = ("gfx1030",), rocm_version = (6, 4))
+ assert "download.pytorch.org/whl/rocm6.4" in calls, calls
+
+
+ "devices,hsa,generic",
+ [
+ # amd-smi / KFD read the physical gfx1010; the runtime runs the spoofed arch.
+ (("gfx1010",), "10.3.0", True),
+ (("gfx1030",), "10.3.0", True),
+ # A spoof onto another uncovered arch still has no wheels (RX 5500 posing as gfx1010).
+ (("gfx1012",), "10.1.0", False),
+ # Unreadable: ROCr ignores it and runs the physical arch.
+ (("gfx1010",), "ten", False),
+ ],
+)
+def test_an_hsa_spoof_is_judged_by_its_target(devices, hsa, generic):
+ calls = routing._run_install(
+ gfx_devices = devices, rocm_version = (6, 4), env = {"HSA_OVERRIDE_GFX_VERSION": hsa}
+ )
+ assert ("download.pytorch.org/whl/rocm6.4" in calls) is generic, calls
+
+
[email protected]("hsa,needs", [("10.3.0", True), ("10.1.0", False)])
+def test_an_hsa_spoof_decides_the_update_preflight(monkeypatch, hsa, needs):
+ fastpath._host(
+ monkeypatch,
+ torch = ("2.10.0+cpu", ""),
+ gfx = ("gfx1010",),
+ env = {"HSA_OVERRIDE_GFX_VERSION": hsa},
+ )
+ assert fastpath._needs_pass() is needs
+
+
+def test_an_existing_rocm_build_is_left_alone():
+ calls = routing._run_install(
+ gfx_devices = ("gfx1010",),
+ rocm_version = (7, 1),
+ torch_probe = routing._ROCM_GENERIC_TORCH,
+ torch_owns_rocm = False,
+ )
+ assert "download.pytorch.org" not in calls, calls
+ assert "no ROCm PyTorch wheel" not in routing._run_install.printed
+
+
+def test_an_explicit_rocm_pin_still_installs():
+ pin = "https://download.pytorch.org/whl/rocm6.4"
+ calls = routing._run_install(
+ gfx_devices = ("gfx1010",),
+ rocm_version = (6, 4),
+ env = {"UNSLOTH_TORCH_INDEX_URL": pin},
+ )
+ assert pin in calls, calls
+
+
+# ── install_python_stack._amd_torch_needs_dependency_pass ────────────────────
+
+
[email protected]("gfx", _UNCOVERED)
+def test_the_update_preflight_stops_forcing_a_pass(monkeypatch, gfx):
+ fastpath._host(monkeypatch, torch = ("2.10.0+cpu", ""), gfx = (gfx,))
+ assert fastpath._needs_pass() is False
+
+
+def test_the_update_preflight_still_forces_a_covered_card(monkeypatch):
+ fastpath._host(monkeypatch, torch = ("2.10.0+cpu", ""), gfx = ("gfx1030",))
+ assert fastpath._needs_pass() is True
+
+
+def test_the_update_preflight_still_forces_a_mixed_host(monkeypatch):
+ fastpath._host(monkeypatch, torch = ("2.10.0+cpu", ""), gfx = ("gfx1010", "gfx1100"))
+ assert fastpath._needs_pass() is True
+
+
+# ── install.sh get_torch_index_url ──────────────────────────────────────────
+
+
+@_POSIX
[email protected]("arch", ["gfx1010", "gfx1010:xnack-", "GFX1012", "gfx1011", "gfx803"])
[email protected]("tag", ["rocm6.4", "rocm7.0", ""])
+def test_install_sh_sends_a_read_uncovered_arch_to_cpu(arch, tag):
+ url, err = guards._run_sh_get_torch_index_url(arch, rocm_tag = tag)
+ assert url.endswith("/cpu"), (url, err)
+ bare = arch.split(":")[0].lower()
+ assert f"AMD GPU detected ({bare}) -- Unsloth has no ROCm PyTorch wheels" in err, err
+ assert "Install the ROCm/HIP SDK" not in err, err
+
+
+@_POSIX
[email protected]("arch", ["gfx1010\ngfx1100", "gfx1030\ngfx1010", "gfx1030"])
+def test_install_sh_keeps_the_generic_tag_with_a_covered_card(arch):
+ url, err = guards._run_sh_get_torch_index_url(arch, rocm_tag = "rocm6.4")
+ assert url.endswith("/rocm6.4"), (url, err)
+ assert "no ROCm PyTorch wheels" not in err, err
+
+
+# ── setup.sh GPU report ─────────────────────────────────────────────────────
+
+
+def _setup_report(
+ gfx: str,
+ gfx_all: str,
+ mkt: str = "",
+ torch_version: str = "",
+) -> str:
+ src = _SETUP_SH.read_text(encoding = "utf-8")
+ venv = tempfile.mkdtemp(dir = os.environ.get("TMPDIR"))
+ if torch_version:
+ tv = Path(venv) / "lib" / "python3.12" / "site-packages" / "torch"
+ tv.mkdir(parents = True)
+ hip = "'7.1.0'" if "rocm" in torch_version else "None"
+ (tv / "version.py").write_text(
+ f"__version__ = '{torch_version}'\nhip: Optional[str] = {hip}\n", encoding = "utf-8"
+ )
+ start = src.index(" # An arch READ as uncovered on every probed GPU")
+ end = src.index(' step "gpu" "AMD ROCm"\n fi\n', start) + len(
+ ' step "gpu" "AMD ROCm"\n fi\n'
+ )
+ funcs = "\n".join(
+ guards._sh_function_body(src, n)
+ for n in ("_setup_supported_gfx_from_name", "_setup_unsupported_gfx_from_name")
+ )
+ script = (
+ 'step() { echo "STEP: $2"; }\nsubstep() { echo " $1"; }\n'
+ '_setup_unsupported_gfx_any() { _setup_unsupported_gfx_from_name "$1"; }\n'
+ f"{funcs}\n_setup_gfx='{gfx}'\n_setup_gfx_all='{gfx_all}'\n_setup_mkt='{mkt}'\n"
+ f"VENV_DIR='{venv}'\n" + src[start:end]
+ )
+ env = {k: v for k, v in os.environ.items() if not k.startswith("UNSLOTH_TORCH_INDEX")}
+ out = subprocess.run(
+ ["bash", "-c", script], stdout = subprocess.PIPE, text = True, timeout = 30, env = env
+ )
+ shutil.rmtree(venv, ignore_errors = True)
+ return out.stdout
+
+
+@_POSIX
+ "gfx,gfx_all,mkt",
+ [
+ ("gfx1010", "gfx1010", "AMD Radeon RX 5700 XT"),
+ ("gfx1010", "gfx1010\ngfx1010", ""),
+ ("gfx803", "gfx803", "Radeon RX 580 Series"),
+ ],
+)
+def test_setup_sh_reports_a_read_uncovered_arch(gfx, gfx_all, mkt):
+ out = _setup_report(gfx, gfx_all, mkt)
+ assert f"STEP: AMD GPU detected ({gfx}) -- no ROCm PyTorch wheels" in out, out
+ assert "torch stays CPU-only" in out, out
+
+
+@_POSIX
+ "gfx,gfx_all,mkt,step",
+ [
+ ("gfx1010", "gfx1010\ngfx1100", "AMD Radeon RX 5700 XT", "AMD Radeon RX 5700 XT (gfx1010)"),
+ ("gfx1100", "gfx1100", "AMD Radeon RX 7900 XTX", "AMD Radeon RX 7900 XTX (gfx1100)"),
+ ("gfx1030", "gfx1030", "", "AMD ROCm (gfx1030)"),
+ ("", "", "AMD Radeon RX 5700 XT", "AMD GPU detected (gfx1010) -- no ROCm PyTorch wheels"),
+ ("", "", "", "AMD ROCm"),
+ ],
+)
+def test_setup_sh_other_reports_are_unchanged(gfx, gfx_all, mkt, step):
+ out = _setup_report(gfx, gfx_all, mkt)
+ assert f"STEP: {step}" in out, out
+
+
+@_POSIX
+ "gfx,gfx_all",
+ [("gfx1010", "gfx1100"), ("gfx1010", "gfx1010\ngfx1100"), ("gfx803", "gfx1030")],
+)
+def test_setup_sh_a_declared_uncovered_arch_ignores_the_physical_peer(monkeypatch, gfx, gfx_all):
+ """install.sh and _runtime_gfx_target route on UNSLOTH_ROCM_GFX_ARCH alone."""
+ monkeypatch.setenv("UNSLOTH_ROCM_GFX_ARCH", gfx)
+ out = _setup_report(gfx, gfx_all, "AMD Radeon RX 7900 XTX")
+ assert f"STEP: AMD GPU detected ({gfx}) -- no ROCm PyTorch wheels" in out, out
+
+
+@_POSIX
+def test_setup_sh_a_declared_covered_arch_is_unchanged(monkeypatch):
+ monkeypatch.setenv("UNSLOTH_ROCM_GFX_ARCH", "gfx1030")
+ out = _setup_report("gfx1030", "gfx1010", "")
+ assert "STEP: AMD ROCm (gfx1030)" in out, out
+
+
+# ── install.sh final GPU summary ────────────────────────────────────────────
+
+
+def _install_summary_gpu_step(probe: str, pinned: bool = False) -> str:
+ src = _INSTALL_SH.read_text(encoding = "utf-8")
+ start = src.index(" # The arch read fine and get_torch_index_url sent it to CPU")
+ tail = ' step "gpu" "AMD GPU (no usable ROCm -- CPU fallback)" "$C_WARN"\n fi\n'
+ end = src.index(tail, start) + len(tail)
+ script = (
+ 'step() { echo "STEP: $2"; }\n_has_amd_rocm_gpu() { return 0; }\n'
+ f"_probe_amd_gfx_arch() {{ printf '%s\\n' '{probe}'; }}\n"
+ f"_torch_index_pinned={'true' if pinned else 'false'}\n_torch_index_leaf=cpu\n"
+ + guards._sh_function_body(src, "_hsa_override_gfx_arch")
+ + "\nif false; then :\nelif _has_amd_rocm_gpu; then\n"
+ + src[start:end]
+ + "fi\n"
+ )
+ out = subprocess.run(["sh", "-c", script], stdout = subprocess.PIPE, text = True, timeout = 30)
+ return out.stdout
+
+
+@_POSIX
[email protected]("probe", ["gfx1010", "gfx1010:xnack-\ngfx1010", "gfx803"])
+def test_install_summary_names_the_uncovered_arch(probe):
+ bare = probe.split(":")[0].split("\n")[0]
+ out = _install_summary_gpu_step(probe)
+ assert f"STEP: AMD GPU ({bare}, no ROCm PyTorch wheels -- CPU fallback)" in out, out
+ assert "no usable ROCm" not in out, out
+
+
+@_POSIX
[email protected]("probe", ["", "gfx1010\ngfx1100", "gfx1030"])
+def test_install_summary_other_hosts_are_unchanged(probe):
+ assert "STEP: AMD GPU (no usable ROCm -- CPU fallback)" in _install_summary_gpu_step(probe)
+
+
+@_POSIX
+def test_install_summary_a_pin_still_wins():
+ out = _install_summary_gpu_step("gfx1010", pinned = True)
+ assert "STEP: AMD GPU (torch index pinned: cpu)" in out, out
+
+
+def _amd_smi_probe_harness(monkeypatch, physical: str):
+ """The stub probe answers like amd-smi: the physical arch, whatever the spoof says."""
+ real = guards._INDEX_URL_STUBS
+ monkeypatch.setattr(
+ guards,
+ "_INDEX_URL_STUBS",
+ real.replace(
+ "_probe_amd_gfx_arch() { printf '%s\\n' \"${UNSLOTH_ROCM_GFX_ARCH:-}\" "
+ "| tr '[:upper:]' '[:lower:]'; }",
+ f"_probe_amd_gfx_arch() {{ echo {physical}; }}",
+ ),
+ )
+ assert guards._INDEX_URL_STUBS != real, "probe stub not found"
+
+
+@_POSIX
+ "physical,hsa,tail",
+ [("gfx1010", "10.3.0", "/rocm6.4"), ("gfx1012", "10.1.0", "/cpu"), ("gfx1010", "ten", "/cpu")],
+)
+def test_install_sh_an_hsa_spoof_is_judged_by_its_target(monkeypatch, physical, hsa, tail):
+ _amd_smi_probe_harness(monkeypatch, physical)
+ monkeypatch.setenv("HSA_OVERRIDE_GFX_VERSION", hsa)
+ url, err = guards._run_sh_get_torch_index_url("", rocm_tag = "rocm6.4")
+ assert url.endswith(tail), (url, err)
+
+
+@_POSIX
+def test_install_sh_the_warning_names_the_spoof_escape(monkeypatch):
+ monkeypatch.delenv("HSA_OVERRIDE_GFX_VERSION", raising = False)
+ _url, err = guards._run_sh_get_torch_index_url("gfx1010", rocm_tag = "rocm6.4")
+ assert "HSA_OVERRIDE_GFX_VERSION, export it and re-run" in err, err
+
+
+@_POSIX
+def test_setup_sh_a_spoof_onto_an_uncovered_arch_still_warns(monkeypatch):
+ monkeypatch.setenv("HSA_OVERRIDE_GFX_VERSION", "10.1.0")
+ out = _setup_report("gfx1012", "gfx1012", "AMD Radeon RX 5500 XT")
+ assert "STEP: AMD GPU detected (gfx1010) -- no ROCm PyTorch wheels" in out, out
+
+
+@_POSIX
+ "env",
+ [{"HSA_OVERRIDE_GFX_VERSION": "10.3.0"}, {"ROCR_VISIBLE_DEVICES": "1"}],
+ ids = ["hsa-spoof", "rocr-mask"],
+)
+def test_setup_sh_a_spoof_or_rocr_mask_keeps_the_old_report(monkeypatch, env):
+ """rocminfo in setup.sh is ROCR-filtered, so a masked covered peer is invisible there."""
+ for k, v in env.items():
+ monkeypatch.setenv(k, v)
+ out = _setup_report("gfx1010", "gfx1010", "AMD Radeon RX 5700 XT")
+ assert "STEP: AMD Radeon RX 5700 XT (gfx1010)" in out, out
+
+
+@_POSIX
+def test_setup_sh_a_declared_arch_outranks_the_rocr_mask(monkeypatch):
+ monkeypatch.setenv("ROCR_VISIBLE_DEVICES", "1")
+ monkeypatch.setenv("UNSLOTH_ROCM_GFX_ARCH", "gfx1010")
+ out = _setup_report("gfx1010", "gfx1010", "")
+ assert "STEP: AMD GPU detected (gfx1010) -- no ROCm PyTorch wheels" in out, out
+
+
+@_POSIX
+ "hsa,step",
+ [
+ ("10.3.0", "AMD GPU (no usable ROCm -- CPU fallback)"),
+ ("10.1.0", "AMD GPU (gfx1010, no ROCm PyTorch wheels -- CPU fallback)"),
+ ],
+)
+def test_install_summary_an_hsa_spoof_is_judged_by_its_target(monkeypatch, hsa, step):
+ monkeypatch.setenv("HSA_OVERRIDE_GFX_VERSION", hsa)
+ assert f"STEP: {step}" in _install_summary_gpu_step("gfx1012")
+
+
+@_POSIX
[email protected]("torch_version", ["2.10.0a0+rocm7.10.0", "2.9.1+rocm6.4"])
+def test_setup_sh_a_kept_rocm_torch_is_not_called_cpu_only(torch_version):
+ """studio update keeps an existing ROCm build (TheRock, hand-installed)."""
+ out = _setup_report("gfx1010", "gfx1010", "AMD Radeon RX 5700 XT", torch_version)
+ assert "STEP: AMD Radeon RX 5700 XT (gfx1010)" in out, out
+ assert "CPU-only" not in out, out
+
+
+@_POSIX
+def test_setup_sh_a_cpu_torch_still_gets_the_warning():
+ out = _setup_report("gfx1010", "gfx1010", "AMD Radeon RX 5700 XT", "2.10.0+cpu")
+ assert "STEP: AMD GPU detected (gfx1010) -- no ROCm PyTorch wheels" in out, out
diff --git a/tests/studio/install/test_unsupported_arch_routing_guards_8529.py b/tests/studio/install/test_unsupported_arch_routing_guards_8529.py
index 252be7181a2..e992d10189f 100644
--- a/tests/studio/install/test_unsupported_arch_routing_guards_8529.py
+++ b/tests/studio/install/test_unsupported_arch_routing_guards_8529.py
@@ -312,6 +312,8 @@ def _run_sh_get_torch_index_url(arch: str, rocm_tag: str = "") -> "tuple[str, st
+ "\n"
+ bnb_floor_fn
+ "\n"
+ + _sh_function_body(src, "_hsa_override_gfx_arch")
+ + "\n"
+ _sh_function_body(src, "get_torch_index_url")
+ "\n"
+ _INDEX_URL_STUBS