Repository navigation
ggml: rebuild a reused meta split whose views another backend's rebuilds reset - #33
Merged
Merged
Conversation
…lds reset A meta buffer keeps the device tensors of the views made of its tensors in two compute containers that rotate as graphs are rebuilt: a graph's views go into the current one, and each rebuild resets the other one. A meta backend reuses the split it built for a graph it computes again (same uid), and that split points at its views' device tensors in the container of its time. Another backend whose graphs view the same buffer rotates that buffer's containers with each of its own rebuilds, and its second rebuild resets the container the reused split points into and gives the memory to its own views. Since #27, DeepSeek-V4.1's DSpark drafter multiplies a rows view of the target's output head, so the drafter's graphs view the target's weight buffer. With one graph slot (LLAMA_GRAPH_SLOTS=0) the target's reused split computed a node with the drafter's rows view as its source: every RPC server aborted at ggml-cuda/binbcast.cu:417 on a MUL of a view of hc_mixes-0 with output.weight (rows), a Q6_K view. Two graph slots build splits from clones, which point into no container. Each container now counts its resets. A split records, for each buffer holding one of its nodes or of their sources outside the buffer's static container, the container it points into and that count, and a split reused without a rebuild is rebuilt when a count has moved. The rebuild makes the views again, as it already does for a reused graph's split. A split built from clones skips the check. Sources count because a scheduler computes a graph in splits whose graphs have no leafs, so a view a node reads can be made in an earlier split. test-meta-shared-views: one meta backend computes out = x * view(s, 0..n), a second allocates and computes fresh graphs that view s[n..2n), and the first computes its graph again without allocating it, whole and as a split holding the product alone. Before this change the reused graph computed x * s[n..2n) in both cases.
There was a problem hiding this comment.
🟢 Approved
No active review issues are identified for the change addressing stale view reuse across meta backends.
No open issues 🎉
What changed in this PR
This PR fixes stale view reuse in the meta backend when another backend rebuilds graphs that share the same buffer, addressing the single-graph-slot failure with the DSpark drafter.
Changes:
- Track compute-container reset generations and rebuild cached splits when their recorded containers have changed.
- Track containers used by both nodes and their sources, while skipping validation for clone-backed splits.
- Add a CPU regression test covering whole-graph and scheduler-style split reuse across two meta backends.
| File | Description |
|---|---|
| tests/test-meta-shared-views.cpp | Tests shared-buffer view correctness after another backend rebuilds its graphs. |
| tests/CMakeLists.txt | Registers the regression test for non-dynamic CPU builds. |
| ggml/src/ggml-backend-meta.cpp | Tracks container generations and invalidates stale cached splits. |
Review effort: Balanced
lukekim
added a commit
to spiceai/spiceai
that referenced
this pull request
Nov 5, 2026
…16049) spiceai/llama.cpp#33 rebuilds a meta split a backend would reuse when another backend's rebuilds have reset the containers holding its views. Since spiceai/llama.cpp#27 the DSpark drafter's graphs view the target's weights, and with one graph slot (LLAMA_GRAPH_SLOTS=0) DeepSeek-V4.1 split by tensor aborted on its first or second request at ggml-cuda/binbcast.cu:417. Spice's default of two graph slots builds splits from clones and did not reach it. The ledger records the pin and a row for #33, a GAP covered by the fork's test-meta-shared-views, and the GAP count moves from 58 to 59.
lukekim
added a commit
to spiceai/spiceai
that referenced
this pull request
Nov 8, 2026
…es (#16079) * deps(llama-cpp): pin llama.cpp to spiceai-b11999 at the squash of spiceai/llama.cpp#23 Moves `llama-cpp-src` from 2bedd1f7 (tag b11999-spiceai.1) to 3a536dbf, the tip of spiceai-b11999, three commits further on: - spiceai/llama.cpp#21 deletes a POOL_1D split-state handler left unused by the b11984 merge. - spiceai/llama.cpp#20 splits Mistral Large 4 and its DSpark drafter across devices. - spiceai/llama.cpp#23 reads a DSpark draft token as the row's largest logit when the drafter's CPU chain is top-k alone. `docs/dev/fork_patches.md` records the new pin and the three patches; #20 and #23 are GAP rows, #21 needs no guard. * deps(llama-cpp): move the llama.cpp pin to the squash of spiceai/llama.cpp#25 spiceai/llama.cpp#25 adds `llama_get_unsampled_logits_ith`, which reads an output's full logits row after one synchronize, or returns NULL when a backend sampler sampled the row. The DSpark drafter's pick now uses it. `docs/dev/fork_patches.md` records the new pin and adds the patch's row. * perf(llama-cpp): read a row's logits with one synchronize through llama_get_unsampled_logits_ith * docs(fork-patches): measure Mistral Large 4's layer-split cost in the tensor-split row The row said a layer split runs several times slower. Stock llama-server at f68fea35 with the DSpark drafter across three DGX Sparks measured 7.68 tok/s split by layer against 13.19 split by tensor. * deps(llama-cpp): pin llama.cpp to spiceai-b11999's tip, and keep the MTP head's state with the prompt cache (#16023) * fix(llms): the MTP head's state follows the prompt cache The MTP head pairs a prompt read's first token with the target's hidden state at the position before it, and kept the last request's: a request after another one, or a turn that reuses the previous turn's prompt, drafted differently from the same request on a fresh context (fewer tokens accepted, and with batched verification, different tokens). With the fork's state API (llama.cpp's common_speculative get/set state for its MTP head), the prompt cache saves the head's state with each checkpoint and restores it with it. A cache that can be cut anywhere stashes the head's state where a checkpoint would be, and reuses the cache up to there or up to all of it, where the head's live state is; the debug line says how many shared tokens it read again. Two integration tests on Qwen3.5-0.8B compare the drafts with a fresh context's: a request after another, and a turn after the previous turn. * test(llms): check the second request's drafts over eight requests, so the guard fails on Metal too * style(llms): rustfmt the MTP head state change * deps(llama-cpp): pin llama.cpp to spiceai-b11999 at the squash of spiceai/llama.cpp#31 The pin moves from the squash of spiceai/llama.cpp#25 to the branch's tip, which adds #22 (carrying #18 and #19 over from spiceai-b11803), #24, #26, #27, #29, #30 and #31. The ledger gets a row for each, #19's defaults go into the levers row, and the MTP head-state guards from the previous commits guard #31. * style(llama-cpp): rustfmt the MTP state bindings * fix(llms): keep the prompt cache's shared prefix for a DFlash or DSpark drafter The head-state change treated every draft model behind the speculative shim as a head that carries its state from one read to the next. A DFlash or DSpark drafter keeps none, so on a cache that can be cut anywhere nothing was ever stashed, and every request whose prompt shared only part of the cache read it all again from position 0. On Mistral Large 4 with its DSpark drafter split across three nodes, each request reused 0 of its 35 prompt tokens instead of 34, which changed its prefill batches and its replies. Only an MTP head now counts as one. * deps(llama-cpp): pin llama.cpp to the squash of spiceai/llama.cpp#33 (#16049) spiceai/llama.cpp#33 rebuilds a meta split a backend would reuse when another backend's rebuilds have reset the containers holding its views. Since spiceai/llama.cpp#27 the DSpark drafter's graphs view the target's weights, and with one graph slot (LLAMA_GRAPH_SLOTS=0) DeepSeek-V4.1 split by tensor aborted on its first or second request at ggml-cuda/binbcast.cu:417. Spice's default of two graph slots builds splits from clones and did not reach it. The ledger records the pin and a row for #33, a GAP covered by the fork's test-meta-shared-views, and the GAP count moves from 58 to 59. * test(llms-llamacpp): require at least one non-empty MTP draft in regression helpers Copilot: generate/generate_after_read could pass with every draft empty. Assert each helper produced at least one non-empty draft before returning. * test(llms-llamacpp): compare whole replies when every MTP draft matches The prompt-cache guards compared the two runs' replies only up to the shorter one. A reply grows by the step's token and the drafts the target accepted, and the final step's next token is never appended, so two runs whose final steps accepted different numbers of drafts give one reply that is a prefix of the other, and the prefix comparison passed. With the same drafts at every step the runs take the same steps, so both guards now require the whole replies to be equal once every draft matches. Watched failing: with the final step's reply one token short in one run, both guards passed before this change, and fail with it ("whose drafts match at every step").
mikemikimike
pushed a commit
to mikemikimike/spiceai
that referenced
this pull request
Nov 8, 2026
…ceai/llama.cpp#33, and keep the MTP head's state with the prompt cache (spiceai#15922) * deps(llama-cpp): pin llama.cpp to spiceai-b11999 at the squash of spiceai/llama.cpp#23 Moves `llama-cpp-src` from 2bedd1f7 (tag b11999-spiceai.1) to 3a536dbf, the tip of spiceai-b11999, three commits further on: - spiceai/llama.cpp#21 deletes a POOL_1D split-state handler left unused by the b11984 merge. - spiceai/llama.cpp#20 splits Mistral Large 4 and its DSpark drafter across devices. - spiceai/llama.cpp#23 reads a DSpark draft token as the row's largest logit when the drafter's CPU chain is top-k alone. `docs/dev/fork_patches.md` records the new pin and the three patches; spiceai#20 and spiceai#23 are GAP rows, spiceai#21 needs no guard. * deps(llama-cpp): move the llama.cpp pin to the squash of spiceai/llama.cpp#25 spiceai/llama.cpp#25 adds `llama_get_unsampled_logits_ith`, which reads an output's full logits row after one synchronize, or returns NULL when a backend sampler sampled the row. The DSpark drafter's pick now uses it. `docs/dev/fork_patches.md` records the new pin and adds the patch's row. * perf(llama-cpp): read a row's logits with one synchronize through llama_get_unsampled_logits_ith * docs(fork-patches): measure Mistral Large 4's layer-split cost in the tensor-split row The row said a layer split runs several times slower. Stock llama-server at f68fea35 with the DSpark drafter across three DGX Sparks measured 7.68 tok/s split by layer against 13.19 split by tensor. * deps(llama-cpp): pin llama.cpp to spiceai-b11999's tip, and keep the MTP head's state with the prompt cache (spiceai#16023) * fix(llms): the MTP head's state follows the prompt cache The MTP head pairs a prompt read's first token with the target's hidden state at the position before it, and kept the last request's: a request after another one, or a turn that reuses the previous turn's prompt, drafted differently from the same request on a fresh context (fewer tokens accepted, and with batched verification, different tokens). With the fork's state API (llama.cpp's common_speculative get/set state for its MTP head), the prompt cache saves the head's state with each checkpoint and restores it with it. A cache that can be cut anywhere stashes the head's state where a checkpoint would be, and reuses the cache up to there or up to all of it, where the head's live state is; the debug line says how many shared tokens it read again. Two integration tests on Qwen3.5-0.8B compare the drafts with a fresh context's: a request after another, and a turn after the previous turn. * test(llms): check the second request's drafts over eight requests, so the guard fails on Metal too * style(llms): rustfmt the MTP head state change * deps(llama-cpp): pin llama.cpp to spiceai-b11999 at the squash of spiceai/llama.cpp#31 The pin moves from the squash of spiceai/llama.cpp#25 to the branch's tip, which adds spiceai#22 (carrying spiceai#18 and spiceai#19 over from spiceai-b11803), spiceai#24, spiceai#26, spiceai#27, spiceai#29, spiceai#30 and spiceai#31. The ledger gets a row for each, spiceai#19's defaults go into the levers row, and the MTP head-state guards from the previous commits guard spiceai#31. * style(llama-cpp): rustfmt the MTP state bindings * fix(llms): keep the prompt cache's shared prefix for a DFlash or DSpark drafter The head-state change treated every draft model behind the speculative shim as a head that carries its state from one read to the next. A DFlash or DSpark drafter keeps none, so on a cache that can be cut anywhere nothing was ever stashed, and every request whose prompt shared only part of the cache read it all again from position 0. On Mistral Large 4 with its DSpark drafter split across three nodes, each request reused 0 of its 35 prompt tokens instead of 34, which changed its prefill batches and its replies. Only an MTP head now counts as one. * deps(llama-cpp): pin llama.cpp to the squash of spiceai/llama.cpp#33 (spiceai#16049) spiceai/llama.cpp#33 rebuilds a meta split a backend would reuse when another backend's rebuilds have reset the containers holding its views. Since spiceai/llama.cpp#27 the DSpark drafter's graphs view the target's weights, and with one graph slot (LLAMA_GRAPH_SLOTS=0) DeepSeek-V4.1 split by tensor aborted on its first or second request at ggml-cuda/binbcast.cu:417. Spice's default of two graph slots builds splits from clones and did not reach it. The ledger records the pin and a row for spiceai#33, a GAP covered by the fork's test-meta-shared-views, and the GAP count moves from 58 to 59. * test(llms-llamacpp): require at least one non-empty MTP draft in regression helpers Copilot: generate/generate_after_read could pass with every draft empty. Assert each helper produced at least one non-empty draft before returning.
vatsalp2008
pushed a commit
to vatsalp2008/spiceai
that referenced
this pull request
Nov 9, 2026
…n sequence (spiceai#16106) * feat(llama-cpp): decode and draft for several sequences in one context A context can hold several sequences on one shared cache (`with_n_seq_max`, `with_kv_unified`), and a batch can carry tokens of any of them (`Batch::add_seq`). Truncation and the partial state a prompt checkpoint saves now take a sequence (`truncate_seq`, `partial_state_seq`, `restore_partial_state_seq`), and refuse one the context does not hold instead of reaching the llama.cpp assertion that ends the process. The MTP shim drafts for every sequence of the target through the pinned fork's per-sequence speculative API: `begin`, `accept` and the head's saved state take a sequence, and one `draft_many` call drafts for several sequences in one pass of the head. It refuses an unknown sequence, two requests for one sequence, and a batch whose sequences are interleaved. The engine still decodes one request at a time in sequence 0; serving several requests together is spiceai#15598. * test(llms-llamacpp): a sequence's prompt checkpoint restores into that sequence beside another Sequence 1 saves its recurrent and draft-head state at a split, reuses the prefix for the next turn, and drafts and replies exactly as the turn read whole into sequence 1 of a fresh context, while sequence 0 holds another prompt in both. * feat(llms-llamacpp): decode several requests together, each in its own sequence (spiceai#16107) * feat(llms-llamacpp): decode several requests together, each in its own sequence The engine can serve up to `concurrent_requests` requests at once in one context: each step decodes one batch holding every running request's next token, and with a draft head its draft from one pass of the head, so the weights are read once for all of them. A request that arrives while others run reads its prompt into the free sequence whose cache shares the most of it, and decodes from the next step. It is admitted with room for its prompt and its whole possible reply, so a running request never runs out of cache; one that does not fit waits, and idle sequences' caches are emptied, longest unused first, to make room. A request whose client reads slowly waits rather than holding the step, and one whose client leaves frees its sequence. Each sequence keeps its own prompt cache, with checkpoints and the draft head's state saved and restored per sequence. `concurrent_requests` is an internal option that only tests set: the engine still serves one request at a time until continuous batching is enabled (spiceai#15598). * fix(llms-llamacpp): idle caches give up their room even when no request runs A request admitted while every sequence was idle skipped making room, so the other sequences' idle caches kept their cells and a prompt that needed them failed with "the context has no room left for the batch". Admission now always empties the idle caches it does not reuse, longest unused first, until the request fits; with nothing running the request is served as it would be alone. `idle_caches_give_up_their_room_to_a_request_that_needs_it` failed with that error before and passes now. The decode thread also takes at most one queued request per sequence between steps, so requests arriving faster than they are taken cannot hold off the running ones' steps, and the internal ceiling is capped at 8 requests, which keeps a step's batch within the context's batch size. * test(llms-llamacpp): show requests decode together, not one after another, in the overlap and leaving-client tests The overlap test's first client now stops reading after its first chunk, and its reply holds more tokens than a client buffers. One request at a time would wait on that client and never reach the second request, which is as long, so a step that waited on a paused client would stall it too. The leaving-client test drops its client only once the other request has streamed more chunks than a client buffers, so the leaving request is paused on its full buffer and the closed-client cleanup runs while the other reply still decodes. STREAM_BUFFER is public so the tests can size those replies against it. * test(llms-llamacpp): compare whole replies when every MTP draft matches (spiceai#16079) * deps(llama-cpp): pin llama.cpp to spiceai-b11999 at the squash of spiceai/llama.cpp#23 Moves `llama-cpp-src` from 2bedd1f7 (tag b11999-spiceai.1) to 3a536dbf, the tip of spiceai-b11999, three commits further on: - spiceai/llama.cpp#21 deletes a POOL_1D split-state handler left unused by the b11984 merge. - spiceai/llama.cpp#20 splits Mistral Large 4 and its DSpark drafter across devices. - spiceai/llama.cpp#23 reads a DSpark draft token as the row's largest logit when the drafter's CPU chain is top-k alone. `docs/dev/fork_patches.md` records the new pin and the three patches; spiceai#20 and spiceai#23 are GAP rows, spiceai#21 needs no guard. * deps(llama-cpp): move the llama.cpp pin to the squash of spiceai/llama.cpp#25 spiceai/llama.cpp#25 adds `llama_get_unsampled_logits_ith`, which reads an output's full logits row after one synchronize, or returns NULL when a backend sampler sampled the row. The DSpark drafter's pick now uses it. `docs/dev/fork_patches.md` records the new pin and adds the patch's row. * perf(llama-cpp): read a row's logits with one synchronize through llama_get_unsampled_logits_ith * docs(fork-patches): measure Mistral Large 4's layer-split cost in the tensor-split row The row said a layer split runs several times slower. Stock llama-server at f68fea35 with the DSpark drafter across three DGX Sparks measured 7.68 tok/s split by layer against 13.19 split by tensor. * deps(llama-cpp): pin llama.cpp to spiceai-b11999's tip, and keep the MTP head's state with the prompt cache (spiceai#16023) * fix(llms): the MTP head's state follows the prompt cache The MTP head pairs a prompt read's first token with the target's hidden state at the position before it, and kept the last request's: a request after another one, or a turn that reuses the previous turn's prompt, drafted differently from the same request on a fresh context (fewer tokens accepted, and with batched verification, different tokens). With the fork's state API (llama.cpp's common_speculative get/set state for its MTP head), the prompt cache saves the head's state with each checkpoint and restores it with it. A cache that can be cut anywhere stashes the head's state where a checkpoint would be, and reuses the cache up to there or up to all of it, where the head's live state is; the debug line says how many shared tokens it read again. Two integration tests on Qwen3.5-0.8B compare the drafts with a fresh context's: a request after another, and a turn after the previous turn. * test(llms): check the second request's drafts over eight requests, so the guard fails on Metal too * style(llms): rustfmt the MTP head state change * deps(llama-cpp): pin llama.cpp to spiceai-b11999 at the squash of spiceai/llama.cpp#31 The pin moves from the squash of spiceai/llama.cpp#25 to the branch's tip, which adds spiceai#22 (carrying spiceai#18 and spiceai#19 over from spiceai-b11803), spiceai#24, spiceai#26, spiceai#27, spiceai#29, spiceai#30 and spiceai#31. The ledger gets a row for each, spiceai#19's defaults go into the levers row, and the MTP head-state guards from the previous commits guard spiceai#31. * style(llama-cpp): rustfmt the MTP state bindings * fix(llms): keep the prompt cache's shared prefix for a DFlash or DSpark drafter The head-state change treated every draft model behind the speculative shim as a head that carries its state from one read to the next. A DFlash or DSpark drafter keeps none, so on a cache that can be cut anywhere nothing was ever stashed, and every request whose prompt shared only part of the cache read it all again from position 0. On Mistral Large 4 with its DSpark drafter split across three nodes, each request reused 0 of its 35 prompt tokens instead of 34, which changed its prefill batches and its replies. Only an MTP head now counts as one. * deps(llama-cpp): pin llama.cpp to the squash of spiceai/llama.cpp#33 (spiceai#16049) spiceai/llama.cpp#33 rebuilds a meta split a backend would reuse when another backend's rebuilds have reset the containers holding its views. Since spiceai/llama.cpp#27 the DSpark drafter's graphs view the target's weights, and with one graph slot (LLAMA_GRAPH_SLOTS=0) DeepSeek-V4.1 split by tensor aborted on its first or second request at ggml-cuda/binbcast.cu:417. Spice's default of two graph slots builds splits from clones and did not reach it. The ledger records the pin and a row for spiceai#33, a GAP covered by the fork's test-meta-shared-views, and the GAP count moves from 58 to 59. * test(llms-llamacpp): require at least one non-empty MTP draft in regression helpers Copilot: generate/generate_after_read could pass with every draft empty. Assert each helper produced at least one non-empty draft before returning. * test(llms-llamacpp): compare whole replies when every MTP draft matches The prompt-cache guards compared the two runs' replies only up to the shorter one. A reply grows by the step's token and the drafts the target accepted, and the final step's next token is never appended, so two runs whose final steps accepted different numbers of drafts give one reply that is a prefix of the other, and the prefix comparison passed. With the same drafts at every step the runs take the same steps, so both guards now require the whole replies to be equal once every draft matches. Watched failing: with the final step's reply one token short in one run, both guards passed before this change, and fail with it ("whose drafts match at every step").
spiceemma
pushed a commit
to wangyusheng1985/spiceai
that referenced
this pull request
Nov 10, 2026
… on a split model (spiceai#16172) * feat(llama-cpp): decode and draft for several sequences in one context A context can hold several sequences on one shared cache (`with_n_seq_max`, `with_kv_unified`), and a batch can carry tokens of any of them (`Batch::add_seq`). Truncation and the partial state a prompt checkpoint saves now take a sequence (`truncate_seq`, `partial_state_seq`, `restore_partial_state_seq`), and refuse one the context does not hold instead of reaching the llama.cpp assertion that ends the process. The MTP shim drafts for every sequence of the target through the pinned fork's per-sequence speculative API: `begin`, `accept` and the head's saved state take a sequence, and one `draft_many` call drafts for several sequences in one pass of the head. It refuses an unknown sequence, two requests for one sequence, and a batch whose sequences are interleaved. The engine still decodes one request at a time in sequence 0; serving several requests together is spiceai#15598. * test(llms-llamacpp): a sequence's prompt checkpoint restores into that sequence beside another Sequence 1 saves its recurrent and draft-head state at a split, reuses the prefix for the next turn, and drafts and replies exactly as the turn read whole into sequence 1 of a fresh context, while sequence 0 holds another prompt in both. * feat(llms-llamacpp): decode several requests together, each in its own sequence (spiceai#16107) * feat(llms-llamacpp): decode several requests together, each in its own sequence The engine can serve up to `concurrent_requests` requests at once in one context: each step decodes one batch holding every running request's next token, and with a draft head its draft from one pass of the head, so the weights are read once for all of them. A request that arrives while others run reads its prompt into the free sequence whose cache shares the most of it, and decodes from the next step. It is admitted with room for its prompt and its whole possible reply, so a running request never runs out of cache; one that does not fit waits, and idle sequences' caches are emptied, longest unused first, to make room. A request whose client reads slowly waits rather than holding the step, and one whose client leaves frees its sequence. Each sequence keeps its own prompt cache, with checkpoints and the draft head's state saved and restored per sequence. `concurrent_requests` is an internal option that only tests set: the engine still serves one request at a time until continuous batching is enabled (spiceai#15598). * fix(llms-llamacpp): idle caches give up their room even when no request runs A request admitted while every sequence was idle skipped making room, so the other sequences' idle caches kept their cells and a prompt that needed them failed with "the context has no room left for the batch". Admission now always empties the idle caches it does not reuse, longest unused first, until the request fits; with nothing running the request is served as it would be alone. `idle_caches_give_up_their_room_to_a_request_that_needs_it` failed with that error before and passes now. The decode thread also takes at most one queued request per sequence between steps, so requests arriving faster than they are taken cannot hold off the running ones' steps, and the internal ceiling is capped at 8 requests, which keeps a step's batch within the context's batch size. * test(llms-llamacpp): show requests decode together, not one after another, in the overlap and leaving-client tests The overlap test's first client now stops reading after its first chunk, and its reply holds more tokens than a client buffers. One request at a time would wait on that client and never reach the second request, which is as long, so a step that waited on a paused client would stall it too. The leaving-client test drops its client only once the other request has streamed more chunks than a client buffers, so the leaving request is paused on its full buffer and the closed-client cleanup runs while the other reply still decodes. STREAM_BUFFER is public so the tests can size those replies against it. * test(llms-llamacpp): compare whole replies when every MTP draft matches (spiceai#16079) * deps(llama-cpp): pin llama.cpp to spiceai-b11999 at the squash of spiceai/llama.cpp#23 Moves `llama-cpp-src` from 2bedd1f7 (tag b11999-spiceai.1) to 3a536dbf, the tip of spiceai-b11999, three commits further on: - spiceai/llama.cpp#21 deletes a POOL_1D split-state handler left unused by the b11984 merge. - spiceai/llama.cpp#20 splits Mistral Large 4 and its DSpark drafter across devices. - spiceai/llama.cpp#23 reads a DSpark draft token as the row's largest logit when the drafter's CPU chain is top-k alone. `docs/dev/fork_patches.md` records the new pin and the three patches; spiceai#20 and spiceai#23 are GAP rows, spiceai#21 needs no guard. * deps(llama-cpp): move the llama.cpp pin to the squash of spiceai/llama.cpp#25 spiceai/llama.cpp#25 adds `llama_get_unsampled_logits_ith`, which reads an output's full logits row after one synchronize, or returns NULL when a backend sampler sampled the row. The DSpark drafter's pick now uses it. `docs/dev/fork_patches.md` records the new pin and adds the patch's row. * perf(llama-cpp): read a row's logits with one synchronize through llama_get_unsampled_logits_ith * docs(fork-patches): measure Mistral Large 4's layer-split cost in the tensor-split row The row said a layer split runs several times slower. Stock llama-server at f68fea35 with the DSpark drafter across three DGX Sparks measured 7.68 tok/s split by layer against 13.19 split by tensor. * deps(llama-cpp): pin llama.cpp to spiceai-b11999's tip, and keep the MTP head's state with the prompt cache (spiceai#16023) * fix(llms): the MTP head's state follows the prompt cache The MTP head pairs a prompt read's first token with the target's hidden state at the position before it, and kept the last request's: a request after another one, or a turn that reuses the previous turn's prompt, drafted differently from the same request on a fresh context (fewer tokens accepted, and with batched verification, different tokens). With the fork's state API (llama.cpp's common_speculative get/set state for its MTP head), the prompt cache saves the head's state with each checkpoint and restores it with it. A cache that can be cut anywhere stashes the head's state where a checkpoint would be, and reuses the cache up to there or up to all of it, where the head's live state is; the debug line says how many shared tokens it read again. Two integration tests on Qwen3.5-0.8B compare the drafts with a fresh context's: a request after another, and a turn after the previous turn. * test(llms): check the second request's drafts over eight requests, so the guard fails on Metal too * style(llms): rustfmt the MTP head state change * deps(llama-cpp): pin llama.cpp to spiceai-b11999 at the squash of spiceai/llama.cpp#31 The pin moves from the squash of spiceai/llama.cpp#25 to the branch's tip, which adds spiceai#22 (carrying spiceai#18 and spiceai#19 over from spiceai-b11803), spiceai#24, spiceai#26, spiceai#27, spiceai#29, spiceai#30 and spiceai#31. The ledger gets a row for each, spiceai#19's defaults go into the levers row, and the MTP head-state guards from the previous commits guard spiceai#31. * style(llama-cpp): rustfmt the MTP state bindings * fix(llms): keep the prompt cache's shared prefix for a DFlash or DSpark drafter The head-state change treated every draft model behind the speculative shim as a head that carries its state from one read to the next. A DFlash or DSpark drafter keeps none, so on a cache that can be cut anywhere nothing was ever stashed, and every request whose prompt shared only part of the cache read it all again from position 0. On Mistral Large 4 with its DSpark drafter split across three nodes, each request reused 0 of its 35 prompt tokens instead of 34, which changed its prefill batches and its replies. Only an MTP head now counts as one. * deps(llama-cpp): pin llama.cpp to the squash of spiceai/llama.cpp#33 (spiceai#16049) spiceai/llama.cpp#33 rebuilds a meta split a backend would reuse when another backend's rebuilds have reset the containers holding its views. Since spiceai/llama.cpp#27 the DSpark drafter's graphs view the target's weights, and with one graph slot (LLAMA_GRAPH_SLOTS=0) DeepSeek-V4.1 split by tensor aborted on its first or second request at ggml-cuda/binbcast.cu:417. Spice's default of two graph slots builds splits from clones and did not reach it. The ledger records the pin and a row for spiceai#33, a GAP covered by the fork's test-meta-shared-views, and the GAP count moves from 58 to 59. * test(llms-llamacpp): require at least one non-empty MTP draft in regression helpers Copilot: generate/generate_after_read could pass with every draft empty. Assert each helper produced at least one non-empty draft before returning. * test(llms-llamacpp): compare whole replies when every MTP draft matches The prompt-cache guards compared the two runs' replies only up to the shorter one. A reply grows by the step's token and the drafts the target accepted, and the final step's next token is never appended, so two runs whose final steps accepted different numbers of drafts give one reply that is a prefix of the other, and the prefix comparison passed. With the same drafts at every step the runs take the same steps, so both guards now require the whole replies to be equal once every draft matches. Watched failing: with the final step's reply one token short in one run, both guards passed before this change, and fail with it ("whose drafts match at every step"). * perf(llama-cpp): take a greedy request's picks from the argmax output on a split model On a model split across nodes, a request that picks greedily alone (no penalties, no end-of-generation ban, no grammar) now decodes with the fork's argmax output on. A model whose output head the split divides by rows, DeepSeek-V4.1 today, then computes each row's pick on the devices that hold the head and sends back the picks instead of gathering every row's logits; any other model computes its logits as before and llama.cpp takes their first maximum. The single path sets the mode per request before its prompt is read; the batching path keeps it on while every running request picks greedily alone. Changing the mode rebuilds the graph, so the context calls llama.cpp only when it changes. * test(llms-llamacpp): decode several requests together on a split model, against one node's replies A model split across two ranks loads to decode two requests at once and runs two cases: - Two greedy requests together, which take their picks from the argmax output. - A penalized request that joins a greedy one after its first chunk and leaves before it, turning the argmax output off while it runs and on again after. Each reply must equal one node's reply to the same request alone. The batching tests' helpers are shared with the distributed tests for this, and two calls in batching.rs are formatted as rustfmt writes them.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A meta backend reused a graph's split after another backend's rebuilds had reset the device tensors that split pointed at. With one graph slot (
LLAMA_GRAPH_SLOTS=0), DeepSeek-V4.1 with its DSpark drafter aborted on its first or second request since #27.How it happens:
The abort, on stock
llama-serverat 6b673b0 under gdb: every RPC server stopped atggml-cuda/binbcast.cu:417(GGML_ASSERT(src1->type == GGML_TYPE_F32 || …)). The node was the target'snode_44, a MUL of a view ofhc_mixes-0, and its second source was the drafter's view:The change (
ggml/src/ggml-backend-meta.cpp):Tests
test-meta-shared-views(new). It runs on two copies of the CPU device:out = x * view(s, 0..n).s[n..2n).macOS (Apple M3 Max), CPU build, three runs of each build, 2026-11-05:
ggml-backend-meta.cppAt 6b673b0, A's reused graph computes with B's view:
Existing tests, with this PR:
test-meta-graph-slots,test-meta-async-read,test-meta-gather-exactandtest-argmax-splitpass.test-llama-archspasses:all 145 test(s) passed.test-meta-shared-viewsfails at 6b673b0 (exit 1, the split case) and passes with this PR.test-meta-graph-slots,test-meta-gather-exactandtest-argmax-splitpass, includingtest-argmax-splitonCUDA0.Lab A/B: stock
llama-server, 6b673b0 against this PRSetup:
-sm tensor).LLAMA_GRAPH_SLOTS=0)binbcast.cu:417on all three serversReview
An independent review of the first version found the source-only case. A split can read a view through a node's source without the view's buffer being among its nodes' buffers. The split case in the test reproduces it: that version fails the case, and this one passes it. The same review found no use-after-free in the records. They name only buffers of the graph with the recorded uid, and are checked only when that uid is computed again.