Skip to content

Unsloth Studio (AMD, Windows): don't treat a GPU whose multi-arch kernel pack is missing as covered - #13231

Merged
danielhanchen merged 1 commit into
mainfrom
studio-amd-multiarch-kpack-gate
Oct 11, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
studio-amd-multiarch-kpack-gate

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

The problem

On Windows, Studio installs AMD's multi-arch PyTorch with only the device pack for the GPU it chose: torch[device-gfx1101]==2.11.0+rocm7.14.0 on a Ryzen desktop with an RX 7800 XT. Each device pack adds one file, torch/.kpack/torch_gfxNNNN.kpack, and libtorch_hip loads kernels from ../.kpack/torch_@[email protected]. So the gfx1036 integrated GPU next to that card has no torch kernels.

The training / Transformers arch gate from #8791 (rocm_gpu_ids_without_torch_kernels) decides coverage from torch.cuda.get_arch_list(). In the multi-arch build that list is compiled in and names every arch the build supports, whether its pack is installed or not. Read from the 2.11.0+rocm7.14.0 wheel's libtorch_python:

gfx1010 gfx1011 gfx1012 gfx1030 gfx1031 gfx1032 gfx1033 gfx1034 gfx1035 gfx1036 gfx1100 gfx1101 gfx1102 gfx1103 gfx1200 gfx1201 gfx1150 gfx1151 gfx1152 gfx1153 gfx908 gfx90a gfx942 gfx950 gfx1250

So on Windows the gate reads the iGPU as covered, automatic selection can put a training run on it, and an explicit pick of it is not refused. That is the failure #8792 fixed for the Linux family wheels, back on the Windows route. It is reachable on the #8847 host: the iGPU's free reading is Windows' shared pool, half of system RAM, so on 32 GB or more it ranks level with or above a 16 GB card.

The change

_torch_kernel_pack_arches lists the installed torch_gfxNNNN.kpack files when torch has a .kpack directory. Both the coverage gate and the "has kernels for ... only" message intersect get_arch_list() with that set. It fails open, exactly like the existing gate:

  • no .kpack directory (pytorch.org wheels, AMD family wheels, Linux): no change
  • an empty directory, no pack files, or a pack name that is not a concrete arch (a family pack such as torch_gfx110x.kpack could cover devices no token names): no change
  • every device uncovered: the existing guard still leaves selection alone

Tests

studio/backend/tests/test_training_gpu_arch_gate.py::TestMultiArchKernelPacks, with the multi-arch arch list above and a real .kpack directory:

case main this branch
gfx1036 iGPU + gfx1101, only torch_gfx1101.kpack iGPU kept iGPU dropped
explicit pick of that iGPU accepted refused, "kernels for gfx1101 only"
both packs installed nothing dropped nothing dropped
no .kpack dir / empty dir / family pack / no pack files nothing dropped nothing dropped

The first two fail on main and pass here; the others pass on both. test_gpu_selection.py, test_gpu_selection_sandbox.py, test_training_gpu_arch_gate.py, test_training_vram_coexistence.py, test_rocm_multi_gpu_vram_system_wide.py, test_rocm_live_telemetry_hip_ids.py and test_chat_load_during_training.py: 415 passed.

On real hardware

AMD Windows 11 runner, Radeon 8060S (gfx1151), Python 3.12. torch[device-gfx1100]==2.11.0+rocm7.14.0 from AMD's multi-arch index, so this GPU has no kernel pack, the same shape as an iGPU beside the card the install chose. One process per checkout:

kernel packs (a * 2 + 1).sum() on the GPU coverage reading says the GPU is covered
main torch_gfx1100.kpack hipErrorInvalidImage ("device kernel image is invalid") all 22 arches of get_arch_list() yes
this branch torch_gfx1100.kpack hipErrorInvalidImage gfx1100 no
this branch, after pip install amd-torch-device-gfx1151 torch_gfx1100.kpack, torch_gfx1151.kpack 12288.0, matmul 262144.0 gfx1100, gfx1151 yes

So a missing pack really means a failed launch, get_arch_list() does not reflect it, and the pack files do. The runner has one GPU, so the multi-GPU selection itself is shown by the unit tests above, not here.

Related: #8847, #8792

@danielhanchen danielhanchen self-assigned this Oct 10, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 10, 2026
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 10, 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-10-10T12:21:12.737557Z 87acac9 Manual request
ℹ️ 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.

@danielhanchen

Copy link
Copy Markdown
Member 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: 87acac9f78

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

Comment on lines +5551 to +5555
arch = match.group(1).lower()
# A pack naming a family or generic target could cover devices no token names.
if not _CONCRETE_GFX_ARCH.match(arch):
return None
arches.add(arch)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Validate pack versions before declaring an arch covered

On the Windows multi-arch update path, the existence of this filename does not prove that the pack matches the currently imported torch build. If the selected GPU or pinned ROCm tag changes, installing the new extra can leave an unrelated older amd-torch-device-gfx* distribution—and its .kpack file—in the environment; the installer itself checks device-package version specifiers in studio/install_python_stack.py:418-429 for this reason. This loop nevertheless adds that stale arch to supported, so a GPU using it remains selectable and can fail at kernel launch. Resolve the owning device distribution and verify its version against torch, rather than trusting the filename alone.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Leaving this as is. A stale pack needs both a pinned multi-arch tag bump and a different GPU chosen on the same venv, and on that host main already reads every arch as covered from get_arch_list(), so this reading is never wider than main's. The common case, one pack installed for the chosen card next to an iGPU with none, is what this fixes.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member 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: 87acac9f78

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

Comment on lines +5553 to +5554
if not _CONCRETE_GFX_ARCH.match(arch):
return None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep concrete packs when a family pack is present

On Windows multi-arch installs that contain a family pack alongside the selected leaf pack (for example, torch_gfx110x.kpack plus torch_gfx1101.kpack), this immediately returns None and prevents rocm_gpu_ids_without_torch_kernels() from intersecting the compiled architecture list with any installed packs. The installer explicitly treats family kernel packs as part of a complete device extra (studio/install_python_stack.py:397-435), so this layout can make the new gate inert and leave the reported gfx1036 iGPU selectable even though only the gfx1101 leaf was installed. Preserve the concrete entries while handling or conservatively expanding the family entry instead of discarding the entire inventory.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No published family pack ships a torch_*.kpack: amd-torch-device-gfx110x / gfx115x for 2.11.0+rocm7.14.0, 2.11.0+rocm7.14.1 and 2.12.0+rocm7.14.1 (win_amd64) carry only torch/lib/aotriton.images/amd-gfx1xxx/, and the leaf packs carry the single torch/.kpack/torch_gfxNNNN.kpack. The bail-out only fires on a layout AMD does not ship today, and there it keeps main's behaviour rather than guessing what a family file covers.

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.

1 participant