Skip to content

Studio: name the GPU agent, not the CPU, in the rocminfo probe - #9498

Merged
danielhanchen merged 9 commits into
unslothai:mainfrom
oobabooga:amd-rocminfo-gpu-name
Aug 23, 2026
Merged

danielhanchen merged 9 commits into
unslothai:mainfrom
oobabooga:amd-rocminfo-gpu-name

Conversation

@oobabooga

@oobabooga oobabooga commented Aug 21, 2026 •

Copy link
Copy Markdown
Member

Problem

On an AMD host both the installer and unsloth studio update reported the processor as the GPU. On a Ryzen AI MAX+ 395 (gfx1151):

gpu            AMD ROCm (gfx1151)
               GPU: AMD RYZEN AI MAX+ 395 w/ Radeon 8060S

rocminfo lists the CPU agent before the GPU agents, and both scripts took the first Marketing Name: line in the whole output:

awk -F': ' '/Marketing Name:/{...; if($2){print $2; exit}}'

On a real gfx1151 runner that parser prints AMD RYZEN AI MAX+ 395 w/ Radeon 8060S. The arch shown next to it came from a separate grep, so the two halves of the line could describe different devices.

Change

_rocminfo_gpu_records emits one gfx|marketing name record per rocminfo GPU agent, in agent order, and the summary selects a record with the same visible-device index that already picked the arch. Identical awk in install.sh and studio/setup.sh, with a test asserting the two copies stay byte-identical, since the installer and the updater must not name different cards on the same host.

Details the parser has to get right:

  • The value is everything after the first colon rather than -F': ', so AMD Instinct MI300X OAM: 750W SKU survives intact.
  • A GPU agent that reports no marketing name still emits its slot (gfx1030|), or every later device shifts down one ordinal.
  • The agent name is matched as a leading gfx token followed by something that cannot extend it, so a target id (gfx90a:sramecc+:xnack-) still registers while the ISA section's Name: amdgcn-amd-amdhsa--gfx1151 does not.
  • With no GPU agent at all, the first marketing name is reported with an empty arch. That is what an APU without a gfx token showed before, so the fallback path is unchanged.
  • The rocminfo arch list is no longer deduplicated, because there is now one record per device: two cards of the same arch are two ordinals, and collapsing them resolved every mask past 0 to card 0.

The two probes have different shapes, so install.sh now follows the division of labour studio/setup.sh already had:

  • When rocminfo names something but enumerates no device and amd-smi then supplies an arch, the leftover record is dropped. Kept, it would win the selection and discard that arch.
  • The amd-smi name is read only when rocminfo produced no records. Its rows are not indexed here, so a device that reported no name of its own must stay unnamed rather than borrow another device's.

Deliberately unchanged: visibility-mask handling, the amd-smi and KFD detection fallbacks, the name-based arch inference table, and the ordering of the arms in the summary. setup.sh calls rocminfo once instead of three times, which follows from building the records rather than being a separate goal.

Verification

  • tests/sh/test_rocminfo_gpu_name_7307.sh: 15 assertions on the parser, covering the CPU-first host, two discrete cards with index selection, two cards of one arch, a blank marketing name keeping its slot, an embedded colon, a target-id agent name, and the no-GPU-agent fallback.
  • tests/sh/test_install_gpu_summary_probe_sources.sh: 10 assertions driving the real probe-and-select block out of install.sh with stub probes, pinning down which source wins in each combination. It builds its PATH from scratch, because the host running it may itself have a real rocminfo and amd-smi.
  • On an AMD DevLab gfx1151 host with real rocminfo output: the previous parser prints AMD RYZEN AI MAX+ 395 w/ Radeon 8060S, both patched copies print gfx1151|AMD Radeon Graphics. The NPU agent (aie2p, Device Type DSP) and both ISA Name: lines produce no records. Both new test files pass in full on that host.
  • Parser output is identical under GNU awk 5.2, mawk and busybox awk.
  • Locally: tests/sh 52/52; tests/studio/install/ plus tests/python/test_cross_platform_parity.py and tests/python/test_windows_no_torch_setup.py at 2574 passed, 118 skipped.
  • On the AMD host, tests/studio/install/ fails the same 6 tests with and without the change (3 in test_managed_node_runtime.py, 1 in test_rocm_gfx_spoof_7331.py, 2 in test_unsupported_arch_routing_guards_8529.py), and tests/sh the same 1 (test_install_rollback_lifecycle.sh, which needs signal traps the runner does not allow). That baseline was measured with this change and Studio: escape the dependency fast path when AMD torch is the wrong wheel #9499 both applied.
  • bash -n and dash -n on install.sh, bash -n on studio/setup.sh, git diff --check.

Related: #7307. Replaces the reporting half of #8606.

@danielhanchen

Copy link
Copy Markdown
Member

Confirmed install.sh and studio/setup.sh still take the first Marketing Name in rocminfo, so the CPU agent gets printed as the GPU, and the record-per-agent parser lines the name up with the arch that was already selected. Will get this reviewed.

…rts that were untested

Follow-up to the rocminfo record parser in this branch, in the same two blocks.

amd-smi upper-cases every key in its human-readable output (amdsmi_logger.py
_capitalize_keys calls key.upper()), so `amd-smi static --asic` prints MARKET_NAME.
The parser matched /[Mm]arket.?[Nn]ame/, which needs a literal lowercase "arket", so
on a real host the fallback printed nothing at all. On an amd-smi-only box the
summary therefore lost the GPU name outright rather than replacing the CPU's with
the card's, which is the opposite of what this branch is for. The key is now matched
case-folded, and the value is read past the FIRST colon only, so
"MARKET_NAME: AMD Instinct MI300X OAM: 750W SKU" survives -- the same truncation the
rocminfo parser here already fixed. Older title-cased "Market Name" still works.
Both copies stay byte identical.

Tests, all of which failed before the change or covered nothing:

- tests/sh/test_setup_gpu_summary_probe_sources.sh is new. install.sh had an
  end-to-end probe test and studio/setup.sh had none, which is the wrong way round:
  install.sh's value is a display label, while $_setup_gfx is forwarded as
  --rocm-gfx to install_llama_prebuilt.py (setup.sh:2568) and to the whisper
  installer (:3309), so a wrong ordinal there picks the wrong binary. It drives the
  real detection and selection block with stub probes on a PATH built from scratch,
  and pins the probe call counts, which is what holds the three-rocminfo-calls-to-one
  improvement in place.

- test_rocminfo_gpu_name_7307.sh no longer restates the production selector in a
  local _pick(). A restated copy cannot fail when the real one changes: re-adding
  !seen[$0]++ to production left all 15 assertions green. It is now read out of
  install.sh, and setup.sh's copy is asserted equal to it, so the two scripts must
  agree on selection as well as on parsing.

- New cases for the two guards nothing exercised: an ISA line repeating a target id
  (what the leading ^ in the gfx match rejects; without it, match() finds gfx90a at
  offset 20 while substr() still cuts from RLENGTH+1 and emits a bogus "amdgcn"
  device), and a gfx token wider than the cap, which must drop the device rather
  than report a truncated arch.

- The amd-smi stub no longer makes `amd-smi list` emit TARGET_GRAPHICS_VERSION. Real
  list prints BDF / UUID / KFD_ID and no gfx token, so the fallthrough to
  `static --asic` was never exercised. Fixtures now use the real MARKET_NAME
  spelling, keep a title-cased one, and add an embedded colon.

- A Ryzen iGPU plus two identical R9700s, selected at device 2. The two dGPU records
  are byte identical, so a selector that folds duplicate lines away resolves that
  device back to the iGPU at ordinal 0.

- Both harnesses now run the extracted block under the same set flags as the real
  scripts (set -eu for install.sh, set -euo pipefail for setup.sh).

Verification: tests/sh 52/52. Parser output identical under gawk 5.2.1, gawk --posix,
mawk 1.3.4 and busybox awk 1.36.1, under LC_ALL=C and C.UTF-8, including CRLF and
non-ASCII names. tests/studio/install/ plus tests/python/test_cross_platform_parity.py
and test_windows_no_torch_setup.py: 2708 passed, 3 failed, 3 skipped, with the failing
and skipped node IDs identical to the merge base (the three are test_managed_node_runtime
and pre-existing). 12 mutants over the parser, the selector and the amd-smi arm, all 12
killed. bash -n on both scripts, dash -n on install.sh, git diff --check.

No AMD hardware here, so everything above is fixture- or stub-driven.
@danielhanchen

Copy link
Copy Markdown
Member

Thanks for splitting this out of #8606. The bug is real, the fix is right, and I could not find a host shape where it breaks something that worked. I pushed one follow-up commit to your branch (f2abb1546) since maintainer_can_modify was on. Details below, and there is a list at the end of things I deliberately did not touch.

No AMD hardware on any runner or on my box, so everything here is fixture- or stub-driven, and I have said which is which.

The bug is real, and this fixes it

I extracted the real probe block from install.sh and studio/setup.sh at the merge base and at your head, and drove all four through stub rocminfo / amd-smi on a PATH built from scratch, over 31 fixture shapes:

host before after
Strix Halo, CPU agent first, NPU + ISA blocks gfx1151 / AMD RYZEN AI MAX+ 395 w/ Radeon 8060S gfx1151 / AMD Radeon Graphics
2 GPUs, HIP_VISIBLE_DEVICES=1 gfx1100 / AMD EPYC 7763 64-Core Processor gfx1100 / AMD Radeon RX 7900 XTX
two gfx1100 cards, index 1 gfx1100 / AMD EPYC 7763 64-Core Processor gfx1100 / AMD Radeon PRO W7900
MI300X OAM: 750W SKU gfx942 / AMD EPYC 9654 96-Core Processor gfx942 / AMD Instinct MI300X OAM: 750W SKU
CPU-only rocminfo, amd-smi has the arch gfx1100 / AMD Ryzen 9 5950X (two different devices) gfx1100 / AMD Radeon RX 7900 XTX

Two things worth calling out that the description does not:

The ordinal fix reaches wheel and prebuilt selection, not just the label. Dropping !seen[$0]++ means duplicate arches no longer collapse. On three devices with HIP_VISIBLE_DEVICES=2, _setup_gfx goes from gfx90a (the wrong card, reached by falling out of range) to gfx1100, and studio/setup.sh:2568 / :3309 forward that as --rocm-gfx. That is the most valuable part of this PR and it had no test.

rocminfo invocations drop 3 to 1 in setup.sh and 2 to 1 in install.sh, measured with a logging stub.

Ground truth I checked rather than recalled: rocminfo.cc:604-656 fixes the field order as Name then Uuid then Marketing Name then Vendor Name and only later Device Type, so gating on Device Type would need buffering and your ordering assumption holds. The cache Name: at :1064 is behind #ifdef ENABLE_CACHE_DUMP, which no build defines. And ROCR-Runtime's own processor table has 39 entries with a maximum of four characters after gfx, so the width cap costs nothing today.

Nothing else breaks

Cartesian product of [Linux, WSL, macOS] x [NVIDIA, AMD, CPU-only], plus XPU, Apple Silicon, iGPU-shadowing-dGPU, RDNA1, KFD-only and both-tools-absent, driving the real regions at base and head. Every non-AMD cell is byte-identical to the base. NVIDIA still wins on a mixed AMD-plus-NVIDIA box, including the WSL shape where nvidia-smi works but /proc/driver/nvidia/gpus is absent. Every AMD cell differs only in the name, except the duplicate-arch row above.

Windows is untouched: install.ps1 and studio/setup.ps1 are byte-identical to the base, they never call rocminfo, and they read names from Win32_VideoController, which enumerates display adapters only, so the CPU-first bug is structurally impossible there. No browser or frontend code is in the diff.

tests/studio/install/ plus tests/python/test_cross_platform_parity.py and test_windows_no_torch_setup.py, same venv, head against merge base: 2708 passed, 3 failed, 3 skipped on both sides, with the failing and skipped node IDs identical. The three are test_managed_node_runtime and are pre-existing. tests/sh 52/52.

What I pushed

amd-smi upper-cases every key in its human-readable output (amdsmi_logger.py _capitalize_keys calls key.upper()), so static --asic prints MARKET_NAME, and /[Mm]arket.?[Nn]ame/ needs a literal lowercase arket. That arm has never fired on a real host. It matters here because this PR narrowed when it is consulted: on an amd-smi-only box the summary went from printing the CPU's name to printing no name at all, which is the opposite of the goal. Reproduced with a faithful stub:

rocminfo: CPU agent only.  amd-smi: MARKET_NAME: AMD Radeon RX 7900 XTX / gfx1100
  base                 gfx1100|AMD Ryzen 9 5950X 16-Core Processor
  head, before the fix gfx1100|
  head, after the fix  gfx1100|AMD Radeon RX 7900 XTX

Now matched case-folded and read past the first colon only, so MARKET_NAME: AMD Instinct MI300X OAM: 750W SKU survives too. Title-cased Market Name still works. Both copies stay byte identical.

Test changes, in the same commit:

  • tests/sh/test_setup_gpu_summary_probe_sources.sh is new. install.sh had an end-to-end probe test and setup.sh had none, which is backwards: install.sh's value is a label, setup.sh's picks binaries. It drives the real detection and selection block and pins the probe call counts, which is what holds the 3-to-1 improvement in place.
  • _pick() no longer restates the production selector. A restated copy cannot fail when the real one changes: I re-added !seen[$0]++ to production and all 15 assertions stayed green. It is now read out of install.sh, and setup.sh's copy is asserted equal to it.
  • The two untested guards now have cases. An ISA line repeating a target id, which is what the leading ^ rejects (without it, match finds gfx90a at offset 20 while substr still cuts from RLENGTH + 1 and emits a bogus amdgcn device that shifts every later ordinal), and an over-wide gfx token, which must drop the device rather than report a truncated arch.
  • The amd-smi list stub was making list emit TARGET_GRAPHICS_VERSION. Real list prints BDF, UUID and KFD_ID and no gfx token, so the fallthrough to static --asic was never exercised. Fixtures now use the real spelling and add an embedded colon.
  • A Ryzen iGPU plus two identical R9700s, selected at device 2. The two dGPU records are byte identical, so a selector that folds duplicate lines away resolves that device back to the iGPU at ordinal 0.
  • Both harnesses now run under the same set flags as the real scripts.

Because a test that cannot fail is not coverage, I mutated 12 behaviours across the parser, the selector and the amd-smi arm. Before: 6 of 9 killed, survivors were the trailing-character guard, the ^ anchor and the production dedup. After: 12 of 12 killed, no survivors. Parser output is identical under gawk 5.2.1, gawk --posix, mawk 1.3.4 and busybox awk 1.36.1, under LC_ALL=C and C.UTF-8, including CRLF and non-ASCII names.

Left alone deliberately, each with a reproducer

None of these is a blocker and none is a regression from this PR, but three of them are the same bug class you are fixing, so they are worth their own change rather than a quiet rewrite of your branch.

1. The summary and the wheel routing now disagree about the arch. install.sh:4596 still deduplicates, because its grep -oE also sees every ISA line. On [gfx1100, gfx1100, gfx1151]:

idx   routing gfx   summary gfx
1     gfx1151       base gfx1151 ok    head gfx1100  DISAGREE
2     gfx1100       base gfx1100 ok    head gfx1151  DISAGREE

At the base both were wrong together; now the printed arch is right and routing still is not, so a Strix third device is announced as gfx1151 and routed as gfx1100. The wheel outcome is unchanged from today, so nothing breaks, but the halves no longer describe the same device. Fixing it means feeding routing the same records parser, which also touches the HSA_OVERRIDE_GFX_VERSION spoof correction, so it wants its own tests.

2. _amd_gpu_radeon is set by an unscoped grep over every marketing name (install.sh:4502), which is the CPU-agent bug again, in the path that picks the wheel index:

rocminfo with an MI210 as the only GPU and a Ryzen 7940HS CPU
  _amd_gpu_radeon=true, matched on "AMD Ryzen 9 7940HS w/ Radeon 780M Graphics"

That routes an Instinct card to repo.radeon.com at :5106. Pre-existing and ~230 lines above your diff.

3. The visible-device mask is applied twice on the rocminfo path. rocminfo is an ROCr client, and amd_filter_device.h:85-126 documents that ROCR_VISIBLE_DEVICES filters and reorders the agents ROCr surfaces. Both scripts then index that already-filtered list again. ROCR_VISIBLE_DEVICES=1 is right by accident (one entry, index out of range, falls back to 0), but 1,2 selects the second visible device rather than the first masked one. HIP_VISIBLE_DEVICES is unaffected, since rocminfo never honoured it. A correct fix has to index per source, because amd-smi is not filtered by ROCr, so the two arms need different indices. install.sh:3467 already unsets both masks for the wheel probe and is the precedent.

4. A blank rocminfo name no longer falls back to amd-smi. With [ -z "$_gpu_disp_records" ] in place, a card that reports gfx1030 and no Marketing Name stays unnamed even when amd-smi knows it. I left this as you wrote it: on a multi-GPU host the base was borrowing another card's name, and unnamed beats confidently wrong. Worth a line in the description.

5. The gpus == 0 fallback record is dead in studio/setup.sh. The records are only read when _setup_gfx_all is non-empty, and every other arm clears them, so |<name> can never be selected there. Only install.sh consumes it. Not a regression, but the "keep in sync" comments imply a parity the callers do not have.

Happy to take 1 to 3 in a follow-up unless you would rather own them.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

…minfo path

The rocminfo path pairs each device's arch with its own name; the amd-smi fallback did
not. Its arch was indexed by HIP_VISIBLE_DEVICES / ROCR_VISIBLE_DEVICES while the name
came from a separate awk that exited on the first MARKET_NAME, so selecting any adapter
past 0 announced that adapter's arch with adapter 0's name. Reproduced on three
adapters, before:

  HIP_VISIBLE_DEVICES=0  gfx90a|AMD Instinct MI210
  HIP_VISIBLE_DEVICES=1  gfx1100|AMD Instinct MI210     <- MI210 is device 0
  HIP_VISIBLE_DEVICES=2  gfx1201|AMD Instinct MI210

This is not only a label. amd-smi 6.1.1 ships MARKET_NAME with no
TARGET_GRAPHICS_VERSION (its documented static output has the former and not the
latter), and with no gfx token the arch is inferred from the name, so on such a host
the first adapter's name decided $_setup_gfx and therefore the --rocm-gfx handed to
install_llama_prebuilt.py and the whisper installer. On two adapters, before:

  HIP_VISIBLE_DEVICES=1  gfx arch inferred from GPU name: gfx1100   <- selected card is gfx1201

_amd_smi_gpu_records / _setup_amd_smi_gpu_records emit one `gfx|marketing name` per
`GPU: N` block, in enumeration order, the same record shape and the same selector the
rocminfo path already uses, so both halves of the report always describe one device.
An adapter that reports neither field still occupies its slot. Both copies are byte
identical and a test asserts it, as for the rocminfo parser.

Two follow-on simplifications, not separate changes: `static --asic` is parsed once
instead of grepped twice, and the standalone unindexed name lookup is gone. The record
only replaces rocminfo's when amd-smi actually enumerated something, so a silent
amd-smi still leaves the APU fallback name alone.

Tests: the amd-smi arm now has the coverage the rocminfo arm had. Three adapters
selected at 0, 1, 2 and out of range; a build with names and no gfx token, asserting
the inference follows the selected adapter; the parser-identity assertion; and the
`static --asic` call count, which drops 2 to 1.

Verification: tests/sh 52/52, the three GPU-probe files 20/20/20 under gawk 5.2.1,
mawk 1.3.4 and busybox awk 1.36.1. tests/studio/install/ plus
tests/python/test_cross_platform_parity.py and test_windows_no_torch_setup.py: 2708
passed, 3 failed, 3 skipped, failing and skipped node IDs identical to the merge base.
12 mutants over the two parsers, the selector and both amd-smi arms, all killed.
A [Linux, WSL, macOS] x [NVIDIA, AMD, CPU-only] sweep of both scripts at base and head
leaves every non-AMD cell byte identical. bash -n on both, dash -n on install.sh,
git diff --check.

No AMD hardware here, so all of it is fixture- and stub-driven.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

Comment-only pass: no executable line changed in install.sh, studio/setup.sh
or the three shell tests (verified by comparing comment-stripped signatures
before and after). tests/sh suite: 52 ran, 0 failed.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🚀

Reviewed commit: 45d9775927

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

…er set -u

studio/setup.sh runs with set -euo pipefail and _setup_gfx was never in the
initializer group, so the new `if [ -z "$_setup_gfx" ]` fallback read an unset
variable on every arm that detects an AMD GPU without producing a record: the
KFD sysfs fallback, and an amd-smi that answers `list` but returns nothing from
`static --asic`. Those hosts got an unbound-variable abort out of
`unsloth studio update` instead of falling through to the source build.

install.sh already initialized its copy; this brings setup.sh in line.

The test harness had been seeding _setup_gfx itself, which is what hid this. It
now extracts the real initializer group, and asserts the KFD-shaped path reaches
the end, that every variable the selection block reads is initialized up front,
and that a list-but-not-static amd-smi is handled. Removing the fix fails 5
assertions. tests/sh: 52 ran, 0 failed.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

… mask

amd-smi enumerates in discovery order over its KFD view. HIP_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES index HIP/ROCr order, which the library derives from the KFD
node id instead, and the two disagree on real hardware (MI350X SPX/NPS1). Indexing
amd-smi records directly with the mask therefore selects another adapter, and
_setup_gfx becomes --rocm-gfx for the llama.cpp and whisper prebuilts, so the
installer can fetch a binary built for a different architecture.

The untranslated indexing predates this branch, but the old selector deduplicated
architectures, which hid it on a uniform cluster. Dropping that dedup so duplicate
architectures keep separate ordinals is what makes a heterogeneous amd-smi host
return a genuinely wrong per-ordinal arch.

Adds _amd_smi_hip_order / _setup_amd_smi_hip_order, reading HIP_ID from
`amd-smi list -e` (ROCm 6.4.0+), the mapping AMD publishes for exactly this. Same
rules as the Python side in studio/backend/utils/hardware/amd.py
get_hip_id_by_gpu_index: all or nothing, so an older CLI that rejects -e, a hip_id
reading N/A, a colliding id or an out-of-range id all keep discovery order rather
than half-applying a map. rocminfo is an HSA client and already reports in ROCr
order, so that path is left alone.

The records reach awk on stdin behind a sentinel rather than through `-v`: POSIX
awk forbids a physical newline in a -v value and gawk --posix makes it fatal, which
would have emptied the amd-smi arm outright on a strict awk. gawk, mawk and busybox
awk all tolerate it, so the tests now run the real helper under gawk --posix too.

tests/sh: 52 ran, 0 failed. The three targeted suites (23 + 24 + 32) pass under
gawk, gawk --posix, mawk and busybox awk. Removing the reorder fails 5 assertions;
restoring the -v form fails 3.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…id map

Keeping discovery order when `amd-smi list -e` is unavailable still let the mask
index an untranslated list, so on ROCm before 6.4, or when the map is partial or
colliding, an ordinal could still name one adapter while selecting another, and
that value is forwarded as --rocm-gfx.

The reorder helper now reports which index space the records came back in on its
first output line, and the caller declines when there is no usable map AND the
adapters do not agree on an architecture. Identical adapters and single-adapter
hosts are unaffected: every ordinal yields the same arch either way, so declining
there would regress multi-GPU ROCm<6.4 hosts that are not actually ambiguous.
UNSLOTH_ROCM_GFX_ARCH still overrides, and setup.sh now says so when it declines.

The new flags are initialized with the rest of the group, so the assertion added
for the earlier set -u fix covers them.

tests/sh: 52 ran, 0 failed. Targeted suites 23 + 26 + 35, green under gawk,
gawk --posix, mawk and busybox awk. Disabling the decline fails 5 assertions;
widening it to every multi-adapter host fails 5 others.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 23, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 23, 2026
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Aug 23, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…ty gate

The gate added for the HIP id map compared records on TARGET_GRAPHICS_VERSION
alone. amd-smi 6.1.1 does not report that field at all, so on such a host every
record has an empty arch, the distinct count collapses to one, and two unlike
adapters bypassed the guard. The arch is inferred from the marketing name in that
case, so a wrong ordinal still produced a wrong --rocm-gfx, which is the exact
path the gate exists to close.

Records are now compared on the arch when they have one and on the name when they
do not. Matching names prove interchangeability; differing names do not prove the
opposite, since an RX 7900 XTX and an XT both infer gfx1100, so this over-declines
rather than under-declines. Comparing inferred architectures exactly would need the
name table, which install.sh keeps as an inline case rather than a function, and
the two scripts have to stay in step.

tests/sh: 52 ran, 0 failed. Targeted suites 23 + 28 + 37, green under gawk,
gawk --posix, mawk and busybox awk. Reverting the gate to arch-only fails the new
assertion in both harnesses.
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: aa299352ee

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

The ambiguity gate reached for wc, which neither install.sh nor studio/setup.sh
used anywhere before this branch, where head, tail and sort were already in use.
Folding the count into the awk that was already running drops the new dependency
and two of the three processes.

No behaviour change: tests/sh 52 ran, 0 failed, and the targeted suites are
unchanged at 23 + 28 + 37 under gawk, gawk --posix, mawk and busybox awk.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 23, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 2edb934c60

ℹ️ 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

Verified on real Strix Halo hardware

Everything in this review so far was fixture- and stub-driven, since there is no AMD GPU on my box. I ran the probe on an AMD DevLab ephemeral runner, which is the same hardware class as the #7307 report: Ryzen AI MAX+ 395 with Radeon 8060S, gfx1151, ROCm 7.2.1, AMDSMI 26.2.2, Ubuntu 24.04.

The headline question, running the real install.sh probe region from each tree against the same live rocminfo:

merge base 7a0ecc2a5   gfx=[gfx1151]  name=[AMD RYZEN AI MAX+ 395 w/ Radeon 8060S]   <- the CPU
PR head   2edb934c6    gfx=[gfx1151]  name=[AMD Radeon Graphics]                      <- the GPU

That is #7307 reproduced and fixed on the machine that reported it. The arch is unchanged at gfx1151 on both sides, so the name is corrected without disturbing what routes the wheel.

The raw tool output also settles four things that were, until now, only read out of source:

  • amd-smi static --asic prints MARKET_NAME: AMD Radeon Graphics, upper-cased. The pre-existing /[Mm]arket.?[Nn]ame/ pattern could never have matched it, so that fallback really was dead code on any current host, which is what f2abb15 fixed.
  • amd-smi list prints only BDF / UUID / KFD_ID / NODE_ID / PARTITION_ID, with no gfx token anywhere, so the arch genuinely has to come from static --asic.
  • amd-smi list -e reports HIP_ID: 0, so the HIP id map that cf12571 and later commits rely on is present and parseable on a current ROCm.
  • rocminfo lists the CPU agent first, the GPU as agent 2 with Name: gfx1151, and the NPU as agent 3 named aie2p with Device Type: DSP. The NPU is not named gfx*, so it cannot be mistaken for a device and shift the ordinals. The GPU agent's ISA sub-lines read Name: amdgcn-amd-amdhsa--gfx1151, which is exactly what the anchored ^gfx match exists to reject.

Suites on that host: test_rocminfo_gpu_name_7307.sh 23 passed, test_install_gpu_summary_probe_sources.sh 28 passed, test_setup_gpu_summary_probe_sources.sh 35 passed with 1 skipped. The skip is correct: that file guards its KFD assertions behind [ -e /dev/kfd ], and this host has a real one. Full tests/sh: 52 ran, 0 failed.

@danielhanchen

Copy link
Copy Markdown
Member

Real hardware, round two: the updater path, the set -u abort, and the visibility masks

Same AMD DevLab Strix Halo runner (gfx1151, ROCm 7.2.1). Three things the fixtures could not settle.

1. studio/setup.sh selection, which is the value forwarded as --rocm-gfx. The first report only exercised install.sh, whose output is a display label. Driving setup.sh's real detection and selection block against the live tools:

base 7a0ecc2a5   _setup_gfx=[gfx1151]  _setup_mkt=[AMD RYZEN AI MAX+ 395 w/ Radeon 8060S]
head 2edb934c6   _setup_gfx=[gfx1151]  _setup_mkt=[AMD Radeon Graphics]

2. The set -u abort, on a genuinely KFD-only host. /dev/kfd is real on this machine, so trimming rocminfo and amd-smi off PATH makes the KFD sysfs arm the one that fires, which is the shape that has no gfx and no name. Comparing 45d9775 (this branch, before _setup_gfx was initialized) against head:

45d977592   studio/setup.sh: line 47: _setup_gfx: unbound variable
2edb934c6   REACHED END  _setup_gfx=[]

So that was a live abort of unsloth studio update on real AMD hardware, not only a theoretical one, and head falls through to the source build as intended.

3. ROCR_VISIBLE_DEVICES really does filter what rocminfo prints. Counting gfx agents in rocminfo under each mask:

ROCR_VISIBLE_DEVICES=[]    -> 1     HIP_VISIBLE_DEVICES=[0] -> 1
ROCR_VISIBLE_DEVICES=[0]   -> 1     HIP_VISIBLE_DEVICES=[1] -> 1
ROCR_VISIBLE_DEVICES=[1]   -> 0     HIP_VISIBLE_DEVICES=[9] -> 1
ROCR_VISIBLE_DEVICES=[9]   -> 0
ROCR_VISIBLE_DEVICES=[-1]  -> 0
ROCR_VISIBLE_DEVICES=[0,1] -> 1

HIP_VISIBLE_DEVICES does not affect rocminfo at all. This confirms a pre-existing issue that is not introduced by this PR and is identical in base and head: when ROCR_VISIBLE_DEVICES is set, both scripts index an already-filtered agent list by the mask's first value. On a multi-GPU host with ROCR_VISIBLE_DEVICES=1,2, rocminfo prints two agents and the code selects index 1, which is the second visible device rather than the first masked one. Worth a separate issue; I have deliberately not touched it here.

4. Every mask, base vs head, through install.sh. Seven HIP_VISIBLE_DEVICES values (empty, 0, 1, 9, -1, 0,1, a UUID token) and three ROCR_VISIBLE_DEVICES values. Base names the CPU in all ten, head names the GPU in all ten, and the arch is gfx1151 throughout. Under ROCR_VISIBLE_DEVICES=1, where rocminfo reports no agent at all, head still resolves the card through amd-smi, which reads KFD directly and ignores the mask.

Caveat worth stating: this pool is single-GPU, so it cannot exercise the multi-adapter ordinal work in cf12571, 46b686c, 36c0828 and aa29935. Those remain fixture-verified. What the hardware does confirm for them is that amd-smi list -e exists and reports a parseable HIP_ID on a current ROCm.

@danielhanchen

Copy link
Copy Markdown
Member

End to end: the real installer, on the reporting hardware

The earlier hardware reports ran the probe region extracted out of the scripts. That shares the parser but not the surrounding script, so it could in principle have been right while a real run still printed the wrong thing. This is bash install.sh, no flags, exactly as a user runs it, on an AMD DevLab Strix Halo runner (Ryzen AI MAX+ 395, gfx1151, ROCm 7.2.1):

##### merge base 7a0ecc2a5
  gpu            AMD ROCm (gfx1151)
                 ROCm: /opt/rocm
                 hipconfig: 7.2.53211-e1a6bc5663
                 GPU: AMD RYZEN AI MAX+ 395 w/ Radeon 8060S     <- the CPU

##### PR head 2edb934c6
  gpu            AMD ROCm (gfx1151)
                 ROCm: /opt/rocm
                 hipconfig: 7.2.53211-e1a6bc5663
                 GPU: AMD Radeon Graphics                        <- the GPU

That is the #7307 output format, with the reported value on the left and the corrected one on the right.

Two details worth recording. The GPU summary is emitted at install.sh:4842, well before the first uv pip install at :5067, so the run is stopped once it has reported and nothing is installed; both sides show zero install lines. And the untouched neighbours on that block are byte-identical across base and head (ROCm: /opt/rocm, hipconfig: 7.2.53211-e1a6bc5663), so the change moves the GPU name and nothing else.

The job asserts the difference rather than relying on reading it: if base and head produced the same string it would have failed.

@danielhanchen

Copy link
Copy Markdown
Member

The red parity (windows-latest) is pre-existing on main, not from this PR

Recording the attribution so the failing check is not read as this branch's.

The parity assertions themselves pass: 516 passed, 2 skipped. The job fails in a later step under the same name, tests/studio/test_install_rollback_lifecycle.ps1:

Test-StudioPathPresent: The term 'Test-StudioPathPresent' is not recognized as a name of a
cmdlet, function, script file, or executable program.

The same failure, with the same 516 passed, 2 skipped immediately before it, is on main:

run branch head parity pytest failure
32620040644 amd-rocminfo-gpu-name 2edb934 516 passed, 2 skipped Test-StudioPathPresent
32619888472 main 90644db 516 passed, 2 skipped Test-StudioPathPresent
32619788861 main f1f95f7 516 passed, 2 skipped Test-StudioPathPresent

It is also failing on amd-rocm-fastpath-probe and worktree-venv-clear-recreate. The last green run of this workflow was fix/studio-duplicate-metadata-integrity at 05:05, so something landed on main just after that.

This branch changes five files, install.sh, studio/setup.sh and three tests/sh/*.sh, and no .ps1 at all. Test-StudioPathPresent is defined in install.ps1:4018 and the test evaluates an extracted region where it is not in scope. Nothing here can reach it.

Staging CI, run on owned repos to spare the org queue, is green on this head: 43 workflows across two branches, all success, including Windows UI / API / GGUF, Mac Studio Install Matrix, cross-platform parity and Backend CI.

@danielhanchen

Copy link
Copy Markdown
Member

Both red checks bisect to 90644db on main, not to this branch

Updating my earlier note: there are two failures now, and both come from the same main-side commit, 90644db9e "Studio: repair duplicate package metadata during updates (#8515)". It touched install.sh, install.ps1, studio/setup.sh and studio/setup.ps1.

Repo tests (CPU) fails in tests/sh/test_setup_desktop_backend_version_fastpath.sh. That test extracts the version fastpath block out of studio/setup.sh by pattern, and the extracted snippet now starts at an elif, so it does not parse:

fastpath_blk.sh: line 1: syntax error near unexpected token `elif'
Results: 3 passed, 3 failed

Bisected on plain origin/main, with none of this branch's code present:

dc26127a4  the commit that added the test    6 passed, 0 failed
90644db9e  #8515                             3 passed, 3 failed   <- first bad
47670fa93  #9499, current main tip           3 passed, 3 failed

parity (windows-latest) is the same shape on the PowerShell side. The parity assertions pass, 516 passed, 2 skipped; the job then fails in tests/studio/test_install_rollback_lifecycle.ps1 because the region it evaluates no longer has Test-StudioPathPresent in scope, and #8515 edited install.ps1 at @@ -5886,8 +5886,27 @@. It reproduces on main at 90644db9e and f1f95f71f, and on amd-rocm-fastpath-probe and worktree-venv-clear-recreate. The last green run of that workflow was fix/studio-duplicate-metadata-integrity, which suggests the same commit's fallout is already being worked on.

This branch changes five files: install.sh, studio/setup.sh and three tests/sh/*.sh. Neither failing test reads anything it touches.

One thing worth flagging for anyone else rebasing onto current main: a local tests/sh run can be fully green while CI is red, because CI builds the PR merged into current main. My tree reported 52 ran, 0 failed; re-merging main and rerunning reproduces both failures immediately.

Staging CI on owned repos, run on this head, was 43 workflows across two branches, all success.

@danielhanchen
danielhanchen merged commit f3b88ec into unslothai:main Aug 23, 2026
74 of 78 checks passed
LeoBorcherding added a commit to LeoBorcherding/unsloth that referenced this pull request Aug 25, 2026
_gfx_targets_per_device parsed a second time what _rocminfo_gpu_records (unslothai#9498)
and _amd_smi_gpu_records already parse for the GPU summary, so delete it and read
the gfx half of those records instead. Both move up to the probe-parser block so
the arch routing can call them; their bodies are unchanged, so the studio/setup.sh
mirrors and their tests stay as they are.

One parser per tool now, shared by the routing block and the display block: a mask
ordinal indexes cards in both, and a duplicate arch cannot collapse two devices
into one entry in either.

The amd-smi shim in test_gfx_probe_survives_no_match_under_set_e answered every
subcommand with "GPU: gfx1151", which is not a shape amd-smi emits; it now answers
`list` with BDF only and `static --asic` with TARGET_GRAPHICS_VERSION, so the test
proves the fallthrough it describes. Same for the flat-output amd-smi stub in
test_install_sh_still_indexes_amd_smi_output_under_a_rocr_mask.
danielhanchen added a commit that referenced this pull request Sep 15, 2026
…NA4 to rocm6.4 (#9672)

* Fix ROCm detection on split Debian stacks

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Harden ROCm detection on split Debian stacks

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* close the gaps in the gfx1102/RDNA4 rocm6.4 floor

Three fixes on top of the split-Debian ROCm detection work.

studio/install_python_stack.py gated the kernel-less-wheel repair on
_gfx_needs_rocm64_generic_index(ver), so a gfx1200 host reading ROCm 6.4 or
newer skipped it entirely and studio update left an installed +rocm6.1 build
in place. Split the runtime-target test from the host-version test: the index
reroute stays version-gated, the repair now runs on the target alone.

install.sh resolved _runtime_gfx from HIP_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES only. AMD documents CUDA_VISIBLE_DEVICES as a HIP
visibility variable and recommends it for cross-vendor portability, so a mixed
gfx1100 + gfx1200 host masked with CUDA_VISIBLE_DEVICES=1 selected gfx1200 at
runtime while the installer routed for gfx1100. Resolve the three variables
first-set-wins, matching _pick_visible_index.

install.sh also took UNSLOTH_ROCM_GFX_ARCH verbatim, so a value copied from a
HIP gcnArchName (gfx1200:xnack-) matched none of the bare architecture
patterns. Strip the suffix and surrounding whitespace the way _gfx906_env and
_runtime_target_needs_rocm64_generic_index already do.

Regressions cover all three, and each fails without its fix.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* keep the real host ROCm release for repo.radeon.com

get_torch_index_url clips its leaf to a family PyTorch publishes: ROCm 6.5
becomes rocm6.4, 7.3 and newer become rocm7.2, and no leaf ever carries a
patch level. repo.radeon.com does publish rocm-rel-6.5 and rocm-rel-7.2.1,
so passing that leaf into get_radeon_wheel_url pointed a Radeon host at an
older directory, or at none when only the patch-level directory exists. The
caller's X.Y.Z to X.Y retry cannot recover it because a leaf is already X.Y.

Treat the resolved leaf as a floor instead. The host probe runs as before and
wins whenever it reads no older than the leaf, so 6.5.0 and 7.2.1 reach their
own directories. The leaf takes over when the probe is missing or older than
the resolver's answer, which is the split Debian host whose hipconfig reports
5.7, the case the argument was added for.

tests/sh/test_rocm_version_source_disagreement.sh covers both directions and
extracts the new comparison helper alongside the functions it tests.

* index visible-device masks by device, not by arch

HIP_VISIBLE_DEVICES, ROCR_VISIBLE_DEVICES and CUDA_VISIBLE_DEVICES carry device
ordinals, but install.sh built its gfx list with a flat grep and then
de-duplicated it before indexing. On a host enumerating gfx1100, gfx1100,
gfx1200 an ordinal of 2 ran past the end of the two-entry list and silently
fell back to the first gfx1100, so the selected RDNA 4 card never reached the
rocm6.4 floor and received wheels with no kernels for it.

The de-duplication was not gratuitous: rocminfo prints a device's arch on both
its Name and ISA lines, so counting raw tokens is wrong too. _gfx_targets_per_device
splits on agent headers and takes one token per device, exactly as
_detect_amd_gfx_codes(dedup=False) does in studio/install_python_stack.py, and
falls back to first-seen order for flat output such as amd-smi's. With the list
now one entry per device, the indexing step no longer de-duplicates.

Also refreshes the gfx906 comment that justified its policy by the old
de-duplication, and extracts the new helper in the two Strix probe tests that
run the detection block standalone.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* do not re-index an rocr mask rocminfo already applied

ROCR_VISIBLE_DEVICES is an ROCr-level mask, so rocminfo returns only the
selected agents, already in the mask's order. Indexing that filtered list again
by the mask's first ordinal double-applies it: on physical gfx1100,gfx1200 with
ROCR_VISIBLE_DEVICES=1,0 rocminfo reports gfx1200,gfx1100 and ordinal 1 picked
gfx1100, leaving the runtime-selected gfx1200 on kernel-less wheels.

Track which probe answered and skip the ordinal when rocminfo answered and
ROCR_VISIBLE_DEVICES is the first-set mask, matching the _LAST_AMD_GFX_PROBE
check in _runtime_target_needs_rocm64_generic_index. HIP_VISIBLE_DEVICES and
CUDA_VISIBLE_DEVICES are applied by the HIP runtime rather than by ROCr, and
amd-smi ignores all three, so both keep ordinal indexing.

The existing ROCR row in the visible-mask test modelled an impossible host,
rocminfo listing both GPUs while ROCR_VISIBLE_DEVICES selected one, and is
replaced by cases that report what a masked rocminfo actually returns.

* split amd-smi device blocks and repair floored wheels on migration

Two gaps in the gfx1102/RDNA 4 rocm6.4 floor.

The per-device gfx parser recognised rocminfo's "Agent N" and hipinfo's
"Device #N" but not amd-smi's "GPU: N" and "GPU[N]", which install.sh already
parses at line 3104 for its GPU-presence check. Without rocminfo, a host with
gfx1100, gfx1100, gfx1200 therefore collapsed to two entries and an ordinal of 2
fell out of range, so the selected RDNA 4 card missed the floor.
_detect_amd_gfx_codes had the same omission and is fixed alongside. A header
sharing its line with the token, as "GPU[0] : gfx1100" does, now contributes
that token instead of dropping it.

The migrated-environment repair only reinstalled torch when torch.version.hip
was empty, so a legacy venv already carrying a kernel-less +rocm6.1 wheel
finished migration with it after printing the reroute warning. It now also
reinstalls when the architecture floor selected rocm6.4 and the installed wheel
reports an older family, matching _installed_rocm_wheel_is_below on the Python
side. _venv_torch_rocm_below reads the family from the venv's torch, and an
unidentifiable family counts as older, as it does in Python.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* key the migrated repair on the gpu, not on whether the leaf moved

The flag the migrated repair reads was set inside the reroute, so it only
covered hosts detected at ROCm 6.0 to 6.3. A gfx1102/gfx1200/gfx1201 host
already reading 6.4 or newer selects a good index without rerouting, so the
flag stayed false and a legacy venv carrying +rocm6.1 kept it, which is the
same shape as the earlier install_python_stack.py fix that separated
_gfx_rocm64_target from _gfx_rocm64_floor.

_gfx_rocm64_target now records that the runtime GPU needs the floor at all,
independent of the leaf, and the reroute stays gated on the detected version.
An explicit index pin still skips the whole block, so it never triggers the
extra reinstall.

The routing harness in the tests returns the flag alongside the leaf, and
test_install_sh_marks_the_floor_target_independently_of_the_leaf pins it for
gfx1200 on rocm6.1, rocm6.4 and rocm7.2, with gfx1100 as the negative.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Keep floored gfx1102/gfx1200/gfx1201 off the Radeon repo; memoise ROCm detection

The rocm6.4 floor rewrote TORCH_INDEX_URL but left _amd_gpu_radeon set, so on a
Radeon-branded card the install took the Radeon branch and the floored index was
only its fallback. repo.radeon.com's newest pairing trio under rocm-rel-6.4/ is
torch 2.6.0+rocm6.4.0, whose rocBLAS Tensile libraries carry gfx1030/1100/1101/
1200/1201/908/942 and no gfx1102 at all, and rocm-rel-7.2/ is narrower still
(gfx120X-all, gfx90a, gfx942, gfx950). The arch the floor exists for therefore
still received a wheel with no kernels for it. Clear the flag whenever one of the
three arches is the runtime target, mirroring the gfx906 branch below, which
clears it even when its own reroute is a no-op.

Memoise _detect_rocm_version on the _TORCH_RUNTIME_PROBE pattern already in the
file. _ensure_rocm_torch() runs twice on Linux and the detector no longer
short-circuits, so all five sources were probed twice and the source-disagreement
warning printed twice where install.sh prints it once. The host ROCm stack cannot
change mid-run, so unlike the torch probe nothing invalidates it after a pip
operation; the reset exists for the autouse test fixtures.

Correct install_llama_prebuilt.py's claim that its detector mirrors install.sh
and _detect_rocm_version(). It no longer does: no status gate, no HSA runtime,
still first-answer-wins. The detector itself is left to a follow-up since it
moves llama.cpp asset selection rather than the torch family.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Read rocm-core over the distro HSA package, and stop tests reading the host

rocm-core comes from AMD's repo and marks the ROCm release; libhsa-runtime64-1
comes from the distro archive and tracks the archive. Ubuntu 24.04 with AMD's
ROCm 7.2 repo really does carry rocm-core 7.2.1 beside Ubuntu's own
libhsa-runtime64-1 5.7.1-2build1, so voting them as peers made every healthy
host print a disagreement warning naming a 5.7 reading that means nothing.
AMD's own HSA package is hsa-rocr, under a different name and versioned 1.x.
Debian ships no rocm-core, so the fallback still fires exactly where it was
added and the reported host still resolves rocm6.1.

Also stop three TestDetectRocmVersion cases reading the developer's machine:
the detector no longer returns at the first answer, so an unpatched test picks
up the host's real hipconfig or dpkg packages and CI never sees it.

And terminate records in the dpkg stub. $(...) strips trailing newlines, so a
real "\n" showformat concatenated every package onto one line and the
multi-package assertion only ever tested the first record.

* Split the gfx floor and installed-wheel repair out to a follow-up

danielhanchen asked for this PR to stay the ROCm version-source change, so the
per-device gfx indexing, the gfx1102/gfx1200/gfx1201 rocm6.4 floor and the
migrated installed-wheel repair all move out. They are one dependency chain
rather than three separable pieces: the floor needs per-device indexing to read
the right runtime arch, and the repair keys off the floor target.

Kept here: get_radeon_wheel_url taking the already-resolved leaf. Without it a
split Debian host resolves rocm6.1 and then the Radeon branch re-probes from
scratch, rediscovers hipconfig 5.7 and asks for rocm-rel-5.7/, so it closes a
hole this change opens rather than adding scope.

* Index AMD visible-device masks by device, and floor gfx1102/RDNA4 to rocm6.4

Split out of #8886 so that PR stays the ROCm version-source change. Stacked on
it: the floor consumes the leaf #8886 resolves.

One dependency chain. _gfx_targets_per_device emits one gfx token per device, so
a visible-device mask selects a card rather than an arch. The floor then reads
the right runtime arch and routes gfx1102/gfx1200/gfx1201 to the generic rocm6.4
wheels, which are the oldest family shipping their kernels. The migrated repair
keys off that floor target so an upgraded venv stops keeping a kernel-less wheel.

* Collapse the per-device gfx probe onto the existing GPU record helpers

_gfx_targets_per_device parsed a second time what _rocminfo_gpu_records (#9498)
and _amd_smi_gpu_records already parse for the GPU summary, so delete it and read
the gfx half of those records instead. Both move up to the probe-parser block so
the arch routing can call them; their bodies are unchanged, so the studio/setup.sh
mirrors and their tests stay as they are.

One parser per tool now, shared by the routing block and the display block: a mask
ordinal indexes cards in both, and a duplicate arch cannot collapse two devices
into one entry in either.

The amd-smi shim in test_gfx_probe_survives_no_match_under_set_e answered every
subcommand with "GPU: gfx1151", which is not a shape amd-smi emits; it now answers
`list` with BDF only and `static --asic` with TARGET_GRAPHICS_VERSION, so the test
proves the fallthrough it describes. Same for the flat-output amd-smi stub in
test_install_sh_still_indexes_amd_smi_output_under_a_rocr_mask.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* amd-smi: take the bracketed GPU[N] header too, arch and all

The record parser only opened a device on `GPU: N`, so amd-smi's other header
shape, `GPU[0]  : gfx1100`, produced no records at all. That shape is not
hypothetical: it carries the arch on the header line itself with no
TARGET_GRAPHICS_VERSION following, and the rest of the tree already reads it.
_has_amd_rocm_gpu matches `gpu[ ]*[:[][ ]*[0-9]` at install.sh:3208, the Python
detector matches the same at install_python_stack.py:1660, and the per-device
split at :1814 carries a comment saying install.sh parses the same shapes. It
did not.

Consequence on an amd-smi-only host (no rocminfo): _gfx_all came back empty, so
_runtime_gfx was empty and every arch policy this PR adds was skipped without a
word. A gfx1200 box resolving ROCm 6.1 keeps the kernel-less rocm6.1 wheels
instead of being floored to rocm6.4, which is the case the PR exists for.

Header shapes now both open a record, and the header's own gfx token is taken
when it has one. Applied to studio/setup.sh identically; the parity assertion in
test_rocminfo_gpu_name_7307.sh caught the two copies drifting on a comment while
this was being written.

Three cases added to that suite, which now sources the amd-smi parser rather than
only diffing the two copies of it: bracketed multi-device keeps one record per
device in order, the keyed form still pairs arch with name, and a header with no
arch stays empty instead of borrowing the next device's.

Verified: 26 passed, 0 failed on Git Bash. test_install_gpu_summary_probe_sources
and test_setup_gpu_summary_probe_sources report identical results with and
without this commit on this box (0/28 and 3/37); they need a POSIX symlink the
environment cannot make, and pass on the Linux runner.

* Translate amd-smi order before indexing it, and keep unreadable adapters

Two ways the arch routing could read the wrong adapter, both from treating a
position in a list as if it were a device id.

Order. amd-smi enumerates in discovery order, which is not the order HIP numbers
devices, and the routing applied a HIP/ROCR/CUDA ordinal to it directly. The
translation already existed: _amd_smi_hip_order builds a HIP_ID map from
`amd-smi list -e`, and the GPU summary has used it all along. Routing now runs
the same translation, and when no map comes back and the adapters are not alike
it declines with a warning rather than guess, which is the call the summary
already makes on the same evidence.

    discovery [gfx90a MI210, gfx1200 RX 9070], HIP order reversed
    HIP_VISIBLE_DEVICES=0   before: gfx90a    after: gfx1200
    HIP_VISIBLE_DEVICES=1   before: gfx1200   after: gfx90a
    same, no HIP_ID map     before: gfx90a    after: declines

Blank slots. _amd_smi_gpu_records emits an empty gfx field on purpose so an
adapter whose arch it cannot read keeps its ordinal, and the index step then
filtered those lines out with NF, collapsing the list. Command substitution ate
a trailing one too.

    [blank, gfx1151], HIP_VISIBLE_DEVICES=0
    before: gfx1151, so the Strix reroute fired on device 0's behalf
    after:  unknown, which matches no policy

_gfx_arch_slots does that preservation, and prints nothing when NO adapter has an
arch so the probe chain still falls through to the next source.

Two places deliberately keep the old behaviour. rocminfo is an ROCr client and
already enumerates in the order HIP numbers from, which is the premise the mask
handling was written on, so it is marked hip and skips the check. Identical
adapters skip it too: every ordinal gives the same answer, so there is nothing
to get wrong.

Seven cases added to test_rocminfo_gpu_name_7307.sh, which now sources
_gfx_arch_slots and _amd_smi_hip_order. 33 passed, 0 failed on Git Bash.
sh -n and bash -n clean. test_install_gpu_summary_probe_sources and
test_setup_gpu_summary_probe_sources report 0/28 and 3/37 with and without this
commit alike; they need a POSIX symlink this box cannot make.

The decline path itself is three lines of shell inside the routing block and is
not covered end to end here: that needs the block harness, which is one of the
two suites the environment cannot run. Its inputs are covered.

* Define _amd_smi_hip_order before the routing calls it, and inject it into the tests

Both are the same mistake in two places: a shell helper that is not in scope
where it is used, hidden by an `|| true`.

install.sh is sequential and the GPU probing runs at top level, inside the case
opened at 4806. The translation call added last push sits at 4847; the helper was
defined at 5108, 261 lines further down. So on every amd-smi host the shell said
command not found, `|| true` swallowed it, _gfx_smi_out came back empty, and the
next two lines erased records that were fine. Reproduced in three lines:

    out=$(printf 'x\n' | _fn 'recs' || true); echo "[$(printf '%s\n' "$out" | head -1)]"
    _fn() { echo hip; }
    -> _fn: command not found
    -> []

Moved next to _gfx_arch_slots at 3590, ahead of both call sites. Body unchanged,
so the install.sh/setup.sh parity assertion still holds.

Same shape in tests/studio/install/test_rocm_support.py. Its probe blocks are
extracted from install.sh and run with only the helpers the harness injects, and
that list was still the two record parsers. The routing block calls
_gfx_arch_slots now, so bash printed `_gfx_arch_slots: command not found` four
times and then a syntax error. Added both new helpers to _gpu_record_helpers,
with a note on why a missing one is worse than a loud failure: the block's
`|| true` turns it into an empty arch list and the assertion passes for the
wrong reason.

Four cases added to test_rocminfo_gpu_name_7307.sh asserting each helper is
defined above its first call, by order rather than by line number so a later edit
does not have to update them. Checked against b8fbc16 to confirm the guard
actually fires: FAIL _amd_smi_hip_order def=5108 firstuse=4847 there, PASS here.

37 passed, 0 failed. sh -n, bash -n and python -m ast all clean.

Not re-run: tests/studio/install/test_rocm_support.py. It downloads models and
filled this disk mid-run, taking a baseline comparison with it. The
command-not-found lines it printed are gone, which is what the harness change was
for, but I am not quoting a pass count I did not watch finish.

* Answer `amd-smi list -e` in the routing stubs so the ordinal tests test an ordinal

The amd-smi stubs ignored argv and returned the ASIC listing for every call,
`amd-smi list -e` included. So the routing block saw no HIP_ID map, and with
unlike adapters known only in discovery order it correctly declined to apply an
ordinal and left the caller's leaf alone. The leaf it left alone was rocm6.1,
the default these tests pass in.

That is a real miss, not a cosmetic one, and it was hiding in the pass column:

  splits_amd_smi_gpu_headers[HIP_VISIBLE_DEVICES=2]  expected rocm6.4 got rocm6.1
  splits_amd_smi_gpu_headers[HIP_VISIBLE_DEVICES=1]  expected rocm6.1 got rocm6.1
  still_indexes_amd_smi_output_under_a_rocr_mask     expected rocm6.1 got rocm6.1

Only the first failed. The other two agree with the decline by coincidence, so
they were asserting nothing about the header splitting and the ROCR indexing
they are named for.

_amd_smi_stub answers `list -e` with a HIP_ID map, identity by default, which is
what a caller indexing the listing directly already assumes. Both call sites use
it. Added a third test that withholds the map on the same adapters and asserts
the decline, so the behaviour that was silently absorbing these three now has
one test that means to land there.

4 passed, 0 failed, and the old stubs reproduce the table above against the same
install.sh.

Verified by running the harness's own assembled script from a file rather than
through pytest. Git Bash on Windows truncates a `bash -c` payload at 8188 bytes
and these scripts are ~23.5k, so every test in this class dies there with a
syntax error from the cut, whatever the branch. That is this machine, not the
diff; the Linux runner executes them normally.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Compose the ROCr and HIP visibility layers instead of shadowing one with the other

rocminfo is an ROCr client, so its output is already filtered by
ROCR_VISIBLE_DEVICES. The routing then picked the first variable that was SET
across all three layers, so an ROCr mask that had already done its work shadowed
CUDA_VISIBLE_DEVICES, the HIP-layer alias, which should select among the
survivors. With ROCR_VISIBLE_DEVICES=2,1 and CUDA_VISIBLE_DEVICES=1 the target
is the second survivor; the old chain named the first and floored the index for
the wrong card.

Consult only the HIP layer once rocminfo has applied the ROCr one, mirroring
_HIP_LAYER_MASKS in studio/install_python_stack.py, which already did this.

* Make the generic-wheel floor tests independent of the host's own torch

TestGfx1102Rocm64Floor._ensure_for_gfx patched the detectors but left
_installed_rocm_wheel_family and _torch_requires_rocm_sdk reading the RUNNING
interpreter. The scenarios it sets up install generic pytorch.org wheels, which
do not pull rocm[libraries], so the per-arch family is None by construction.

On a gfx1151 Strix Halo runner whose venv holds 2.11.0+rocm7.13.0 they answered
gfx1151 instead. The per-arch repick arm then saw _have != _want, reinstalled,
and test_installed_64_wheel_left_alone_on_newer_host and
test_unaffected_arch_not_repaired_on_newer_host failed on AMD hardware while
passing on every CUDA or CPU box, this one included.

Pin both to the scenario. A test about the generic-wheel floor must not depend
on what the machine running it happens to have installed.

* Tighten the comments this change adds

Comments only. Every load-bearing fact stays: the issue numbers, the POSIX awk
constraint on -v newlines, the two amd-smi header shapes, why an unreadable arch
keeps its slot, why the ROCr and HIP layers compose rather than shadow, and the
keep-in-sync pointers to studio/setup.sh and install_python_stack.py.

Applied to studio/setup.sh as well: test_rocminfo_gpu_name_7307.sh asserts the
two copies of the amd-smi parser and HIP reorder are byte identical, so editing
one alone breaks parity. The same test also sed-matches the first-set-wins
comment to lift a block, so that anchor line is preserved verbatim.

* Scrub CUDA_VISIBLE_DEVICES in the generic-wheel floor fixture

_visible_masks_select_no_gpu reads CUDA_VISIBLE_DEVICES as the HIP alias when
HIP_VISIBLE_DEVICES is unset, so a host running the suite with
CUDA_VISIBLE_DEVICES="" (a CPU CI shard, or a developer hiding a CUDA card)
made _runtime_gfx_target answer no GPU and the three debian-split floor tests
took the generic index instead of the per-arch one. The fixture already
scrubbed the HIP and ROCr masks; scrub the CUDA one too, as the other
fixtures in this file do. 625 pass with the variable empty, set and unset.

* Tighten the comments this change adds for PR #9672

* Fall through to amd-smi static --asic when list carries no arch for PR #9672

* Layer ROCR_VISIBLE_DEVICES under the HIP index on the amd-smi path for PR #9672

* Decline arch routing on a ROCr UUID mask over unlike amd-smi adapters for PR #9672

---------

Co-authored-by: Natani L. Mayday <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Maheswar Kumar <[email protected]>
Co-authored-by: danielhanchen <[email protected]>
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…NA4 to rocm6.4 (unslothai#9672)

* Fix ROCm detection on split Debian stacks

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Harden ROCm detection on split Debian stacks

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* close the gaps in the gfx1102/RDNA4 rocm6.4 floor

Three fixes on top of the split-Debian ROCm detection work.

studio/install_python_stack.py gated the kernel-less-wheel repair on
_gfx_needs_rocm64_generic_index(ver), so a gfx1200 host reading ROCm 6.4 or
newer skipped it entirely and studio update left an installed +rocm6.1 build
in place. Split the runtime-target test from the host-version test: the index
reroute stays version-gated, the repair now runs on the target alone.

install.sh resolved _runtime_gfx from HIP_VISIBLE_DEVICES and
ROCR_VISIBLE_DEVICES only. AMD documents CUDA_VISIBLE_DEVICES as a HIP
visibility variable and recommends it for cross-vendor portability, so a mixed
gfx1100 + gfx1200 host masked with CUDA_VISIBLE_DEVICES=1 selected gfx1200 at
runtime while the installer routed for gfx1100. Resolve the three variables
first-set-wins, matching _pick_visible_index.

install.sh also took UNSLOTH_ROCM_GFX_ARCH verbatim, so a value copied from a
HIP gcnArchName (gfx1200:xnack-) matched none of the bare architecture
patterns. Strip the suffix and surrounding whitespace the way _gfx906_env and
_runtime_target_needs_rocm64_generic_index already do.

Regressions cover all three, and each fails without its fix.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* keep the real host ROCm release for repo.radeon.com

get_torch_index_url clips its leaf to a family PyTorch publishes: ROCm 6.5
becomes rocm6.4, 7.3 and newer become rocm7.2, and no leaf ever carries a
patch level. repo.radeon.com does publish rocm-rel-6.5 and rocm-rel-7.2.1,
so passing that leaf into get_radeon_wheel_url pointed a Radeon host at an
older directory, or at none when only the patch-level directory exists. The
caller's X.Y.Z to X.Y retry cannot recover it because a leaf is already X.Y.

Treat the resolved leaf as a floor instead. The host probe runs as before and
wins whenever it reads no older than the leaf, so 6.5.0 and 7.2.1 reach their
own directories. The leaf takes over when the probe is missing or older than
the resolver's answer, which is the split Debian host whose hipconfig reports
5.7, the case the argument was added for.

tests/sh/test_rocm_version_source_disagreement.sh covers both directions and
extracts the new comparison helper alongside the functions it tests.

* index visible-device masks by device, not by arch

HIP_VISIBLE_DEVICES, ROCR_VISIBLE_DEVICES and CUDA_VISIBLE_DEVICES carry device
ordinals, but install.sh built its gfx list with a flat grep and then
de-duplicated it before indexing. On a host enumerating gfx1100, gfx1100,
gfx1200 an ordinal of 2 ran past the end of the two-entry list and silently
fell back to the first gfx1100, so the selected RDNA 4 card never reached the
rocm6.4 floor and received wheels with no kernels for it.

The de-duplication was not gratuitous: rocminfo prints a device's arch on both
its Name and ISA lines, so counting raw tokens is wrong too. _gfx_targets_per_device
splits on agent headers and takes one token per device, exactly as
_detect_amd_gfx_codes(dedup=False) does in studio/install_python_stack.py, and
falls back to first-seen order for flat output such as amd-smi's. With the list
now one entry per device, the indexing step no longer de-duplicates.

Also refreshes the gfx906 comment that justified its policy by the old
de-duplication, and extracts the new helper in the two Strix probe tests that
run the detection block standalone.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* do not re-index an rocr mask rocminfo already applied

ROCR_VISIBLE_DEVICES is an ROCr-level mask, so rocminfo returns only the
selected agents, already in the mask's order. Indexing that filtered list again
by the mask's first ordinal double-applies it: on physical gfx1100,gfx1200 with
ROCR_VISIBLE_DEVICES=1,0 rocminfo reports gfx1200,gfx1100 and ordinal 1 picked
gfx1100, leaving the runtime-selected gfx1200 on kernel-less wheels.

Track which probe answered and skip the ordinal when rocminfo answered and
ROCR_VISIBLE_DEVICES is the first-set mask, matching the _LAST_AMD_GFX_PROBE
check in _runtime_target_needs_rocm64_generic_index. HIP_VISIBLE_DEVICES and
CUDA_VISIBLE_DEVICES are applied by the HIP runtime rather than by ROCr, and
amd-smi ignores all three, so both keep ordinal indexing.

The existing ROCR row in the visible-mask test modelled an impossible host,
rocminfo listing both GPUs while ROCR_VISIBLE_DEVICES selected one, and is
replaced by cases that report what a masked rocminfo actually returns.

* split amd-smi device blocks and repair floored wheels on migration

Two gaps in the gfx1102/RDNA 4 rocm6.4 floor.

The per-device gfx parser recognised rocminfo's "Agent N" and hipinfo's
"Device #N" but not amd-smi's "GPU: N" and "GPU[N]", which install.sh already
parses at line 3104 for its GPU-presence check. Without rocminfo, a host with
gfx1100, gfx1100, gfx1200 therefore collapsed to two entries and an ordinal of 2
fell out of range, so the selected RDNA 4 card missed the floor.
_detect_amd_gfx_codes had the same omission and is fixed alongside. A header
sharing its line with the token, as "GPU[0] : gfx1100" does, now contributes
that token instead of dropping it.

The migrated-environment repair only reinstalled torch when torch.version.hip
was empty, so a legacy venv already carrying a kernel-less +rocm6.1 wheel
finished migration with it after printing the reroute warning. It now also
reinstalls when the architecture floor selected rocm6.4 and the installed wheel
reports an older family, matching _installed_rocm_wheel_is_below on the Python
side. _venv_torch_rocm_below reads the family from the venv's torch, and an
unidentifiable family counts as older, as it does in Python.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* key the migrated repair on the gpu, not on whether the leaf moved

The flag the migrated repair reads was set inside the reroute, so it only
covered hosts detected at ROCm 6.0 to 6.3. A gfx1102/gfx1200/gfx1201 host
already reading 6.4 or newer selects a good index without rerouting, so the
flag stayed false and a legacy venv carrying +rocm6.1 kept it, which is the
same shape as the earlier install_python_stack.py fix that separated
_gfx_rocm64_target from _gfx_rocm64_floor.

_gfx_rocm64_target now records that the runtime GPU needs the floor at all,
independent of the leaf, and the reroute stays gated on the detected version.
An explicit index pin still skips the whole block, so it never triggers the
extra reinstall.

The routing harness in the tests returns the flag alongside the leaf, and
test_install_sh_marks_the_floor_target_independently_of_the_leaf pins it for
gfx1200 on rocm6.1, rocm6.4 and rocm7.2, with gfx1100 as the negative.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Keep floored gfx1102/gfx1200/gfx1201 off the Radeon repo; memoise ROCm detection

The rocm6.4 floor rewrote TORCH_INDEX_URL but left _amd_gpu_radeon set, so on a
Radeon-branded card the install took the Radeon branch and the floored index was
only its fallback. repo.radeon.com's newest pairing trio under rocm-rel-6.4/ is
torch 2.6.0+rocm6.4.0, whose rocBLAS Tensile libraries carry gfx1030/1100/1101/
1200/1201/908/942 and no gfx1102 at all, and rocm-rel-7.2/ is narrower still
(gfx120X-all, gfx90a, gfx942, gfx950). The arch the floor exists for therefore
still received a wheel with no kernels for it. Clear the flag whenever one of the
three arches is the runtime target, mirroring the gfx906 branch below, which
clears it even when its own reroute is a no-op.

Memoise _detect_rocm_version on the _TORCH_RUNTIME_PROBE pattern already in the
file. _ensure_rocm_torch() runs twice on Linux and the detector no longer
short-circuits, so all five sources were probed twice and the source-disagreement
warning printed twice where install.sh prints it once. The host ROCm stack cannot
change mid-run, so unlike the torch probe nothing invalidates it after a pip
operation; the reset exists for the autouse test fixtures.

Correct install_llama_prebuilt.py's claim that its detector mirrors install.sh
and _detect_rocm_version(). It no longer does: no status gate, no HSA runtime,
still first-answer-wins. The detector itself is left to a follow-up since it
moves llama.cpp asset selection rather than the torch family.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Read rocm-core over the distro HSA package, and stop tests reading the host

rocm-core comes from AMD's repo and marks the ROCm release; libhsa-runtime64-1
comes from the distro archive and tracks the archive. Ubuntu 24.04 with AMD's
ROCm 7.2 repo really does carry rocm-core 7.2.1 beside Ubuntu's own
libhsa-runtime64-1 5.7.1-2build1, so voting them as peers made every healthy
host print a disagreement warning naming a 5.7 reading that means nothing.
AMD's own HSA package is hsa-rocr, under a different name and versioned 1.x.
Debian ships no rocm-core, so the fallback still fires exactly where it was
added and the reported host still resolves rocm6.1.

Also stop three TestDetectRocmVersion cases reading the developer's machine:
the detector no longer returns at the first answer, so an unpatched test picks
up the host's real hipconfig or dpkg packages and CI never sees it.

And terminate records in the dpkg stub. $(...) strips trailing newlines, so a
real "\n" showformat concatenated every package onto one line and the
multi-package assertion only ever tested the first record.

* Split the gfx floor and installed-wheel repair out to a follow-up

danielhanchen asked for this PR to stay the ROCm version-source change, so the
per-device gfx indexing, the gfx1102/gfx1200/gfx1201 rocm6.4 floor and the
migrated installed-wheel repair all move out. They are one dependency chain
rather than three separable pieces: the floor needs per-device indexing to read
the right runtime arch, and the repair keys off the floor target.

Kept here: get_radeon_wheel_url taking the already-resolved leaf. Without it a
split Debian host resolves rocm6.1 and then the Radeon branch re-probes from
scratch, rediscovers hipconfig 5.7 and asks for rocm-rel-5.7/, so it closes a
hole this change opens rather than adding scope.

* Index AMD visible-device masks by device, and floor gfx1102/RDNA4 to rocm6.4

Split out of unslothai#8886 so that PR stays the ROCm version-source change. Stacked on
it: the floor consumes the leaf unslothai#8886 resolves.

One dependency chain. _gfx_targets_per_device emits one gfx token per device, so
a visible-device mask selects a card rather than an arch. The floor then reads
the right runtime arch and routes gfx1102/gfx1200/gfx1201 to the generic rocm6.4
wheels, which are the oldest family shipping their kernels. The migrated repair
keys off that floor target so an upgraded venv stops keeping a kernel-less wheel.

* Collapse the per-device gfx probe onto the existing GPU record helpers

_gfx_targets_per_device parsed a second time what _rocminfo_gpu_records (unslothai#9498)
and _amd_smi_gpu_records already parse for the GPU summary, so delete it and read
the gfx half of those records instead. Both move up to the probe-parser block so
the arch routing can call them; their bodies are unchanged, so the studio/setup.sh
mirrors and their tests stay as they are.

One parser per tool now, shared by the routing block and the display block: a mask
ordinal indexes cards in both, and a duplicate arch cannot collapse two devices
into one entry in either.

The amd-smi shim in test_gfx_probe_survives_no_match_under_set_e answered every
subcommand with "GPU: gfx1151", which is not a shape amd-smi emits; it now answers
`list` with BDF only and `static --asic` with TARGET_GRAPHICS_VERSION, so the test
proves the fallthrough it describes. Same for the flat-output amd-smi stub in
test_install_sh_still_indexes_amd_smi_output_under_a_rocr_mask.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* amd-smi: take the bracketed GPU[N] header too, arch and all

The record parser only opened a device on `GPU: N`, so amd-smi's other header
shape, `GPU[0]  : gfx1100`, produced no records at all. That shape is not
hypothetical: it carries the arch on the header line itself with no
TARGET_GRAPHICS_VERSION following, and the rest of the tree already reads it.
_has_amd_rocm_gpu matches `gpu[ ]*[:[][ ]*[0-9]` at install.sh:3208, the Python
detector matches the same at install_python_stack.py:1660, and the per-device
split at :1814 carries a comment saying install.sh parses the same shapes. It
did not.

Consequence on an amd-smi-only host (no rocminfo): _gfx_all came back empty, so
_runtime_gfx was empty and every arch policy this PR adds was skipped without a
word. A gfx1200 box resolving ROCm 6.1 keeps the kernel-less rocm6.1 wheels
instead of being floored to rocm6.4, which is the case the PR exists for.

Header shapes now both open a record, and the header's own gfx token is taken
when it has one. Applied to studio/setup.sh identically; the parity assertion in
test_rocminfo_gpu_name_7307.sh caught the two copies drifting on a comment while
this was being written.

Three cases added to that suite, which now sources the amd-smi parser rather than
only diffing the two copies of it: bracketed multi-device keeps one record per
device in order, the keyed form still pairs arch with name, and a header with no
arch stays empty instead of borrowing the next device's.

Verified: 26 passed, 0 failed on Git Bash. test_install_gpu_summary_probe_sources
and test_setup_gpu_summary_probe_sources report identical results with and
without this commit on this box (0/28 and 3/37); they need a POSIX symlink the
environment cannot make, and pass on the Linux runner.

* Translate amd-smi order before indexing it, and keep unreadable adapters

Two ways the arch routing could read the wrong adapter, both from treating a
position in a list as if it were a device id.

Order. amd-smi enumerates in discovery order, which is not the order HIP numbers
devices, and the routing applied a HIP/ROCR/CUDA ordinal to it directly. The
translation already existed: _amd_smi_hip_order builds a HIP_ID map from
`amd-smi list -e`, and the GPU summary has used it all along. Routing now runs
the same translation, and when no map comes back and the adapters are not alike
it declines with a warning rather than guess, which is the call the summary
already makes on the same evidence.

    discovery [gfx90a MI210, gfx1200 RX 9070], HIP order reversed
    HIP_VISIBLE_DEVICES=0   before: gfx90a    after: gfx1200
    HIP_VISIBLE_DEVICES=1   before: gfx1200   after: gfx90a
    same, no HIP_ID map     before: gfx90a    after: declines

Blank slots. _amd_smi_gpu_records emits an empty gfx field on purpose so an
adapter whose arch it cannot read keeps its ordinal, and the index step then
filtered those lines out with NF, collapsing the list. Command substitution ate
a trailing one too.

    [blank, gfx1151], HIP_VISIBLE_DEVICES=0
    before: gfx1151, so the Strix reroute fired on device 0's behalf
    after:  unknown, which matches no policy

_gfx_arch_slots does that preservation, and prints nothing when NO adapter has an
arch so the probe chain still falls through to the next source.

Two places deliberately keep the old behaviour. rocminfo is an ROCr client and
already enumerates in the order HIP numbers from, which is the premise the mask
handling was written on, so it is marked hip and skips the check. Identical
adapters skip it too: every ordinal gives the same answer, so there is nothing
to get wrong.

Seven cases added to test_rocminfo_gpu_name_7307.sh, which now sources
_gfx_arch_slots and _amd_smi_hip_order. 33 passed, 0 failed on Git Bash.
sh -n and bash -n clean. test_install_gpu_summary_probe_sources and
test_setup_gpu_summary_probe_sources report 0/28 and 3/37 with and without this
commit alike; they need a POSIX symlink this box cannot make.

The decline path itself is three lines of shell inside the routing block and is
not covered end to end here: that needs the block harness, which is one of the
two suites the environment cannot run. Its inputs are covered.

* Define _amd_smi_hip_order before the routing calls it, and inject it into the tests

Both are the same mistake in two places: a shell helper that is not in scope
where it is used, hidden by an `|| true`.

install.sh is sequential and the GPU probing runs at top level, inside the case
opened at 4806. The translation call added last push sits at 4847; the helper was
defined at 5108, 261 lines further down. So on every amd-smi host the shell said
command not found, `|| true` swallowed it, _gfx_smi_out came back empty, and the
next two lines erased records that were fine. Reproduced in three lines:

    out=$(printf 'x\n' | _fn 'recs' || true); echo "[$(printf '%s\n' "$out" | head -1)]"
    _fn() { echo hip; }
    -> _fn: command not found
    -> []

Moved next to _gfx_arch_slots at 3590, ahead of both call sites. Body unchanged,
so the install.sh/setup.sh parity assertion still holds.

Same shape in tests/studio/install/test_rocm_support.py. Its probe blocks are
extracted from install.sh and run with only the helpers the harness injects, and
that list was still the two record parsers. The routing block calls
_gfx_arch_slots now, so bash printed `_gfx_arch_slots: command not found` four
times and then a syntax error. Added both new helpers to _gpu_record_helpers,
with a note on why a missing one is worse than a loud failure: the block's
`|| true` turns it into an empty arch list and the assertion passes for the
wrong reason.

Four cases added to test_rocminfo_gpu_name_7307.sh asserting each helper is
defined above its first call, by order rather than by line number so a later edit
does not have to update them. Checked against b8fbc16 to confirm the guard
actually fires: FAIL _amd_smi_hip_order def=5108 firstuse=4847 there, PASS here.

37 passed, 0 failed. sh -n, bash -n and python -m ast all clean.

Not re-run: tests/studio/install/test_rocm_support.py. It downloads models and
filled this disk mid-run, taking a baseline comparison with it. The
command-not-found lines it printed are gone, which is what the harness change was
for, but I am not quoting a pass count I did not watch finish.

* Answer `amd-smi list -e` in the routing stubs so the ordinal tests test an ordinal

The amd-smi stubs ignored argv and returned the ASIC listing for every call,
`amd-smi list -e` included. So the routing block saw no HIP_ID map, and with
unlike adapters known only in discovery order it correctly declined to apply an
ordinal and left the caller's leaf alone. The leaf it left alone was rocm6.1,
the default these tests pass in.

That is a real miss, not a cosmetic one, and it was hiding in the pass column:

  splits_amd_smi_gpu_headers[HIP_VISIBLE_DEVICES=2]  expected rocm6.4 got rocm6.1
  splits_amd_smi_gpu_headers[HIP_VISIBLE_DEVICES=1]  expected rocm6.1 got rocm6.1
  still_indexes_amd_smi_output_under_a_rocr_mask     expected rocm6.1 got rocm6.1

Only the first failed. The other two agree with the decline by coincidence, so
they were asserting nothing about the header splitting and the ROCR indexing
they are named for.

_amd_smi_stub answers `list -e` with a HIP_ID map, identity by default, which is
what a caller indexing the listing directly already assumes. Both call sites use
it. Added a third test that withholds the map on the same adapters and asserts
the decline, so the behaviour that was silently absorbing these three now has
one test that means to land there.

4 passed, 0 failed, and the old stubs reproduce the table above against the same
install.sh.

Verified by running the harness's own assembled script from a file rather than
through pytest. Git Bash on Windows truncates a `bash -c` payload at 8188 bytes
and these scripts are ~23.5k, so every test in this class dies there with a
syntax error from the cut, whatever the branch. That is this machine, not the
diff; the Linux runner executes them normally.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Compose the ROCr and HIP visibility layers instead of shadowing one with the other

rocminfo is an ROCr client, so its output is already filtered by
ROCR_VISIBLE_DEVICES. The routing then picked the first variable that was SET
across all three layers, so an ROCr mask that had already done its work shadowed
CUDA_VISIBLE_DEVICES, the HIP-layer alias, which should select among the
survivors. With ROCR_VISIBLE_DEVICES=2,1 and CUDA_VISIBLE_DEVICES=1 the target
is the second survivor; the old chain named the first and floored the index for
the wrong card.

Consult only the HIP layer once rocminfo has applied the ROCr one, mirroring
_HIP_LAYER_MASKS in studio/install_python_stack.py, which already did this.

* Make the generic-wheel floor tests independent of the host's own torch

TestGfx1102Rocm64Floor._ensure_for_gfx patched the detectors but left
_installed_rocm_wheel_family and _torch_requires_rocm_sdk reading the RUNNING
interpreter. The scenarios it sets up install generic pytorch.org wheels, which
do not pull rocm[libraries], so the per-arch family is None by construction.

On a gfx1151 Strix Halo runner whose venv holds 2.11.0+rocm7.13.0 they answered
gfx1151 instead. The per-arch repick arm then saw _have != _want, reinstalled,
and test_installed_64_wheel_left_alone_on_newer_host and
test_unaffected_arch_not_repaired_on_newer_host failed on AMD hardware while
passing on every CUDA or CPU box, this one included.

Pin both to the scenario. A test about the generic-wheel floor must not depend
on what the machine running it happens to have installed.

* Tighten the comments this change adds

Comments only. Every load-bearing fact stays: the issue numbers, the POSIX awk
constraint on -v newlines, the two amd-smi header shapes, why an unreadable arch
keeps its slot, why the ROCr and HIP layers compose rather than shadow, and the
keep-in-sync pointers to studio/setup.sh and install_python_stack.py.

Applied to studio/setup.sh as well: test_rocminfo_gpu_name_7307.sh asserts the
two copies of the amd-smi parser and HIP reorder are byte identical, so editing
one alone breaks parity. The same test also sed-matches the first-set-wins
comment to lift a block, so that anchor line is preserved verbatim.

* Scrub CUDA_VISIBLE_DEVICES in the generic-wheel floor fixture

_visible_masks_select_no_gpu reads CUDA_VISIBLE_DEVICES as the HIP alias when
HIP_VISIBLE_DEVICES is unset, so a host running the suite with
CUDA_VISIBLE_DEVICES="" (a CPU CI shard, or a developer hiding a CUDA card)
made _runtime_gfx_target answer no GPU and the three debian-split floor tests
took the generic index instead of the per-arch one. The fixture already
scrubbed the HIP and ROCr masks; scrub the CUDA one too, as the other
fixtures in this file do. 625 pass with the variable empty, set and unset.

* Tighten the comments this change adds for PR unslothai#9672

* Fall through to amd-smi static --asic when list carries no arch for PR unslothai#9672

* Layer ROCR_VISIBLE_DEVICES under the HIP index on the amd-smi path for PR unslothai#9672

* Decline arch routing on a ROCr UUID mask over unlike amd-smi adapters for PR unslothai#9672

---------

Co-authored-by: Natani L. Mayday <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Maheswar Kumar <[email protected]>
Co-authored-by: danielhanchen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants