Skip to content

Route spoofed Strix Halo GPUs to the AMD per-gfx index - #8480

Merged
danielhanchen merged 16 commits into
mainfrom
fix/gfx_spoof_7331
Aug 12, 2026
Merged

danielhanchen merged 16 commits into
mainfrom
fix/gfx_spoof_7331

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Closes #7331.

What happens today

HSA_OVERRIDE_GFX_VERSION=11.0.0 is 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/cpuinfo and correctly returns gfx1151.
  • That inference is only consulted when the runtime cannot enumerate a GPU. Here it can, so the inference is discarded, with no log line.
  • The Strix reroute intersects {gfx1151, gfx1150, gfx1152} against ["gfx1100"], gets the empty set, and falls through.

Result: download.pytorch.org/whl/rocm6.3 with torch>=2.4,<2.11.0, which resolves to the 2.9.1+rocm6.3 in the report. The first real allocation runs gfx1100 kernels on gfx1151 silicon and the process dies with SIGSEGV. install.sh had the identical gap on the curl | sh path.

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_VERSION is set. With no override there is nothing to doubt.
  • The probe saw exactly one device.
  • That device's arch differs from an inferred RDNA 3.5 APU arch.
  • A source the override cannot reach agrees with the product name:
    1. KFD topology sysfs. amdkfd populates gfx_target_version in 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 is MMMNNRR, so gfx1151 is 110501.
    2. rocminfo re-run with the variable stripped from its environment.
    3. Failing both, the variable statically naming the arch that was reported.

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_DEVICES on 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_ARCH still outranks everything.

test_rocm_support.py::test_inference_yields_to_runtime_visible_gpu asserts 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:

index torch
before, fresh install download.pytorch.org/whl/rocm6.3 torch>=2.4,<2.11.0
before, repair no install; broken torch left in place
after repo.amd.com/rocm/whl/gfx1151/ torch>=2.11.0,<2.12.0
after, mixed host download.pytorch.org/whl/rocm7.1 unchanged

The repair row matters most: affected users already have the bad torch, so has_hip_torch is True and only the Strix reroute can rescue them.

Tests

43 new tests in tests/studio/install/test_rocm_gfx_spoof_7331.py. The install.sh parity 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.py unchanged at 486 passed, 1 skipped. sh -n install.sh passes 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_VERSION will re-spoof gfx1151 wheels after the install is fixed. Both are separate.

danielhanchen and others added 2 commits August 11, 2026 18:26
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.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

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.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 2 commits August 11, 2026 19:46
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.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

danielhanchen and others added 3 commits August 11, 2026 20:14
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.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 11, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 11, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 11, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 11, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 11, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 11, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 11, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 11, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep them coming!

Reviewed commit: 9d9d8a3a1d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: b75e4e6bb1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

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".

@danielhanchen

Copy link
Copy Markdown
Member Author

CI note, since the one red check is not this branch.

mac macos-15-intel / mask / file fails at "Assert llama.cpp loads, and every downloaded Mach-O is native and signed" with:

ModuleNotFoundError: No module named 'torch'

That step runs "$PY" -c "import numpy, safetensors, tokenizers, torch; ...", but the matrix row is

- {os: macos-15-intel, mode: mask, delivery: file, flags: '', experimental: true, overlay: true, allow_working: 'git'}

with no --no-torch, while install.sh auto-enables the same switch on that hardware:

SKIP_TORCH=false
if [ "$_NO_TORCH_FLAG" = true ] || [ "$MAC_INTEL" = true ]; then
    SKIP_TORCH=true
fi

So 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 experimental: true, which the workflow maps to continue-on-error, so it is advisory rather than gating.

Not fixing it here: it belongs in that workflow, not in a ROCm change, and the right fix is a judgement call between adding --no-torch to the row and gating the assertion on the installed flavour. Happy to open it separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Segmentation fault on startup — RAG embeddings warmup crashes on AMD Radeon 8060S (gfx1100) / ROCm 6.3

1 participant