Skip to content

Studio: say when a model only partly fits on the GPU - #8812

Merged
danielhanchen merged 19 commits into
mainfrom
studio-show-partial-offload
Sep 29, 2026
Merged

danielhanchen merged 19 commits into
mainfrom
studio-show-partial-offload

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Aug 14, 2026 •

Copy link
Copy Markdown
Member

From the r/LocalLLaMA review:

many novice users will get burned by ... dense models auto-spilling to RAM

The spill is the right behaviour and this PR does not change it. Refusing instead would break running a large model on a small card, which is exactly what people want partial offload for, and it would regress #7022 (a user with 16 GB VRAM and 112 GB RAM complaining that --fit on blocks a model). The problem is that it happens silently.

What was already there

_OFFLOADED_LAYERS_RE matches llama.cpp's own offloaded N/M layers to GPU, and classify_gpu_offload_lines reduces it to offloaded_at_max > 0. That is the correct answer to "did the GPU work at all", and it is why 12/60 and 60/60 are indistinguishable everywhere downstream.

On the wire, gpu_layers is the request, so in Auto mode it is always -1. Studio does not pick the split: _select_gpus decides the model does not provably fit, returns use_fit, and llama.cpp's --fit on chooses the layer count. So a half-offloaded load was byte-identical to a fully offloaded one, and both got the same green "loaded" toast. The only way to discover it was to notice the model was slow.

The codebase already knows what it costs. _fit_context_to_vram shrinks context, and the serving-slot reducer says so directly: "Prefer fewer serving slots on GPU over --fit on offload: ... decode collapses ~3x (#6718)". It works hard to avoid the spill and then says nothing when it happens anyway.

What changes

  • parse_gpu_offload_counts keeps (offloaded, total) from the same line, using the same largest-M rule so a draft or MTP model's much smaller line cannot be reported instead of the main model
  • recorded on the backend, published as offloaded_layers / offload_total_layers, cleared on unload
  • a logger.warning server-side, and a warning toast: "38 of 60 layers are on the GPU. The rest run on CPU, so generation will be slower. A smaller quantization would fit entirely on the GPU."

Two cases are deliberately excluded. A full offload is the normal case and says nothing. No layers on the GPU is a different failure with its own reporting (the #5106 CPU-fallback path), so folding it in here would double-warn.

Placement is untouched: same decisions, only the reporting. One flag is added, see below.

The offload line is trace-level on current llama.cpp

llama.cpp's "logs : reduce" change (#23021 upstream, in the b11160 prebuilt Studio ships) maps libllama INFO to verbosity 4 (trace) while the default threshold stays 3. So offloaded N/M layers to GPU, the device_info table and the CUDA0 model buffer size lines are no longer printed at all. That silenced this PR's report, and it had already silenced the existing all-CPU classifier (#6339) and the per-GPU model buffer reader, which parse the same lines.

  • probe_server_capabilities reports supports_trace_verbosity only when --help positively lists 4: trace under --verbosity. It fails closed, so older or custom LLAMA_SERVER_PATH builds, where 4 may be debug, keep today's argv.
  • On those builds the launch adds --verbosity 4, unless the user passed any of -lv, --verbosity, --log-verbosity, -v, --log-verbose or --log-disable in extras, or set LLAMA_ARG_LOG_VERBOSITY.
  • Level 4 logs no prompt or reply text (checked with a marker string) and nothing per token. It adds about 200 lines at load and about 30 per request. Decode on a B200 (Qwen3-8B Q4_K_M, 15 requests of 512 tokens per arm, alternating): 216.3 tok/s at level 3 vs 216.8 tok/s at level 4 (medians); prefill 161 vs 159 tok/s.
  • The in-memory stdout buffer was unbounded for the server's lifetime, so it is now capped: the startup head (up to 5000 lines) is always kept, and past 20000 lines the post-startup middle is dropped down to the last 5000.

Real Auto loads on a B200, Qwen3-8B Q4_K_M, with a split forced by holding all but about 3.5 GiB of the card:

load llama.cpp log before (main) after
fits 37/37 no fields offloaded_layers: 37, offload_total_layers: 37, no warning
split 13/37 no fields, plain success offloaded_layers: 13, offload_total_layers: 37, warning

Not in this PR

The same investigation found two larger gaps, both left alone as policy changes rather than transparency:

Verification

  • test_launch_flags_are_capability_gated.py: the trace probe (detected, and closed on older help, a failed probe and no binary), each user opt-out, the emission site, and the bounded buffer

  • the shared backend double (tests/llama_backend_double.py) carries the two new bool runtime fields, which it lacked after merging main (/status answered 500 in test_chat_shared_resident.py)

  • parse_gpu_offload_counts covered for a split load, the draft-versus-main rule, no counted line, and a zero total, plus a test asserting the boolean genuinely cannot tell 12/60 from 60/60

  • isPartialOffload covered for split, full, zero, missing and nonsense counts

  • backend: test_llama_cpp_context_fit.py, test_inference_status_route.py, test_inference_status_loaded_gguf.py, test_slot_offload_fit.py -> 92 passed

  • frontend: npm test 2394 pass / 0 fail, npm run typecheck clean

  • ruff check clean, pre-push gate PASS

test_mcp_server.py and test_rag_ocr_fallback.py fail collection in my environment for missing optional dependencies, identically with and without this branch.

Screenshots

A chat sent with no model loaded auto-loads Gemma 4 E2B (UD-Q4_K_XL) on a B200 held down to about 3.1 GiB free, identically for both sides. The merge base (9970dccb4) is on the left and this branch (f4f2e5696) is on the right, each a fresh install.

The merge base says only that the vision projector went to the CPU. This branch also says 33 of 36 layers are on the GPU, which /api/inference/status reports as offloaded_layers: 33, offload_total_layers: 36:

Toast after the auto-load: merge base on the left, this branch on the right

The same moment on the full chat page:

Chat page after the auto-load: merge base on the left, this branch on the right

Reported as novice users getting burned by dense models auto-spilling to
RAM. The spill itself is right, and refusing instead would break running a
large model on a small card, which is what people want it for. The problem
is that it is silent.

llama.cpp already logs 'offloaded N/M layers to GPU' and Studio already
matches it, then collapses it to a bool, so 12/60 and 60/60 both answer
True. In Auto mode gpu_layers on the wire is -1 because that is the
REQUEST, and Studio does not choose the split: it decides the model does
not provably fit and hands placement to --fit on. So a half-offloaded load
was byte-identical to a full one and got the same green 'loaded' toast,
leaving a stopwatch as the only way to find out.

The counts are kept now, published as offloaded_layers and
offload_total_layers, and a split load gets a warning toast naming the
split and suggesting a smaller quantization. All-on-GPU is unchanged. No
layers on the GPU is left to the existing CPU-fallback path rather than
folded in, so nothing double-warns.

Placement is untouched: same flags, same decisions, only the reporting.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

pre-commit-ci Bot and others added 2 commits August 14, 2026 12:31
… show it on auto-loads too

Two follow-ups from review.

Manual mode is now excluded. When the user pins the split themselves
(gpu_memory_mode == "manual"), llama.cpp reports exactly the layer count they
asked for, so telling them a smaller quantization would fit entirely on the GPU
is advice against their own choice. isPartialOffload now takes gpuMemoryMode and
returns false for it.

The automatic load path now carries the counts. A chat sent with no model loaded
goes through loadAutoLoadCandidate/showAutoLoadSuccess, which never runs the
interactive runtime hook and forwarded only cpu_fallback_reason, so the silent
partial split stayed silent on the one path a new user hits first.
showAutoLoadSuccess takes the counts and both call sites forward them.

The wording moved into partialOffloadDescription so the two paths cannot drift.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…er the other load paths

Four follow-ups from review.

Zero offloaded layers is now a warning rather than an exclusion. It was left
out on the grounds that the CPU-fallback path already reported it, but
cpu_fallback_reason is only ever set for the Vulkan startup-crash recovery, so
an ordinary --fit on load that got nothing onto the GPU announced plain success.
That is the worst version of the problem this change exists for. It gets its own
wording rather than the partial one.

An -ngl passed through llama-server extras now counts as the user's own choice.
Auto mode respects an inherited -ngl instead of stripping it (manual mode is the
one that strips), so gpu_memory_mode alone cannot tell a spill Studio allowed
from a split the user asked for. The backend records whether extras overrode the
placement, beside the counts and from the same extras the load launched with,
and the response carries it as offload_overridden.

Compare mode and recipe runs are covered too. A recipe run loaded its model with
no panel open and toasted plain success unconditionally; compare mode has no
per-pane success toast, but a pane that landed half on the CPU does not just run
slow, it invalidates the comparison being timed, so it warns. All four load
paths now read the split through one shared helper.

The count parser breaks a tie on load order instead of the larger N. Nothing
forces a drafter to have fewer layers than its target, and llama.cpp logs the
main model first, so a fully offloaded 32-layer drafter could otherwise report
32/32 over a main model that got half its layers onto the GPU.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…warning

A --device naming no GPU overrides the layer count outright, so llama.cpp
reports 0/M for a load the user asked to run on CPU. The provenance flag only
covered the layer and fit flags, so that load drew the new all-CPU warning and
was told a smaller quantization would leave room on the GPU.

Reuses _device_selection_is_cpu, which already decides this for the memory
policy and reads the LLAMA_ARG_DEVICE env twin as well as argv.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…r over a known CPU reason

Five follow-ups from review.

A CPU-only host no longer gets the warning. llama.cpp logs "offloaded 0/N
layers to GPU" there like anywhere else, so publishing that count told every
user without a GPU that a smaller quantization would leave room on one they do
not have. The counts are now gated on the same question the classifier asks: a
GPU was detected, the load intended to use it, and it was not a deliberate
CPU-only or arch-gated launch.

Manual mode with GPU Layers on Auto now warns. That configuration hands
placement back to llama.cpp exactly like Auto mode does, but the response still
reads "manual", so suppressing on the mode alone silenced a real automatic
spill. The decision reads the requested count instead.

A --fit on in extras is no longer read as a pinned split. The provenance check
used the wider flag set, which also carries --fit, but --fit on asks llama.cpp
to choose the placement, which is the case worth reporting. --fit off pins
nothing by itself, so the layer flags alone are the right question.

A known reason for the CPU wins over the counts. A recovered Vulkan startup
crash leaves a 0/M line behind it, and the recipe and compare paths read that as
"nothing fit", blaming the model's size for a backend crash and recommending a
quantization that changes nothing. The helper now reads cpu_fallback_reason off
the same response, so every path gets the crash wording without repeating the
precedence rule.

The Audio page is the fifth load path. It loads a GGUF TTS variant and toasted
plain success, so an automatically split TTS model was as silent there as
everywhere else.
chatgpt-codex-connector[bot]

This comment was marked as resolved.

…ed no layers

Both log the same 'offloaded 0/M' line, so a user whose CUDA runtime failed to
resolve was told none of the layers fit and that a smaller quantization would
leave room. Re-downloading a smaller model cannot repair a backend, and the load
already logs the cudart64_X.dll remediation for exactly this state.

llama.cpp prints its device table whenever a GPU backend is visible to it, so an
all-CPU table while Studio itself detected a GPU is the backend failure. That
scan already existed inside classify_gpu_offload_lines as a disconfirmation; it
is now llama_saw_gpu_device, used there and recorded per load as
gpu_backend_unavailable.

The all-CPU warning reads it and says the GPU could not be used, that this is a
backend problem rather than a size one, and points at the llama-server log. A
genuine zero-layer fit keeps the size wording.
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 14, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Aug 14, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

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

Reviewed commit: 0a82461c08

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

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

Copy link
Copy Markdown

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

Reviewed commit: 51fb6400a2

ℹ️ 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 pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 28, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Sep 28, 2026
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Sep 28, 2026
danielhanchen added a commit to Datta0/unsloth-staging-3 that referenced this pull request Sep 28, 2026
chatgpt-codex-connector[bot]

This comment was marked as resolved.

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

Copy link
Copy Markdown
Member Author

@codex review

1 similar comment
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. More of your lovely PRs please.

Reviewed commit: 351b4febb5

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

shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 28, 2026
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 28, 2026
shimmyshimmer pushed a commit to shimmyshimmer/unsloth-staging-4 that referenced this pull request Sep 28, 2026
@danielhanchen
danielhanchen merged commit 01b8b84 into main Sep 29, 2026
61 of 69 checks passed
@danielhanchen
danielhanchen deleted the studio-show-partial-offload branch September 29, 2026 08:29
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