Repository navigation
Carry patches/0020: ggml-alloc validates the leafs before reusing an allocation (fixes the --embedding crash) - #541
Conversation
…location The first full Publish run since b11558 (38648257387, on the b11639 merge) crashed ErrorHandlingTest in all three Java test jobs: SIGSEGV in ggml_gallocr_alloc_graph on Linux, 0xC0000005 with both Windows toolchains. The test loads its model with enableEmbedding() and posts an infill request to it. Cause, upstream since #30445 (cb55ffe6e, b11574..b11612): the LM head is expanded by build_logits() after build_pooling(), so an embeddings context reserves a graph expanding t_embd then t_logits, while a generation step on it expands only t_logits, whose first source is output.weight. Same node and leaf counts, the leafs shifted by one. ggml_gallocr_needs_realloc() validates nodes and their sources but of the leafs only the count, so the input leaf out_ids received the slot of a weight (buffer_id -1) and ggml_vbuffer_tensor_alloc() indexed galloc->buffers[-1]. Reproduced without a downloaded model (random 2-layer llama GGUF with FIM tokens, context 128): infill crashes with --embedding and works without; reverting cb55ffe6e passes, and so does validating the leafs like the nodes. With the patch greedy infill on the --embedding model returns the same tokens as without. Guard: test_gallocr_leafs.cpp, two graphs with the same counts and the leafs swapped. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DdW3CyYtKkK6BQ3VGARo2E
The first version of test_gallocr_leafs.cpp swapped the operands of one add, which moves a node source too -- the check that existed before the patch already caught that, so the test passed without the fix. The guard now keeps both nodes and their sources in place and moves only the leafs, the shape of the llama.cpp case: it dies with SIGSEGV without the patch and passes with it (602/602). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DdW3CyYtKkK6BQ3VGARo2E
|
The two red "Verify GPG signing key" checks do not come from this PR. Both jobs run with This PR does not touch either job or Generated by Claude Code |
|
The review action quit 294 ms after it started, with There is nothing in this diff to fix for it. A re-run makes sense once the action can reach the API again. Generated by Claude Code |
|



Summary
ErrorHandlingTestkilled the fork in four Java test jobs: SIGSEGV on Ubuntu and on macOS 26, 0xC0000005 under both Windows toolchains, each time inggml_gallocr_alloc_graph. On macOSsi_addrwas0xfffffffffffffff8, which isgalloc->buffers[-1]. The test loads its model withenableEmbedding(), and its first test sends that model an infill request. The stack isserver_context_impl::update_slots → llama_context::decode → process_ubatch → ggml_backend_sched_alloc_graph → ggml_gallocr_alloc_graph.cb55ffe6e, "graph: skip the LM head for pooled embeddings") now expands the LM head inbuild_logits(), afterbuild_pooling().t_embdfirst andt_logitssecond. A generation step on the same context expands onlyt_logits, whose first source isoutput.weight.ggml_gallocr_needs_realloc()validates the nodes and their sources, but compares the leafs only by count. So the input leafout_idsgot the slot of a weight (buffer_id -1).patches/0020. It validates the leafs the same way the nodes are validated. With one buffer, an invalid leaf makes the allocator reserve again; otherwise it returns false andggml_backend_schedreserves the graph itself. Upstream master (a0e6dc738) still lacks the check. Not yet filed upstream.test_gallocr_leafs.cpp. Two graphs whose nodes and node sources match and in which only the leafs move.Test plan
--embeddingand works without. A debug print showedout_idsarriving at a slot with no allocation.cb55ffe6emakes the reproduction pass. So does this patch on its own: with greedy sampling (temperature 0), the--embeddingmodel returns the same tokens as the model without it, on repeated runs.ctest602/602.addpassed without the fix, because a moved node source was already caught; the final guard moves only the leafs.ErrorHandlingTestagainst the tiny model, 16/16; model-free native Java tests 27/27.check-patches(13 patches, 95 hunks, 0 problems),check-natives, clang-format 23.1.3.Also red in 38648257387:
Build and Test macOS 15 arm64 (no Metal). That is not a code problem: cloning BoringSSL failed with HTTP 503 fromboringssl.googlesource.com.Related issues / PRs
Follows #539 (b11639). Upstream cause: ggml-org/llama.cpp#30445.
Checklist
CONTRIBUTING.mdandCODE_OF_CONDUCT.md🤖 Generated with Claude Code
https://claude.ai/code/session_01DdW3CyYtKkK6BQ3VGARo2E
Generated by Claude Code