Repository navigation
Route spoofed Strix Halo GPUs to the AMD per-gfx index - #8480
Conversation
HSA_OVERRIDE_GFX_VERSION=11.0.0 is the widely circulated Strix Halo
workaround, and ROCr applies it in userland, so rocminfo hands the
spoofed gfx1100 to every consumer. The installer believed it: the
correct gfx1151 inferred from the product name in /proc/cpuinfo was
discarded, the Strix reroute intersected {gfx1151, gfx1150, gfx1152}
against ["gfx1100"] and got nothing, and torch came from
download.pytorch.org/whl/rocm6.3 as 2.9.1+rocm6.3. The first real
allocation then ran gfx1100 kernels on gfx1151 silicon and segfaulted.
The runtime-visible arch still outranks the product name everywhere it
did before. The correction fires only when HSA_OVERRIDE_GFX_VERSION is
set, the probe saw exactly one device, that device's arch differs from
an inferred RDNA 3.5 APU arch, and a source the override cannot reach
agrees with the product name: KFD topology sysfs first, since amdkfd
writes gfx_target_version from the kernel's own table, then rocminfo
re-run with the variable stripped, and only if neither can answer, the
variable statically naming the arch that was reported.
A mixed Strix APU plus discrete AMD GPU host stays on today's path. Two
devices in the probe declines outright, and so does a kernel that sees a
second GPU the spoofed probe had collapsed away, so the existing
precedence test needed no change.
install.sh carries the same three helpers and the same decision, and the
tests execute both copies over the same eight host shapes rather than
grepping for them.
Three problems with the correction as it stood.
install.sh never fired. The Strix reroute passes `_gfx_all` in raw, and that
is `rocminfo | grep -oE 'gfx[1-9][0-9a-z]{2,3}'` output, which repeats the
token once per Name / ISA line. A single GPU therefore arrives as two or three
lines, the device count read 2 or 3, and the helper returned early on every
real host, #7331's own included. Count DISTINCT tokens instead. The Python
side already splits on agent headers and was unaffected, so the two paths
disagreed on exactly the host the fix exists for: `studio update` repaired the
machine and a fresh `curl | sh` install re-broke it.
The static fallback could fire when it should not. "The variable names the
arch that was reported, so assume a spoof" is indistinguishable from a host
telling the truth: a real RX 7900 XTX in a Ryzen AI Max chassis reports
gfx1100, infers gfx1151 from the CPU product name (the inference reads
/proc/cpuinfo and never looks at the GPU), and presents the identical
fingerprint the moment its owner has the override set for an unrelated reason.
Same for a correct HSA_OVERRIDE_GFX_VERSION=10.3.0 on an RDNA2 card. Both were
rerouted to Strix wheels whenever KFD sysfs was unreadable. Drop the fallback:
corroboration from the kernel or from an unspoofed re-probe is now required,
and a re-probe that still answers the probed arch is read as evidence FOR the
probe rather than as a failure to disprove. Rerouting a working machine to the
wrong wheels is worse than the bug being fixed.
The Python re-probe left the visible-device masks in place while install.sh
cleared them, so a mask pinned to the dGPU hid the second GPU whose presence
is the only thing that vetoes the correction on a mixed host. Clear all three
in both, and add the arch the variable names as a required precondition rather
than a sufficient one: ROCr can only rename an agent to the target the
variable names, so any other reading is real silicon.
Tests: the parity check now builds each side's probe input the way its own
call site does instead of handing both a pre-shaped list, which is what let
the install.sh defect through. Over the resulting matrix the previous code
diverges on 91 of 3360 shapes with install.sh correcting none of them; it is
clean now. Adds the 7900-XTX-in-a-Ryzen-AI-Max cases, executes the shell KFD
parser against a fabricated topology tree rather than grepping it, and passes
create = True where a helper is patched so a run against an older tree fails
on the assertion instead of on AttributeError.
The correction printed "Checking whether the ISA is being spoofed." and then, on every path that decides there is no spoof, said nothing further. That is the CORRECT outcome for a real gfx1100 card in a Ryzen AI Max chassis, and it is the outcome a user is most likely to see, so silence reads as a failure. Report the conclusion in both implementations, naming the source that declined to corroborate and the arch being kept. Also count distinct probe tokens inside the existing awk instead of piping to `wc -l | tr -d`. wc was the one tool the change added to install.sh's dependency set (0 pre-existing uses); this drops it along with two process spawns per call.
install.sh unsets the corroborated spoof for the one launch it performs itself, but that unset dies with the installer: studio/setup.sh runs install_python_stack.py as a child, so the `unsloth studio update` repair, the generated launch-studio.sh and a hand-typed `unsloth studio` all still start with the variable set. Clear it at the CLI chokepoint the exec, the Windows Popen and the in-process paths all pass through, keyed on the install rather than on a hardware probe: AMD's per-gfx index ships rocm_sdk_libraries_<arch> beside single-arch wheels, so an override naming a different arch is provably asking for kernels this install does not contain. A generic multi-arch index brings no such distribution and is left alone, since there the override is often the only thing making the GPU usable.
Clearing HSA_OVERRIDE_GFX_VERSION is only sound because native per-gfx wheels are going in on that branch. The guard checked only that the spoof had been corroborated, not that anything was actually being installed. --no-torch, and the Intel Mac auto-detection that sets the same SKIP_TORCH, reach the reroute and then install no torch at all. Clearing there left the host with the generic wheels it already had and no override, which is strictly worse than either alone: on a spoofed Strix host the override was the only source of usable kernels. The block's own comment already stated the invariant (native wheels are going in); it just did not enforce it. It does now.
The launch-time arbiter read the bare rocm meta-package's Requires-Dist to name the family the install carries kernels for. That is authoritative only while torch actually resolves through it. Switching from AMD's per-gfx index to a generic pytorch.org ROCm one does not uninstall it: the generic wheels vendor their own ROCm libraries and depend on no meta-package, so rocm is orphaned outright, and pip has no autoremove. The stale metadata then named the OLD family and cleared an override that the generic wheels may be the only reason the GPU works at all, which is the opposite of what this code is for. torch's Requires-Dist is now the first discriminator. An unknown shape answers no, so a tree this cannot read is left alone rather than arbitrated on a guess. The venv fixture grows the same dependency edge, since one that never carried it could not tell a live meta-package from an orphaned one.
|
Codex Review: Didn't find any major issues. Keep them coming! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
Codex Review: Didn't find any major issues. Another round soon, please! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
CI note, since the one red check is not this branch.
That step runs - {os: macos-15-intel, mode: mask, delivery: file, flags: '', experimental: true, overlay: true, allow_working: 'git'}with no SKIP_TORCH=false
if [ "$_NO_TORCH_FLAG" = true ] || [ "$MAC_INTEL" = true ]; then
SKIP_TORCH=true
fiSo the leg installs no torch by design and then asserts torch imports. That mismatch predates this branch: the row and the assertion are both untouched here, and this branch changes only install.sh, install_python_stack.py, unsloth_cli/commands/studio.py and two test files, none of which affects SKIP_TORCH or any macOS path. The gfx helpers return immediately when HSA_OVERRIDE_GFX_VERSION is unset, which it always is on macOS, and the ROCm branch is unreachable on Darwin. The row is Not fixing it here: it belongs in that workflow, not in a ROCm change, and the right fix is a judgement call between adding |
Closes #7331.
What happens today
HSA_OVERRIDE_GFX_VERSION=11.0.0is the widely circulated Strix Halo workaround. It is applied in userland by the ROCm thunk, so a gfx1151 host reports gfx1100 to the runtime, which is exactly what the reporter pasted while their hardware is a Radeon 8060S.Unsloth already gets this host right and then throws the answer away:
_infer_linux_amd_gfx_arch()reads "Ryzen AI Max" out of/proc/cpuinfoand correctly returns gfx1151.{gfx1151, gfx1150, gfx1152}against["gfx1100"], gets the empty set, and falls through.Result:
download.pytorch.org/whl/rocm6.3withtorch>=2.4,<2.11.0, which resolves to the2.9.1+rocm6.3in the report. The first real allocation runs gfx1100 kernels on gfx1151 silicon and the process dies with SIGSEGV.install.shhad the identical gap on thecurl | shpath.Nothing in the repo read, logged or validated
HSA_OVERRIDE_GFX_VERSION.The fix
The runtime-visible arch still outranks the product name everywhere it did before. The correction is scoped to the one shape that cannot be a real mixed host, and fires only when all of these hold:
HSA_OVERRIDE_GFX_VERSIONis set. With no override there is nothing to doubt.amdkfdpopulatesgfx_target_versionin the kernel from its per-ASIC device info and exposes it at/sys/class/kfd/kfd/topology/nodes/<N>/properties, so a userland environment variable cannot reach it. Encoding isMMMNNRR, so gfx1151 is 110501.rocminfore-run with the variable stripped from its environment.Two independent readings have to agree against the one spoofed reading. The variable is logged as soon as a disagreement is seen, whatever the verdict.
The repo already walks that same KFD directory in
_has_rocm_gpu(), so this reads a source we were opening anyway.The mixed host is still protected
The precedence exists so a Strix APU plus a discrete AMD GPU, with
HIP_VISIBLE_DEVICESon the dGPU, does not get APU wheels. It keeps today's behaviour by two independent guards: a two-device probe declines outright, and a kernel that sees a second GPU the spoofed probe had collapsed away also declines.UNSLOTH_ROCM_GFX_ARCHstill outranks everything.test_rocm_support.py::test_inference_yields_to_runtime_visible_gpuasserts the old behaviour on this exact host and passes unmodified, because it sets no override and so never reaches the new path. That file is byte-identical in this PR.Routing
Single gfx1151, rocminfo says gfx1100, ROCm 6.3, override set:
download.pytorch.org/whl/rocm6.3torch>=2.4,<2.11.0repo.amd.com/rocm/whl/gfx1151/torch>=2.11.0,<2.12.0download.pytorch.org/whl/rocm7.1The repair row matters most: affected users already have the bad torch, so
has_hip_torchis True and only the Strix reroute can rescue them.Tests
43 new tests in
tests/studio/install/test_rocm_gfx_spoof_7331.py. Theinstall.shparity tests execute both the shell and the Python helper over the same eight host shapes and compare verdicts, rather than grepping, since the two paths silently diverging is how this family of bugs keeps recurring.tests/studio/install/: 1790 passed, 2 skipped before; 1833 passed, 2 skipped after.test_rocm_support.pyunchanged at 486 passed, 1 skipped.sh -n install.shpasses and the formatters produce no diff.There is no AMD hardware and no ROCm CI in this repo, so this is mock-based throughout and has not been validated on real silicon.
Not in this change
The RAG warmup segfault guard (#8474), and a runtime warning that a lingering
HSA_OVERRIDE_GFX_VERSIONwill re-spoof gfx1151 wheels after the install is fixed. Both are separate.