Skip to content

Linux: index AMD visible-device masks by device, and floor gfx1102/RDNA4 to rocm6.4 - #9672

Merged
danielhanchen merged 50 commits into
unslothai:mainfrom
LeoBorcherding:gfx-per-device-and-rocm64-floor
Sep 15, 2026
Merged

danielhanchen merged 50 commits into
unslothai:mainfrom
LeoBorcherding:gfx-per-device-and-rocm64-floor

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Aug 25, 2026 •

Copy link
Copy Markdown
Collaborator

Split out of #8886 at @danielhanchen's request, so that PR stays the ROCm version-source change. Stacked on it: the floor consumes the leaf #8886 resolves, and both touch the same regions of install.sh, so #8886 should land first.

Three pieces, one dependency chain, which is why they arrive together rather than as three PRs.

1. Visible-device masks index devices, not arches. The arch routing now reads the gfx half of _rocminfo_gpu_records and _amd_smi_gpu_records, the same per-device records the GPU summary block already builds, so HIP_VISIBLE_DEVICES=2 on a gfx1100, gfx1100, gfx1200 host selects the third card instead of falling off the end of a deduplicated two-entry list. Also: first-set-wins across HIP_/ROCR_/CUDA_VISIBLE_DEVICES, no re-indexing of a ROCR mask rocminfo already applied, and UNSLOTH_ROCM_GFX_ARCH normalised so a copied HIP gcnArchName still matches.

2. gfx1102 / gfx1200 / gfx1201 floor to the generic rocm6.4 wheels. The newest wheel on the rocm6.1 leaf, torch 2.6.0+rocm6.1, ships Tensile kernels for gfx1030, gfx1100 and gfx1101 only. torch 2.9.1+rocm6.4 adds gfx1102, gfx1200 and gfx1201. Without the floor those cards resolve a wheel with no kernels for them and die at the first BLAS call, the same failure class already special-cased for gfx906.

The floor also clears _amd_gpu_radeon. rocm-rel-6.4/ tops out at torch 2.6.0 with no gfx1102 Tensile libraries and rocm-rel-7.2/ carries neither gfx1102 nor gfx1100, so repo.radeon.com is not a viable source for gfx1102 at any version.

3. Migrated environments repair a floored wheel. A migrated venv keeps its HIP torch, so a pre-6.4 wheel survives an upgrade and studio update was a no-op on exactly the GPUs the floor exists for.

Scope: no changes to ROCm version detection, no wheel-table changes, and explicit UNSLOTH_TORCH_INDEX_* pins stay authoritative throughout.

Validation: on Ubuntu 24.04, tests/studio/install/ 2611 passed with 5 failures identical to upstream/main at 58c721d (2 in test_install_manifest.py, 3 in test_managed_node_runtime.py, all HOME-path assertions, none AMD). tests/sh suites at 23, 28 and 37 assertions. bash -n and sh -n install.sh clean.

Partly verified on hardware. Detection and routing were run on a real Radeon AI PRO R9700 (gfx1201) under WSL2 Ubuntu 24.04 with ROCm 7.2.1 from AMD's Debian packages: real rocminfo output parses to gfx1201|AMD Radeon AI PRO R9700, _runtime_gfx resolves to gfx1201, the leaf moves rocm6.1 to rocm6.4 and _amd_gpu_radeon is cleared. The same block against a genuinely failing rocminfo still exits 0 under set -euo pipefail and leaves the leaf alone.

Not verified: the wheel install and a training run, which is where a missing kernel actually surfaces. The kernel-presence claims come from reading the rocBLAS Tensile library names inside the published wheels, not from running them. The multi-device mask indexing is also stub-only, since that host has one GPU.

Two of the three floored arches are owned here, gfx1201 and gfx1200, but no gfx1102. What would close this: a gfx1102, gfx1200 or gfx1201 owner confirming a real train on the rocm6.4 wheels. gfx1102 matters most, since it is the arch the Radeon repo cannot serve at any version.

Also here: _gfx_targets_per_device has been collapsed into _rocminfo_gpu_records (#9498) and _amd_smi_gpu_records, per review, so there is one parser per tool shared by the routing block and the display block.

Hardware and OS coverage

Every check on this PR ran on hosted GitHub runners, which have no AMD GPU, so all of them exercised software stubs. Unsloth does have a self-hosted AMD runner, but nothing here was run on it. This table is the real test report. A row only counts as a test if the machine had the hardware, and only for the part of the diff that machine actually exercises.

Where it was run

Machine GPU OS / stack What ran What that proves
GitHub Actions, hosted runners none Linux, macOS, Windows every check on this PR that the branch does not break anything else. Nothing about AMD.
WSL2 Ubuntu 24.04, ROCm 7.2.1 (rocm-core, hsa-rocr as .debs) Radeon AI PRO R9700, gfx1201 Linux real rocminfo through the routing block _rocminfo_gpu_records returns gfx1201|AMD Radeon AI PRO R9700 from real output, _runtime_gfx resolves to gfx1201, the leaf moves rocm6.1 to rocm6.4, _gfx_rocm64_target sets, and _amd_gpu_radeon is cleared from true. The floor and the Radeon-branch clear are demonstrated on a real RDNA4 card.
same, with HSA_ENABLE_DXG_DETECTION unset same card, unreachable Linux same block against a failing rocminfo hsa_init fails, the probe returns empty, the block still exits 0 under set -euo pipefail and leaves the leaf alone. The || true guards hold against a real failing tool, not a stub.
same same Linux tests/studio/install/ 2611 passed, test_rocm_support.py 535 passed, tests/sh suites at 23 / 28 / 37, bash -n and sh -n the branch selection logic across every arch and mask shape, against fabricated tool output

Provenance: those suite counts were measured at d828ee0. The head has since moved to 8f95ff28e7 through two merges of main, a pre-commit pass, and one code commit (amd-smi: take the bracketed GPU[N] header too, arch and all). The two hardware rows are unaffected, because no new hardware run has happened, but the counts have not been re-measured at the current head.

Scope limits on that box, stated plainly: it is WSL2, so ROCr reaches the GPU through /dev/dxg and there is no /dev/kfd. The rocminfo output shape is the same as bare metal, which is what the parser consumes, so the parse and the route are genuinely settled. The wheel install and a training run are not. There is one GPU and no amd-smi in that image, so the multi-device and amd-smi branches remain stub-only.

An RX 9060 XT (gfx1200) and a second R9700 are owned but not seated, so neither contributed.

The wheel claims (which rocBLAS Tensile libraries ship in torch 2.6.0+rocm6.1 versus 2.9.1+rocm6.4, and what repo.radeon.com carries under rocm-rel-6.4/ and rocm-rel-7.2/) come from reading the library names inside the published wheels. A real check, but a file listing, not a training run.

What is still missing

Hardware shape Why we care
gfx1102 (RX 7600, 7700S, PRO W7600 / W7500) on Linux the arch the floor exists for most, and the one repo.radeon.com cannot serve at any version, so a wrong floor there has no fallback. Nobody on this thread owns one.
An actual install and train on a floored arch detection and routing are now shown on real gfx1201 silicon, but a missing kernel only surfaces at the first BLAS call. Nothing here has installed the rocm6.4 wheel and trained on it.
Two or more AMD GPUs on one board the per-device mask indexing is the whole first half of this PR. The failing shape is three cards where two share an arch (gfx1100, gfx1100, gfx1200) and HIP_VISIBLE_DEVICES=2 fell off the end of a deduplicated two-entry list. Two R9700s exist here but are not seated together, and even seated they would be two identical gfx1201 cards, which is not the mixed-arch case.
Mixed AMD arches on one board the reason the mask must select a card and not an arch. Stub-only.
A host where amd-smi answers and rocminfo does not the entire amd-smi half of the probe, including the bracketed GPU[N] header added at the current head, the discovery-order-versus-HIP-order question, and adapters whose TARGET_GRAPHICS_VERSION comes back blank. The WSL image above has no amd-smi, so every one of those is stub-only.
A migrated venv holding a pre-6.4 ROCm torch on a floored arch the third piece only fires on an upgrade over an existing install. A fresh install never reaches it.

Bottom line

Solid: on a real gfx1201 card, real rocminfo output parses to one record per device and the rocm6.1 leaf is floored to rocm6.4 with the Radeon branch cleared, and the probe survives a genuinely failing rocminfo. Biggest gap: gfx1102 is the arch this floor matters most for and no one on this thread has one, and nothing has yet installed the floored wheel and trained on it, which is where a missing kernel actually shows.

TaskPuppyNatani and others added 23 commits August 14, 2026 18:31
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.
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.
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.
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.
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.
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.
…m 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.
…e 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.
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.
…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.
@danielhanchen

Copy link
Copy Markdown
Member

Confirmed the per-device indexing fixes the mask path in install.sh, where a deduplicated arch list made HIP_VISIBLE_DEVICES=2 miss the third card, and the rocm6.4 floor matches the wheels that actually ship gfx1102 kernels. The new _gfx_targets_per_device overlaps _rocminfo_gpu_records that main already has at install.sh:4790, so please collapse them into one helper and rebase onto the version-source PR before this lands.

@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author
image

…ith 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.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 14, 2026
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.
@danielhanchen

Copy link
Copy Markdown
Member

Update: running this PR's own install suites on a real gfx1151 Strix Halo Linux runner found a defect that passes on every CUDA and CPU machine, including mine. Fixed in 8a2e597. This is the result I most wanted from the hardware, so the detail is worth recording.

What the hardware said

state passed failed skipped errored
base 289e0df4b 3510 4 525 0
head 3561 6 525 0
merge 3860 6 525 0

The two extra failures are both tests this PR adds:

TestGfx1102Rocm64Floor::test_installed_64_wheel_left_alone_on_newer_host
TestGfx1102Rocm64Floor::test_unaffected_arch_not_repaired_on_newer_host

so nothing pre-existing broke. The harness called it REGRESSION because it compares failing-id sets, which is the right arithmetic and the wrong English: a PR that adds a failing test reads the same as one that breaks an existing test. The accurate statement is that the PR shipped two tests that fail on the hardware they are about.

Verbatim, from the head:

E  AssertionError: Expected 'pip_install' to not have been called. Called 1 times.
E  Calls: [call('ROCm torch (rocm6.4)', '--force-reinstall', '--no-cache-dir', ...
   installed ROCm torch is the gfx1151 build, which carries no
   gfx1200 kernels -- reinstalling for this GPU.

Root cause

TestGfx1102Rocm64Floor._ensure_for_gfx patches the detectors but left _installed_rocm_wheel_family() and _torch_requires_rocm_sdk() unpatched, and those read the running interpreter's torch rather than the scenario. The runner's Studio venv holds 2.11.0+rocm7.13.0, so they answered gfx1151; the per-arch repick arm at install_python_stack.py:5283 then saw _have != _want and reinstalled, tripping both assert_not_called. On a CUDA or CPU host _have is None, the arm never fires, and both tests pass. That is why this was invisible everywhere else.

The fix pins both to the scenario, which is also the honest value for it: these tests install generic pytorch.org wheels (2.8.0+rocm6.4), and a generic wheel does not pull rocm[libraries], so the per-arch family genuinely is None.

    patch.object(m, "_torch_requires_rocm_sdk", return_value = False),
    patch.object(m, "_installed_rocm_wheel_family", return_value = None),

Reproduced and confirmed both ways

I did not want to take a remote failure on trust, so I reproduced it locally by making the test module's stack_mod report a gfx1151 per-arch wheel:

fixed fixture   + simulated gfx1151 interpreter -> 51 passed
reverted fixture + simulated gfx1151 interpreter -> 2 failed, 49 passed
                   (exactly the two that failed on hardware, and only those two)

740 passed, 1 skipped across the three rocm suites at head.

The mask was ruled out, not assumed away

A test that fails only inside a GPU-masked CI job is often the mask. That was checked: the same workflow with HIP_VISIBLE_DEVICES and ROCR_VISIBLE_DEVICES removed produced byte-identical verdicts and observations. And because identical readings could also mean the variable never changed, that was measured too:

torch version.hip is_available device_count arch
masked 2.11.0+rocm7.13.0 7.13.99004 False 0 -
unmasked 2.11.0+rocm7.13.0 7.13.99004 True 1 gfx1151

The mask genuinely flipped device visibility on a genuinely ROCm-enabled torch and the suite result did not move, so the failure is a property of the installed wheel's build tag rather than of what HIP can see.

What this run still could not answer

  • The mask-indexing headline is untested on hardware. One GPU cannot show an ordinal selecting the wrong device. Not spoofed either: --spoof-devices reaches wiring only and would have given a confident wrong answer about exactly the thing under test.
  • gfx1102, gfx1200 and gfx1201 are absent from the pool. The floor is about those arches; every assertion touching them was a mocked comparison, not a routing decision made on that silicon.
  • 519 of the 525 skips are real coverage loss, dominated by pwsh not installed on the runner, so every PowerShell-side install assertion was skipped there at both states. Identically, so the comparison holds, but those paths are untested by this run.

@danielhanchen

Copy link
Copy Markdown
Member

CI triage note, since several checks here are red and none of them are this PR. Posting the evidence rather than asking anyone to take it on trust.

1. Repo tests (CPU, studio) and the staging workflow-trigger lint. Both fail on the same two assertions:

FAILED tests/studio/test_studio_smokes_do_not_trigger_on_the_training_library.py
       ::test_the_filter_lists_exactly_the_github_paths_the_steps_execute[studio-update-smoke.yml]
FAILED tests/studio/test_uv_cache_discipline.py::test_every_warm_installer_job_restores_the_uv_cache
       - these jobs run the installer with no uv download cache: studio-update-smoke.yml:idempotency-windows

This was a transient breakage on main itself. studio-update-smoke.yml gained the test that requires uv-cache-restore before the workflow gained the action; the workflow side landed in b58ea42 at 12:48. Checked directly:

tree uv-cache-restore in idempotency-windows the two tests
upstream main b58ea42 (now) present 11 passed
the base these branches sit on, 289e0df absent 11 passed (the test did not require it yet)

CI runs against main as of run time, and these runs predate 12:48, so they caught the window in between. No PR in this batch touches studio-update-smoke.yml, test_uv_cache_discipline.py or test_studio_smokes_do_not_trigger_on_the_training_library.py (verified across all six). A re-run picks up the fixed main.

2. The three Core jobs fail inside unsloth_zoo @ main - full pytest (CPU) on allocator configuration (PYTORCH_ALLOC_CONF / PYTORCH_CUDA_ALLOC_CONF all None). The same workflow is failure on main itself (run 34820611889), and nothing in this batch reaches unsloth_zoo.

3. Repo tests (CPU, rest) fails on one assertion:

FAILED tests/test_source_read_encoding.py::test_checked_in_file_reads_name_an_encoding
['tests/version_compat/test_bitsandbytes_pinned_symbols.py:288: read_text()']

I ran that test on a clean main checkout and it fails identically, same file and line. It is a genuine small bug (a read_text() without encoding = "utf-8" breaks on Windows the moment that file gains a non-ASCII byte) and deserves its own PR, but it is not this one.

So: buckets 3 and 3 and 3, in the runbook's terms. Nothing here blocks these PRs, and I have re-run the affected jobs now that main carries the fix.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 8a2e597737

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

Merged current main (a6cf596) into this branch, and took over driving it.

The branches had drifted far enough that CI was testing a stale combination rather than the change. The clearest case: tests/sh/test_setup_staged_root.sh failed 4 assertions in CI while passing locally on every tree here, because main had changed the sidecar-removal code and grown the test from 34 assertions to 36, while the branch still carried the 34-assertion version. Old test, new code.

tree assertions result
main a6cf596 36 pass
this branch's old base 289e0df 34 pass
the CI merge commit 34 4 failed

Merged cleanly with no conflicts. Verified before pushing:

  • 65 of 65 shell installer suites pass, zero failures
  • the PR's own suites pass

Two other red checks that were also main's rather than this branch's, for the record:

  • Repo tests (CPU, studio) failed on test_uv_cache_discipline and test_studio_smokes_do_not_trigger_on_the_training_library. main gained the test requiring uv-cache-restore before studio-update-smoke.yml gained the action; the workflow side landed in b58ea42. It clears on a re-run against fixed main, which I confirmed.
  • The three Core jobs fail inside unsloth_zoo @ main on allocator configuration, and that workflow is red on main itself.

Still genuinely outstanding and not from this branch: tests/test_source_read_encoding.py flags tests/version_compat/test_bitsandbytes_pinned_symbols.py:288 for a read_text() with no encoding = "utf-8". It reproduces on a clean main checkout, same file and line. Worth its own small PR since it breaks on Windows the moment that file gains a non-ASCII byte.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 14, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

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.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
_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.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 15, 2026
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Sep 15, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Re-validated on current main (1e07231) with the branch merged, on real gfx1151 Strix Halo hardware on Linux and Windows, and through a hermetic installer matrix. Four commits pushed today: a fixture fix, a comments-only pass, and two fixes described below.

Before and after

Before: main collects the AMD architecture list with grep -oE 'gfx...' | sort -u and then indexes that deduplicated list with HIP_VISIBLE_DEVICES, so on a host with a repeated architecture the mask picks the wrong card. Measured against an identical synthetic three-adapter rocminfo (gfx1100, gfx1100, gfx1200):

HIP_VISIBLE_DEVICES actual card main picks this branch picks
unset gfx1100 gfx1100 gfx1100
1 gfx1100 gfx1200 gfx1100
2 gfx1200 gfx1100 gfx1200

On an amd-smi-only host main also applies a HIP ordinal to amd-smi's discovery order; this branch translates through amd-smi list -e first and declines rather than guesses when the map is unavailable and the adapters differ.

After: one record per adapter, indexed by the mask, and a per-arch generic-wheel floor: gfx1102 to rocm6.3, gfx1200 and gfx1201 to rocm6.4, read from the kernels each published wheel actually carries.

What I changed today

The three test_debian_split_affected_gfx_leaves_the_kernel_less_generic_wheel cases failed on any host running the suite with CUDA_VISIBLE_DEVICES="", which is what CPU shards and developers hiding a CUDA card do. _visible_masks_select_no_gpu reads that variable as the HIP alias when HIP_VISIBLE_DEVICES is unset, so the fixture saw no GPU and took the generic index. The fixture already scrubbed the HIP and ROCr masks; it now scrubs the CUDA one too, like the other fixtures in the file. 625 pass with the variable empty, set and unset.

Second pass: an amd-smi fallback this branch had broken

On a host where rocminfo yields nothing, main reads the arch from amd-smi list and, when that carries no gfx token, from amd-smi static --asic. Stock amd-smi list on ROCm 6.x prints ids only (GPU, BDF, UUID, KFD_ID), so the second probe is the one that normally answers. The new record parser emits one |-separated record per device even when the arch column is empty, so the [ -z ... ] test that used to trigger the static --asic probe saw a non-empty string and skipped it, and the routing fell through to the generic wheel on exactly the amd-smi-only hosts the floor exists for. The fallback is now keyed on whether any record carries an arch. A case in test_rocminfo_gpu_name_7307.sh drives the extracted fallback with a fake amd-smi whose list has no arch; it fails on the previous head ('') and passes now (gfx1151) under bash, dash and sh. The routing matrix is byte-identical to the previous head in all 183 cells, so nothing else moved.

Third pass: the ROCr layer on the amd-smi path

The P1 review item was right. amd-smi is not ROCr-filtered, so with both ROCR_VISIBLE_DEVICES and HIP_VISIBLE_DEVICES set the first-set-wins pick indexed the whole HIP-ordered inventory with the HIP ordinal and ignored the ROCr subset. ROCR_VISIBLE_DEVICES now subsets the inventory first (ordinals in mask order, none in range keeps the whole list, as _rocr_visible_subset and _pick_visible_index do in install_python_stack.py) and HIP or CUDA indexes the survivors. With arches gfx1100, gfx1200, gfx1100 and ROCR=1,0 plus HIP=1 the block routed to gfx1200 before and routes to gfx1100 now; test_install_sh_layers_rocr_under_hip_for_amd_smi fails on the previous head and passes here. The rocminfo path is unchanged because rocminfo output is already ROCr-filtered. The routing matrix is byte-identical to the previous head in all 183 cells.

Evidence

Real hardware, self-hosted gfx1151 Linux:

job base head verdict
tests/studio/install ROCm support, arch parity, AMD fastpath (re-run on the final head) 728 passed, 0 failed 782 passed, 0 failed NO_REGRESSION
every tests/sh installer suite under bash, dash and sh (re-run on the final head) 0 failed under bash; 11 suites fail under dash and sh at both states (bash-only suites) same set, 0 new NO_REGRESSION

Windows 11 gfx1151, re-run on the final head: test_rocm_support.py reports 14 newly failing tests at the head, the same 13 as before plus the new ROCr layering case, every one of them an install.sh-through-bash test. All 13 are the new TestGfx1102Rocm64Floor cases that drive install.sh through bash, and on those boxes bash.exe is the WSL stub, which is also why 40 pre-existing tests in the same file (TestInstallShStructure, TestStrixRocm71Override, TestRocmGfxForwarding and friends) fail there at the base. The repository only runs this file on Linux. Same cause, same class, not a regression.

Installer matrix, 183 cells over [Linux, WSL, macOS, Windows msys] x [NVIDIA, AMD, CPU, XPU pin] x tool states: this branch differs from main in 42 cells and every one is either the intended floor (gfx1102 below 6.3, gfx1200 and gfx1201 below 6.4), the mask cells above, or two consequences the code comments document: the Radeon repo flag is cleared on floored arches because that repo's rocm-rel-6.4 trio ships no gfx1102, and a copied gcnArchName suffix such as gfx1201:sramecc+:xnack- is now trimmed before comparison. Every NVIDIA, macOS, WSL and CPU cell is byte-identical to main. The four record helpers the block now calls were moved above the call site; the block was also assembled in file order and run under dash on four AMD cells with identical answers, so there is no POSIX ordering bug.

Hosted runners (ubuntu-latest, macos-15, windows-latest, the whole of test_rocm_support.py and the shell suite): STAGING_R2_9672. The reds in that file are all tests main already ships, and none of them is one this branch adds or touches: on Ubuntu, TestProgressStepCountMatchesTotal and TestWindowsRocmTorchaoGuard call install_python_stack(), which on that bare runner exits 1 with "unsloth is not installed"; on macOS, TestEnsureRocmTorch and TestGfx906LegacyReroute never see a pip call because _ensure_rocm_torch returns at its IS_MACOS guard, and the repository runs that file on Linux only; on Windows, the install.sh-through-bash tests hit the WSL stub as above. The same four classes pass locally on main (76) and on this branch (78) with the CI dependency set installed.

Old installs and updating

unsloth studio update re-runs the routing on every update. Across 8 architectures x 7 installed-torch states a forced reinstall fires only in the floored cells: gfx1102 on rocm6.1 or 6.2, gfx1200 and gfx1201 on rocm6.1 through 6.3. A gfx1102 host already on rocm6.3 is left alone, which is the case the original flat 6.4 floor would have needlessly reinstalled. CUDA, CPU and MLX venvs never reach this branch.

Not tested here

The pool has one gfx1151 per box, so the multi-adapter mask headline was demonstrated on synthetic rocminfo and amd-smi output, not on a mixed machine. No gfx1102, gfx1200 or gfx1201 card exists in the pool, so the floor is measured from wheel contents and never run on the silicon it affects. NVIDIA, XPU and MLX are covered by the matrix only.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 15, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 54d641db28

ℹ️ 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
danielhanchen merged commit 838f4bd into unslothai:main Sep 15, 2026
70 of 72 checks passed
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.

4 participants