Repository navigation
Studio: name the llama.cpp graph-scheduler abort and stop reloading into it - #6741
Conversation
…en CPU-only / multi-NUMA GGUF inference On a CPU-only host, large MLA / sparse-attention / MTP GGUFs (e.g. GLM-5.2) abort in llama.cpp's graph scheduler (GGML_ASSERT(*cur_backend_id != -1) in ggml_backend_sched_split_graph) because the backend cannot run an op in the graph. Studio showed a generic "invalid GGUF or out of memory" message and, since a startup crash 500s the load, the UI replayed /load and re-read the whole model (hundreds of GB) into the same crash on a loop while sitting at 99%. Changes (all in studio/backend): - Detect the scheduler abort, memo (binary, model) as non-retryable, and fail the next /load fast with an actionable message (mirrors the existing tensor-split memo). - CPU-only safe defaults (user flags still win): --fit off (its estimator hits the same abort, llama.cpp #21932, and mis-counts MTP KV #23472/#24117), --flash-attn off, and an auto context capped to a RAM-aware ceiling. - NUMA auto-interleave: wrap with numactl --interleave=all when the model overflows the largest node's free RAM but fits across all nodes. - CPU RAM preflight warning when weights exceed available RAM. GPU and Apple paths are unchanged. Adds unit tests for the classifier, the memo, the NUMA decision, and the CPU-only command defaults.
Per llama.cpp multi-NUMA guidance (ggml-org/llama.cpp#19102), numactl --interleave=all alone does not spread pages evenly across nodes; it must be paired with --numa distribute. Add it when auto-interleave engages, unless the user already set --numa.
- Emit --fit off explicitly on CPU. The flag defaults to on in recent llama.cpp, so setting use_fit = False only skipped --fit on and still ran the graph-reserve fitting step (same abort path) on the first attempt. - Key the scheduler-abort memo per variant (model plus hf_variant / gguf_path) so a failed quant does not block trying a different quant of the same repo, which the error message itself suggests. - Move the memo fail-fast guard ahead of _kill_process so a known-bad reload does not tear down a working server before returning the error. - Floor the CPU context to the minimum when weights alone exceed the RAM budget, where the fit helper returns the requested ceiling unchanged and KV could OS-kill the load. - Decide NUMA interleave on the resident footprint (weights plus KV at the capped context), not weights alone, so a model whose weights fit a node but whose footprint does not still interleaves. Adds tests for each fix.
- Size the NUMA footprint KV estimate for the launched --parallel slots (it defaulted to n_parallel=1), so a multi-slot KV that overflows a node still triggers interleave. - Include the launch settings (context, spec, extra_args) in the scheduler-abort memo key, so an identical replay stays blocked but changing -c, disabling spec, or picking a different quant (the recovery the error message recommends) is allowed to retry.
Follow-up review on the CPU-only / NUMA hardening: - Treat a user-forced zero offload (-ngl 0 / --n-gpu-layers 0 / --gpu-layers 0) as CPU-only even when a GPU is visible, so the safe defaults (--fit off, --flash-attn off, NUMA interleave) and the RAM-aware context fit apply instead of a GPU launch that then runs on CPU and hits the graph-reserve abort. - Size the CPU context fit against the fitted footprint (weights + compute buffer), not raw weights, so a context that only fits when the buffer is ignored can no longer slip through and get OS-killed at startup. - Size the NUMA interleave decision against the full resident footprint (fitted weights + KV at the launched parallel slots + MTP reserve). model_size_fit and the MTP reserve are bound before the fit try so the GPU-selection except path cannot leave them unbound. New and updated unit tests plus the offline simulation cover the zero-offload path and the math.
Follow-up review on the CPU-only / NUMA hardening: - Account for MTP memory in the CPU context fit. mtp_engaged alone is a no-op once budget_frac is set, so pass the byte-accurate MTP overhead fn; the cap no longer ignores the MTP draft KV. - Fit auto contexts at or below the 32k ceiling too, not only above it, so a large small-context GGUF that still exceeds RAM is reduced toward the minimum instead of being OS-killed at startup. - Recompute the NUMA footprint MTP reserve at the post-cap context; the pre-cap reserve overstated a capped million-token model and could skip a viable interleave. - Surface the "interleave cannot help" decision (footprint exceeds total RAM across all nodes), not only the missing-numactl case. - Defer recording the scheduler-abort memo until the text-only mmproj fallback is ruled out, so a vision model that recovers text-only is not blocked by the fail-fast guard on its next load. Unit tests and the offline simulations updated and passing.
Follow-up review on the CPU-only / NUMA hardening: - Respect an explicit user --numa policy. Auto-interleave wraps the process with a numactl argv prefix the user cannot override, so when the user sets --numa we now skip the wrapper (and --numa distribute) instead of forcing interleaving over their placement. - Check the total-RAM condition before numactl availability in decide_interleave, so a model too large for total free RAM gets the smaller-quant / free-memory guidance instead of being told to install numactl, which could never help. Unit tests cover both cases.
…e MLA MTP Follow-up review on the CPU-only / NUMA hardening: - Detect --device/-dev none as a CPU-only launch too, not just -ngl 0, and treat the GPU-layers and device controls independently (each flag's last value wins). - Lower max_available_ctx when the CPU cap reduces the launched context, so /status and the UI safe-zone advertise the real window instead of the unlaunched native size. - Skip the MTP reserve in the CPU cap and NUMA footprint when Auto drops embedded MTP for MLA models (GLM-5.2/DeepSeek/Kimi); the launch emits ngram-mod there, so reserving a target-KV copy needlessly shrank the context. GPU paths keep the existing _mtp_will_engage. - Stub structlog/loggers/httpx in the new CPU-default and NUMA test files so a dependency-light run can collect them, matching the existing abort test. The two test files now pass in a pytest-only venv (the import previously failed on structlog via loggers). Unit tests (44) and simulations pass.
The formatter wraps long argument lines, so pin the MTP fit/footprint assertions on whitespace-stripped source instead of an exact single line.
…e abort early Follow-up review on the CPU-only / NUMA hardening: - Reserve a flat MTP fraction in the CPU context fit when MTP engages but the draft KV cannot be byte-sized (mtp_overhead_fn is None): budget_frac otherwise skips the flat reserve, so the fit could pick a context that OOMs once the draft allocates. - Bound the NUMA local-placement decision on the smallest node's free RAM, not the largest. The loader is not pinned, so first-touch may land on any node; interleave a footprint that fits only the larger node instead of gambling on placement. - Capture the first launch's scheduler abort before the no-spec MTP fallback resets the stdout tail, then fold it into the terminal memo decision, so a fallback that fails for another reason does not drop the memo and let the UI replay the load. Unit tests and the offline simulations updated and passing.
Follow-up review on the CPU-only / NUMA hardening: - Restrict the NUMA topology to the cpuset-allowed nodes (/proc/self/status Mems_allowed_list). numactl --interleave=all only spans those, so under a Docker/systemd cpuset that exposes the host's nodes but allows one, the decision no longer sums RAM the child cannot use and wrap a launch that OOMs. - Honor env-forced CPU offload: _extra_args_forces_cpu_offload now also reads the inherited LLAMA_ARG_N_GPU_LAYERS / LLAMA_ARG_DEVICE the child would apply, so a GPU host running with LLAMA_ARG_N_GPU_LAYERS=0 or LLAMA_ARG_DEVICE=none gets the CPU-only safe defaults. CLI extras still win over the env. Unit tests and the offline simulations updated and passing.
Keep only what the reported bug needs: recognise GGML_ASSERT(*cur_backend_id != -1), say what it means, and fail fast on an identical reload instead of re-reading the weights into the same crash. The same assert also fires when the model does not fit in memory, so the message names both causes. Drop the CPU-only launch defaults (--fit off, 32k context cap, RAM preflight) and the numactl interleave: each changed behaviour for every CPU user without fixing the abort, and the context cap shrank loads that fit. They can come back as their own PRs with measurements.
|
@codex security review |
sched_reserve / graph_reserve frames appear in every reserve-time crash, so a CUDA out-of-memory abort (GGML_ASSERT(err == cudaSuccess) under ggml_gallocr_reserve_n) was reported as the scheduler abort and memo-blocked. Require the assert text or the ggml_backend_sched_split_graph frame it fires in. The same assert can mean the model did not fit, and freeing memory can make the identical load succeed, so an explicit reload (force_reload) bypasses the memo; automatic replays stay blocked.
🛡️ Codex Security ReviewSecurity review completed. No security issues were found in this pull request. Reviewed commit: Only the user who started this review can view the report in Codex. ℹ️ About Codex security reviews in GitHubThis is an experimental Codex feature. Security reviews are triggered when:
Once complete, Codex will leave suggestions, or a comment if no findings are found. |
… hint, forced reload, text-only retry
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5d6bcc348a
ℹ️ 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".
| if "failed to initialize context" in text or "ggml_assert(" in text: | ||
| return False | ||
| return "ggml_backend_sched_split_graph" in text |
There was a problem hiding this comment.
Require reserve frames before matching truncated aborts
When another ggml_backend_sched_split_graph failure's diagnostic line has scrolled out of the captured tail, this fallback classifies it as the cur_backend_id failure solely because the remaining backtrace contains ggml_abort and ggml_backend_sched_split_graph. The tests themselves identify context-initialization and split-allocation aborts that share this frame; with enough intervening thread output, those markers disappear and the matcher both reports the wrong remedy and can memoize the unrelated failure. Require evidence such as the accompanying graph_reserve/sched_reserve frames rather than accepting the bare split-graph frame.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing: the matcher only runs on a crashed startup, and every startup call into split_graph comes through sched_reserve / graph_reserve, so those frames would not tell the alternate aborts apart. What remains is a host malloc failure for a tiny ggml context, whose visible messages are already excluded and whose cause (memory) the message already names.
| _abort_memo_model = repr( | ||
| ( | ||
| replace(intent, hf_token = None, force_reload = False, verified_gguf = None), | ||
| _vram_frac, | ||
| _model_memory_settings_or_none(), |
There was a problem hiding this comment.
Use the launch's Model Memory snapshot in the memo key
If Model Memory settings change after this read but before capture_model_memory_settings() later snapshots the settings used for fitting and launch, an abort is recorded under the old setting pair even though the child ran with the new pair. A subsequent attempt using the old settings is then incorrectly blocked despite never having been tried, while an identical retry of the actually aborted configuration is allowed. Capture one coherent settings snapshot before the fail-fast check and reuse it for both the key and launch.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing: this needs a Model Memory save to land inside one in-flight load and the user to then switch back to the earlier pair; the worst case is one extra refusal that an explicit reload clears. Moving the capture (which publishes the pending launch pair) ahead of the fail-fast would change when a refused load claims that pair.
|
Codex Review: Didn't find any major issues. Another round soon, 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". |
Problem
Loading some large GGUFs (reported: GLM-5.2 UD-Q6_K, ~583 GB, on a CPU-only host) aborts inside llama.cpp at startup:
The ggml scheduler could not place part of the model's graph on any backend. That happens when the llama.cpp build lacks an operation the model needs on that device (new attention types on CPU), and the same assert also fires when the model does not fit in memory (canonical/inference-snaps#343).
Studio made it worse in two ways:
Changes
All in
studio/backend/core/inference/llama_cpp.py(+69 lines):_is_sched_reserve_abortmatches the assert text or theggml_backend_sched_split_graphframe it fires in (the frame survives a short stderr tail where theGGML_ASSERTline has scrolled past the[New LWP]dump); the bare frame counts only when no other abort message from that function (context init, split allocation) is visible. It deliberately ignores the genericsched_reserve/graph_reserveframes, which a CUDA out-of-memory abort during reserve also passes through, and excludes the split-axis abort (Studio: vision model tensor-parallel crash loop + MTP drafter VRAM not reserved on Windows #6415).unsloth studio update, a smaller quant, a lower context, speculative decoding off).unsloth studio update) and the whole load request, makes an identical reload fail fast before the running server is torn down. Any changed setting (quant, context, Tensor Parallelism, speculative decoding) retries, and so does an explicit reload, since freeing memory can make the identical load fit; it clears the entry, so only a repeat abort blocks again. The one-shot Hub cache hint is left out of the key, so a first download that aborts is not replayed once more. It is recorded only when the load ends terminally, so a fallback that recovers (text-only, CPU replay) is never blocked; an abort in the vision text-only retry is detected too.Tests
studio/backend/tests/test_sched_reserve_abort.py: the matcher (full log, short tail, split-axis exclusion, unrelated crashes), the classifier message, memo round trip and mtime invalidation, andload_modeldriven with a fake llama-server that aborts: the cause is named, an identical replay spawns nothing and keeps the running server, and a changed context, Tensor Parallelism or an explicit reload retries, and a CUDA out-of-memory abort is not mistaken for it.On main the same driver shows the generic message and 2 llama-server spawns per replay; on this branch the replay spawns 0. The 210 llama.cpp backend test files show no new failures against main.