Skip to content

fix(amd): gate training GPU selection on the installed torch build's arch coverage - #8791

Merged
danielhanchen merged 26 commits into
unslothai:mainfrom
LeoBorcherding:fix-training-gpu-arch-gate
Sep 1, 2026
Merged

danielhanchen merged 26 commits into
unslothai:mainfrom
LeoBorcherding:fix-training-gpu-arch-gate

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Aug 14, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #8792.

Problem

PR #7670 gated llama-server placement on the llama.cpp bundle's built-arch list. Training never sees that gate: prepare_gpu_selection -> auto_select_gpu_ids ranks by free VRAM alone, so an uncovered iGPU stays in the selection, device_map="balanced" shards layers onto it, and the load dies with hipErrorInvalidKernelFile. Full repro, logs and environment in #8792.

mapped_targets cannot answer for torch: it describes a different binary, and the two can cover different archs on the same host. The wheel's own answer is torch.cuda.get_arch_list(), which was not wired into product code anywhere.

Fix

New rocm_gpu_ids_without_torch_kernels() returns the physical ids whose reported arch is outside that list, and auto_select_gpu_ids drops them before the rank.

Applied once, before every exit. Three of the four exits return the whole visible set, so filtering only the ranked path would have left the reported host broken.

Compares what the device presents, not its silicon. Under HSA_OVERRIDE_GFX_VERSION an unsupported card presents a supported arch, and that override is the standard workaround for this class of problem, so it has to keep working. Same direction #7670 chose, and pinned by a test here.

Explicit picks are untouched, matching #7670: a user pin keeps its own error rather than being quietly relocated.

Fails open on a non-ROCm host, an unreadable or non-concrete arch list, a UUID/MIG mask whose ordinals cannot be named back to physical ids, an unreadable device arch, and a filter that would drop every device it could read. Sending a working machine to CPU is worse than the bug.

Two fixes from review

Non-concrete tokens in get_arch_list(). Worse on ROCm 6.4+, where a generic code object next to concrete targets is normal, and the case where this PR would otherwise be a silent no-op on exactly the hosts that need it. The list is now rejected whole when any token is non-concrete, the same all-or-nothing rule as _installed_llama_gfx_archs. Three parametrised cases cover generic-first, generic-last and a family label between concrete tokens; without the fix each one drops a gfx1101 the wheel does run.

ROCR on Windows. _get_parent_visible_gpu_spec preferred ROCR on every ROCm host, while llama_cpp.py:5195 and _emit_child_gpu_visibility both treat ROCr as Linux-only. Fixed there rather than in this caller, so the gate and the telemetry/pin paths share one answer instead of gaining a third mask reader. It only changes behaviour on Windows with HIP unset and ROCR set.

Two more fixed after simulation

Ordinal-to-physical overflow silently changed namespace. physical_ids[ordinal] if ordinal < len(physical_ids) else ordinal minted overflow ordinals as physical ids that already belong to other devices. torch.cuda.device_count() and _get_parent_visible_gpu_spec() can legitimately disagree: the count is frozen at context init while the spec re-reads the environment live, and before init device_count() goes through _device_count_amdsmi(), which does not see the HIP layer at all (with ROCR=0,1,2,3 and CUDA=0, PyTorch reports 4 where the runtime gives 1).

Measured end to end through the real auto_select_gpu_ids: three torch ordinals, HIP_VISIBLE_DEVICES=2,0, dGPU covered at physical 2. Base selects [2], correctly. This branch returned ids=[] mode=fallback_all, and an empty list is not "inherit", it is "no GPU", so a working two-card host would have trained on CPU. Fixed. The first fix over-corrected by bailing whenever ordinals outnumbered ids, which would have disabled the gate on the reported host, because unmasked the ids come from amd-smi and amd-smi routinely misses the iGPU. The unmasked case now extends the list, where the ordinal is the physical id; only the masked case bails.

The all-uncovered guard compared a set against a count. len(unsupported), a set of ids, was compared with readable, a count of ordinals, so a mask naming one id twice collapsed the set and let the drop-everything case through.

On the apply_gpu_ids() change

It is beyond the title, and it is necessary: the gate emits physical ids that flow into apply_gpu_ids, and under a non-identity ROCr mask the old code wrote a physical id into HIP's ROCr-relative index space. The premise matches rocclr and PyTorch's own comment that ROCR is processed first and reduces the set HIP can select from; Windows and PAL neither reorder nor observe ROCR, hence the win32 guard.

Blast radius measured exhaustively: 1152 rows, [Windows, Linux, WSL, Mac] x [NVIDIA, AMD, CPU, no torch] x 12 masks x 4 pins. 81 rows change, all of them ROCm, non-Windows, with a non-identity ROCR_VISIBLE_DEVICES. Zero change on NVIDIA including stale-ROCR-on-NVIDIA, CPU, Windows, no mask, identity ROCR, HIP set, stacked, UUID, empty and trailing comma.

One case is deliberately not byte-identical: single-GPU AMD with ROCR_VISIBLE_DEVICES=1. Base wrote HIP=1, out of range in a one-agent list, so torch saw no GPU. Head writes HIP=0. The old behaviour was broken and the change fixes it.

Open question: the duplicated arch reader

This reads the four gcnArchName spellings inline rather than reusing core/training/worker.py::_rocm_classify_unified_memory, which is the opposite of what I was asked to do in #7670.

Correcting my own earlier reasoning here: there are four arch readers, not three (worker.py:1858, the new hardware.py:4353, plus hardware.py:1601 and hardware.py:2887), and the import-direction argument does not support keeping them. worker.py:55 imports utils.hardware at module level, so hardware importing worker at module level would be circular, but the refactor moves the function down into hardware.py, which is the acyclic direction. hardware.py:1471 already does a deferred from core.training.worker import _rocm_classify_unified_memory on the GPU-inventory path, so the lazy-import cost is already being paid and the move would remove that edge.

Consolidating all four is not behaviour-preserving: hardware.py:2887 is a deliberately raw join key for _match_adapter_used_by_luid (#8863) against a Windows driver string, and normalising it changes what joins against what. The right end state is to consolidate the two four-spelling readers and leave the two raw ones with a comment saying why.

I still think that belongs in a follow-up rather than here, since this PR already runs 688 insertions into code that just stabilised. Say if you would rather have it in one go.

Note for anyone touching this: only gcnArchName exists in upstream PyTorch. gcn_arch_name, arch_name and gfx_arch_name have zero hits. On CUDA builds gcnArchName aliases prop.name and returns something like NVIDIA B200, so the ROCm-build early return is load-bearing rather than decorative.

Tests

49 in test_training_gpu_arch_gate.py, all mock-based: torch, the arch attributes, get_arch_list and the visibility masks are faked. Covers the reported host shape, HSA_OVERRIDE survival, all four arch spellings, the xnack suffix, ordinal-to-physical mapping under a mask, the fail-open corpus, and all four selector exits including a control asserting a fully covered host selects exactly as before. Each wiring assertion is mutation-checked: unfiltering the device list fails the ranked test, unfiltering the fallbacks fails the other two.

Hardware coverage

Needs: rocm, gpu, integrated_gpu, discrete_gpu, multi_gpu_amd, windows

host leg result
hosted CI, no GPU full suite, fully mocked, plus mutation check on each wiring assertion 45 passed, all mutations caught
self-hosted gfx1151 (Strix Halo) / Linux / ROCm 7.2.1 base vs head, two devices torch really enumerates CONFIRMED
reporter #8792, 7800 XT plus 7600X iGPU / Windows original hipErrorInvalidKernelFile repro reported, not re-run against this branch

About the gfx1151 run

This host has one GPU. Rather than mock device_count(), the run interposes the HIP runtime with LD_PRELOAD so hipGetDeviceCount reports two and phantom ordinals fold onto the real device. torch then enumerates two devices because the C++ runtime does (torch._C._cuda_getDeviceCount() == 2), and the probe allocates a tensor and runs a matmul on both before the gate is asked anything, so a shim that silently failed makes the run inconclusive rather than a pass. A control leg without the shim records that the unshimmed host really has one device.

One Python patch remains: the arch string of device 1. The gate compares a device's arch against get_arch_list(), so with both devices reporting the real gfx1151 neither is uncovered and there is nothing to find. The amd-smi binary is additionally stubbed on the selection leg only, because hardware.py enumerates through amd-smi rather than torch; the stub wraps the real amd-smi and duplicates its entry, shaping the copy to win a free-VRAM-only ranking so the base cannot pick the good card by tie-break. The gate leg needs neither.

Base has no gate and hands the uncovered device over; head names device 1 uncovered and keeps device 0.

Not covered

shape why
two physical AMD GPUs the phantom device above is device 0 wearing another number: shared memory, shared compute, serialised. It shows the gate reaching its decision on devices torch is not merely pretending to have, and says nothing about a model really sharding across two cards
windows the _get_parent_visible_gpu_spec fix only changes behaviour on Windows with HIP unset and ROCR set, and is exercised against mocks only
HSA_OVERRIDE_GFX_VERSION on real silicon survival is pinned by a test, never observed on a card that needs it

The reporter has the affected machine and has tested every previous round.

…ls for

unslothai#7670 gated llama-server placement on the llama.cpp bundle's built-arch
list. Training never sees that gate: prepare_gpu_selection ->
auto_select_gpu_ids ranks by free VRAM alone, so on a mixed ROCm host the
iGPU stays in the selection, device_map="balanced" shards layers onto it,
and the load dies with hipErrorInvalidKernelFile ("CUDA error: invalid
kernel file") before the first step. Reported on the unslothai#7669 machine, which
still fails there after unslothai#7670 merged.

The wheel's own answer is torch.cuda.get_arch_list(), which was not wired
into product code anywhere. Compare it against what each device PRESENTS,
not its silicon, so HSA_OVERRIDE_GFX_VERSION keeps working: that override
exists to make an unsupported card present a supported arch, and it is the
standard workaround for this class of problem.

Applied once, before the rank and before every fallback: three of the four
exits return the whole visible set, which is how both cards reached the
child on the reported host. Explicit picks are untouched, matching unslothai#7670.

Fails open on a non-ROCm host, an unreadable or non-concrete arch list, a
UUID/MIG mask whose ordinals cannot be named back to physical ids, an
unreadable device arch, and a filter that would drop every device it could
read, since sending a working machine to CPU is worse than the bug.

27 tests, mock-based (no ROCm CI, no AMD hardware here). Each wiring
assertion mutation-checked: unfiltering the device list fails the ranked
test, unfiltering the fallbacks fails the other two.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…nore ROCR on Windows

torch.cuda.get_arch_list() can carry a generic code object (gfx11-generic)
next to concrete targets on ROCm 6.4+ wheels. Filtering the generic token out
and treating the concrete remainder as the build's whole coverage marks a card
the wheel does run as uncovered, so a gfx1100/gfx1101 host loses the gfx1101
to automatic selection. Reject the list whole when any token is non-concrete,
the same all-or-nothing rule the llama.cpp gate applies to mapped_targets.

_get_parent_visible_gpu_spec also read ROCR_VISIBLE_DEVICES on every ROCm host,
but ROCr is Linux-only: a stray value on Windows masks nothing, so taking it as
the ordinal->physical map renames one card by another card's id and the gate
drops the wrong GPU. Ignore it there, matching the llama.cpp visibility
resolver, which never writes ROCR on Windows either.
@LeoBorcherding LeoBorcherding self-assigned this Aug 18, 2026
@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

Both P2s were real; fixed in 0a4f2ec, plus main merged in.

Non-concrete tokens in get_arch_list() — right, and worse on ROCm 6.4+ where a generic code object next to concrete targets is normal. The list is now rejected whole when any token is non-concrete, same all-or-nothing rule as _installed_llama_gfx_archs. Three parametrised cases cover generic-first, generic-last and a family label between concrete tokens; without the fix each one drops a gfx1101 the wheel does run.

ROCR on Windows — also right, and it is _get_parent_visible_gpu_spec that is wrong, not just this caller: it prefers ROCR on every ROCm host while llama_cpp.py:5195 and _emit_child_gpu_visibility both treat ROCr as Linux-only. Fixed there, so the gate and the telemetry/pin paths share one answer instead of gaining a third mask reader. It only changes behaviour on Windows with HIP unset and ROCR set, which nothing in the codebase produces. Tests pin all three: ROCR maps ordinals on Linux, is ignored on Windows, and a HIP mask still maps on Windows.

@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 480431f0af

ℹ️ About Codex in GitHub

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

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

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

chatgpt-codex-connector[bot]

This comment was marked as resolved.

LeoBorcherding and others added 5 commits August 19, 2026 03:36
…n ROCr

apply_gpu_ids writes HIP_VISIBLE_DEVICES and deliberately leaves an inherited
ROCR_VISIBLE_DEVICES alone, but HIP indexes the agents ROCr already filtered, not
the host. So the physical id it writes means a different device: with
ROCR_VISIBLE_DEVICES=1,0 and the gate excluding physical GPU 0, auto-selection
keeps [1], apply_gpu_ids writes HIP=1, and HIP index 1 of the ROCr list IS
physical 0 -- the card just excluded. With ROCR_VISIBLE_DEVICES=2,3 the id is
past the agent count and the worker sees no GPU at all, which is the
torch.cuda.is_available() failure the old comment here described.

Translates the pin to post-ROCr ordinals instead of dropping the ROCr mask.
Dropping it would re-expose every agent it hides, including the unsupported one
the arch gate exists to keep away from HSA enumeration -- the same reason
llama.cpp's _emit_child_gpu_visibility emits post-ROCr ordinals on its
prefer_rocr path. Inert unless ROCR_VISIBLE_DEVICES is set, and an identity mask
translates to itself, so any host that never set ROCR by hand is byte-identical.

Windows is excluded (no ROCr layer, mirroring the mask reads elsewhere), an
inherited HIP mask is already ROCr-relative and left alone, and a UUID mask or an
id from another space leaves the value untouched.

Tests: seven cases on the pin the gate's ids produce, two of which fail without
the translation.
…ch-gate

# Conflicts:
#	studio/backend/utils/hardware/hardware.py
@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

Merged main, now up to date. The only conflict was a comment in _get_parent_visible_gpu_spec: #9362 landed the identical rocr_vis = None if sys.platform == "win32" guard upstream, so the ROCR half of the two review fixes above is main's now, not this branch's. I took main's wording, and the diff is back to just the arch gate. Flagging it since the body still claims that fix.

The open P2 is addressed, on a different line than it is anchored to. Of the two remedies offered I took the second, translate rather than avoid stacking. _rocr_relative_visibility (hardware.py:4231) runs inside apply_gpu_ids at :4340, before HIP is written at :4368. The gate keeps speaking physical ids, which is the space auto_select_gpu_ids works in, and the translation happens once at the pin.

Driving the exact case from the finding, ROCR_VISIBLE_DEVICES=1,0 with physical 0 excluded:

selection keeps physical [1]
  HIP pin written : "0"  -> ROCr agent 1   the supported card
  without it      : HIP=1 -> ROCr agent 0   the excluded card
identity mask 0,1: "1" -> "1", unchanged

An identity mask is a no-op, so a host that never set ROCR by hand is unaffected.

CI. The three Chat UI Tests legs on the previous head were main's own: UI CI was red on main at 21:52 and 22:03 and green at 22:36 after #9654. Checks are re-running on this head now, and I will follow up on anything that stays red. Locally test_gpu_selection.py, test_setup_llama_cpp_backend.py and test_stt_ggml_sidecar.py fail the same 25 tests at this head and at upstream/main, same node ids, so nothing here regresses. 40 pass in test_training_gpu_arch_gate.py, ruff check and git diff --check clean.

Still unverified on hardware, unchanged from the matrix in the body: the defect needs two AMD GPUs on one board and no runner has that.

@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: e713575328

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

Two of the three review findings were real, on the ordinal-to-physical map and
on the ROCr translation.

The gate paired a torch ordinal with _get_parent_visible_gpu_spec()'s numeric
ids, which no longer describe each other once something renumbers them.
GPU_DEVICE_ORDINAL reorders at the ROCclr layer and the spec never reads it; a
ROCr mask under a HIP/CUDA one leaves the spec naming ROCr's agents while torch
counts what survived both. Under ROCR="2,0,1" + CUDA="1,2" that excludes the
covered card and keeps the uncovered one, the exact inversion of the fix. Both
states already have predicates here, the ones the amd-smi VRAM translation
declines on, so the gate now declines on them too.

apply_gpu_ids translated a pin to ROCr-relative ordinals on the strength of
ROCR_VISIBLE_DEVICES being set. Schedulers export both families of visibility
variable, so a Linux NVIDIA node can inherit a ROCR mask that means nothing
there, and translating against it moved the CUDA pin to another card. ROCm is
now settled from the build (IS_ROCM, else torch.version.hip / __version__)
before anything is written, the same stale-mask caution
_get_parent_visible_gpu_spec applies to HIP_VISIBLE_DEVICES. The HIP mirror
keeps its wider env-var test: writing HIP on a host that turns out to be NVIDIA
is inert, where a missed mirror strands a ROCm worker.

The third finding, failing the whole probe on any unreadable device arch, is
not taken. Skipping one unreadable device leaves that card exactly as eligible
as it was before this gate existed; discarding the answer puts the
known-uncovered cards back with it and re-breaks the reported host. The
docstring did promise the stronger behaviour, so it now says what the code
does, and a parametrised test pins the boundary in both spellings.

Tests: 45 pass. Each new assertion mutation-checked -- dropping the renumbering
guard fails both renumber tests, ungating the translation fails the NVIDIA
test, and applying the whole-probe remedy fails both unreadable-device cases.
The review fixes were written on e713575 at 03:04, ten minutes after the branch
picked up a main merge on origin at 02:54, so the two diverged. Merging base in
rather than rebasing, because a rebase here means a force-push and this PR
already has a review thread and a pinned CI history on it.

Clean auto-merge. Only hardware.py overlapped and the edits are in different
functions.
@LeoBorcherding

LeoBorcherding commented Aug 26, 2026 •

Copy link
Copy Markdown
Collaborator Author

Two of the three are real and fixed in 2107c55d. The third I'm not taking, reasoning below.

P2 renumbered ordinal mappings: taken. You're right that numeric_ids stops being an ordinal-to-physical map the moment something renumbers the two apart. GPU_DEVICE_ORDINAL reorders at the ROCclr layer and no visibility spec here reads it, and a ROCr mask under a HIP/CUDA one leaves the spec naming ROCr's agents while torch counts what survived both. Under ROCR_VISIBLE_DEVICES=1,0 plus CUDA_VISIBLE_DEVICES=1 the spec says [1, 0] but torch ordinal 0 is physical 0, so the gate would have excluded the covered card and kept the uncovered one, which is precisely the inversion of what it's for.

Both states already had predicates in this module, the ones the amd-smi index translation declines on, so the gate now declines on the same two at hardware.py:4210 and returns an empty set. Covered by test_gpu_device_ordinal_renumbers_the_map_away and test_stacked_rocr_and_cuda_masks_renumber_the_map_away.

P2 gate ROCr translation on a confirmed ROCm backend: taken. Schedulers export both families of visibility variable, so a Linux NVIDIA node can inherit a ROCR mask that means nothing there, and translating against it moved the CUDA pin to a different card. ROCm is now settled from the build at hardware.py:4891 (IS_ROCM, else torch.version.hip or rocm in __version__) before anything is written, and the translation at :4909 only runs behind it. test_a_stale_rocr_var_on_nvidia_does_not_move_the_pin pins your exact example.

The HIP mirror below it keeps the wider env-var test on purpose. Writing HIP_VISIBLE_DEVICES on a host that turns out to be NVIDIA is inert, whereas a missed mirror strands a ROCm worker, so the two want different thresholds.

P2 fail open when any device architecture is unreadable: not taken.

The remedy costs more than the case it fixes. On your three-GPU host, skipping the unreadable device leaves that card exactly as eligible as it was before this gate existed. Returning an empty set instead puts the known-uncovered card back alongside it, so the reported failure comes back on a host we can positively identify, in order to maybe help one we can't read at all. That trades a certain regression for a speculative fix.

Also merged main. The branch had drifted from f849da3e47. Tests are 45 passing, and each new assertion is mutation-checked: dropping the renumbering guard fails both renumber tests, ungating the translation fails the NVIDIA test, and applying the whole-probe remedy fails both unreadable-device cases.

@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

ci failures unrelated to pr
Uploading image.png…

@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

ci failures unrelated to pr
image

chatgpt-codex-connector[bot]

This comment was marked as resolved.

The branch was behind main, so the Python 3.13 red was staleness rather than
content: the failures named the OpenAI responses adapter, async singleton
access and parallel slot routing, none of which this PR touches. Merging main
so the checks mean something. No conflicts.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 28, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 28, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Aug 31, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-01T03:35:25.042522Z 2ed2277 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Comment-only pass over the two files this PR adds to. Comment lines among
the PR's added lines go from 211 to 63, a 70 percent reduction.

Deleted rather than reworded: docstrings that restated a helper signature
or a test name, pointers to other code, development narrative, and
measured detail belonging in the PR description. Long narrative
docstrings collapse to the constraint they carry.

Survivors are correctness constraints the code does not state, issue
citations, and the wrong-alternative cases the gate exists to avoid: the
ROCr translation example and why clearing the mask is the wrong fix, the
build-not-env-var predicate in apply_gpu_ids, the stacked ROCR and CUDA
ordinal arithmetic, and the detection fixture that prevents a cross-test
IS_ROCM leak.

comment_tools.py check --changed --strip-docstrings verifies no code
changed. tests/test_training_gpu_arch_gate.py passes, 45 tests.
@danielhanchen

Copy link
Copy Markdown
Member

Consolidating my earlier comments on this PR into one summary, and deleting the rest to keep the thread reviewable.

Validated on real AMD hardware (gfx1151 Strix Halo)

leg verdict how the defect was produced
Detection CONFIRMED unspoofed: AMD's real gfx110X-all wheel does not cover this gfx1151, and a real matmul dies device kernel image is invalid, the error from #8792
Selection CONFIRMED base ranks the uncovered device first on free VRAM and selects it; head excludes it and keeps the real card
Non-regression CONFIRMED a covered single-GPU host selects and masks identically at base and head, under every visibility mask
Fail-open CONFIRMED an all-uncovered host keeps its GPU rather than being sent to CPU

The selection leg ran against two devices torch genuinely enumerates: torch.cuda.device_count() and torch._C._cuda_getDeviceCount() both report 2, and both devices hold real tensors and run real kernels. Two things are still fabricated and worth stating plainly: the arch string presented for device 1, and the amd-smi binary on the selection leg only, because hardware.py enumerates through amd-smi rather than torch. The gate leg needs neither.

Not shown, and it needs hardware: a model actually sharding across two physical AMD GPUs of different architectures. The second device here is the real GPU wearing another number, so memory and compute are shared.

Two things I changed on the branch

  • d83bbeb7 fixed the new test file leaking IS_ROCM = True into the rest of the pytest session. Reproducible on a plain NVIDIA box by reordering two files.
  • The comment pass above is comment-only, verified by comment_tools check and independently at AST level.

One open question for you, not more testing

_CONCRETE_GFX_ARCH rejects the arch list whole if any token is non-concrete. On this runner rocminfo reports the GPU advertising both gfx1151 and gfx11-generic code objects, so a wheel whose get_arch_list() carries a generic token is a real possibility on ROCm 6.4+, and the gate would then never fire. The shipped wheel does not trigger it. Worth deciding whether fail-open is the right answer there or whether concrete tokens should be filtered out of a mixed list rather than voiding it.

Separately: this PR also rewrites apply_gpu_ids() to translate CUDA_VISIBLE_DEVICES through a new _rocr_relative_visibility(), which changes visibility semantics for every ROCm host including single-GPU ones. That is beyond the title and is a maintainer call rather than a test result.

torch.cuda.device_count() is frozen at the first torch.cuda call, but
_get_parent_visible_gpu_spec() re-reads the visibility vars on every call. Once
apply_gpu_ids() narrows the mask in a process that has already touched
torch.cuda, the gate sees more ordinals than the mask has ids, and
physical_ids[ordinal] if ordinal < len(physical_ids) else ordinal quietly
switches namespace for the overflow.

With HIP_VISIBLE_DEVICES=2,0 and three live ordinals that names ordinal 2 as
physical 2, which is the covered card sitting at ordinal 0. The gate then
returns {0, 2}, _covered() removes every visible id, and auto_select_gpu_ids
returns [] in fallback_all. An empty list is not "inherit parent visibility",
it is "no GPU", so a working two-card host trains on CPU. Verified on a real
NVIDIA box that device_count() does not follow a later CUDA_VISIBLE_DEVICES
change, so the precondition is reachable rather than theoretical.

Bail out instead when the ordinals outnumber the ids: without a total
ordinal -> id map the probe cannot name anything back, and failing open is what
the rest of this function already does.

Also count the all-uncovered guard in ordinals. It compared len(unsupported),
a set of ids, against a count of devices, so a mask naming one id twice ("0,0")
read two rejected devices as one and let the drop-everything case through.

48 pass, and the three new tests fail with either hunk reverted.
The previous commit bailed out whenever torch reported more ordinals than the
visible spec had ids. That is right when a mask is in play, but with no mask at
all the ids come from get_physical_gpu_count(), which on ROCm is amd-smi, and
amd-smi routinely does not enumerate the integrated GPU. unslothai#8792 is a 7800 XT
next to a 7600X iGPU, so the reported host is exactly the one where amd-smi
returns 1 while torch sees 2, and bailing there would disable the fix on it.

Unmasked there is no renumbering, so ordinal is the physical id by construction
and the list can simply be extended. Keep the bail-out for the masked case,
where the two really are different namespaces.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

pre-commit-ci Bot and others added 3 commits September 1, 2026 01:23
An unreadable device is still selectable, so it is not part of "every device
is uncovered": bailing out then handed the known-uncovered card back to the
picker even though another GPU remained and nothing would have forced CPU.

Stop re-translating ids that already went through an inherited CUDA mask.
rocclr reads CUDA_VISIBLE_DEVICES as the HIP-layer mask when
HIP_VISIBLE_DEVICES is empty (rocclr/device/rocm/rocdevice.cpp:391), so with
ROCR_VISIBLE_DEVICES=1,0 and CUDA_VISIBLE_DEVICES=1 the parent had already
indexed the ROCr agents once. Translating again resolved to ROCr agent 0,
which is the physical GPU the parent hid.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 1, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 1, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 1, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 1, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 1, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 1, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Sep 1, 2026
@unslothai unslothai deleted a comment from LeoBorcherding Sep 1, 2026
@unslothai unslothai deleted a comment from LeoBorcherding Sep 1, 2026
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 55c8537f58

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

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.

[Bug] AMD: training auto-selection picks a gfx1036 iGPU the torch wheel has no kernels for — "CUDA error: invalid kernel file"

3 participants