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.

Unsloth Studio installer (AMD/Linux): send RDNA 4 cards (RX 9000, R9700) to AMD's gfx120X wheels (#11935)

Daniel Hancc44b7d2977d
diff --git a/install.sh b/install.sh
index cc7b970eb52..4aad9d3d408 100755
--- a/install.sh
+++ b/install.sh
@@ -6579,6 +6579,8 @@ _amd_gpu_radeon=false
_gfx_rocm64_target=false
_gfx_rocm64_floor_maj=""
_gfx_rocm64_floor_min=""
+_amd_arch_index_routed=false
+_amd_arch_index_family=""
if [ "$_torch_index_pinned" = false ]; then
# On the LEAF, like every other index classifier here: the AMD per-arch mirror is https://repo.amd.com/ROCM/whl/gfx120X-all/, so a whole-URL */rocm* glob brands every per-arch reroute as Radeon and the summary then reports repo.radeon.com wheels that were never fetched. The two older per-arch reroutes each clear the flag by hand afterwards; matching the leaf is what stops the next one from having to.
case "$_torch_index_leaf" in
@@ -6599,6 +6601,21 @@ _rocm_leaf_below() {
return 1
}
# 0 when the venv's torch has no identifiable rocm family at $2.$3 or newer, mirroring _installed_rocm_wheel_is_below in studio/install_python_stack.py
+# Venv torch's AMD per-arch family from the `rocm` meta-package (as install_python_stack.py); empty if unknown.
+_venv_torch_amd_family() {
+ "$1" -c 'import re
+from importlib import metadata
+try:
+ reqs = metadata.requires("rocm") or []
+except Exception:
+ reqs = []
+for r in reqs:
+ m = re.search(r"rocm[-_]sdk[-_]libraries[-_]([A-Za-z0-9][A-Za-z0-9._-]*)", r, re.I)
+ if m:
+ print(re.split(r"[=<>!~;,\[\]()\s]", m.group(1))[0].lower().replace("_", "-"))
+ break' 2>/dev/null || true
+}
+
_venv_torch_rocm_below() {
_vtr_leaf=$("$1" -c 'import re, torch; m = re.search(r"rocm([0-9]+)\.([0-9]+)", getattr(torch, "__version__", "") or ""); print("rocm%s.%s" % m.groups() if m else "")' 2>/dev/null || true)
[ -n "$_vtr_leaf" ] || return 0
@@ -6613,6 +6630,8 @@ case "$_torch_index_leaf" in
_gfx_rocm64_target=false
_gfx_rocm64_floor_maj=""
_gfx_rocm64_floor_min=""
+ _amd_arch_index_routed=false
+ _amd_arch_index_family=""
# One record per adapter in probe enumeration order, indexed by HIP_VISIBLE_DEVICES / ROCR_VISIBLE_DEVICES so the mask selects a CARD. A deduplicated arch list could not: gfx1100 + gfx1100 + gfx1200 ran off the end of a two-entry list, and a Strix iGPU + dGPU box rerouted the selected dGPU to the Strix per-gfx index. `|| true` on each probe so one that finds nothing does not abort the installer under set -euo pipefail before the next fallback. UNSLOTH_ROCM_GFX_ARCH overrides probing, mirroring setup.sh and the display block.
_gfx_all=$(printf '%s' "${UNSLOTH_ROCM_GFX_ARCH:-}" | tr '[:upper:]' '[:lower:]' | tr -d '[:space:]')
# strip a copied hip gcnArchName suffix, matching _gfx906_env below and the python helper
@@ -6747,6 +6766,8 @@ case "$_torch_index_leaf" in
_amd_strix_base="${_amd_strix_base%/}"
done
TORCH_INDEX_URL="${_amd_strix_base}/${_strix_gfx}/"
+ _amd_arch_index_routed=true
+ _amd_arch_index_family="$_strix_gfx"
TORCH_CONSTRAINT="torch>=2.11.0,<2.12.0"
# Pin companions to 2.11 (per-gfx index publishes them independently).
TORCHVISION_CONSTRAINT="torchvision>=0.26.0,<0.27.0"
@@ -6761,6 +6782,37 @@ case "$_torch_index_leaf" in
echo " [WARN] (~/.bashrc, ~/.profile) as well, or the next terminal restores it." >&2
fi
fi
+ # RDNA 4 generic wheels below 7.13 have a null HIP _grouped_mm (TheRock #5284); leaf rewritten so the rocm6.4 floor cannot undo it.
+ _rdna4_gfx=""
+ if [ "$_gfx906_env" != "gfx906" ]; then
+ case "$_runtime_gfx" in
+ gfx1200|gfx1201) _rdna4_gfx="$_runtime_gfx" ;;
+ esac
+ fi
+ # gfx120X-all publishes cp310+ only, so a 3.9 venv keeps the generic wheels.
+ if [ -n "$_rdna4_gfx" ] && [ "$("${VENV_DIR:-}/bin/python" -c 'import sys; print("%d.%d" % sys.version_info[:2])' 2>/dev/null || true)" = "3.9" ]; then
+ _rdna4_gfx=""
+ fi
+ if [ -n "$_rdna4_gfx" ] && _rocm_leaf_below "$_torch_index_leaf" 7 13; then
+ echo "" >&2
+ echo " [WARN] $_rdna4_gfx (RDNA 4) detected -- routing to the AMD arch-specific index" >&2
+ echo " [WARN] torch 2.11+rocm7.13 fixes the RDNA 4 _grouped_mm kernel that the" >&2
+ echo " [WARN] $_torch_index_leaf wheels lack, so training does not fall back to a slow path." >&2
+ echo "" >&2
+ _amd_rdna4_base="${UNSLOTH_AMD_ROCM_MIRROR:-https://repo.amd.com/rocm/whl}"
+ while [ "${_amd_rdna4_base%/}" != "$_amd_rdna4_base" ]; do
+ _amd_rdna4_base="${_amd_rdna4_base%/}"
+ done
+ # Literal, not _amd_arch_index_family_for_gfx: tests lift this arm out whole.
+ TORCH_INDEX_URL="${_amd_rdna4_base}/gfx120X-all/"
+ _amd_arch_index_routed=true
+ _amd_arch_index_family="gfx120x-all"
+ TORCH_CONSTRAINT="torch>=2.11.0,<2.12.0"
+ TORCHVISION_CONSTRAINT="torchvision>=0.26.0,<0.27.0"
+ TORCHAUDIO_CONSTRAINT="torchaudio>=2.11.0,<2.12.0"
+ _amd_gpu_radeon=false
+ _torch_index_leaf="gfx120x-all"
+ fi
# Navi 33 (gfx1102) and RDNA 4 (gfx1200/gfx1201) have no kernels in the
# older generic wheel families. The floor is per arch, read from the
# rocBLAS and hipBLASLt Tensile library names in each leaf's cp312 wheels:
@@ -7612,6 +7664,13 @@ if [ "$_MIGRATED" = true ]; then
# kernels for it. The SAME floor the reroute used, so an adequate wheel is left alone.
substep "reinstalling torch from $_torch_index_leaf (the migrated wheels have no kernels for this GPU)..."
_install_torch_default_index --force-reinstall
+ elif [ "${_amd_arch_index_routed:-false}" = true ] && {
+ _venv_torch_rocm_below "$_VENV_PY" 7 13 ||
+ { _vfam=$(_venv_torch_amd_family "$_VENV_PY")
+ [ -n "$_vfam" ] && [ "$_vfam" != "${_amd_arch_index_family:-}" ]; }; }; then
+ # Below 7.13 or another family's wheel lacks kernels; an unreadable family is left alone.
+ substep "reinstalling torch from the AMD per-arch index (the migrated wheels do not match it)..."
+ _install_torch_default_index --force-reinstall
fi
_gfx906_bnb_prune
fi
diff --git a/studio/backend/tests/test_rocm_torch_explicit_request.py b/studio/backend/tests/test_rocm_torch_explicit_request.py
index 60b290fc092..4863bcd94c8 100644
--- a/studio/backend/tests/test_rocm_torch_explicit_request.py
+++ b/studio/backend/tests/test_rocm_torch_explicit_request.py
@@ -2327,14 +2327,15 @@ def _unreadable_version_host(stack, monkeypatch, gfx: str) -> None:
_mixed_host(stack, monkeypatch, archs = [gfx], kfd = [gfx], rocm = None)
[email protected]("gfx", ["gfx1102", "gfx1200", "gfx1201"])
[email protected]("gfx", ["gfx1102"])
def test_an_unreadable_version_is_judged_as_the_installer_judges_it(stack, monkeypatch, gfx):
"""The two halves must not read the same unreadable version differently."""
_unreadable_version_host(stack, monkeypatch, gfx)
assert stack._forced_rocm_route_is_viable() is False
[email protected]("gfx", ["gfx1151", "gfx1103"])
+# RDNA 4 takes the AMD per-arch route like Strix; those wheels bundle their own ROCm (#11935).
[email protected]("gfx", ["gfx1151", "gfx1103", "gfx1200", "gfx1201"])
def test_an_unreadable_version_still_serves_the_arches_that_do_install(stack, monkeypatch, gfx):
"""The narrowing control."""
_unreadable_version_host(stack, monkeypatch, gfx)
diff --git a/studio/install_python_stack.py b/studio/install_python_stack.py
index 92469e7aac1..10d69d618b6 100644
--- a/studio/install_python_stack.py
+++ b/studio/install_python_stack.py
@@ -196,6 +196,13 @@ def _strix_needs_amd_arch_index(ver: tuple[int, int]) -> bool:
return key is None or key < _ROCM_ARCH_INDEX_FLOOR
+# RDNA 4 below 7.13 reroutes to AMD's per-arch index (TheRock #5284); gfx120X-all is cp310+ only.
+_AMD_ARCH_INDEX_FLOOR_GFX: frozenset[str] = frozenset(
+ {"gfx1151", "gfx1150", "gfx1152"}
+ | ({"gfx1200", "gfx1201"} if sys.version_info >= (3, 10) else set())
+)
+
+
# MI50 / Radeon VII (gfx906, Vega 20): rocm6.4+/7.x wheels bundle ROCm libraries
# whose Tensile kernels dropped gfx906 (rocBLAS "TensileLibrary.dat ... not read
# for gfx906", ROCm/TheRock#1844), failing at the first BLAS call. The rocm6.3
@@ -5584,13 +5591,13 @@ def _rocm_compat_reroute_pending(
"""Whether a compatibility reroute _ensure_rocm_torch performs has not been applied yet.
Neither reroute is about missing kernels, so neither is visible to the wheel-family
- question: Strix wants AMD's 7.13 build over any generic one below the floor, and gfx906
+ question: Strix / RDNA 4 want AMD's 7.13 build over any generic one below the floor, gfx906
wants the last tag whose BLAS still carries it. Both compare against what is installed,
so a host already on the right wheels keeps the fast path.
"""
if not runtime_gfx:
return False
- if runtime_gfx in _HSA_SPOOFABLE_PHYSICAL_GFX and _strix_needs_amd_arch_index(ver):
+ if runtime_gfx in _AMD_ARCH_INDEX_FLOOR_GFX and _strix_needs_amd_arch_index(ver):
return not _already_on_amd_arch_leaf(_GFX_TO_AMD_INDEX_ARCH.get(runtime_gfx), installed_ver)
if _runtime_target_is_gfx906() and _gfx906_needs_legacy_index(ver):
return _GFX906_LEGACY_TAG not in installed_ver
@@ -5953,8 +5960,7 @@ def _ensure_rocm_torch() -> None:
f"(studio/ROCM_RDNA2_APU.md) -- not installing ROCm torch for it.\n"
)
return
- _strix_gfx = {"gfx1151", "gfx1150", "gfx1152"}
- # Only the Strix reroute has a ROCm-version floor.
+ _strix_gfx = _AMD_ARCH_INDEX_FLOOR_GFX
_detected_strix = (
_strix_gfx.intersection(gfx_codes) if _strix_needs_amd_arch_index(ver) else set()
)
@@ -5981,12 +5987,12 @@ def _ensure_rocm_torch() -> None:
"torchaudio>=2.11.0,<2.12.0",
)
_safe_print(
- f" {_selected_gfx} (AMD Strix) is the runtime target with ROCm "
+ f" {_selected_gfx} is the runtime target with ROCm "
f"{ver[0]}.{ver[1]}.\n"
f" Routing torch install to AMD's arch-specific index\n"
f" ({_strip_index_url_credentials(_arch_index_url)}) which serves torch\n"
- f" 2.11.0+rocm7.13.0 with AMD's gfx1150/gfx1151 fixes (more reliable than\n"
- f" the generic pytorch.org rocm7.2 index on ROCm 7.3+ hosts).\n"
+ f" 2.11.0+rocm7.13.0 with AMD's fixes for this GPU (the generic pytorch.org\n"
+ f" wheels below 7.13 lack them).\n"
)
# Only on this branch: these wheels carry _selected_gfx kernels, so
# the runtime must stop reporting the spoofed arch or they have no
@@ -5997,8 +6003,8 @@ def _ensure_rocm_torch() -> None:
else:
_gfx_str = ", ".join(sorted(_detected_strix))
_safe_print(
- f" Strix GPU ({_gfx_str}) present but HIP_VISIBLE_DEVICES "
- f"selects a non-Strix runtime target ({_runtime_gfx});\n"
+ f" AMD per-gfx GPU ({_gfx_str}) present but HIP_VISIBLE_DEVICES "
+ f"selects another runtime target ({_runtime_gfx});\n"
f" skipping AMD per-gfx index override.\n"
)
diff --git a/tests/studio/install/test_missing_kernel_arch_routing_9396.py b/tests/studio/install/test_missing_kernel_arch_routing_9396.py
index 30e4c26a81b..fcc7d288bcc 100644
--- a/tests/studio/install/test_missing_kernel_arch_routing_9396.py
+++ b/tests/studio/install/test_missing_kernel_arch_routing_9396.py
@@ -234,7 +234,8 @@ def test_the_mirror_override_is_honoured():
# ── the neighbours this must not disturb ─────────────────────────────────────
[email protected]("gfx", ["gfx1100", "gfx1102", "gfx1030", "gfx1201"])
+# Not RDNA 4: rerouted below 7.13 (see test_rdna4_takes_the_amd_index_at_every_generic_tag).
[email protected]("gfx", ["gfx1100", "gfx1102", "gfx1030", "gfx1101"])
def test_a_supported_arch_keeps_the_generic_index(gfx):
calls = _run_install(gfx_devices = (gfx,))
assert _GENERIC in calls, calls
@@ -596,7 +597,7 @@ def test_a_leading_integrated_gpu_does_not_pick_the_family(apu):
"""Enumeration order alone puts the APU first on a Ryzen box with a Radeon card. The
family is chosen for ONE arch, so letting the APU decide strands the discrete card the
generic index was serving. _SHADOWING_INTEGRATED_GFX is the existing policy (#7776)."""
- calls = _run_install(gfx_devices = (apu, "gfx1200"))
+ calls = _run_install(gfx_devices = (apu, "gfx1100"))
assert _GENERIC in calls, calls
assert _AMD not in calls, calls
@@ -751,7 +752,7 @@ def test_a_stale_per_arch_family_is_replaced_when_the_target_goes_generic():
HIP_VISIBLE_DEVICES at one, and those wheels carry no kernels for the new target,
while torch.version.hip keeps rocm_torch_ready true and the fallback from running."""
calls = _run_install(
- gfx_devices = ("gfx1200",),
+ gfx_devices = ("gfx1030",),
torch_probe = _ROCM_ARCH_TORCH,
installed_family = "gfx110x-all",
)
@@ -1113,7 +1114,7 @@ def test_a_generic_wheel_is_judged_by_its_own_rocm_tag():
assert f"{_AMD}/gfx120X-all/" in calls, calls
# The wheel that does carry it is left alone, whatever the host version reads.
assert _AMD not in _run_install(
- gfx_devices = ("gfx1200",),
+ gfx_devices = ("gfx1102",),
rocm_version = (6, 3),
torch_probe = _ROCM_GENERIC_TORCH_72,
torch_owns_rocm = False,
@@ -1212,24 +1213,28 @@ def test_a_target_no_index_can_serve_is_not_worth_a_reinstall():
)
[email protected]("gfx", ["gfx1200", "gfx1201"])
@pytest.mark.parametrize(
"rocm_version, rerouted",
- [((6, 0), True), ((6, 3), True), ((6, 4), False), ((7, 1), False)],
+ [((6, 0), True), ((6, 2), True), ((6, 3), False), ((7, 1), False)],
)
-def test_generic_kernel_support_is_keyed_by_the_tag_the_version_selects(
- gfx, rocm_version, rerouted
-):
+def test_generic_kernel_support_is_keyed_by_the_tag_the_version_selects(rocm_version, rerouted):
"""Which arches the generic wheel carries belongs to the wheel a version resolves to, not
- the index as a whole. AMD puts production RDNA 4 at ROCm 6.4, so a current amdgpu beside a
- stale /opt/rocm gets a rocm6.3 wheel with no kernels while a gfx120X-all leaf exists."""
- calls = _run_install(gfx_devices = (gfx,), rocm_version = rocm_version)
+ the index as a whole. gfx1102 first ships in rocm6.3, so a stale /opt/rocm gets an older
+ wheel with no kernels while a gfx110X-all leaf exists."""
+ calls = _run_install(gfx_devices = ("gfx1102",), rocm_version = rocm_version)
if rerouted:
- assert f"{_AMD}/gfx120X-all/" in calls, calls
+ assert f"{_AMD}/gfx110X-all/" in calls, calls
else:
assert _AMD not in calls and _GENERIC in calls, calls
[email protected]("gfx", ["gfx1200", "gfx1201"])
[email protected]("rocm_version", [(6, 0), (6, 3), (6, 4), (7, 1)])
+def test_rdna4_takes_the_amd_index_at_every_generic_tag(gfx, rocm_version):
+ calls = _run_install(gfx_devices = (gfx,), rocm_version = rocm_version)
+ assert f"{_AMD}/gfx120X-all/" in calls, calls
+
+
@pytest.mark.parametrize("rocm_version", [(6, 0), (7, 1)])
def test_an_arch_with_no_recorded_minimum_is_unaffected_by_the_version(rocm_version):
"""The measurement covers rocm7.x; only arches known to postdate an older tag are keyed by
@@ -1274,7 +1279,7 @@ def test_a_masked_gfx906_on_a_mixed_host_is_not_demoted_to_another_dead_wheel():
assert _GENERIC not in calls, calls
# The same stale family with a routable target is still demoted.
_run_install(
- gfx_devices = ("gfx1100", "gfx1200"),
+ gfx_devices = ("gfx1100", "gfx1030"),
env = {"HIP_VISIBLE_DEVICES": "1"},
torch_probe = _ROCM_ARCH_TORCH,
installed_family = "gfx110x-all",
diff --git a/tests/studio/install/test_rocm_support.py b/tests/studio/install/test_rocm_support.py
index 6d4322aea1f..02591746258 100644
--- a/tests/studio/install/test_rocm_support.py
+++ b/tests/studio/install/test_rocm_support.py
@@ -1184,6 +1184,37 @@ class TestEnsureRocmTorch:
assert "gfx1150" in torch_call
assert "torch>=2.11.0,<2.12.0" in torch_call
+ @pytest.mark.parametrize("gfx", ("gfx1200", "gfx1201"))
+ def test_rocm_714_rdna4_routes_to_amd_arch_index(self, gfx):
+ mock_pip, _ = run_ensure_rocm_torch(
+ "2.11.0+rocm7.2|7.14.60850|",
+ _has_rocm_gpu = True,
+ _detect_rocm_version = (7, 14),
+ _detect_amd_gfx_codes = [gfx],
+ )
+ torch_call = str(mock_pip.call_args_list[0])
+ assert "gfx120X-all" in torch_call
+ assert "torch>=2.11.0,<2.12.0" in torch_call
+
+ def test_rocm_714_rdna3_stays_on_generic_cap(self):
+ mock_pip, _ = run_ensure_rocm_torch(
+ "",
+ _has_rocm_gpu = True,
+ _detect_rocm_version = (7, 14),
+ _detect_amd_gfx_codes = ["gfx1100"],
+ )
+ torch_call = str(mock_pip.call_args_list[0])
+ assert "rocm7.2" in torch_call
+ assert "repo.amd.com" not in torch_call
+
+ @pytest.mark.parametrize(
+ ("gfx", "pending"), (("gfx1201", True), ("gfx1200", True), ("gfx1100", False))
+ )
+ def test_rdna4_generic_wheel_is_a_pending_reroute(self, gfx, pending, monkeypatch):
+ monkeypatch.setattr(stack_mod, "_installed_rocm_wheel_family", lambda: None)
+ got = stack_mod._rocm_compat_reroute_pending(gfx, (7, 14), "2.11.0+rocm7.2")
+ assert bool(got) is pending
+
@patch.object(stack_mod, "IS_MACOS", False)
@patch("platform.machine", return_value = "x86_64")
@patch.object(stack_mod, "IS_WINDOWS", False)
@@ -1214,7 +1245,7 @@ class TestEnsureRocmTorch:
_ensure_rocm_torch()
calls = str(mock_pip.call_args_list) + str(mock_pip_try.call_args_list)
assert "gfx1151" not in calls
- assert "non-Strix runtime target (gfx1100)" in buf.getvalue()
+ assert "selects another runtime target (gfx1100)" in buf.getvalue()
# The venv is described by mocks like the hardware: the Strix skip arm asks
# _already_on_amd_arch_leaf, which reads this interpreter's own metadata, so on a host
@@ -1939,6 +1970,8 @@ class TestGfx906LegacyReroute:
# the first family carrying gfx1102/gfx1200/gfx1201, so gfx1102 floors at 6.3; gfx1200 and
# gfx1201 floor at 6.4 to match _GENERIC_WHEEL_GFX_MIN_ROCM and AMD's production matrix.
_GFX_FLOOR_TAG = {"gfx1102": "rocm6.3", "gfx1200": "rocm6.4", "gfx1201": "rocm6.4"}
+# RDNA 4 below 7.13 lands here instead of the rocm6.4 floor.
+_RDNA4_LEAF = "gfx120x-all"
class TestGfx1102Rocm64Floor:
@@ -1952,6 +1985,7 @@ class TestGfx1102Rocm64Floor:
pinned: bool = False,
rocm_ver: tuple = (6, 1),
probe_stdout: str = "\n", # CPU torch -> repair
+ wheel_family = None,
):
m = stack_mod
for name in (
@@ -1983,8 +2017,8 @@ class TestGfx1102Rocm64Floor:
# unpatched these read the RUNNING interpreter's torch instead: on a gfx1151
# Strix Halo runner holding 2.11.0+rocm7.13.0 the per-arch repick arm called
# pip_install, failing the assert_not_called tests on hardware only.
- patch.object(m, "_torch_requires_rocm_sdk", return_value = False),
- patch.object(m, "_installed_rocm_wheel_family", return_value = None),
+ patch.object(m, "_torch_requires_rocm_sdk", return_value = wheel_family is not None),
+ patch.object(m, "_installed_rocm_wheel_family", return_value = wheel_family),
patch.object(m, "_infer_linux_amd_gfx_arch", return_value = None),
patch.object(m, "_detect_rocm_version", return_value = rocm_ver),
patch.object(m, "_detect_amd_gfx_codes", return_value = [gfx]),
@@ -2059,14 +2093,42 @@ class TestGfx1102Rocm64Floor:
def test_installed_64_wheel_left_alone_on_newer_host(self, monkeypatch):
"""A wheel that already has the kernels must not be reinstalled."""
+ pip = self._ensure_for_gfx(
+ "gfx1102",
+ monkeypatch,
+ rocm_ver = (6, 4),
+ probe_stdout = _MARK + "2.8.0+rocm6.4|6.4.43482|\n",
+ )
+ pip.assert_not_called()
+
+ def test_rdna4_generic_64_wheel_moves_to_amd_arch_index(self, monkeypatch):
pip = self._ensure_for_gfx(
"gfx1200",
monkeypatch,
rocm_ver = (6, 4),
probe_stdout = _MARK + "2.8.0+rocm6.4|6.4.43482|\n",
)
+ torch_call = str(pip.call_args_list[0])
+ assert "gfx120X-all" in torch_call
+ assert "torch>=2.11.0,<2.12.0" in torch_call
+
+ def test_rdna4_already_on_amd_arch_wheel_is_left_alone(self, monkeypatch):
+ pip = self._ensure_for_gfx(
+ "gfx1201",
+ monkeypatch,
+ rocm_ver = (7, 14),
+ probe_stdout = _MARK + "2.11.0+rocm7.13.0|7.13.99004|\n",
+ wheel_family = "gfx120x-all",
+ )
pip.assert_not_called()
+ def test_rdna4_pinned_index_stays_authoritative(self, monkeypatch):
+ torch_call = str(
+ self._ensure_for_gfx("gfx1201", monkeypatch, pinned = True).call_args_list[0]
+ )
+ assert "whl/rocm6.1" in torch_call
+ assert "repo.amd.com" not in torch_call
+
def test_unaffected_arch_not_repaired_on_newer_host(self, monkeypatch):
"""gfx1100 has kernels in the older families, so its wheel stays untouched."""
pip = self._ensure_for_gfx(
@@ -2096,11 +2158,11 @@ class TestGfx1102Rocm64Floor:
pin_start = source.rfind('if [ "$_torch_index_pinned" = false ]; then', 0, start)
assert floor_pos >= 0 and pin_start >= 0 and pin_start < start
- for gfx, expected in (
- ("gfx1100", "rocm6.1"),
- ("gfx1102", "rocm6.3"),
- ("gfx1200", "rocm6.4"),
- ("gfx1201", "rocm6.4"),
+ for gfx, expected_url, expected in (
+ ("gfx1100", "rocm6.1", "rocm6.1"),
+ ("gfx1102", "rocm6.3", "rocm6.3"),
+ ("gfx1200", "gfx120X-all", _RDNA4_LEAF),
+ ("gfx1201", "gfx120X-all", _RDNA4_LEAF),
):
script = (
"set -euo pipefail\n"
@@ -2116,7 +2178,10 @@ class TestGfx1102Rocm64Floor:
)
result = _run_bash_script(shell, script, capture_output = True, text = True)
assert result.returncode == 0, result.stderr
- assert result.stdout.strip().endswith(f"/{expected} LEAF:{expected}"), result.stdout
+ out = result.stdout.strip()
+ assert out.endswith(f"/{expected_url} LEAF:{expected}") or out.endswith(
+ f"/{expected_url}/ LEAF:{expected}"
+ ), out
@staticmethod
def _install_sh_routing_result(
@@ -2166,8 +2231,8 @@ class TestGfx1102Rocm64Floor:
@pytest.mark.parametrize(
("mask", "expected"),
(
- ("CUDA_VISIBLE_DEVICES=1", "rocm6.4"),
- ("HIP_VISIBLE_DEVICES=1", "rocm6.4"),
+ ("CUDA_VISIBLE_DEVICES=1", _RDNA4_LEAF),
+ ("HIP_VISIBLE_DEVICES=1", _RDNA4_LEAF),
("CUDA_VISIBLE_DEVICES=0", "rocm6.1"),
# a set-but-empty hip mask selects no gpu instead of deferring to cuda
("HIP_VISIBLE_DEVICES= CUDA_VISIBLE_DEVICES=1", "rocm6.1"),
@@ -2231,8 +2296,8 @@ class TestGfx1102Rocm64Floor:
@pytest.mark.parametrize(
("mask", "expected"),
(
- ("HIP_VISIBLE_DEVICES=2", "rocm6.4"),
- ("CUDA_VISIBLE_DEVICES=2", "rocm6.4"),
+ ("HIP_VISIBLE_DEVICES=2", _RDNA4_LEAF),
+ ("CUDA_VISIBLE_DEVICES=2", _RDNA4_LEAF),
("HIP_VISIBLE_DEVICES=1", "rocm6.1"),
("HIP_VISIBLE_DEVICES=0", "rocm6.1"),
),
@@ -2246,8 +2311,8 @@ class TestGfx1102Rocm64Floor:
("rocr", "arches", "expected"),
(
# rocminfo reports the rocr selection in runtime order, so index 0 is the target
- ("1,0", ("gfx1200", "gfx1100"), "rocm6.4"),
- ("1", ("gfx1200",), "rocm6.4"),
+ ("1,0", ("gfx1200", "gfx1100"), _RDNA4_LEAF),
+ ("1", ("gfx1200",), _RDNA4_LEAF),
("0,1", ("gfx1100", "gfx1200"), "rocm6.1"),
),
)
@@ -2260,7 +2325,7 @@ class TestGfx1102Rocm64Floor:
@pytest.mark.parametrize(
("mask", "expected"),
- (("HIP_VISIBLE_DEVICES=2", "rocm6.4"), ("HIP_VISIBLE_DEVICES=1", "rocm6.1")),
+ (("HIP_VISIBLE_DEVICES=2", _RDNA4_LEAF), ("HIP_VISIBLE_DEVICES=1", "rocm6.1")),
)
def test_install_sh_splits_amd_smi_gpu_headers(self, mask, expected):
"""amd-smi heads each device with "GPU: N", so two gfx1100 cards stay two entries."""
@@ -2315,7 +2380,7 @@ class TestGfx1102Rocm64Floor:
+ self._amd_smi_stub("gfx1200", "gfx1200")
+ "export ROCR_VISIBLE_DEVICES=GPU-deadbeefdeadbeef"
)
- assert self._run_install_sh_routing(preamble) == "rocm6.4"
+ assert self._run_install_sh_routing(preamble) == _RDNA4_LEAF
def test_install_sh_declines_an_ordinal_when_amd_smi_gives_no_hip_map(self):
"""Without `list -e` there is no HIP order, so an ordinal names no known device.
@@ -2334,10 +2399,10 @@ class TestGfx1102Rocm64Floor:
@pytest.mark.parametrize(
("gfx", "leaf", "expected_leaf", "expected_target"),
(
- # already at or above the floor: no reroute, but the arch still needs it
- ("gfx1200", "rocm6.4", "rocm6.4", "true"),
- ("gfx1200", "rocm7.2", "rocm7.2", "true"),
- ("gfx1200", "rocm6.1", "rocm6.4", "true"),
+ # RDNA 4 below 7.13 always reroutes; the floor target stays set
+ ("gfx1200", "rocm6.4", _RDNA4_LEAF, "true"),
+ ("gfx1200", "rocm7.2", _RDNA4_LEAF, "true"),
+ ("gfx1200", "rocm6.1", _RDNA4_LEAF, "true"),
("gfx1100", "rocm6.4", "rocm6.4", "false"),
("gfx1100", "rocm6.1", "rocm6.1", "false"),
),
@@ -2379,6 +2444,9 @@ class TestGfx1102Rocm64Floor:
hip: str,
gfx_target: str,
floor: "tuple[int, int]" = (6, 4),
+ arch_routed: str = "false",
+ venv_family: str = "",
+ routed_family: str = "",
) -> str:
"""Execute install.sh's migrated-environment ROCm repair with a stubbed venv torch."""
shell = shutil.which("bash")
@@ -2402,6 +2470,10 @@ class TestGfx1102Rocm64Floor:
"t.version = v\n"
"sys.modules['torch'] = t\n"
"sys.modules['torch.version'] = v\n"
+ "import importlib.metadata as md\n"
+ f"fam = '{venv_family}'\n"
+ # Always stubbed: an AMD host's own rocm package must not leak in.
+ "md.requires = lambda n: ['rocm-sdk-libraries-' + fam + '==7.13.0'] if fam and n == 'rocm' else []\n"
"exec(sys.argv[1])\n"
'" "$2"\n'
)
@@ -2412,11 +2484,15 @@ class TestGfx1102Rocm64Floor:
+ "\n"
+ _extract_sh_function_body(source, "_venv_torch_rocm_below")
+ "\n"
+ + _extract_sh_function_body(source, "_venv_torch_amd_family")
+ + "\n"
+ "substep() { :; }\n"
+ '_install_torch_default_index() { printf "REINSTALL\\n"; }\n'
+ f'_VENV_PY="{venv_py.replace(os.sep, "/")}"\n'
+ f"_gfx_rocm64_target={gfx_target}\n"
+ f"_gfx_rocm64_floor_maj={floor[0]}\n_gfx_rocm64_floor_min={floor[1]}\n"
+ + f"_amd_arch_index_routed={arch_routed}\n"
+ + f'_amd_arch_index_family="{routed_family}"\n'
+ f'_torch_index_leaf="rocm{floor[0]}.{floor[1]}"\n'
+ source[start:end]
+ '\nprintf "DONE\\n"\n'
@@ -2450,6 +2526,51 @@ class TestGfx1102Rocm64Floor:
assert "DONE" in out, out
assert ("REINSTALL" in out) is reinstalls, out
+ @pytest.mark.parametrize(
+ ("torch_version", "arch_routed", "reinstalls"),
+ (
+ # Routed to a per-arch index: a migrated generic 7.2 wheel is what the route replaces.
+ ("2.11.0+rocm7.2", "true", True),
+ ("2.9.1+rocm6.4", "true", True),
+ ("2.11.0+rocm7.13.0", "true", False),
+ ("2.11.0+rocm7.2", "false", False),
+ ),
+ )
+ def test_install_sh_migrated_repair_honors_the_arch_index_route(
+ self, torch_version, arch_routed, reinstalls
+ ):
+ out = self._run_migrated_rocm_repair(
+ torch_version, "7.2.0", "true", (6, 4), arch_routed = arch_routed
+ )
+ assert "DONE" in out, out
+ assert ("REINSTALL" in out) is reinstalls, out
+
+ @pytest.mark.parametrize(
+ ("venv_family", "routed_family", "reinstalls"),
+ (
+ # A 7.13 wheel for another family (a gfx1151 venv reused on RDNA 4) has no kernels.
+ ("gfx1151", "gfx120x-all", True),
+ ("gfx120X-all", "gfx1151", True),
+ ("gfx120X-all", "gfx120x-all", False),
+ ("gfx1151", "gfx1151", False),
+ ("", "gfx120x-all", False),
+ ),
+ )
+ def test_install_sh_migrated_repair_honors_the_arch_index_family(
+ self, venv_family, routed_family, reinstalls
+ ):
+ out = self._run_migrated_rocm_repair(
+ "2.11.0+rocm7.13.0",
+ "7.13.0",
+ "true",
+ (6, 4),
+ arch_routed = "true",
+ venv_family = venv_family,
+ routed_family = routed_family,
+ )
+ assert "DONE" in out, out
+ assert ("REINSTALL" in out) is reinstalls, out
+
@pytest.mark.parametrize(
"override",
("gfx1200:xnack-", "GFX1200:XNACK-", " gfx1200 ", "gfx1201:sramecc+:xnack-"),
@@ -2457,7 +2578,30 @@ class TestGfx1102Rocm64Floor:
def test_install_sh_normalizes_gcn_arch_name_override(self, override):
"""UNSLOTH_ROCM_GFX_ARCH copied from a HIP gcnArchName still matches the floor."""
preamble = f'export UNSLOTH_ROCM_GFX_ARCH="{override}"'
- assert self._run_install_sh_routing(preamble) == "rocm6.4"
+ assert self._run_install_sh_routing(preamble) == _RDNA4_LEAF
+
+ @pytest.mark.parametrize(
+ ("gfx", "leaf", "expected"),
+ (
+ ("gfx1201", "rocm7.2", _RDNA4_LEAF),
+ ("gfx1200", "rocm7.2", _RDNA4_LEAF),
+ ("gfx1201", "rocm7.13", "rocm7.13"),
+ ("gfx1100", "rocm7.2", "rocm7.2"),
+ ),
+ )
+ def test_install_sh_routes_rdna4_below_713_to_amd_arch_index(self, gfx, leaf, expected):
+ preamble = f'export UNSLOTH_ROCM_GFX_ARCH="{gfx}"'
+ assert self._install_sh_routing_result(preamble, leaf = leaf)[0] == expected
+
+ @pytest.mark.parametrize(("py", "expected"), (("3.9", "rocm6.4"), ("3.12", _RDNA4_LEAF)))
+ def test_install_sh_keeps_rdna4_generic_on_python_39(self, tmp_path, py, expected):
+ """gfx120X-all has no cp39 wheels, so a 3.9 venv keeps the generic rocm6.4 route."""
+ (tmp_path / "bin").mkdir()
+ stub = tmp_path / "bin" / "python"
+ stub.write_text(f"#!/bin/sh\necho {py}\n")
+ stub.chmod(0o755)
+ preamble = f'export UNSLOTH_ROCM_GFX_ARCH="gfx1201"\nVENV_DIR="{tmp_path}"'
+ assert self._install_sh_routing_result(preamble, leaf = "rocm6.4")[0] == expected
# TEST: install_python_stack.py -- torch-index MARKER mechanism (PR #6692)
@@ -8309,3 +8453,17 @@ class TestBnbRocmProvenance:
with patch.object(stack_mod, "pip_install_try", return_value = True) as mock_pip:
assert stack_mod._install_bnb_windows_rocm() is True
assert mock_pip.call_count == 0
+
+
+class _Py39(tuple):
+ major, minor, micro = 3, 9, 18
+
+
+def test_python_39_keeps_rdna4_off_the_amd_arch_index(monkeypatch):
+ monkeypatch.setattr(sys, "version_info", _Py39((3, 9, 18, "final", 0)))
+ spec = importlib.util.spec_from_file_location("studio_install_python_stack_py39", _STACK_PATH)
+ mod = importlib.util.module_from_spec(spec)
+ spec.loader.exec_module(mod)
+ assert not {"gfx1200", "gfx1201"} & mod._AMD_ARCH_INDEX_FLOOR_GFX
+ assert {"gfx1150", "gfx1151", "gfx1152"} <= mod._AMD_ARCH_INDEX_FLOOR_GFX
+ assert {"gfx1200", "gfx1201"} <= stack_mod._AMD_ARCH_INDEX_FLOOR_GFX
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 c3064b8e7c2..81eb82c402b 100644
--- a/tests/studio/install/test_unsupported_arch_routing_guards_8529.py
+++ b/tests/studio/install/test_unsupported_arch_routing_guards_8529.py
@@ -564,14 +564,15 @@ class TestPowerShellMapEvaluated:
# a routing site the assertions above cannot see. Reachability is narrow, but "narrow" is
# not the property this file defends, and the literal is one line per source.
_STRIX_SITES = [
- (_INSTALL_SH, r"^\s*(gfx[0-9a-z|]+)\)\s+_strix_gfx="),
- (_STACK_PY, r"^\s*_strix_gfx\s*=\s*\{([^}]*)\}"),
+ (_INSTALL_SH, r"^\s*(gfx[0-9a-z|]+)\)\s+_strix_gfx=", "gfx1151"),
+ (_INSTALL_SH, r"^\s*(gfx[0-9a-z|]+)\)\s+_rdna4_gfx=", "gfx1201"),
+ (_STACK_PY, r"^_AMD_ARCH_INDEX_FLOOR_GFX\b[^=]*=\s*frozenset\(\s*\{([^}]*)\}", "gfx1151"),
]
-_STRIX_IDS = [p.name for p, _r in _STRIX_SITES]
+_STRIX_IDS = ["install.sh", "install.sh-rdna4", "install_python_stack.py"]
[email protected]("source_path,pattern", _STRIX_SITES, ids = _STRIX_IDS)
-def test_the_strix_reroute_names_no_unsupported_arch(source_path, pattern):
[email protected]("source_path,pattern,routed", _STRIX_SITES, ids = _STRIX_IDS)
+def test_the_strix_reroute_names_no_unsupported_arch(source_path, pattern, routed):
src = source_path.read_text(encoding = "utf-8")
hits = re.findall(pattern, src, re.MULTILINE)
assert hits, f"{source_path.name}: the Strix reroute arm was not found; was it renamed?"
@@ -582,7 +583,7 @@ def test_the_strix_reroute_names_no_unsupported_arch(source_path, pattern):
f"builds a repo.amd.com URL without going through the family map"
)
# Positive control: the arm really does name the arches it is supposed to route.
- assert "gfx1151" in named, f"{source_path.name}: extraction matched nothing useful"
+ assert routed in named, f"{source_path.name}: extraction matched nothing useful"
# ── The CPU summary must blame the card the fallback is actually about ───────