Repository navigation
Studio: say when a model only partly fits on the GPU - #8812
Conversation
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.
… 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.
…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.
…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.
…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.
…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.
|
Codex Review: Didn't find any major issues. 👍 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
|
Codex Review: Didn't find any major issues. Breezy! Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
…in the widened recipe toast
…split is the user's
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. More of your lovely PRs please. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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". |
From the r/LocalLLaMA review:
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 onblocks a model). The problem is that it happens silently.What was already there
_OFFLOADED_LAYERS_REmatches llama.cpp's ownoffloaded N/M layers to GPU, andclassify_gpu_offload_linesreduces it tooffloaded_at_max > 0. That is the correct answer to "did the GPU work at all", and it is why12/60and60/60are indistinguishable everywhere downstream.On the wire,
gpu_layersis the request, so in Auto mode it is always-1. Studio does not pick the split:_select_gpusdecides the model does not provably fit, returnsuse_fit, and llama.cpp's--fit onchooses 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_vramshrinks 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_countskeeps(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 modeloffloaded_layers/offload_total_layers, cleared on unloadlogger.warningserver-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
INFOto verbosity 4 (trace) while the default threshold stays 3. Sooffloaded N/M layers to GPU, thedevice_infotable and theCUDA0 model buffer sizelines 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_capabilitiesreportssupports_trace_verbosityonly when--helppositively lists4: traceunder--verbosity. It fails closed, so older or customLLAMA_SERVER_PATHbuilds, where 4 may be debug, keep today's argv.--verbosity 4, unless the user passed any of-lv,--verbosity,--log-verbosity,-v,--log-verboseor--log-disablein extras, or setLLAMA_ARG_LOG_VERBOSITY.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:
offloaded_layers: 37, offload_total_layers: 37, no warningoffloaded_layers: 13, offload_total_layers: 37, warningNot in this PR
The same investigation found two larger gaps, both left alone as policy changes rather than transparency:
--n-cpu-moe, so a MoE that overflows gets whole-layer spill instead of expert-only offload. Anchor is [Bug]--fit onprevents loading large MoE models like DeepSeek-V4-Flash on consumer hardware; request for UI control over llama-server flags #7022apply_model_memory_policyemits--load-mode mmap+mlock, which keeps mmap on, so CPU-resident tensors stay in pageable memory. Studio's own_LOAD_MODE_RESERVING_VALUESalready excludes that valueVerification
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 bufferthe shared backend double (
tests/llama_backend_double.py) carries the two new bool runtime fields, which it lacked after merging main (/statusanswered 500 intest_chat_shared_resident.py)parse_gpu_offload_countscovered for a split load, the draft-versus-main rule, no counted line, and a zero total, plus a test asserting the boolean genuinely cannot tell12/60from60/60isPartialOffloadcovered for split, full, zero, missing and nonsense countsbackend:
test_llama_cpp_context_fit.py,test_inference_status_route.py,test_inference_status_loaded_gguf.py,test_slot_offload_fit.py-> 92 passedfrontend:
npm test2394 pass / 0 fail,npm run typecheckcleanruff checkclean, pre-push gate PASStest_mcp_server.pyandtest_rag_ocr_fallback.pyfail 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/statusreports asoffloaded_layers: 33, offload_total_layers: 36:The same moment on the full chat page: