Skip to content

Unsloth Studio (AMD): retry an unpinned llama-server arch crash on the cards the build has kernels for - #16513

Merged
danielhanchen merged 8 commits into
unslothai:mainfrom
LeoBorcherding:fix-manual-split-arch-crash
Nov 7, 2026
Merged

danielhanchen merged 8 commits into
unslothai:mainfrom
LeoBorcherding:fix-manual-split-arch-crash

Conversation

@LeoBorcherding

@LeoBorcherding LeoBorcherding commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Reported by a Discord user in the help thread: Windows 11, RX 7900 XTX + Radeon AI PRO R9700 + Ryzen iGPU, a manual GPU split. Every load died with "llama-server crashed at startup ... hide it with ROCR_VISIBLE_DEVICES". The log shows ROCm error: invalid kernel file / current device: 2, and device 2 is the R9700. The installed prebuilt was gfx110X, which has no gfx1201 kernels.

Why nothing caught it

#7670 added two guards for this, and both were skipped:

  • The proactive gate pins llama-server to the covered cards, but only when it can read the build's coverage list (mapped_targets in UNSLOTH_PREBUILT_INFO.json). The log has no Skipping GPU line, so it couldn't.
  • The reactive arch-crash retry runs only when Unsloth pinned the launch (gpu_indices truthy). A manual split with no GPU picked is never pinned.

So all four retries (flash-attn off, no MTP, CPU projector, text-only) crashed the same way. Then the hint pointed at ROCR_VISIBLE_DEVICES, which masks nothing on Windows.

What changes

  • For an unpinned launch, the arch-crash retry now names the crashed card from llama-server's own current device: N, mapped through any inherited mask. It drops that card, and a shared-memory iGPU when a discrete card remains, then respawns with the positional --tensor-split removed. This is the respawn fix(amd): gate ROCm GPU selection and crash recovery on the build's arch coverage #7670 already uses for pinned launches, unchanged. ROCm only: an unmasked CUDA child orders devices by speed, so its ordinal isn't our id.
  • The dropped split is recorded in _arch_gate_dropped_tensor_split, as the proactive gate does, so the next Apply doesn't reload.
  • The Windows HIP crash hint names HIP_VISIBLE_DEVICES.

Tests

The new tests are red on base and green on head: 11 failed / 10 passed vs 21 passed. They're TestUnpinnedArchCrashRetry, the Windows hint case, and a call-site pin that an unpinned launch reaches the retry and records the drop. Across the related suites (arch gate, crash message, companion widening, placement, load-mode matrix, sidecar reserve, auto tensor split), 2600 pass. Four fail on a macOS box and fail identically on base: test_spec_sidecar_fit_reserve_multi_gpu x3 and test_the_launch_env_masks_the_child_to_them.

Hardware

No hosted runner has an AMD GPU. The Strix Halo runner on oobabooga's fork is one gfx1151 APU on Linux, so it can't put a covered and an uncovered discrete card in one Windows box. This table is the test report. Rows A to E: Windows 11, 2x Radeon AI PRO R9700 (gfx1201) + Radeon iGPU (gfx1036), ROCm b11985 prebuilts, Qwen3-0.6B Q4_K_M, gpu_layers=999, tensor_split=1,1,1. Rows F and G: Windows 11, RX 5700 XT (gfx1010, uncovered) + RX 6500 XT (gfx1034, covered), the b11985-mix-c116c32 gfx103X build through LLAMA_SERVER_PATH (no coverage file, so the gate can't read it), SmolLM2-135M Q4_K_M, gpu_layers=999, tensor_split=1,1, same env for both with only llama_cpp.py swapped.

run code llama.cpp build coverage list result verified
A base 073f6e0 gfx120X readable gate skips GPU 2, pins [0, 1], loads and chats measured
A2 base gfx120X emptied loads; llama.cpp itself leaves the iGPU out when a dGPU is present measured
B base gfx110X emptied device kernel image is invalid on device 0, no arch retry, load fails (the reported crash) measured
C head 31d4231 gfx110X emptied "kernel-image error on GPU(s) [0] ... Retrying on GPU(s) [1]", split dropped, iGPU excluded; GPU 1 is also uncovered, so the load still fails measured
D head gfx120X readable same as A, no regression measured
E head gfx120X emptied same as A2, no regression measured
F base 073f6e0 gfx103X unreadable invalid kernel file on device 0 (5700 XT), only the no-flash retry, same crash, load fails (HTTP 500) measured
G head 186046e gfx103X unreadable same crash, then the arch-crash retry on the 6500 XT alone: loads and chats. The reporter's shape, one covered + one uncovered card measured

Server log, run B (base):

GPUs free: [] (manual mode), selected: None, --fit: off
[llama-server] E ROCm error: device kernel image is invalid
[llama-server] E   current device: 0, in function ggml_cuda_kernel_launch at ggml-cuda\common.cuh:1740
llama-server exited with code 3221226505.
llama-server hard-crashed at startup (exit 3221226505) with flash attention on; retrying once with --flash-attn off
[llama-server] E ROCm error: device kernel image is invalid
llama-server exited with code 3221226505.
Error loading model: llama-server failed to start.

Server log, run C (head):

GPUs free: [] (manual mode), selected: None, --fit: off
[llama-server] E ROCm error: device kernel image is invalid
[llama-server] E   current device: 0, in function ggml_cuda_kernel_launch at ggml-cuda\common.cuh:1740
llama-server exited with code 3221226505.
llama-server crashed with a HIP kernel-image error on GPU(s) [0] -- the llama.cpp build has no kernels for that arch. Retrying on GPU(s) [1].
Dropped --tensor-split for the arch-crash retry: its shares are positional over the visible devices and the narrowed set re-indexes them.
[llama-server] E ROCm error: device kernel image is invalid

Bottom line: on real hardware, the crash reproduces on base, and on head the retry drops the uncovered card and the load recovers on the covered one (run G). Not run: Linux ROCm with a mixed pair, where the retry masks through ROCR_VISIBLE_DEVICES and reads current device through that re-indexing.

Still unknown: whether the reporter's gate failed because the install file predates mapped_targets or because the per-card arch lookup came back empty on Windows. The retry covers both.

… have kernels

A manual GPU split, or an arch gate that cannot read the installed build's
coverage, launches llama-server with no device mask. When a card the build
has no kernels for takes part of the split, the child dies with
"invalid kernel file" and the existing arch-crash retry skips it because it
only handles pinned launches, so every fallback crashes the same way.

Name the crashed card from the child's own "current device: N", drop it
(and a shared-memory iGPU when a discrete card remains), and respawn on the
rest with the positional --tensor-split removed. The Windows crash hint now
names HIP_VISIBLE_DEVICES, since ROCR_VISIBLE_DEVICES masks nothing there.
A manual split pins the child's GPU order and the arch gate can pin it to
its survivors without setting gpu_indices, so "current device: N" indexes
that mask rather than the parent's. Also refresh the retry comment and keep
f only on the hint segment with a placeholder.
…ser device pick

An inherited UUID/MIG mask resolves to no ids, so the child's ordinal can't be
read as a physical id without risking a hidden card; and a user --device or
LLAMA_ARG_DEVICE numbers cards by the unnarrowed set, which narrowing would
re-point. Both now keep the original error.
… LLAMA_ARG_MAIN_GPU

GPU_DEVICE_ORDINAL filters HIP ordinals without showing up in the mask
readers, and an inherited LLAMA_ARG_MAIN_GPU survives into the respawn,
where narrowing would point it at a different card.
@LeoBorcherding

LeoBorcherding commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator Author

Pushed 186046e.

The unpinned retry now maps llama-server's current device: N through the child's own mask (_child_gpu_physical_ids) instead of the parent's. A manual split's order pin and the arch gate's survivor pin both mask the child without setting gpu_indices, so the parent's numbering could name the wrong card.

The retry now keeps the original error instead of guessing when the card can't be named safely:

  • an inherited UUID or MIG mask with no child mask of its own;
  • GPU_DEVICE_ORDINAL set;
  • a user --device / --main-gpu, or LLAMA_ARG_DEVICE / LLAMA_ARG_MAIN_GPU, on an unpinned launch.

Each of these would otherwise renumber the child's devices out from under it.

The Windows hint keeps f only on the segment with a placeholder. Five tests added: 2605 pass in the related suites, plus the same four that fail on base on macOS.

The hardware runs in the body were measured at 31d4231. The changes since then only narrow when the retry fires, and none of them applies to that box (no inherited mask, no GPU_DEVICE_ORDINAL, no device selector), so runs B–E still describe this head.

@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

Codex is clean at 186046e (on the fork mirror, LeoBorcherding/unsloth#706).

@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author
image

@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

CI is clean on the fork mirror at 186046e (LeoBorcherding/unsloth#706): 50 pass. The only failures are the ones main has too (Core zoo test_quantized_decode_keeps_each_rows_padding_mask, Repo tests studio test_no_raw_pixel_text_utilities), and Chat UI Tests hit the fork runner's timeout, while the same job passed here at this commit.

@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

Ran this on tester at 186046e: Windows 11 25H2, RX 5700 XT (gfx1010, uncovered) + RX 6500 XT (gfx1034, covered), llama.cpp b11985 gfx103X, SmolLM2-135M. That's the covered + uncovered pair the hardware table was missing.

Verdict: each piece of the fix works on the reporter's shape. Not yet run: one Unsloth Studio-driven load end to end.

  • Unpinned launch, both cards visible: ROCm error: invalid kernel file, current device: 0, aborts. Base has no retry for this.
  • _unpinned_arch_crash_retry on that real log with real ROCm torch: ([0], [1]).
  • The retry's Windows env (HIP_VISIBLE_DEVICES=1 CUDA_VISIBLE_DEVICES=1, split dropped): only the 6500 XT enumerates; loads and chats.
  • With a readable coverage list, base already skips GPU 0, so this only matters when the list can't be read.
  • PR tests on that box: head 338 passed; base llama_cpp.py under head's tests 16 failed.
hardware shape changed by this PR what ran still needed
covered + uncovered discrete, Windows yes tester at 186046e: crash, retry picks [1], retry env loads one Unsloth Studio manual-split load with the list unreadable
two uncovered + iGPU, Windows yes R9700 box at 31d4231 (runs B, C in the body) nothing
readable coverage list no tester; R9700 runs A, D, E nothing
NVIDIA / CUDA no (_host_torch_is_rocm() early return) mocked test only nothing on hardware
Linux ROCm, mixed discrete yes (ROCR_VISIBLE_DEVICES path) not run a Linux box with one covered and one uncovered card

Full results: LeoBorcherding#706 (comment)

@LeoBorcherding

Copy link
Copy Markdown
Collaborator Author

Ran the remaining row on a Windows box with a covered and an uncovered card: RX 6500 XT (gfx1034) + RX 5700 XT (gfx1010), Windows 11, llama.cpp b11985-mix-c116c32 gfx103X pointed at through LLAMA_SERVER_PATH (so the gate can't read its coverage), SmolLM2-135M Q4_K_M, manual split 1,1. Same env both times, only llama_cpp.py swapped.

base 073f6e0 head 186046e
first launch invalid kernel file, current device: 0 (5700 XT) same
retry no-flash retry only, same crash arch-crash retry on the 6500 XT alone
result load fails, HTTP 500 loads, chat replies

This is the reporter's situation (one card the build covers, one it doesn't), and the fix recovers it end to end in Unsloth Studio.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 7, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-07T14:06:10.825857Z fbdeb55 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.

@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: 781d21ee4a

ℹ️ 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 +31593 to +31595
_crashed, _remaining = self._unpinned_arch_crash_retry(
_arch_crash_tail, _enumerated, _child_gpu_physical_ids
)

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 Remap companion device selections on the unpinned retry

For an unpinned manual ROCm load with --mmproj-device ROCm1 or --spec-draft-device ROCm1, a kernel-image crash on GPU 0 now retries with only physical GPU 1 visible, but retains ROCm1 in argv. The existing _widen_pin_ids_for_companion_devices contract says these tokens use “unpinned numbering,” so the surviving selector must become ROCm0. _cache_target_unknown checks only main-device flags, while _companion_fit_mask remains None on the unpinned path, so the subsequent companion refit is skipped. This leaves an invalid device selector—or selects the wrong GPU with a larger surviving set—and defeats recovery despite the selected companion GPU being usable. Preserve and remap companion selections against the original child order, or decline narrowing when those selections cannot be preserved.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in a0da6cb: the unpinned retry now hands the companion refit the child's device order, so a ROCm companion on a surviving card is renumbered (test_a_companion_device_on_the_survivor_is_renumbered).

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@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: a0da6cb784

ℹ️ 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 +31599 to +31602
and any(
_flag_name(str(tok)) in flags
for tok in cmd
for flags in _COMPANION_DEVICE_FLAG_GROUPS

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 Remap the environment-selected projector before narrowing

For an unpinned two-GPU ROCm vision load with MTMD_BACKEND_DEVICE=ROCm1, a kernel-image crash on GPU 0 now retries with only physical GPU 1 visible, but this argv-only check leaves _companion_fit_mask unset and the environment value unchanged. The argv fix does not cover this environment fallback, which the existing projector-placement code recognizes at llama_cpp.py:27135-27142. The survivor is now ROCm0, so the retained projector selector is invalid, defeating recovery despite its chosen GPU being usable. Remap the environment-selected projector through the child's original device order too, or decline narrowing when that selection cannot be preserved.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed in fbdeb55: a GPU MTMD_BACKEND_DEVICE now opts the unpinned launch out of narrowing like LLAMA_ARG_MAIN_GPU, so its original error stands (test_a_user_device_env_keeps_its_error).

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Swish!

Reviewed commit: fbdeb55198

ℹ️ 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 95c5d58 into unslothai:main Nov 7, 2026
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.

2 participants