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.

install.sh: install for the discrete AMD GPU when an iGPU is listed first (#12963)

Daniel Hand346d8c33818
diff --git a/install.sh b/install.sh
index 8c2c93e9486..7b0d9cd75c2 100755
--- a/install.sh
+++ b/install.sh
@@ -6961,6 +6961,9 @@ case "$_torch_index_leaf" in
echo " [WARN] Set UNSLOTH_ROCM_GFX_ARCH to name the target explicitly." >&2
echo "" >&2
_runtime_gfx=""
+ elif [ "$_gfx_space" = hip ] && [ -z "${UNSLOTH_ROCM_GFX_ARCH:-}" ] && [ -n "$_runtime_gfx" ]; then
+ # Unmasked iGPU listed first: install for the discrete card (#7776), as setup.sh does.
+ _runtime_gfx=$(_amd_prefer_discrete_gfx "$_gfx_all" "$_runtime_gfx")
fi
fi
# An explicit UNSLOTH_ROCM_GFX_ARCH=gfx906 pins the runtime target to the MI50 / Radeon VII path and must win over Strix probe-order detection on a mixed Strix + MI50 host, so the Strix reroute is suppressed when it is set. Normalize a copied HIP gcnArchName (gfx906:sramecc-:xnack- to gfx906) and trim whitespace so the suffix or a stray newline does not defeat the exact gfx906 comparisons below.
@@ -7208,10 +7211,29 @@ elif _torch_index_url_is_rocm "$TORCH_INDEX_URL"; then
_gpu_disp_gfx_all=$(amd-smi list 2>/dev/null | grep -oE 'gfx[1-9][0-9a-z]{2,3}' || true)
[ -z "$_gpu_disp_gfx_all" ] && \
_gpu_disp_gfx_all=$(printf '%s\n' "$_gpu_disp_smi_records" | awk -F'|' '$1 != "" { print $1 }')
+ # amd-smi is not ROCr-filtered: keep ROCr's survivors first, as the routing block does.
+ if [ -n "${ROCR_VISIBLE_DEVICES:-}" ] && [ "$ROCR_VISIBLE_DEVICES" != "-1" ]; then
+ for _gpu_disp_v in _gpu_disp_smi_records _gpu_disp_gfx_all; do
+ eval "_gpu_disp_in=\$$_gpu_disp_v"
+ [ -n "$_gpu_disp_in" ] || continue
+ _gpu_disp_kept=$(printf '%s\n' "$_gpu_disp_in" | awk -v m="$ROCR_VISIBLE_DEVICES" '
+ NF { v[n++] = $0 }
+ END { k = split(m, t, ","); for (i = 1; i <= k; i++) { gsub(/[[:space:]]/, "", t[i]); if (t[i] !~ /^[0-9]+$/) continue; x = t[i] + 0; if (x >= n || (x in s)) break; s[x] = 1; print v[x] } }')
+ [ -n "$_gpu_disp_kept" ] && eval "$_gpu_disp_v=\$_gpu_disp_kept"
+ done
+ fi
# A silent amd-smi does not own the device list: keep rocminfo's APU fallback.
[ -n "$_gpu_disp_smi_records" ] && _gpu_disp_records="$_gpu_disp_smi_records"
fi
- _gpu_vis="${HIP_VISIBLE_DEVICES:-${ROCR_VISIBLE_DEVICES:-}}"
+ # Same masks as the routing block: rocminfo is already ROCr-filtered, CUDA is HIP's alias.
+ _gpu_vis=""
+ for _gpu_vis_m in HIP_VISIBLE_DEVICES CUDA_VISIBLE_DEVICES; do
+ eval "_gpu_vis_set=\${$_gpu_vis_m+x}"
+ if [ -n "$_gpu_vis_set" ]; then
+ eval "_gpu_vis=\$$_gpu_vis_m"
+ break
+ fi
+ done
_gpu_vis_idx=0
if [ -n "$_gpu_vis" ] && [ "$_gpu_vis" != "-1" ]; then
_gpu_first="${_gpu_vis%%,*}"
@@ -7223,6 +7245,18 @@ elif _torch_index_url_is_rocm "$TORCH_INDEX_URL"; then
'NF { a[n++]=$0 } END { if(idx>=n) idx=0; if(n>0) print a[idx+0] }')
_gpu_disp_gfx=${_gpu_disp_record%%|*}
_gpu_disp_mkt=${_gpu_disp_record#*|}
+ # Only when the routing block ran: a pinned index installs what it names, not the dGPU.
+ if [ "$_torch_index_pinned" = false ] && [ -z "${UNSLOTH_ROCM_GFX_ARCH:-}" ] && [ -n "$_gpu_disp_gfx" ]; then
+ _gpu_disp_pref=$(_amd_prefer_discrete_gfx \
+ "$(printf '%s\n' "$_gpu_disp_records" | awk -F'|' '$1 != "" { print $1 }')" "$_gpu_disp_gfx")
+ if [ -n "$_gpu_disp_pref" ] && [ "$_gpu_disp_pref" != "$_gpu_disp_gfx" ]; then
+ substep "Integrated $_gpu_disp_gfx enumerated first; installing for discrete $_gpu_disp_pref"
+ substep "Set UNSLOTH_ROCM_GFX_ARCH=$_gpu_disp_gfx to target the integrated GPU instead."
+ _gpu_disp_gfx="$_gpu_disp_pref"
+ _gpu_disp_mkt=$(printf '%s\n' "$_gpu_disp_records" | awk -F'|' -v gfx="$_gpu_disp_gfx" \
+ '$1 == gfx { print $2; exit }')
+ fi
+ fi
fi
# Only pre-TARGET_GRAPHICS_VERSION amd-smi lands here: names but no arch in the record.
if [ -z "$_gpu_disp_gfx" ]; then
diff --git a/tests/sh/test_install_gpu_summary_probe_sources.sh b/tests/sh/test_install_gpu_summary_probe_sources.sh
index f18b693bdc5..59c896a884c 100755
--- a/tests/sh/test_install_gpu_summary_probe_sources.sh
+++ b/tests/sh/test_install_gpu_summary_probe_sources.sh
@@ -13,6 +13,13 @@ trap 'rm -rf "$WORK"' EXIT
sed -n '/^_rocminfo_gpu_records()/,/^}/p' "$INSTALL_SH"
sed -n '/^_amd_smi_gpu_records()/,/^}/p' "$INSTALL_SH"
sed -n '/^_amd_smi_hip_order()/,/^}/p' "$INSTALL_SH"
+ for _fn in _amd_prefer_discrete_gfx _amd_gfx_is_shadowing_integrated _amd_gfx_has_wheel_route \
+ _amd_arch_index_family_for_gfx _amd_generic_tag_carries_gfx; do
+ sed -n "/^${_fn}()/,/^}/p" "$INSTALL_SH"
+ done
+ echo '_detect_rocm_version_tag() { echo rocm7.2; }'
+ echo 'substep() { :; }'
+ echo '_torch_index_pinned=${STUB_PINNED:-false}'
echo ""
# Extract the probe and selection block.
awk '/^ _gpu_disp_gfx_all=""/ {on=1}
@@ -46,7 +53,8 @@ case "$1 $2" in
# `list -e` carries HIP_ID and nothing else of interest; an older CLI rejects the
# flag outright, which is the STUB_AMDSMI_E="" case.
"list -e") [ -z "${STUB_AMDSMI_E:-}" ] || cat "$STUB_AMDSMI_E" ;;
- "list "*) sed -n 's/^\(GPU: [0-9]*\).*/\1 BDF: 0000:03:00.0 UUID: aaaa-bbbb KFD_ID: 1/p' "$STUB_AMDSMI" ;;
+ "list "*) [ -z "${STUB_AMDSMI_LIST:-}" ] || { cat "$STUB_AMDSMI_LIST"; exit 0; }
+ sed -n 's/^\(GPU: [0-9]*\).*/\1 BDF: 0000:03:00.0 UUID: aaaa-bbbb KFD_ID: 1/p' "$STUB_AMDSMI" ;;
"static "*) cat "$STUB_AMDSMI" ;;
esac
STUB
@@ -63,6 +71,7 @@ summary() {
STUB_ROCMINFO="$1" STUB_AMDSMI="$2" \
${STUB_AMDSMI_E:+STUB_AMDSMI_E="$STUB_AMDSMI_E"} \
${3:+HIP_VISIBLE_DEVICES="$3"} \
+ ${SUMMARY_ENV:-} \
/bin/bash -c 'set -eu; . "$1"; printf "%s|%s\n" "$_gpu_disp_gfx" "$_gpu_disp_mkt"' _ "$WORK/block.sh"
}
@@ -362,6 +371,61 @@ assert_eq "identical adapters still resolve without a map" \
assert_eq "one adapter resolves without a map" \
"gfx1100|AMD Radeon RX 7900 XTX" "$(summary "$WORK/empty" "$WORK/smi_fixture" 0)"
+cat > "$WORK/roc_two_rev" <<'EOF'
+Agent 1
+*******
+ Name: AMD EPYC 7763 64-Core Processor
+ Marketing Name: AMD EPYC 7763 64-Core Processor
+ Device Type: CPU
+*******
+Agent 2
+*******
+ Name: gfx1100
+ Marketing Name: AMD Radeon RX 7900 XTX
+ Device Type: GPU
+*******
+Agent 3
+*******
+ Name: gfx90a
+ Marketing Name: AMD Instinct MI210
+ Device Type: GPU
+EOF
+
+echo "=== an unmasked iGPU listed first does not name the card ==="
+# The routing block installs for the discrete card here (#7776); the banner must agree.
+assert_eq "the discrete card and its own name are announced" \
+ "gfx1201|AMD Radeon AI PRO R9700" "$(summary "$WORK/roc_twins" "$WORK/empty")"
+assert_eq "a mask naming the iGPU is honoured" \
+ "gfx1036|AMD Radeon Graphics" "$(summary "$WORK/roc_twins" "$WORK/empty" 0)"
+
+echo "=== the banner reads the routing block's masks ==="
+assert_eq "CUDA_VISIBLE_DEVICES selects like HIP_VISIBLE_DEVICES" \
+ "gfx1100|AMD Radeon RX 7900 XTX" \
+ "$(SUMMARY_ENV=CUDA_VISIBLE_DEVICES=1 summary "$WORK/roc_two_gpus" "$WORK/empty")"
+# rocminfo already lists ROCr's survivors in mask order; indexing them by ROCr again
+# named the second survivor.
+assert_eq "an ROCr mask is not applied twice to rocminfo output" \
+ "gfx1100|AMD Radeon RX 7900 XTX" \
+ "$(SUMMARY_ENV=ROCR_VISIBLE_DEVICES=1,0 summary "$WORK/roc_two_rev" "$WORK/empty")"
+# amd-smi is not ROCr-filtered, so ROCr picks survivors and HIP indexes them.
+assert_eq "amd-smi: ROCr survivors, then HIP" "gfx90a|AMD Instinct MI210" \
+ "$(STUB_AMDSMI_E="$WORK/smi_e_identity" SUMMARY_ENV=ROCR_VISIBLE_DEVICES=2,0 \
+ summary "$WORK/empty" "$WORK/smi_three" 1)"
+assert_eq "amd-smi: an ROCr mask alone still selects its card" "gfx1201|AMD Radeon AI PRO R9700" \
+ "$(STUB_AMDSMI_E="$WORK/smi_e_identity" SUMMARY_ENV=ROCR_VISIBLE_DEVICES=2 \
+ summary "$WORK/empty" "$WORK/smi_three")"
+
+# Older amd-smi: `static --asic` names no arch, `list` prints `GPU[N] : gfx...`.
+printf 'GPU: 0\n' > "$WORK/smi_no_asic"
+printf 'GPU[0] : gfx1036\nGPU[1] : gfx1201\n' > "$WORK/smi_list_gfx"
+assert_eq "amd-smi list-only arches: ROCr survivors, then HIP" "gfx1201|" \
+ "$(SUMMARY_ENV="ROCR_VISIBLE_DEVICES=1 STUB_AMDSMI_LIST=$WORK/smi_list_gfx" \
+ summary "$WORK/empty" "$WORK/smi_no_asic")"
+
+echo "=== a pinned index keeps the enumerated card ==="
+assert_eq "no discrete repick when routing was skipped" "gfx1036|AMD Radeon Graphics" \
+ "$(SUMMARY_ENV=STUB_PINNED=true summary "$WORK/roc_twins" "$WORK/empty")"
+
echo ""
echo "Results: $PASS passed, $FAIL failed"
[ "$FAIL" -eq 0 ]
diff --git a/tests/studio/install/test_rocm_support.py b/tests/studio/install/test_rocm_support.py
index dc5b76fc255..6cc35977101 100644
--- a/tests/studio/install/test_rocm_support.py
+++ b/tests/studio/install/test_rocm_support.py
@@ -108,6 +108,11 @@ def _gpu_record_helpers(source: str) -> str:
"_amd_smi_gpu_records",
"_gfx_arch_slots",
"_amd_smi_hip_order",
+ "_amd_prefer_discrete_gfx",
+ "_amd_gfx_is_shadowing_integrated",
+ "_amd_gfx_has_wheel_route",
+ "_amd_arch_index_family_for_gfx",
+ "_amd_generic_tag_carries_gfx",
)
)
@@ -2312,6 +2317,28 @@ class TestGfx1102Rocm64Floor:
)
assert self._run_install_sh_routing(preamble) == expected
+ @pytest.mark.parametrize(
+ ("arches", "mask", "expected"),
+ (
+ # An unmasked iGPU listed first used to pick the wheels and strand the dGPU.
+ (("gfx1036", "gfx1201"), "", _RDNA4_LEAF),
+ (("gfx1103", "gfx1201"), "", _RDNA4_LEAF),
+ (("gfx1201", "gfx1036"), "", _RDNA4_LEAF),
+ # A mask names the device, so the iGPU it selects keeps the route.
+ (("gfx1036", "gfx1201"), "HIP_VISIBLE_DEVICES=0", "rocm6.1"),
+ (("gfx1036", "gfx1201"), "CUDA_VISIBLE_DEVICES=0", "rocm6.1"),
+ (("gfx1036",), "", "rocm6.1"),
+ ),
+ )
+ def test_install_sh_prefers_the_discrete_gpu_over_a_leading_igpu(self, arches, mask, expected):
+ preamble = (
+ "rocminfo() { printf '"
+ + "".join(f"Name: {a}\\n" for a in arches)
+ + "'; }\n"
+ + "".join(f"export {assignment}\n" for assignment in mask.split())
+ )
+ assert self._run_install_sh_routing(preamble) == expected
+
@staticmethod
def _rocminfo_stub(*arches: str) -> str:
"""A rocminfo stub whose agents repeat their gfx token across Name and ISA."""