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): use ROCm 6.4 PyTorch on ROCm 6.0 to 6.3 so bitsandbytes training doesn't crash (#10277)

Natani L. Mayday267f03500f1a
diff --git a/install.sh b/install.sh
index 6a9d084a089..54a44958881 100755
--- a/install.sh
+++ b/install.sh
@@ -5701,6 +5701,21 @@ _detect_rocm_version_tag() {
printf '%s\n' "$_rt_best"
}
+# The generic bitsandbytes ROCm wheel is built for the rocm6.4 ABI. Keep the
+# published ROCm leaf mapping in get_torch_index_url intact for explicit and
+# legacy callers, but floor automatic generic selections to this compatible tag.
+_ROCM_BNB_GENERIC_FLOOR_TAG="rocm6.4"
+_rocm_bnb_compatible_generic_tag() {
+ case "$1" in
+ rocm6.0|rocm6.0.*|rocm6.1|rocm6.1.*|rocm6.2|rocm6.2.*|rocm6.3|rocm6.3.*)
+ printf '%s\n' "$_ROCM_BNB_GENERIC_FLOOR_TAG"
+ ;;
+ *)
+ printf '%s\n' "$1"
+ ;;
+ esac
+}
+
# ── Detect GPU and choose PyTorch index URL ──
# Mirrors Get-TorchIndexUrl in install.ps1.
# On CPU-only machines this returns the cpu index, avoiding the solver
@@ -5859,10 +5874,20 @@ get_torch_index_url() {
(*)
echo "$_base/rocm7.2" ;;
esac)
+ _rocm_selected_tag=${_rocm_index##*/}
+ # Automatic generic 6.0-6.3 selections floor to rocm6.4, the oldest ROCm the bitsandbytes
+ # wheel ships a library for (#10273). A sole gfx906 keeps the literal tag for its legacy
+ # route and BNB skip. Normalize like _is_gfx906_bnb_skip: rocminfo names each agent twice
+ # and an override keeps its ISA suffix; a mixed host dedupes to two arches and floors.
+ _bnb_floor_gfx=$(printf '%s\n' "$_amd_gfx_probe" \
+ | sed 's/:.*$//' | tr -d '[:blank:]' | awk 'NF && !seen[$0]++')
+ case "$_bnb_floor_gfx" in
+ (gfx906) : ;;
+ (*) _rocm_index="$_base/$(_rocm_bnb_compatible_generic_tag "$_rocm_selected_tag")" ;;
+ esac
# No UNSLOTH_TORCH_INDEX_FAMILY hint: newer leaves have nothing inside _TORCH_CEILING (#10657).
- _rocm_leaf=${_rocm_index##*/}
- if [ "$_rocm_tag" != "$_rocm_leaf" ]; then
- echo "[INFO] No validated PyTorch for ROCm ${_rocm_tag#rocm}; capping to the $_rocm_leaf index (its wheels bundle their own runtime, so this is expected)." >&2
+ if [ "$_rocm_tag" != "$_rocm_selected_tag" ]; then
+ echo "[INFO] No validated PyTorch for ROCm ${_rocm_tag#rocm}; capping to the $_rocm_selected_tag index (its wheels bundle their own runtime, so this is expected)." >&2
fi
echo "$_rocm_index"
return
@@ -6397,6 +6422,25 @@ _pick_radeon_wheel() {
esac
}
+# True when torch $1 (X.Y) can run torch.compile on the Python of Radeon wheel tag $2 (cpXY):
+# Dynamo reached 3.13 in torch 2.6 and 3.14 in 2.10. rocm-rel-6.4's only cp313 torch is 2.5.1,
+# which imports fine and then fails the first training step.
+_radeon_torch_compiles_for_pytag() {
+ case "$2" in
+ cp313) _rtc_need=6 ;;
+ cp314) _rtc_need=10 ;;
+ *) return 0 ;;
+ esac
+ _rtc_major="${1%%.*}"
+ _rtc_minor="${1#*.}"
+ _rtc_minor="${_rtc_minor%%.*}"
+ case "$_rtc_major$_rtc_minor" in
+ ''|*[!0-9]*) return 1 ;;
+ esac
+ [ "$_rtc_major" -gt 2 ] && return 0
+ [ "$_rtc_major" -eq 2 ] && [ "$_rtc_minor" -ge "$_rtc_need" ]
+}
+
# ── ROCm-on-WSL bootstrap for AMD Strix Halo (gfx1151) ───────────────────────
# Idempotent, no-op without librocdxg, best-effort; sudo-tee when not root.
_persist_rocm_wsl_dropin() {
@@ -8114,6 +8158,15 @@ elif [ -n "$TORCH_INDEX_URL" ]; then
done
fi
+ # A matched set can still be unusable for training on this Python; the ROCm index
+ # carries newer builds for it (rocm6.4 has torch 2.9.1 for cp313).
+ _sel_torch_ver=$(_extract_version "$_torch_whl" "torch")
+ if [ "$_radeon_versions_match" = true ] && [ -n "$_sel_torch_ver" ] && \
+ ! _radeon_torch_compiles_for_pytag "$_sel_torch_ver" "$_RADEON_PYTAG"; then
+ substep "[WARN] Radeon repo's newest $_RADEON_PYTAG PyTorch is $_sel_torch_ver, which cannot run torch.compile on this Python" "$C_WARN"
+ _radeon_versions_match=false
+ fi
+
if [ -z "$_torch_whl" ] || [ -z "$_tv_whl" ] || [ -z "$_ta_whl" ] || \
[ "$_radeon_versions_match" != true ]; then
substep "[WARN] Radeon repo lacks a compatible wheel set for this Python; falling back to ROCm index ($(_strip_index_url_credentials "$TORCH_INDEX_URL"))" "$C_WARN"
diff --git a/studio/backend/tests/test_rocm_torch_explicit_request.py b/studio/backend/tests/test_rocm_torch_explicit_request.py
index 4863bcd94c8..9b84fa79e2d 100644
--- a/studio/backend/tests/test_rocm_torch_explicit_request.py
+++ b/studio/backend/tests/test_rocm_torch_explicit_request.py
@@ -153,6 +153,16 @@ def _shell_function(name: str) -> str:
raise AssertionError(f"unterminated function {name}")
+def _shell_constant(name: str) -> str:
+ """One top-level `NAME=value` assignment from install.sh."""
+ install_sh = Path(__file__).resolve().parents[3] / "install.sh"
+ return next(
+ line
+ for line in install_sh.read_text(encoding = "utf-8").splitlines()
+ if line.startswith(f"{name}=")
+ )
+
+
def _clean_env(extra: "dict | None" = None) -> dict:
"""The runner's environment minus the two things that decide these cases by themselves."""
env = {
@@ -237,6 +247,10 @@ def _index_url(env: str, stubs: str) -> str:
stubs,
# The stubs above name this host's arch family, so it is not lifted here.
*_wheel_route_defs(arch_family = False),
+ # The generic route floors its leaf through this helper; left undefined, the
+ # substitution is empty and every generic pick reads as a bare ".../whl/".
+ _shell_constant("_ROCM_BNB_GENERIC_FLOOR_TAG"),
+ _shell_function("_rocm_bnb_compatible_generic_tag"),
_shell_function("get_torch_index_url"),
f"{env} get_torch_index_url",
]
diff --git a/studio/install_python_stack.py b/studio/install_python_stack.py
index 93e32f7290f..4d672d672c5 100644
--- a/studio/install_python_stack.py
+++ b/studio/install_python_stack.py
@@ -182,6 +182,24 @@ def _generic_pytorch_rocm_tag(ver: tuple[int, int]) -> str | None:
)
+# The generic bitsandbytes ROCm wheel is currently built for the rocm6.4 ABI. Keep
+# the published host-to-index mapping above literal (callers may still explicitly
+# select an older leaf), but floor automatic generic installs so torch and bnb agree.
+_GENERIC_ROCM_BNB_COMPAT_FLOOR = (6, 4)
+_GENERIC_ROCM_BNB_COMPAT_TAG = "rocm6.4"
+
+
+def _automatic_generic_pytorch_rocm_tag(ver: tuple[int, int]) -> str | None:
+ """Generic tag for an automatic install, floored to the BNB-compatible ABI."""
+ tag = _generic_pytorch_rocm_tag(ver)
+ if tag is None:
+ return None
+ key = next((k for k, candidate in _ROCM_TORCH_INDEX.items() if candidate == tag), None)
+ if key is not None and key < _GENERIC_ROCM_BNB_COMPAT_FLOOR:
+ return _GENERIC_ROCM_BNB_COMPAT_TAG
+ return tag
+
+
_ROCM_ARCH_INDEX_FLOOR = (7, 13) # AMD per-arch index ships torch 2.11+rocm7.13
@@ -5935,6 +5953,12 @@ def _amd_torch_needs_dependency_pass() -> bool:
# floor still needs the 7.13 fixes, and a sole gfx906 above rocm6.3 has no BLAS kernels.
if _rocm_compat_reroute_pending(_tail_gfx, _tail_ver, _version.lower()):
return True
+ # The generic bitsandbytes wheel is built for the rocm6.4 ABI. An automatic host therefore
+ # needs a torch reinstall when its existing generic wheel still names an older ABI;
+ # explicit pins, per-arch wheels, and gfx906 are excluded by the helper so their
+ # established routing remains authoritative.
+ if _generic_rocm_bnb_floor_pending(_tail_gfx, _detect_rocm_version(), _version.lower()):
+ return True
return _rocm_torch_family_needs_repair(_tail_gfx, _detect_rocm_version(), _tail_host)
@@ -5989,6 +6013,34 @@ def _installed_generic_rocm_tag() -> "tuple[int, int] | None":
return (int(_m.group(1)), int(_m.group(2))) if _m else None
+def _generic_rocm_bnb_floor_pending(
+ runtime_gfx: "str | None", host_ver: "tuple[int, int] | None", installed_ver: str
+) -> bool:
+ """Whether an automatic generic torch install predates the generic BNB ABI floor.
+
+ This is deliberately separate from ``_generic_pytorch_rocm_tag``: the latter is the
+ literal host-to-published-index resolver and remains authoritative for explicit pins.
+ Per-architecture AMD wheels own their ROCm runtime, and gfx906 keeps its legacy
+ rocm6.3-or-older path, so neither is subject to the generic BNB floor.
+ """
+ if (
+ not runtime_gfx
+ or runtime_gfx.lower() == "gfx906"
+ or host_ver is None
+ or _explicit_torch_index_url() is not None
+ ):
+ return False
+ if _torch_requires_rocm_sdk():
+ return False
+ if _generic_pytorch_rocm_tag(host_ver) is None:
+ return False
+ _installed_match = re.search(r"\+rocm(\d+)\.(\d+)", (installed_ver or "").lower())
+ if _installed_match is None:
+ return False
+ _installed_ver = (int(_installed_match.group(1)), int(_installed_match.group(2)))
+ return _installed_ver < _GENERIC_ROCM_BNB_COMPAT_FLOOR
+
+
def _rocm_torch_family_needs_repair(
runtime_gfx: "str | None",
ver: "tuple[int, int] | None" = None,
@@ -6386,6 +6438,7 @@ def _ensure_rocm_torch() -> "bool | None":
# for an arch the generic wheel carries no kernels for at all.
_arch_index_url: "str | None" = None
_arch_index_pkgs: "tuple[str, str, str] | None" = None
+ _runtime_gfx: "str | None" = None
# An explicit ROCm pin wins; otherwise both reroutes share one hardware probe. Skipped
# once the inferred-arch install above has run: it resolves the same index, so re-deriving
# it here only force-reinstalls what was just downloaded.
@@ -6649,6 +6702,23 @@ def _ensure_rocm_torch() -> "bool | None":
# normalization, so asking it alone loses nothing, and ORing the override back in would
# walk the no-GPU mask guard it applies above that read.
_runtime_is_gfx906 = _runtime_target_is_gfx906()
+ # The generic bitsandbytes ROCm wheel targets the rocm6.4 ABI. Re-run the automatic
+ # generic torch selection when an existing generic wheel below that ABI would otherwise
+ # be paired with it. This is intentionally after the per-arch/missing-kernel routing and
+ # excludes explicit pins and gfx906's legacy path.
+ if (
+ rocm_torch_ready
+ and _rocm_pin is None
+ and not _inferred_arch_installed
+ and _arch_index_url is None
+ and not _runtime_is_gfx906
+ and _generic_rocm_bnb_floor_pending(_runtime_gfx, ver, _installed_torch_ver)
+ ):
+ _safe_print(
+ " installed generic ROCm torch is below the rocm6.4 bitsandbytes ABI floor "
+ "-- reinstalling from the compatible generic index."
+ )
+ rocm_torch_ready = False
# Reroute torch to the last gfx906-capable wheel family (rocm6.3) only when the
# host ROCm version would otherwise pick a newer, kernel-less index -- and never
# over an explicit pin or an active Strix reroute (the pin/Strix path installs
@@ -6730,7 +6800,20 @@ def _ensure_rocm_torch() -> "bool | None":
elif _rocm_pin_unusable:
tag = _pin_family
else:
- tag = _generic_pytorch_rocm_tag(ver)
+ # Automatic generic installs must use the ABI floor required by the
+ # generic bitsandbytes wheel, but only for a target known NOT to be gfx906:
+ # gfx906 keeps its legacy rocm6.0-6.3 path (rocm6.4 has no gfx906 BLAS
+ # kernels), and an unreadable arch might be one, so it keeps the literal
+ # resolver as before. _runtime_gfx also carries a KFD-only reading that
+ # _runtime_is_gfx906 does not see. Same gfx906 exclusion as the repair above.
+ _bnb_floor_target = (
+ bool(_runtime_gfx) and _runtime_gfx.lower() != "gfx906" and not _runtime_is_gfx906
+ )
+ tag = (
+ _automatic_generic_pytorch_rocm_tag(ver)
+ if _bnb_floor_target
+ else _generic_pytorch_rocm_tag(ver)
+ )
if tag is None:
_safe_print(
f" No PyTorch wheel for ROCm {ver[0]}.{ver[1]} -- skipping torch reinstall"
diff --git a/tests/sh/test_get_torch_index_url.sh b/tests/sh/test_get_torch_index_url.sh
index ffd44426d60..615d0f8c32d 100755
--- a/tests/sh/test_get_torch_index_url.sh
+++ b/tests/sh/test_get_torch_index_url.sh
@@ -79,6 +79,9 @@ _FAKE_ROCM_DIR=$(mktemp -d)
echo ""
sed -n '/^_detect_rocm_version_tag()/,/^}/p' "$INSTALL_SH"
echo ""
+ sed -n '/^_ROCM_BNB_GENERIC_FLOOR_TAG=/p' "$INSTALL_SH"
+ sed -n '/^_rocm_bnb_compatible_generic_tag()/,/^}/p' "$INSTALL_SH"
+ echo ""
sed -n '/^get_torch_index_url()/,/^}/p' "$INSTALL_SH"
} | sed -e "s|/usr/bin/nvidia-smi|$_FAKE_SMI_DIR/nvidia-smi-absent|g" \
-e "s|/opt/rocm|$_FAKE_ROCM_DIR|g" \
@@ -87,7 +90,7 @@ _FAKE_ROCM_DIR=$(mktemp -d)
for _fn in _rocm_tag_from_amd_smi _rocm_tag_from_version_file _rocm_tag_from_hipconfig \
_rocm_tag_from_dpkg _rocm_tag_from_rpm _highest_rocm_tag \
- _detect_rocm_version_tag get_torch_index_url; do
+ _detect_rocm_version_tag _rocm_bnb_compatible_generic_tag get_torch_index_url; do
if ! grep -q "^$_fn()" "$_FUNC_FILE"; then
echo "FAIL: install.sh no longer defines $_fn() at column 0"
exit 1
@@ -156,11 +159,12 @@ MOCK
# the GPU presence check (amd-smi list) also succeeds in tests.
make_mock_amd_smi() {
_dir=$(mktemp -d)
+ _gfx_arch="${2:-gfx1100}"
cat > "$_dir/amd-smi" <<MOCK
#!/bin/sh
case "\$1" in
list)
- printf 'GPU: 0\\n BDF: 0000:03:00.0\\n NAME: gfx1100\\n'
+ printf 'GPU: 0\\n BDF: 0000:03:00.0\\n NAME: $_gfx_arch\\n'
;;
*)
cat <<AMD_OUT
@@ -173,6 +177,62 @@ MOCK
echo "$_dir"
}
+# amd-smi above emits ONE gfx token, which is not the shape a real host produces:
+# _probe_amd_gfx_arch greps every match out of rocminfo, and rocminfo names each
+# agent twice (Name: and the ISA Name:), so one card reads as two identical lines.
+# Any gfx comparison that matters has to be exercised against this shape.
+# $1 ROCm version, $2 gfx arch, $3 GPU agent count (default 1).
+make_mock_rocminfo() {
+ _dir=$(make_mock_amd_smi "$1" "$2")
+ _rocm_gfx="$2"
+ _rocm_agents="${3:-1}"
+ {
+ echo '#!/bin/sh'
+ echo "cat <<'ROCMINFO_OUT'"
+ echo 'ROCk module is loaded'
+ echo 'Agent 1'
+ echo ' Name: AMD Ryzen 9 5950X'
+ echo ' Device Type: CPU'
+ _i=0
+ while [ "$_i" -lt "$_rocm_agents" ]; do
+ echo "Agent $((_i + 2))"
+ echo " Name: $_rocm_gfx"
+ echo ' Device Type: GPU'
+ echo ' ISA Info:'
+ echo " Name: amdgcn-amd-amdhsa--$_rocm_gfx:sramecc-:xnack-"
+ _i=$((_i + 1))
+ done
+ echo 'ROCMINFO_OUT'
+ } > "$_dir/rocminfo"
+ chmod +x "$_dir/rocminfo"
+ echo "$_dir"
+}
+
+# Same, for a mixed host: $2 is a space-separated arch list, one GPU agent each.
+make_mock_rocminfo_multi() {
+ _dir=$(make_mock_amd_smi "$1" "${2%% *}")
+ _rocm_n=1
+ {
+ echo '#!/bin/sh'
+ echo "cat <<'ROCMINFO_OUT'"
+ echo 'ROCk module is loaded'
+ echo 'Agent 1'
+ echo ' Name: AMD Ryzen 9 5950X'
+ echo ' Device Type: CPU'
+ for _a in $2; do
+ _rocm_n=$((_rocm_n + 1))
+ echo "Agent $_rocm_n"
+ echo " Name: $_a"
+ echo ' Device Type: GPU'
+ echo ' ISA Info:'
+ echo " Name: amdgcn-amd-amdhsa--$_a:sramecc-:xnack-"
+ done
+ echo 'ROCMINFO_OUT'
+ } > "$_dir/rocminfo"
+ chmod +x "$_dir/rocminfo"
+ echo "$_dir"
+}
+
# Build a minimal tools directory with symlinks to essential commands
# (uname, grep, head, etc.) but WITHOUT nvidia-smi or amd-smi.
_TOOLS_DIR=$(mktemp -d)
@@ -385,10 +445,10 @@ case "$(tr '\n' ' ' < "$_dir/bounds")" in *45*) _result=retried ;; *) _result="b
assert_eq "the retry uses the 45s bound" "retried" "$_result"
rm -rf "$_dir"
-# 9) ROCm 6.3 (no nvidia-smi) -> rocm6.3
+# 9) ROCm 6.3 (no nvidia-smi) -> rocm6.4 for the generic BNB ABI floor
_dir=$(make_mock_amd_smi "6.3")
_result=$(run_func "$_dir")
-assert_eq "ROCm 6.3 -> rocm6.3" "https://download.pytorch.org/whl/rocm6.3" "$_result"
+assert_eq "ROCm 6.3 automatic generic floor -> rocm6.4" "https://download.pytorch.org/whl/rocm6.4" "$_result"
rm -rf "$_dir"
# 10) ROCm 7.1 (no nvidia-smi) -> rocm7.1
@@ -417,10 +477,61 @@ rm -rf "$_cuda_dir" "$_amd_dir" "$_combined_dir"
_result=$(run_func "none")
assert_eq "no GPU -> cpu" "https://download.pytorch.org/whl/cpu" "$_result"
-# 14) ROCm 6.1 (no nvidia-smi) -> rocm6.1
+# 14) ROCm 6.1 (no nvidia-smi) -> rocm6.4 for the generic BNB ABI floor
_dir=$(make_mock_amd_smi "6.1")
_result=$(run_func "$_dir")
-assert_eq "ROCm 6.1 -> rocm6.1" "https://download.pytorch.org/whl/rocm6.1" "$_result"
+assert_eq "ROCm 6.1 automatic generic floor -> rocm6.4" "https://download.pytorch.org/whl/rocm6.4" "$_result"
+rm -rf "$_dir"
+
+# 14a) The other old supported tags share the same automatic generic floor.
+_dir=$(make_mock_amd_smi "6.0")
+_result=$(run_func "$_dir")
+assert_eq "ROCm 6.0 automatic generic floor -> rocm6.4" "https://download.pytorch.org/whl/rocm6.4" "$_result"
+rm -rf "$_dir"
+
+_dir=$(make_mock_amd_smi "6.2")
+_result=$(run_func "$_dir")
+assert_eq "ROCm 6.2 automatic generic floor -> rocm6.4" "https://download.pytorch.org/whl/rocm6.4" "$_result"
+rm -rf "$_dir"
+
+# gfx906 is intentionally exempt from the generic floor; its later installer block
+# keeps the legacy rocm6.3 route for hosts whose detected tag is newer than 6.3.
+_dir=$(make_mock_amd_smi "6.1" "gfx906")
+_result=$(run_func "$_dir")
+assert_eq "gfx906 ROCm 6.1 keeps its legacy generic tag" "https://download.pytorch.org/whl/rocm6.1" "$_result"
+rm -rf "$_dir"
+
+# The exemption must survive the shape REAL discovery produces, not just the single
+# token amd-smi emits. rocminfo names each agent twice, so one MI50 probes as
+# "gfx906\ngfx906"; comparing the raw probe floored it to rocm6.4 and handed it to
+# the legacy reroute, which then rewrote it to rocm6.3 instead of the literal tag.
+_dir=$(make_mock_rocminfo "6.1" "gfx906" 1)
+_result=$(run_func "$_dir")
+assert_eq "gfx906 via rocminfo (agent named twice) keeps rocm6.1" "https://download.pytorch.org/whl/rocm6.1" "$_result"
+rm -rf "$_dir"
+
+_dir=$(make_mock_rocminfo "6.1" "gfx906" 2)
+_result=$(run_func "$_dir")
+assert_eq "two gfx906 agents still keep rocm6.1" "https://download.pytorch.org/whl/rocm6.1" "$_result"
+rm -rf "$_dir"
+
+# A copied HIP gcnArchName in the override keeps its ISA suffix; every other gfx906
+# comparison in install.sh strips it, so this one must too.
+_dir=$(make_mock_amd_smi "6.1" "gfx906")
+_result=$(UNSLOTH_ROCM_GFX_ARCH=gfx906:sramecc-:xnack- run_func "$_dir")
+assert_eq "suffixed gfx906 override keeps rocm6.1" "https://download.pytorch.org/whl/rocm6.1" "$_result"
+rm -rf "$_dir"
+
+# The floor itself must still reach a non-gfx906 host through the same real shape.
+_dir=$(make_mock_rocminfo "6.1" "gfx1100" 1)
+_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"
+
+# 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")
+assert_eq "mixed gfx906 + gfx1100 host floors to rocm6.4" "https://download.pytorch.org/whl/rocm6.4" "$_result"
rm -rf "$_dir"
# 15) ROCm 6.4 (no nvidia-smi) -> rocm6.4
@@ -463,10 +574,10 @@ _result=$(run_func "$_dir")
assert_eq "N/A amd-smi version -> cpu" "https://download.pytorch.org/whl/cpu" "$_result"
rm -rf "$_dir"
-# 20) ROCm version with trailing text (e.g. "6.3.1-beta") -> rocm6.3
+# 20) ROCm version with trailing text (e.g. "6.3.1-beta") -> rocm6.4 floor
_dir=$(make_mock_amd_smi "6.3.1-beta")
_result=$(run_func "$_dir")
-assert_eq "ROCm 6.3.1-beta -> rocm6.3" "https://download.pytorch.org/whl/rocm6.3" "$_result"
+assert_eq "ROCm 6.3.1-beta automatic generic floor -> rocm6.4" "https://download.pytorch.org/whl/rocm6.4" "$_result"
rm -rf "$_dir"
# 22) CUDA 12.6 still works after ROCm changes (regression check)
@@ -682,6 +793,12 @@ assert_eq "url override trailing slash stripped" "https://mirror.example.com/whl
_result=$(UNSLOTH_TORCH_INDEX_URL="https://mirror.example.com/whl/cu130" UNSLOTH_TORCH_INDEX_FAMILY="cu128" run_func "none")
assert_eq "url override beats family override -> url" "https://mirror.example.com/whl/cu130" "$_result"
+# 44a) Explicit ROCm pins remain authoritative and are not floored.
+_result=$(UNSLOTH_TORCH_INDEX_FAMILY="rocm6.1" run_func "none")
+assert_eq "explicit ROCm family pin remains rocm6.1" "https://download.pytorch.org/whl/rocm6.1" "$_result"
+_result=$(UNSLOTH_TORCH_INDEX_URL="https://download.pytorch.org/whl/rocm6.1" run_func "none")
+assert_eq "explicit ROCm URL pin remains rocm6.1" "https://download.pytorch.org/whl/rocm6.1" "$_result"
+
# 45) An empty override is ignored (falls through to normal detection).
_result=$(UNSLOTH_TORCH_INDEX_FAMILY="" UNSLOTH_TORCH_INDEX_URL="" run_func "none")
assert_eq "empty overrides ignored -> detected cpu" "https://download.pytorch.org/whl/cpu" "$_result"
diff --git a/tests/sh/test_radeon_repo_compile_floor.sh b/tests/sh/test_radeon_repo_compile_floor.sh
new file mode 100755
index 00000000000..b7cb233a948
--- /dev/null
+++ b/tests/sh/test_radeon_repo_compile_floor.sh
@@ -0,0 +1,75 @@
+#!/bin/bash
+# SPDX-License-Identifier: AGPL-3.0-only
+# Copyright 2026-present the Unsloth AI Inc. team. All rights reserved. See /studio/LICENSE.AGPL-3.0
+# The Radeon repo route must not install a torch that cannot run torch.compile on
+# the venv's Python. repo.radeon.com rocm-rel-6.4 carries torch 2.5.1 as its only
+# cp313 build; a fresh Linux install creates a Python 3.13 venv, so a Radeon card
+# floored to rocm6.4 got a venv that imports but fails "Dynamo is not supported on
+# Python 3.13+" on the first training step. The ROCm index has 2.9.1 for cp313.
+# Helpers are extracted from install.sh and sourced.
+set -e
+
+SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
+. "$SCRIPT_DIR/_harness.sh"
+INSTALL_SH="${1:-$SCRIPT_DIR/../../install.sh}"
+
+_FUNC_FILE=$(mktemp)
+{
+ sed -n '/^_pick_radeon_wheel()/,/^}/p' "$INSTALL_SH"
+ sed -n '/^_radeon_torch_compiles_for_pytag()/,/^}/p' "$INSTALL_SH"
+} > "$_FUNC_FILE"
+grep -q '^_radeon_torch_compiles_for_pytag()' "$_FUNC_FILE" || { echo "FATAL: helper not extracted"; exit 1; }
+. "$_FUNC_FILE"
+rm -f "$_FUNC_FILE"
+
+_can() { if _radeon_torch_compiles_for_pytag "$1" "$2"; then echo yes; else echo no; fi; }
+
+echo "=== _radeon_torch_compiles_for_pytag: Dynamo per Python ==="
+assert_eq "2.5 on cp313 cannot compile" "no" "$(_can 2.5 cp313)"
+assert_eq "2.6 on cp313 compiles" "yes" "$(_can 2.6 cp313)"
+assert_eq "2.9 on cp313 compiles" "yes" "$(_can 2.9 cp313)"
+assert_eq "2.9 on cp314 cannot compile" "no" "$(_can 2.9 cp314)"
+assert_eq "2.10 on cp314 compiles" "yes" "$(_can 2.10 cp314)"
+assert_eq "3.0 on cp314 compiles" "yes" "$(_can 3.0 cp314)"
+assert_eq "2.5 on cp312 is unconstrained" "yes" "$(_can 2.5 cp312)"
+assert_eq "unparsable version on cp313 is refused" "no" "$(_can abc cp313)"
+
+echo "=== the real rocm-rel-6.4 listing ==="
+# Wheel names as published under https://repo.radeon.com/rocm/manylinux/rocm-rel-6.4/.
+_RADEON_BASE_URL="https://repo.radeon.com/rocm/manylinux/rocm-rel-6.4/"
+_RADEON_LISTING=$(for w in \
+ torch-2.5.1%2Brocm6.4.0.git640334b6-cp312-cp312-linux_x86_64.whl \
+ torch-2.5.1%2Brocm6.4.0.git640334b6-cp313-cp313-linux_x86_64.whl \
+ torch-2.6.0%2Brocm6.4.0.git2fb0ac2b-cp312-cp312-linux_x86_64.whl \
+ torchvision-0.20.1%2Brocm6.4.0.git04d8fc4a-cp313-cp313-linux_x86_64.whl \
+ torchvision-0.21.0%2Brocm6.4.0.git4040d51f-cp312-cp312-linux_x86_64.whl \
+ torchaudio-2.5.0%2Brocm6.4.0.git56bc006d-cp313-cp313-linux_x86_64.whl \
+ torchaudio-2.6.0%2Brocm6.4.0.gitd8831425-cp312-cp312-linux_x86_64.whl; do
+ printf '<a href="%s">%s</a>\n' "$w" "$w"; done)
+_ver_of() { printf '%s' "${1##*/}" | sed 's/%2[Bb]/+/g' | sed -n 's|^torch-\([0-9]*\.[0-9]*\).*|\1|p'; }
+
+_RADEON_PYTAG=cp313
+_w=$(_pick_radeon_wheel torch)
+assert_eq "cp313 newest torch in rocm-rel-6.4 is 2.5" "2.5" "$(_ver_of "$_w")"
+assert_eq "and the route rejects it" "no" "$(_can "$(_ver_of "$_w")" "$_RADEON_PYTAG")"
+_RADEON_PYTAG=cp312
+_w=$(_pick_radeon_wheel torch)
+assert_eq "cp312 newest torch in rocm-rel-6.4 is 2.6" "2.6" "$(_ver_of "$_w")"
+assert_eq "and the route keeps it" "yes" "$(_can "$(_ver_of "$_w")" "$_RADEON_PYTAG")"
+
+echo "=== the check gates the Radeon install ==="
+_loop=$(grep -n 'Loop downwards to find the first complete matching trio' "$INSTALL_SH" | head -1 | cut -d: -f1)
+_guard=$(grep -n '! _radeon_torch_compiles_for_pytag "\$_sel_torch_ver" "\$_RADEON_PYTAG"' "$INSTALL_SH" | head -1 | cut -d: -f1)
+_fallback=$(grep -n 'Radeon repo lacks a compatible wheel set for this Python' "$INSTALL_SH" | head -1 | cut -d: -f1)
+_install=$(grep -n 'installing PyTorch from Radeon repo' "$INSTALL_SH" | head -1 | cut -d: -f1)
+assert_eq "check runs after the trio search, before the fallback decision" "yes" \
+ "$([ -n "$_loop" ] && [ -n "$_guard" ] && [ -n "$_fallback" ] && [ "$_loop" -lt "$_guard" ] && [ "$_guard" -lt "$_fallback" ] && [ "$_fallback" -lt "$_install" ] && echo yes)"
+assert_eq "a rejected set clears the match flag the fallback reads" "yes" \
+ "$(sed -n "${_guard},$((_guard + 3))p" "$INSTALL_SH" | grep -q '_radeon_versions_match=false' && echo yes)"
+
+echo ""
+if [ "$FAIL" -gt 0 ]; then
+ echo "$FAIL check(s) FAILED"
+ exit 1
+fi
+echo "All $PASS checks passed"
diff --git a/tests/sh/test_rocm_bad_arch_gate.sh b/tests/sh/test_rocm_bad_arch_gate.sh
index 82bb0919e3b..6e9e1eaeffc 100755
--- a/tests/sh/test_rocm_bad_arch_gate.sh
+++ b/tests/sh/test_rocm_bad_arch_gate.sh
@@ -145,6 +145,7 @@ trap 'rm -rf "$_FN_FILE" "$_GATE_FILE" "$_REROUTE_FILE" "$_E2E_DIR" "$_FAKE_SMI_
# Same extraction contract as tests/sh/test_get_torch_index_url.sh: a missed helper makes the
# ROCm branch answer cpu and these pass for the wrong reason. The ROCm assertion below guards it.
{
+ sed -n '/^_ROCM_BNB_GENERIC_FLOOR_TAG=/p' "$INSTALL_SH"
for _fn in _run_bounded _cvd_hides_nvidia _has_amd_rocm_gpu _has_usable_nvidia_gpu \
_ensure_rocm_probe_env _rocm_torch_explicitly_requested \
_probe_amd_gfx_arch _amd_gfx_select_ordinals \
@@ -154,7 +155,8 @@ trap 'rm -rf "$_FN_FILE" "$_GATE_FILE" "$_REROUTE_FILE" "$_E2E_DIR" "$_FAKE_SMI_
_nvidia_cu126_verdict _cap_cuda_family_for_pre_turing \
_rocm_tag_from_amd_smi _rocm_tag_from_version_file _rocm_tag_from_hipconfig \
_rocm_tag_from_dpkg _rocm_tag_from_rpm _highest_rocm_tag \
- _detect_rocm_version_tag _kfd_gfx_targets get_torch_index_url; do
+ _detect_rocm_version_tag _kfd_gfx_targets _rocm_bnb_compatible_generic_tag \
+ get_torch_index_url; do
sed -n "/^$_fn()/,/^}/p" "$INSTALL_SH"
echo ""
done
diff --git a/tests/sh/test_rocm_no_version_arch_route.sh b/tests/sh/test_rocm_no_version_arch_route.sh
index 33e9bc1dc2e..7ee0bf20e4d 100644
--- a/tests/sh/test_rocm_no_version_arch_route.sh
+++ b/tests/sh/test_rocm_no_version_arch_route.sh
@@ -68,6 +68,9 @@ _FAKE_PROC_NV_DIR=$(mktemp -d)
echo ""
sed -n '/^_detect_rocm_version_tag()/,/^}/p' "$INSTALL_SH"
echo ""
+ sed -n '/^_ROCM_BNB_GENERIC_FLOOR_TAG=/p' "$INSTALL_SH"
+ sed -n '/^_rocm_bnb_compatible_generic_tag()/,/^}/p' "$INSTALL_SH"
+ echo ""
sed -n '/^get_torch_index_url()/,/^}/p' "$INSTALL_SH"
} | sed -e "s|/usr/bin/nvidia-smi|$_FAKE_SMI_DIR/nvidia-smi-absent|g" \
-e "s|/proc/driver/nvidia|$_FAKE_PROC_NV_DIR|g" \
@@ -75,7 +78,7 @@ _FAKE_PROC_NV_DIR=$(mktemp -d)
> "$_FUNC_FILE"
for _fn in _rocm_sdk_install_hint _rocm_tag_from_hipconfig _rocm_tag_from_rpm \
- _detect_rocm_version_tag _amd_arch_index_family_for_gfx get_torch_index_url; do
+ _detect_rocm_version_tag _rocm_bnb_compatible_generic_tag _amd_arch_index_family_for_gfx get_torch_index_url; do
if ! grep -q "^$_fn()" "$_FUNC_FILE"; then
echo " FAIL: install.sh no longer defines $_fn() at column 0"
exit 1
diff --git a/tests/sh/test_rocm_version_source_disagreement.sh b/tests/sh/test_rocm_version_source_disagreement.sh
index 0d04e394309..0b33e440d3e 100755
--- a/tests/sh/test_rocm_version_source_disagreement.sh
+++ b/tests/sh/test_rocm_version_source_disagreement.sh
@@ -75,6 +75,9 @@ _FAKE_PROC_NV_DIR=$(mktemp -d)
echo ""
sed -n '/^_detect_rocm_version_tag()/,/^}/p' "$INSTALL_SH"
echo ""
+ sed -n '/^_ROCM_BNB_GENERIC_FLOOR_TAG=/p' "$INSTALL_SH"
+ sed -n '/^_rocm_bnb_compatible_generic_tag()/,/^}/p' "$INSTALL_SH"
+ echo ""
sed -n '/^get_torch_index_url()/,/^}/p' "$INSTALL_SH"
echo ""
sed -n '/^_radeon_host_ver_not_older()/,/^}/p' "$INSTALL_SH"
@@ -89,7 +92,7 @@ _FAKE_PROC_NV_DIR=$(mktemp -d)
# below fail as a plain "cpu" with no hint why.
for _fn in _rocm_tag_from_amd_smi _rocm_tag_from_version_file _rocm_tag_from_hipconfig \
_rocm_tag_from_dpkg _rocm_tag_from_rpm _highest_rocm_tag \
- _detect_rocm_version_tag get_torch_index_url get_radeon_wheel_url \
+ _detect_rocm_version_tag _rocm_bnb_compatible_generic_tag get_torch_index_url get_radeon_wheel_url \
_radeon_host_ver_not_older; do
if ! grep -q "^$_fn()" "$_FUNC_FILE"; then
echo " FAIL: install.sh no longer defines $_fn() at column 0"
@@ -366,7 +369,7 @@ echo "=== test_rocm_version_source_disagreement ==="
reset_sources
add_hipconfig "5.7.31921-0"
add_dpkg_hsa_runtime "1:6.1.2-1"
-assert_eq "Debian 13 hipconfig 5.7 + HSA runtime 6.1 -> rocm6.1" "$_BASE/rocm6.1" "$(run_index)"
+assert_eq "Debian 13 hipconfig 5.7 + HSA runtime 6.1 -> automatic rocm6.4 floor" "$_BASE/rocm6.4" "$(run_index)"
_warn=$(run_warnings)
case "$_warn" in
*"require ROCm 6.0+"*) assert_eq "the same host emits no 6.0+ gate warning" "" "$_warn" ;;
@@ -383,8 +386,8 @@ reset_sources
add_dpkg_packages \
"libhsa-runtime64-1|installed|6.4.3+dfsg-4" \
"rocm-core|installed|1:6.1.2-2"
-assert_eq "installed rocm-core outranks a HIGHER distro HSA reading -> rocm6.1" \
- "$_BASE/rocm6.1" "$(run_index)"
+assert_eq "installed rocm-core outranks a HIGHER distro HSA reading -> automatic rocm6.4 floor" \
+ "$_BASE/rocm6.4" "$(run_index)"
assert_eq "and the outranked HSA reading is not named as a disagreement" "" "$(run_warnings)"
reset_sources
@@ -397,21 +400,21 @@ assert_eq "Ubuntu + AMD repo warns about nothing" "" "$(run_warnings)"
reset_sources
add_hipconfig "5.7.31921-0"
add_dpkg_hsa_runtime "1:6.1.2-1"
-assert_eq "no rocm-core, so the installed HSA runtime still votes -> rocm6.1" \
- "$_BASE/rocm6.1" "$(run_index)"
+assert_eq "no rocm-core, so the installed HSA runtime still votes -> automatic rocm6.4 floor" \
+ "$_BASE/rocm6.4" "$(run_index)"
# 2. Same shape from /opt/rocm/.info/version. This one already worked by position,
# so it is here to pin that the rewrite did not lose it.
reset_sources
add_hipconfig "5.7.31921-0"
add_version_file "6.1.2-98"
-assert_eq "hipconfig 5.7 + version file 6.1 -> rocm6.1" "$_BASE/rocm6.1" "$(run_index)"
+assert_eq "hipconfig 5.7 + version file 6.1 -> automatic rocm6.4 floor" "$_BASE/rocm6.4" "$(run_index)"
# 3. And from rpm, the last source in the order.
reset_sources
add_hipconfig "5.7.31921-0"
add_rpm_rocm_core "6.3.0"
-assert_eq "hipconfig 5.7 + rocm-core 6.3 (rpm) -> rocm6.3" "$_BASE/rocm6.3" "$(run_index)"
+assert_eq "hipconfig 5.7 + rocm-core 6.3 (rpm) -> automatic rocm6.4 floor" "$_BASE/rocm6.4" "$(run_index)"
# 4. Not only a floor problem: amd-smi answering first with a lower version must
# not shadow a newer runtime either.
@@ -438,15 +441,15 @@ assert_eq "agreeing sources emit no disagreement breadcrumb" "" "$(run_warnings)
reset_sources
add_hipconfig "6.1.40093-0"
add_dpkg_rocm_core "1:7.0.0-1" config-files
-assert_eq "config-files rocm-core 7.0 on a 6.1 host -> rocm6.1, not rocm7.0" \
- "$_BASE/rocm6.1" "$(run_index)"
+assert_eq "config-files rocm-core 7.0 on a 6.1 host -> automatic rocm6.4 floor, not rocm7.0" \
+ "$_BASE/rocm6.4" "$(run_index)"
assert_eq "the dead dpkg entry is not even named as a disagreement" "" "$(run_warnings)"
reset_sources
add_hipconfig "6.1.40093-0"
add_dpkg_hsa_runtime "1:7.0.0-1" config-files
-assert_eq "config-files HSA runtime 7.0 on a 6.1 host -> rocm6.1, not rocm7.0" \
- "$_BASE/rocm6.1" "$(run_index)"
+assert_eq "config-files HSA runtime 7.0 on a 6.1 host -> automatic rocm6.4 floor, not rocm7.0" \
+ "$_BASE/rocm6.4" "$(run_index)"
assert_eq "the dead HSA entry is not named as a disagreement" "" "$(run_warnings)"
# 5c. The live entry still has to win, or the fix for the reported bug is gone.
@@ -454,8 +457,8 @@ assert_eq "the dead HSA entry is not named as a disagreement" "" "$(run_warnings
reset_sources
add_hipconfig "5.7.31921-0"
add_dpkg_rocm_core "1:6.1.2-1" installed
-assert_eq "installed rocm-core 6.1 still beats hipconfig 5.7 -> rocm6.1" \
- "$_BASE/rocm6.1" "$(run_index)"
+assert_eq "installed rocm-core 6.1 still beats hipconfig 5.7 -> automatic rocm6.4 floor" \
+ "$_BASE/rocm6.4" "$(run_index)"
# 5d. The states an interrupted dpkg operation leaves behind are not "installed"
# either, and none of them describes a runtime the GPU can use.
@@ -463,8 +466,8 @@ for _dead in config-files half-installed unpacked half-configured; do
reset_sources
add_hipconfig "6.1.40093-0"
add_dpkg_rocm_core "1:7.2.0-1" "$_dead"
- assert_eq "dpkg state '$_dead' at 7.2 does not select wheels -> rocm6.1" \
- "$_BASE/rocm6.1" "$(run_index)"
+ assert_eq "dpkg state '$_dead' at 7.2 does not select wheels -> automatic rocm6.4 floor" \
+ "$_BASE/rocm6.4" "$(run_index)"
done
# ── 5e. A stale-HIGH reading in each source position, one at a time ─────────
@@ -552,12 +555,13 @@ assert_contains "unparseable sources are treated as no version at all" \
reset_sources
add_hipconfig "0.0.0"
add_version_file "6.2.0-1"
-assert_eq "major-0 source ignored, 6.2 wins -> rocm6.2" "$_BASE/rocm6.2" "$(run_index)"
+assert_eq "major-0 source ignored, 6.2 wins -> automatic rocm6.4 floor" "$_BASE/rocm6.4" "$(run_index)"
-# ── 12. Supported-tag normalisation is unchanged ────────────────────────────
+# ── 12. Supported-tag normalisation and the automatic BNB floor ─────────────
# PyTorch publishes major.minor index leaves only, so patch levels normalise;
-# 6.5+ clips to the last 6.x wheel set and 7.3+ caps to the latest known.
-for _case in "6.0.2:rocm6.0" "6.1.3:rocm6.1" "6.2.4:rocm6.2" "6.3.1:rocm6.3" \
+# automatic generic 6.0-6.3 hosts floor to rocm6.4, while 6.5+ clips to the
+# last 6.x wheel set and 7.3+ caps to the latest known.
+for _case in "6.0.2:rocm6.4" "6.1.3:rocm6.4" "6.2.4:rocm6.4" "6.3.1:rocm6.4" \
"6.4.1:rocm6.4" "7.0.1:rocm7.0" "7.1.0:rocm7.1" "7.2.1:rocm7.2" \
"6.5.0:rocm6.4" "6.9.0:rocm6.4" "7.3.0:rocm7.2" "8.0.0:rocm7.2"; do
_ver="${_case%%:*}"
@@ -592,7 +596,7 @@ reset_sources
add_amd_smi_line "N/A"
add_version_file "6.1.3-42"
assert_eq "amd-smi N/A beside amdgpu 6.10 does not outvote a real 6.1" \
- "$_BASE/rocm6.1" "$(run_index)"
+ "$_BASE/rocm6.4" "$(run_index)"
# ── 14. A wedged rpmdb must not hang the installer ─────────────────────────
# Highest-wins short-circuits nothing, so `rpm -q` now always runs where it used to
diff --git a/tests/studio/install/test_amd_fastpath_probe.py b/tests/studio/install/test_amd_fastpath_probe.py
index d2b92f1a5a9..ec6f680ceeb 100644
--- a/tests/studio/install/test_amd_fastpath_probe.py
+++ b/tests/studio/install/test_amd_fastpath_probe.py
@@ -55,6 +55,10 @@ def _host(
for name, value in (env or {}).items():
monkeypatch.setenv(name, value)
monkeypatch.setattr(stack, "IS_LINUX", linux)
+ # Pinned like IS_LINUX: on a Windows or macOS runner the module reads sys.platform as
+ # win32/darwin and _ensure_rocm_torch takes that branch, so the stubbed host installs nothing.
+ monkeypatch.setattr(stack, "IS_WINDOWS", False)
+ monkeypatch.setattr(stack, "IS_MACOS", False)
monkeypatch.setattr(stack, "NO_TORCH", no_torch)
monkeypatch.setattr(stack, "_TORCH_BACKEND", backend)
monkeypatch.setattr(stack.platform, "machine", lambda: machine)
@@ -136,6 +140,124 @@ def test_a_rocm_wheel_keeps_the_fast_path(monkeypatch, torch):
assert _needs_pass() is False
[email protected]("rocm_ver", [(6, 0), (6, 1), (6, 2), (6, 3)])
+def test_automatic_generic_torch_uses_the_bnb_compatibility_floor(monkeypatch, rocm_ver):
+ """Fresh automatic generic installs floor old host ROCm tags to rocm6.4."""
+ _host(monkeypatch, torch = ("2.6.0+cpu", ""), gfx = ("gfx1100",), rocm_ver = rocm_ver)
+ installs = _repair_installs(monkeypatch)
+ assert installs == ["https://download.pytorch.org/whl/rocm6.4"]
+
+
+ "rocm_ver, expected",
+ [
+ ((6, 4), "rocm6.4"),
+ ((7, 0), "rocm7.0"),
+ ((7, 1), "rocm7.1"),
+ ((7, 2), "rocm7.2"),
+ ],
+)
+def test_automatic_generic_torch_keeps_newer_published_families(monkeypatch, rocm_ver, expected):
+ _host(monkeypatch, torch = ("2.6.0+cpu", ""), gfx = ("gfx1100",), rocm_ver = rocm_ver)
+ installs = _repair_installs(monkeypatch)
+ assert installs == [f"https://download.pytorch.org/whl/{expected}"]
+
+
[email protected]("rocm_ver", [(6, 0), (6, 1), (6, 2), (6, 3)])
+def test_stale_automatic_generic_rocm_torch_escapes_the_update_fast_path(monkeypatch, rocm_ver):
+ _host(
+ monkeypatch,
+ torch = (f"2.6.0+rocm{rocm_ver[0]}.{rocm_ver[1]}", f"{rocm_ver[0]}.{rocm_ver[1]}"),
+ gfx = ("gfx1100",),
+ rocm_ver = rocm_ver,
+ )
+ assert _needs_pass() is True
+ installs = _repair_installs(monkeypatch)
+ assert installs == ["https://download.pytorch.org/whl/rocm6.4"]
+
+
+ "rocm_ver, installed_tag",
+ [((6, 4), "6.3"), ((7, 0), "6.1")],
+)
+def test_old_generic_tag_is_repaired_even_when_host_selects_newer_rocm(
+ monkeypatch, rocm_ver, installed_tag
+):
+ _host(
+ monkeypatch,
+ torch = (f"2.6.0+rocm{installed_tag}", installed_tag),
+ gfx = ("gfx1100",),
+ rocm_ver = rocm_ver,
+ )
+ assert _needs_pass() is True
+
+
+ "rocm_ver, installed",
+ [
+ ((6, 4), "2.6.0+rocm6.4"),
+ ((7, 0), "2.9.0+rocm7.0"),
+ ((7, 1), "2.10.0+rocm7.1"),
+ ((7, 2), "2.11.0+rocm7.2"),
+ ],
+)
+def test_compatible_automatic_generic_rocm_torch_keeps_the_fast_path(
+ monkeypatch, rocm_ver, installed
+):
+ _host(
+ monkeypatch,
+ torch = (installed, installed.split("+rocm", 1)[-1]),
+ gfx = ("gfx1100",),
+ rocm_ver = rocm_ver,
+ )
+ assert _needs_pass() is False
+ installs = _repair_installs(monkeypatch)
+ assert installs == []
+
+
+ "env",
+ [
+ {"UNSLOTH_TORCH_INDEX_FAMILY": "rocm6.1"},
+ {"UNSLOTH_TORCH_INDEX_URL": "https://download.pytorch.org/whl/rocm6.1"},
+ ],
+)
+def test_explicit_rocm6_1_pins_remain_authoritative(monkeypatch, env):
+ _host(
+ monkeypatch,
+ torch = ("2.6.0+cpu", ""),
+ gfx = ("gfx1100",),
+ rocm_ver = (6, 1),
+ env = env,
+ )
+ installs = _repair_installs(monkeypatch)
+ assert installs == ["https://download.pytorch.org/whl/rocm6.1"]
+
+
+ "env",
+ [
+ {"UNSLOTH_TORCH_INDEX_FAMILY": "rocm6.1"},
+ {"UNSLOTH_TORCH_INDEX_URL": "https://download.pytorch.org/whl/rocm6.1"},
+ ],
+)
+def test_explicit_rocm6_1_build_is_not_marked_stale(monkeypatch, env):
+ _host(
+ monkeypatch,
+ torch = ("2.6.0+rocm6.1", "6.1"),
+ gfx = ("gfx1100",),
+ rocm_ver = (6, 1),
+ env = env,
+ )
+ assert _needs_pass() is False
+
+
+def test_gfx906_legacy_torch_routing_is_not_floored_to_generic_bnb_rocm6_4(monkeypatch):
+ _host(monkeypatch, torch = ("2.6.0+cpu", ""), gfx = ("gfx906",), rocm_ver = (6, 4))
+ installs = _repair_installs(monkeypatch)
+ assert installs == ["https://download.pytorch.org/whl/rocm6.3"]
+
+
@pytest.mark.parametrize("gfx", ["gfx1150", "gfx1151"])
def test_a_strix_host_on_a_wheel_without_its_kernels_forces_the_pass(monkeypatch, gfx):
"""rocm6.4 does not carry gfx1150/gfx1151 (AMD dates support to 7.1), and
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 769233ca503..d024533925d 100644
--- a/tests/studio/install/test_missing_kernel_arch_routing_9396.py
+++ b/tests/studio/install/test_missing_kernel_arch_routing_9396.py
@@ -1570,9 +1570,10 @@ def test_a_floor_leaf_still_repairs_a_sub_211_build_of_its_own_family():
def test_a_generic_only_target_gets_its_tag_floor_on_a_fresh_install_too():
"""gfx950 has no AMD per-arch leaf, so the only way to give it kernels is a generic tag
- that carries it (rocm7.0+). That floor was applied solely to a host already on ROCm wheels
- that had to be demoted, so a fresh install or a CPU/CUDA torch walked past it and a stale
- /opt/rocm put the card on rocm6.3. Which tag carries an arch is a fact about the arch."""
+ that carries it (rocm7.0+), so its architecture floor still chooses rocm7.2 on ROCm6.3.
+ Automatic generic installs for covered arches also honor the BNB floor: a fresh CPU/CUDA
+ install for gfx1100 on that host uses rocm6.4 instead of the stale rocm6.3 tag. Which tag
+ carries an arch is a fact about the arch."""
for _probe in (_CPU_TORCH, None):
calls = _run_install(
gfx_devices = ("gfx950",),
@@ -1588,8 +1589,9 @@ def test_a_generic_only_target_gets_its_tag_floor_on_a_fresh_install_too():
torch_probe = _CPU_TORCH,
torch_owns_rocm = False,
)
- # An arch the generic wheel serves at every tag is untouched: no floor to apply.
- assert f"{_GENERIC}6.3" in _run_install(
+ # An arch the generic wheel serves at every tag has no architecture floor, but automatic
+ # generic installs still honor the bitsandbytes compatibility floor.
+ assert f"{_GENERIC}6.4" in _run_install(
gfx_devices = ("gfx1100",),
rocm_version = (6, 3),
torch_probe = _CPU_TORCH,
@@ -1711,10 +1713,9 @@ def test_a_generic_only_target_installs_when_the_rocm_version_is_unreadable():
def test_a_generic_only_target_pinned_to_a_stale_tag_is_reinstalled():
- """Forcing the pass is half a repair: a generic build names no family, so the family arm
- declines, there is no per-arch index to move to, and torch.version.hip keeps the fallback
- from running. A gfx950 pinned to rocm6.3 survived every update, and the preflight asked
- for a pass the install refused."""
+ """An automatically selected generic +rocm6.3 build is below the bitsandbytes floor, so a
+ gfx1100 host on ROCm7.2 is repaired to the generic rocm7.2 family. Compatible generic
+ builds still remain untouched, including the generic-only gfx950 controls above."""
for _ver in ((7, 2), None):
assert f"{_GENERIC}7.2" in _run_install(
gfx_devices = ("gfx950",),
@@ -1731,11 +1732,11 @@ def test_a_generic_only_target_pinned_to_a_stale_tag_is_reinstalled():
torch_owns_rocm = False,
)
assert "torch" not in _kept, (_ver, _kept)
- # So is an arch the generic wheel serves at every tag.
+ # An arch the generic wheel serves at every tag still repairs a stale generic ABI tag.
_served = _run_install(
gfx_devices = ("gfx1100",),
rocm_version = (7, 2),
torch_probe = _ROCM_GENERIC_TORCH_63,
torch_owns_rocm = False,
)
- assert "torch" not in _served, _served
+ assert f"{_GENERIC}7.2" in _served, _served
diff --git a/tests/studio/install/test_rocm_support.py b/tests/studio/install/test_rocm_support.py
index 30f9df201ce..e36bb728417 100644
--- a/tests/studio/install/test_rocm_support.py
+++ b/tests/studio/install/test_rocm_support.py
@@ -1179,10 +1179,19 @@ class TestEnsureRocmTorch:
assert mock_pip_try.call_args.kwargs["force_pip"] is True
def test_rocm_63_selects_correct_tag(self):
- """ROCm 6.3 should select rocm6.3 tag."""
- mock_pip, _ = run_ensure_rocm_torch(_has_rocm_gpu = True, _detect_rocm_version = (6, 3))
+ """Automatic generic ROCm 6.3 installs use the bitsandbytes-compatible floor.
+
+ The floor needs a target known not to be gfx906, so the arch is declared; an
+ unreadable arch keeps the literal tag (test_unreadable_arch_keeps_the_literal_generic_tag).
+ """
+ mock_pip, _ = run_ensure_rocm_torch(
+ _has_rocm_gpu = True,
+ _detect_rocm_version = (6, 3),
+ _detect_amd_gfx_codes = ["gfx1100"],
+ _infer_linux_amd_gfx_arch = None,
+ )
torch_call = mock_pip.call_args_list[0]
- assert "rocm6.3" in str(torch_call)
+ assert "rocm6.4" in str(torch_call)
def test_query_pytorch_mirror_skips_the_generic_rocm_pin(self, monkeypatch):
"""A synthesized rocm leaf after ?token= is neither usable nor a fallback license."""
@@ -2065,7 +2074,15 @@ _RDNA4_LEAF = "gfx120x-all"
class TestGfx1102Rocm64Floor:
- """Navi 33 / RDNA 4 need a generic PyTorch ROCm family at or above their own floor."""
+ """Navi 33 / RDNA 4 need a generic PyTorch ROCm family at or above their own floor.
+
+ Two independent floors meet on this code path and the selected leaf is the higher
+ of them. _GENERIC_WHEEL_GFX_MIN_ROCM is per-arch and about missing Tensile kernels;
+ the generic bitsandbytes ABI floor is arch-independent and about
+ libbitsandbytes_rocm64.so being the oldest ROCm library in the wheel Unsloth
+ installs. An arch with no kernel floor can therefore still move, which is what the
+ gfx1100 cases below record.
+ """
@staticmethod
def _ensure_for_gfx(
@@ -2076,6 +2093,7 @@ class TestGfx1102Rocm64Floor:
rocm_ver: tuple = (6, 1),
probe_stdout: str = "\n", # CPU torch -> repair
wheel_family = None,
+ kfd = None,
):
m = stack_mod
for name in (
@@ -2111,7 +2129,13 @@ class TestGfx1102Rocm64Floor:
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]),
+ patch.object(m, "_detect_amd_gfx_codes", return_value = [gfx] if gfx else []),
+ # None leaves KFD sysfs unpatched, as before; a list stands in for the topology.
+ (
+ contextlib.nullcontext()
+ if kfd is None
+ else patch.object(m, "_kfd_gfx_targets", return_value = kfd)
+ ),
patch("platform.machine", return_value = "x86_64"),
patch("subprocess.run", return_value = probe),
):
@@ -2139,10 +2163,19 @@ class TestGfx1102Rocm64Floor:
assert unaffected not in stack_mod._GENERIC_WHEEL_GFX_MIN_ROCM
assert stack_mod._generic_tag_lacks_kernels(unaffected, (6, 0)) is False
- def test_debian_split_gfx1100_keeps_rocm61(self, monkeypatch):
- """A Debian split host resolving rocm6.1 must leave gfx1100 on rocm6.1."""
+ def test_debian_split_gfx1100_stays_generic_at_the_bnb_floor(self, monkeypatch):
+ """A Debian split host resolving rocm6.1 keeps gfx1100 on a GENERIC wheel.
+
+ This class's subject is the per-arch reroute, and the answer for gfx1100 is
+ still no: it has kernels in every measured family, so it never goes to
+ repo.amd.com. The leaf is rocm6.4 rather than the resolved rocm6.1 because a
+ second, arch-independent floor now applies on top -- the generic bitsandbytes
+ wheel carries no ROCm library below libbitsandbytes_rocm64.so, so pairing it
+ with a +rocm6.1 torch is the unslothai#10273 segfault. The two floors compose
+ as a maximum; this asserts the composition, not the kernel floor alone.
+ """
torch_call = str(self._ensure_for_gfx("gfx1100", monkeypatch).call_args_list[0])
- assert "rocm6.1" in torch_call
+ assert "rocm6.4" in torch_call
assert "repo.amd.com" not in torch_call
@pytest.mark.parametrize(
@@ -2165,12 +2198,18 @@ class TestGfx1102Rocm64Floor:
assert index in torch_call
assert "whl/rocm6.1" not in torch_call
- def test_a_gfx1102_host_already_on_rocm63_is_left_alone(self, monkeypatch):
- """rocm6.3 already carries gfx1102, so moving it anywhere would be churn."""
+ def test_a_gfx1102_host_on_rocm63_stays_generic(self, monkeypatch):
+ """rocm6.3 already carries gfx1102, so it never needs the per-arch index.
+
+ rocm6.3 satisfies the kernel floor for gfx1102, which is why this stays on a
+ generic wheel instead of repo.amd.com. It lands on rocm6.4 rather than 6.3
+ because the bitsandbytes ABI floor applies to every arch; 6.4 carries gfx1102
+ kernels too, so nothing is lost by taking the higher of the two.
+ """
torch_call = str(
self._ensure_for_gfx("gfx1102", monkeypatch, rocm_ver = (6, 3)).call_args_list[0]
)
- assert "whl/rocm6.3" in torch_call
+ assert "whl/rocm6.4" in torch_call
assert "repo.amd.com" not in torch_call
def test_explicit_rocm61_pin_remains_authoritative(self, monkeypatch):
@@ -2219,15 +2258,51 @@ class TestGfx1102Rocm64Floor:
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."""
+ def test_kernel_unaffected_arch_is_still_repaired_below_the_bnb_floor(self, monkeypatch):
+ """An installed +rocm6.1 wheel is repaired even where the kernel floor is silent.
+
+ gfx1100 has kernels in every measured family, so the kernel floor leaves it
+ alone and it never reaches repo.amd.com. It is still reinstalled, because the
+ installed +rocm6.1 torch is below the generic bitsandbytes ABI: that pairing is
+ exactly the unslothai#10273 crash, and leaving it in place is what this PR
+ exists to stop.
+
+ This is the one case where the two floors disagree about whether to act, and it
+ has a real cost: a working install is replaced. The left-alone half of the
+ original intent is covered by test_installed_64_wheel_left_alone_on_newer_host,
+ where the installed wheel already satisfies the ABI and nothing is touched.
+ """
pip = self._ensure_for_gfx(
"gfx1100",
monkeypatch,
rocm_ver = (6, 4),
probe_stdout = _MARK + "2.8.0+rocm6.1|6.1.40093|\n",
)
- pip.assert_not_called()
+ torch_call = str(pip.call_args_list[0])
+ assert "whl/rocm6.4" in torch_call
+ assert "repo.amd.com" not in torch_call
+
+ def test_kfd_only_gfx906_keeps_the_literal_generic_tag(self, monkeypatch):
+ """A runtime-only ROCm host (no rocminfo/amd-smi) names its MI50 only through KFD.
+
+ _runtime_target_is_gfx906 reads the userland probes alone, so it answers False
+ here; the floor must still see gfx906 through the selected runtime target, or the
+ MI50 is moved to rocm6.4, which ships no gfx906 BLAS kernels.
+ """
+ torch_call = str(self._ensure_for_gfx("", monkeypatch, kfd = ["gfx906"]).call_args_list[0])
+ assert "whl/rocm6.1" in torch_call
+ assert "whl/rocm6.4" not in torch_call
+
+ def test_unreadable_arch_keeps_the_literal_generic_tag(self, monkeypatch):
+ """No probe, KFD reading or inference names the arch: it might be gfx906.
+
+ The BNB floor applies only to a target known not to be gfx906, so this host keeps
+ the literal rocm6.0-6.3 selection it had before the floor existed. install.sh
+ never reaches its floor for an unreadable arch either (it returns the cpu index).
+ """
+ pip = self._ensure_for_gfx("", monkeypatch, kfd = [])
+ for call in pip.call_args_list:
+ assert "whl/rocm6.4" not in str(call)
def test_install_sh_floors_resolved_rocm61_by_runtime_gfx(self):
"""Exercise install.sh's generic-routing block with a resolved leaf.
@@ -2883,6 +2958,54 @@ class TestRocmTorchIndex:
)
assert tag == "rocm6.4"
+ @pytest.mark.parametrize(
+ "ver, published, automatic",
+ [
+ ((6, 0), "rocm6.0", "rocm6.4"),
+ ((6, 1), "rocm6.1", "rocm6.4"),
+ ((6, 2), "rocm6.2", "rocm6.4"),
+ ((6, 3), "rocm6.3", "rocm6.4"),
+ ((6, 4), "rocm6.4", "rocm6.4"),
+ ((7, 0), "rocm7.0", "rocm7.0"),
+ ((7, 1), "rocm7.1", "rocm7.1"),
+ ((7, 2), "rocm7.2", "rocm7.2"),
+ ],
+ )
+ def test_automatic_generic_tag_adds_only_the_bnb_floor(self, ver, published, automatic):
+ assert stack_mod._generic_pytorch_rocm_tag(ver) == published
+ assert stack_mod._automatic_generic_pytorch_rocm_tag(ver) == automatic
+
+ def test_shell_and_python_automatic_floor_are_in_parity(self):
+ """The install.sh helper must floor exactly the same old generic tags as Python."""
+ source = _INSTALL_SH_PATH.read_text(encoding = "utf-8")
+ constant = re.search(r"^_ROCM_BNB_GENERIC_FLOOR_TAG=.*$", source, re.M)
+ helper = _extract_sh_function_body(source, "_rocm_bnb_compatible_generic_tag")
+ assert constant and helper
+ shell = shutil.which("sh")
+ if not shell:
+ pytest.skip("POSIX shell needed for resolver parity")
+ tags = tuple(_ROCM_TORCH_INDEX.values())
+ script = (
+ "set -eu\n"
+ + constant.group(0)
+ + "\n"
+ + helper
+ + "\n"
+ + "for tag in "
+ + " ".join(tags)
+ + '; do _rocm_bnb_compatible_generic_tag "$tag"; done\n'
+ )
+ result = subprocess.run([shell, "-c", script], capture_output = True, text = True)
+ assert result.returncode == 0, result.stderr
+ shell_tags = result.stdout.splitlines()
+ python_tags = [
+ stack_mod._automatic_generic_pytorch_rocm_tag(ver)
+ for ver, tag in _ROCM_TORCH_INDEX.items()
+ if tag in tags
+ ]
+ # The dict is ordered newest-first, as is the shell input above.
+ assert shell_tags == python_tags
+
# TEST: hardware.py -- IS_ROCM flag and detect_hardware
@@ -3391,6 +3514,7 @@ class TestInstallShStructure:
sh_path = PACKAGE_ROOT / "install.sh"
source = sh_path.read_text(encoding = "utf-8")
assert 'echo "$_base/rocm7.2"' in source # fallback for unknown future versions
+ assert "_rocm_bnb_compatible_generic_tag" in source
assert "rocm6.*" in source
assert "rocm7.0" in source
assert "rocm7.1" in source
@@ -3775,6 +3899,8 @@ class TestInstallShStructure:
fn = _extract_sh_function_body(source, "get_torch_index_url")
probe_fn = _extract_sh_function_body(source, "_probe_amd_gfx_arch")
family_fn = _extract_sh_function_body(source, "_amd_arch_index_family_for_gfx")
+ bnb_floor_constant = re.search(r"^_ROCM_BNB_GENERIC_FLOOR_TAG=.*$", source, re.M)
+ bnb_floor_fn = _extract_sh_function_body(source, "_rocm_bnb_compatible_generic_tag")
arch_fns = "\n".join(
_extract_sh_function_body(source, _n)
for _n in (
@@ -3799,7 +3925,7 @@ class TestInstallShStructure:
"_detect_rocm_version_tag",
)
]
- assert fn and probe_fn and family_fn and arch_fns
+ assert fn and probe_fn and family_fn and arch_fns and bnb_floor_constant and bnb_floor_fn
assert all(version_fns), "ROCm version helpers not found in install.sh"
with tempfile.TemporaryDirectory() as d:
# Neutralise the host's real ROCm: the version chain reads
@@ -3837,6 +3963,10 @@ class TestInstallShStructure:
+ "\n"
+ "\n".join(version_fns)
+ "\n"
+ + bnb_floor_constant.group(0)
+ + "\n"
+ + bnb_floor_fn
+ + "\n"
+ fn
+ "\n"
"get_torch_index_url\n"
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 e240e15a3c9..252be7181a2 100644
--- a/tests/studio/install/test_unsupported_arch_routing_guards_8529.py
+++ b/tests/studio/install/test_unsupported_arch_routing_guards_8529.py
@@ -294,6 +294,11 @@ _detect_rocm_version_tag() { [ -n "${_STUB_ROCM_TAG:-}" ] && printf '%s\\n' "$_S
def _run_sh_get_torch_index_url(arch: str, rocm_tag: str = "") -> "tuple[str, str]":
"""Run install.sh's real get_torch_index_url with UNSLOTH_ROCM_GFX_ARCH=arch."""
src = _INSTALL_SH.read_text(encoding = "utf-8")
+ # The automatic generic arm in get_torch_index_url calls this production helper. Keep
+ # the isolated shell harness sourced from install.sh rather than copying its policy here.
+ bnb_floor_constant = re.search(r"^_ROCM_BNB_GENERIC_FLOOR_TAG=.*$", src, re.MULTILINE)
+ bnb_floor_fn = _sh_function_body(src, "_rocm_bnb_compatible_generic_tag")
+ assert bnb_floor_constant and bnb_floor_fn
script = (
_sh_function_body(src, "_amd_arch_index_family_for_gfx")
+ "\n"
@@ -303,6 +308,10 @@ def _run_sh_get_torch_index_url(arch: str, rocm_tag: str = "") -> "tuple[str, st
+ "\n"
+ _sh_function_body(src, "_amd_sole_index_arch")
+ "\n"
+ + bnb_floor_constant.group(0)
+ + "\n"
+ + bnb_floor_fn
+ + "\n"
+ _sh_function_body(src, "get_torch_index_url")
+ "\n"
+ _INDEX_URL_STUBS