Skip to content

Unsloth Studio (AMD/ROCm): warn about, and refuse, a GPU the installed PyTorch has no kernels for - #11571

Merged
danielhanchen merged 8 commits into
unslothai:mainfrom
LeoBorcherding:fix/studio-explicit-gpu-without-kernels
Sep 25, 2026
Merged

danielhanchen merged 8 commits into
unslothai:mainfrom
LeoBorcherding:fix/studio-explicit-gpu-without-kernels

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Sep 22, 2026 •

Copy link
Copy Markdown
Collaborator

fixes #11569

The problem in plain words

On AMD, PyTorch ships its GPU code ("kernels") pre-compiled per card family, and the Unsloth Studio installer picks one family from the card it sees at install time. If a second AMD card from another generation is in the box, the installed PyTorch has no code for it. Unsloth Studio still lists that card like any other ROCm GPU and lets you pick it for training, and the job then dies on its first operation.

This came from an RX 6500 XT (RDNA2, gfx1034) next to an RX 5700 XT (RDNA1, gfx1010) on the gfx103X-all wheels:

kernels built for: gfx1030, gfx1031, gfx1032, gfx1033, gfx1034, gfx1035, gfx1036
GPU 0: AMD Radeon RX6500 XT   | gfx1034        | 3.98 GiB
GPU 1: AMD Radeon RX 5700 XT  | gfx1010:xnack- | 7.98 GiB

pick GPU 1 -> torch.AcceleratorError: CUDA error: device kernel image is invalid

Automatic selection is already safe: rocm_gpu_ids_without_torch_kernels() has dropped such cards since #8792. The manual path never asked it. And with 8 GB free on the 5700 XT against a nearly full 6500 XT, the manual pick is the natural one.

What this PR does

  • Refuses the pick with a real message. prepare_gpu_selection() runs explicit ids through the same gate and raises the ValueError the route already turns into a 400:

    GPU 1 (AMD Radeon RX 5700 XT, gfx1010) cannot run the PyTorch build this Unsloth Studio installed, which has kernels for gfx1030, gfx1031, gfx1032, gfx1033, gfx1034, gfx1035, gfx1036 only. Pick another GPU, or reinstall Unsloth Studio for that card.
    
  • Tells the UI. get_backend_visible_gpu_info() stamps each physical GPU row with torch_kernels: true|false. Vulkan rows get no verdict, those ordinals belong to llama.cpp, not PyTorch.

  • Shows it in the GPU picker. That is the GPUs list in a model's load settings (the panel with GPU Layers; training itself has no picker and always uses automatic selection, which already skips such cards). There the card reads GPU 1: AMD Radeon RX 5700 XT · 8 GiB · no kernels in this PyTorch build, the tooltip explains it, and the switch will not turn on. If a saved selection already named the card before the wheels changed, it can still be switched off.

The gate itself is unchanged, so everything it fails open on (a remapped ordinal space, an unreadable arch, a build that covers nothing) still fails open here. No card is newly hidden; only a card auto-selection already refuses is now refused when picked by hand, with an explanation.

Not in this PR

setup.ps1 picks the wheel family from the first enumerated card and only prints a warning when that card is an integrated GPU (Resolve-ShadowingGfxPick). Two discrete cards from different families get no message, so the install log never says the second card is not covered. That is a separate change and is listed in #11569.

Tests

New TestExplicitPickWithoutTorchKernels in tests/test_gpu_selection.py: an uncovered manual pick is rejected with the card and the arch list in the message, a covered pick next to an uncovered card is accepted, a host where everything is covered is untouched, inventory rows carry the flag and Vulkan rows do not, an empty inventory never calls the gate.

tests/test_gpu_selection.py + test_gpu_selection_sandbox.py on this Windows ROCm PC: 114 passed, 10 failed, and the same 10 fail on untouched main here (they assume a mocked host and this one has two real ROCm cards). Frontend: tsc -b shows no errors in the four touched files (the remaining errors are missing optional modules in a borrowed node_modules), eslint is clean on the three hooks, and the pre-existing findings in model-config-page.tsx are all outside the changed lines.

Run against the real two-card PC with the patched backend on the path:

gate says uncovered: [1]
gpu_ids=[1]    -> 400: GPU 1 (AMD Radeon RX 5700 XT, gfx1010) cannot run the PyTorch build this Unsloth Studio installed, which has kernels for gfx1030, ... gfx1036 only. Pick another GPU, or reinstall Unsloth Studio for that card.
gpu_ids=[0]    -> accepted [0] (explicit)
gpu_ids=[0, 1] -> 400, same message
inventory rows: [{"index": 0, "name": "AMD Radeon RX6500 XT", "torch_kernels": true}, {"index": 1, "name": "AMD Radeon RX 5700 XT", "torch_kernels": false}]

The picker label is typechecked and present in the served bundle of a branch build, but not yet clicked through in the running app, hence the draft.

Status

Rebased on current main (includes #11615). Backend behaviour re-checked live on a per-branch Unsloth Studio (stock gfx103X torch, both cards present): get_backend_visible_gpu_info() marks the RX 5700 XT torch_kernels: false, reject_gpu_ids_without_torch_kernels([1]) raises the message quoted above, and the served frontend chunk carries the label and the torchKernels field. Once #11755 lands and a box has the multi-arch torch, both cards are covered and this PR's label never appears there, which is the intended outcome: it only speaks up for a card the installed build genuinely cannot run.

Two discrete AMD cards from different generations look identical in the
GPU picker, but the ROCm torch wheel Studio installs carries kernels for
one family only. Auto-selection has skipped the uncovered card since
unslothai#8792; an explicit pick went straight to the worker, which died on its
first tensor with hipErrorInvalidImage ("device kernel image is
invalid").

prepare_gpu_selection now runs explicit ids through the same
rocm_gpu_ids_without_torch_kernels() gate and raises the ValueError the
route already turns into a 400, naming the card, its gfx target and the
targets the wheel was built for. The backend-visible inventory stamps
each physical row with `torch_kernels`, and the training picker shows
"no kernels in this PyTorch build" on such a row and will not switch it
on; a saved selection that already names it can still be switched off.

Found with an RX 6500 XT (gfx1034) next to an RX 5700 XT (gfx1010) on
gfx103X-all wheels. Vulkan rows carry no verdict: those ordinals are
llama.cpp's, not torch's.
@LeoBorcherding LeoBorcherding changed the title Studio: refuse and label a GPU the installed torch has no kernels for Unsloth Studio (AMD/ROCm): warn about, and refuse, a GPU the installed PyTorch has no kernels for Sep 22, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Confirmed that a manual pick in prepare_gpu_selection skips the check automatic selection already applies, so an unsupported second AMD card still gets offered. Will get this reviewed once it is out of draft.

@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

status for review: rebased on current main (has #11615). backend re-checked live on a per-branch Unsloth Studio with the stock gfx103X torch and both cards present: the inventory marks the RX 5700 XT torch_kernels false, a manual pick of it is refused with the message in the description, and the served frontend chunk carries the new label and field. what i have not done is click the greyed-out row in a running app, only read it out of the built bundle, so treat the frontend half as typechecked and bundled rather than clicked. with #11755 in, a box with the multi-arch torch never shows the label, which is the intended outcome. marking ready since the backend half is what changes behaviour.

@LeoBorcherding
LeoBorcherding marked this pull request as ready for review September 24, 2026 07:09

@LeoBorcherding LeoBorcherding left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Codex findings, via a mirror

Codex does not answer on this repository, so it ran against a copy of this pull request's commits at LeoBorcherding/unsloth-staging-review#14. It looked at 90c4c9e918 there, which is this PR's b9e1ba54b replayed onto main 89ed32d6e. Nothing was reviewed or resolved on the copy: the findings are here, in Codex's words, to be worked through on this pull request.

2 findings, inline below where the line is on this diff.

className="min-w-0 truncate text-ui-12 text-muted-foreground"
title={
d.torchKernels === false
? "The installed PyTorch build has no kernels for this card, so a job pinned to it fails on its first tensor. Reinstall Unsloth Studio for this card to use it."

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

P2 Base the GGUF picker on llama.cpp kernel coverage

This picker is rendered only through GgufAdvancedSettings for GGUF loads, so these IDs control llama.cpp rather than PyTorch. The llama backend determines ROCm compatibility independently from the binary's mapped_targets in _installed_llama_gfx_archs; therefore, when the PyTorch wheel omits an architecture that an installed/custom llama.cpp binary supports, this condition falsely labels and disables a usable GPU. Surface coverage for the runtime being configured instead of applying torch_kernels here.

Codex's original comment: https://github.com/LeoBorcherding/unsloth-staging-review/pull/14#discussion_r4093054264

disabled={
(isGpuChecked(d.index) && singleGpuInUse) ||
(!isGpuChecked(d.index) && d.torchKernels === false)
}

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

P2 Prevent leaving a flagged GPU as the sole selection

When selectedGpuIds is null, every device is considered checked and singleGpuInUse is false on a multi-GPU host. With one supported and one flagged card, the user can therefore uncheck the supported card first, committing only the flagged ID; this condition then disables that remaining switch because it is the sole checked device. The resulting load is explicitly pinned to the very card this guard intends to prevent selecting, so the implicit selection must exclude flagged cards or removing the final supported card must be blocked.

Codex's original comment: https://github.com/LeoBorcherding/unsloth-staging-review/pull/14#discussion_r4093054273

danielhanchen and others added 2 commits September 25, 2026 08:02
The picker is only rendered for GGUF loads, which run on llama.cpp and never
reach the torch kernel gate, so it greyed out cards llama.cpp can serve. Drop
the lock, its label and the inventory stamping that only fed it; explicit
torch loads are still refused in prepare_gpu_selection.
@shimmyshimmer

shimmyshimmer commented Sep 25, 2026 •

Copy link
Copy Markdown
Member

Review record for #11571, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#84.

Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found.

Round 1 — reviewed mirror f4f5c9037b (this PR's 552b81c14)

chatgpt-codex-connector[bot] (on the mirror)

🛡️ Codex Security Review

Security review completed. No security issues were found in this pull request.

Reviewed commit: f4f5c9037b

View security finding report

Only the user who started this review can view the report in Codex.

No triage reaction was recorded on the mirror

chatgpt-codex-connector[bot] (on the mirror)

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: f4f5c9037b

No triage reaction was recorded on the mirror

Verdict

The round converged at mirror f4f5c9037b (this PR's 552b81c14).

This is the review as it stood at that commit. Anything pushed to this PR afterwards was not part of it.

_describe_rocm_gpus read gcnArchName only, so on AMD SDK / Radeon wheels the
message dropped the arch the gate had just judged. Share the gate's own
attribute fallback so the label and the verdict read the same field.
danielhanchen added a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 25, 2026
@danielhanchen
danielhanchen merged commit 4c17ada into unslothai:main Sep 25, 2026
36 of 40 checks passed
shaojun pushed a commit to shaojun/unsloth that referenced this pull request Sep 29, 2026
…kernels for (unslothai#11571)

An explicit gpu_ids pick of a ROCm card the installed PyTorch has no kernels for (for example an RX 5700 XT, gfx1010, beside an RX 6500 XT on the gfx103X wheels) went straight to the worker, which died on its first tensor with hipErrorInvalidImage. Auto-selection has skipped such cards since unslothai#8792; prepare_gpu_selection now runs explicit ids through the same gate and raises the ValueError the routes already return as a 400, naming the card, its arch and the arch list the wheel was built for.

The gate is unchanged, so every case it fails open on (masked or remapped ordinals, unreadable arch, a build that covers no visible card) still fails open. GGUF and diffusion loads do not go through this path and are unaffected.

Fixes unslothai#11569.
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.

Unsloth Studio (AMD/ROCm): a second AMD GPU the installed PyTorch cannot run is still offered for training, and the installer never warns

3 participants