Repository navigation
Tensor split for Mistral Large 4 and its DSpark drafter - #20
Conversation
Splits its MLA attention by whole query heads, as GLM5-Next's MLA layers are split, so the model can run tensor-parallel across devices. The rules under the meta backend: - attn_q.weight splits along its rows (axis 1), attn_k_b/attn_v_b along their head axis (2), attn_ssmax weight and bias along their one value per head (0), and attn_output along its input (0), all by whole heads, from attn_output's split; the head granularity keeps a quant block of attn_output from straddling two devices. - the latent cache and the DSA indexer's key cache (both cache_k_l<il>), the latent projection (attn_kv_a_mqa) and the whole indexer stay mirrored: every device computes the one latent KV head and the top-k in full and attends over the whole latent with its own heads, so the indexer's selection across all heads is never approximated. - the shared expert splits as DeepSeek-V4's and GLM5-Next's do (up and gate along their rows, down along its input); the routed experts, the dense lead layer and the output use the generic rules. The per-head SSMax scale is now repeated over the tokens and multiplied by the position term, instead of the position being repeated over the heads, so a scale split by heads keeps its heads (the meta backend broadcasts a mirrored operand only along a size-1 axis). The product is the same per element. The test fixture gives mistral-large4 six heads and one latent KV head, as the GGUF has, so the split divides whole heads on 2 or 3 devices.
A DSpark drafter of a split Mistral Large 4 aborted on its first decode: as an arch-dflash model it got the generic split rules, so its latent K cache split while the latent it writes there stays whole (handle_set_rows), and its attn_q split by generic heads against a mirrored attn_k_b (unsupported mul_mat split states). The drafter's dense MLA stages (a dflash model with kv_lora_rank, the one build_arch_graph serves with graph_mistral_large4) now take the target's rules: latent cache and attn_kv_a_mqa mirrored, attn_q, attn_k_b/attn_v_b and attn_output split by whole query heads, in the same head granularity. Its draft-only tensors (fc, mask_embd, the Markov head) stay mirrored as before. The Markov head adds its bias to whole vocabulary rows and takes their argmax, but a split output head (the target's, which the drafter shares) yields logits split by vocabulary rows, so they are now gathered before the head whenever that head's model is tensor-split; with LLAMA_TENSOR_LOGITS_GATHER the existing build_logits_gather does it.
There was a problem hiding this comment.
🟡 Changes recommended
With LLAMA_TENSOR_LOGITS_GATHER=1 and LLAMA_DSPARK_SPLIT=1, the MLA drafter’s fc.weight split sends a sharded activation directly to RMS norm, causing the meta backend to abort before KV injection.
1 open issue
What changed in this PR
Enables tensor splitting for Mistral Large 4 and its DSpark drafter in llama.cpp, extending multi-device inference beyond layer splitting.
Changes:
- Adds whole-head attention splitting while mirroring latent caches and indexer tensors.
- Adjusts SSMax broadcasting and gathers drafter logits before operations requiring the full vocabulary.
- Updates architecture test metadata for two- and three-device splits.
| File | Description |
|---|---|
tests/test-llama-archs.cpp |
Uses six query heads and one latent KV head for Mistral Large 4 tests. |
src/models/mistral-large4.cpp |
Reorders SSMax multiplication to support head-split broadcasting. |
src/models/dflash.cpp |
Gathers split logits before the drafter's Markov head. |
src/llama-model.cpp |
Defines split axes, mirroring rules, and head granularity for the target and drafter. |
src/llama-arch.cpp |
Enables Mistral Large 4 tensor-split support. |
Review effort: Balanced
…rm when the drafter is split With LLAMA_TENSOR_LOGITS_GATHER=1 and LLAMA_DSPARK_SPLIT=1 the fc.weight projection leaves each device an axis-0 shard, and the RMS norm that follows reads whole rows, so the meta backend aborted at ggml-backend-meta.cpp:627. Gather it first, as the logits gather does.
|
Responding to the Copilot review and to CI on 6237114. Drafter split with logits gather (the review's headline, thread on The This PR does not touch The |
There was a problem hiding this comment.
🔵 Needs a closer look
Full-size IQ2_XXS runs diverge on 6/8 prompts across split modes and drafted versus undrafted output, requiring maintainer-led logit-margin analysis to distinguish numerical sensitivity from correctness regressions.
No open issues 🎉
1 resolved since last review
Review effort: Balanced
|
Addressed #20 (review): the full-size divergences are now margin-walked against an independent oracle. The results are in the PR description under Margin walk at the first differing token. Oracle. Upstream b11999 Method. For each prompt where two configurations' replies differ, both replies are tokenized and the first differing token is found. The oracle then ranks both tokens after the prompt plus the shared tokens. The prompt's token count matched each run's recorded count on all 8 prompts. Results. Each configuration repeats its own replies exactly, and 6 of 8 replies differ between any two of them:
At 4 of the 6 stock-vs-split positions, the oracle ranks stock's own token second. The stock build flips between its decode path and its prompt-batch path at exactly these positions, so they are near-ties that move with numerics. They are not a split computing wrongly. No walk found a continuation outside the top 3 or a margin above 0.44 nats. A correction to the first walk. Cutting back to the last space scored a shared word on 5 rows, and on 2 rows it added a CI, following up my earlier comment. The The x64 job was cancelled by fail-fast. On #21, which removes the variable, all three ubuntu jobs and the ASan, UBSan and TSan |
|
Addressed #20 (review). Logit parity on the full model is now measured, in the PR description under Logit parity over wikitext-2. Setup. Same UD-IQ2_XXS GGUF and three nodes, 2026-10-30.
|
|
Addressed #20 (review): the fused kernels that change are identified, and the PR description is updated. Method. I built 5df2bd1 and its base 2bedd1f with each fusion logged: the On the rpc-server holding layers 1–24, over the 41 evaluations of each layer:
The base build alone moves as far. With |
There was a problem hiding this comment.
🔵 Needs a closer look
A model/backend maintainer needs to assess whether the SSMax rewrite’s altered CUDA MoE fusion selection and reported numerical drift—KLD around 0.074–0.076 and roughly 7% changed top-token predictions—are acceptable for the production quantized model.
No open issues 🎉
Review effort: Balanced
… split The per-head order a tensor split needs computes the same values, but it changes which CUDA MoE fusions pass their buffer-overlap check, and with them the logits. Keeping upstream's graph for every other split mode keeps a layer split's logits identical to upstream's.
|
Addressed #20 (review) in 1eeb32d. The drift on a layer split is gone rather than left for a maintainer to accept. The change. The per-head SSMax order is now built only under Measured on the same full-model run (40 wikitext-2 chunks, scored against the fork base's saved logits):
The PR description's Logit parity over wikitext-2 section now reports 1eeb32d. It keeps the fusion diff that explains why the order depends on the split mode. |
…9-ml4-tensor-split
There was a problem hiding this comment.
🔵 Needs a closer look
Backend-owner validation is needed to determine whether the reported tensor-split drift (0.0739 mean KLD and 93.05% top-token agreement) is acceptable for multi-device MLA/DSpark inference across CUDA and Metal.
No open issues 🎉
Review effort: Balanced
…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").
…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.
…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").
… 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.

What this changes
Mistral Large 4 (
mistral-large4) can split across devices (LLAMA_SPLIT_MODE_TENSOR). Upstream lists it as unable to tensor-split, so a model this size could only layer-split across nodes. Rules inllama_meta_device_get_split_state:attn_qrows, the heads ofattn_k_bandattn_v_b,attn_ssmax(one value per head), and the input ofattn_output. The head granularity is the existing MLA one, which keeps a quant block ofattn_outputon one device; on the IQ2_XXS GGUF that's 2-head steps, so 22/22/20 of 64 heads on three ranks.cache_k_l<il>),attn_kv_a_mqaand the whole indexer are mirrored. Every rank computes the latent and the indexer's top-k in full, so the selection across heads is never approximated.Under a tensor split, the SSMax scale is built as
s[h] * pos[t]instead ofpos[t] * s[h]. The meta backend broadcasts a mirrored operand only along a size-1 axis, and each element is the same product in the other order. Every other split mode keeps upstream's graph (1eeb32d). The other order changes which CUDA MoE fusions pass their buffer-overlap check, and that moved a layer split's logits (below).Its DSpark drafter splits with it (6237114). The drafter's MLA stages (a
dflashmodel withkv_lora_rank, which is howbuild_arch_graphpicksgraph_mistral_large4) take the same rules. Without them, its latent cache split while the latent written to it stayed whole, and the first decode aborted inhandle_set_rows. The logits from the target's split output head are also gathered before the Markov head, which adds a full-vocabulary bias and takes the argmax.test-llama-archsgivesmistral-large4six heads and one latent KV head (the GGUF has one), so the split divides whole heads on two or three devices.Evidence
macOS, Metal:
test-llama-archs -a mistral-large4: the Meta row is OK (9.84e-08). Over three local Metal rpc-servers (--rpc) it is OK (9.32e-07). Before the change the Meta row aborted atggml-backend-meta.cpp:856.test-llama-archs:all 548 test(s) passed(again at 1eeb32d, where-a mistral-large4's Meta row is OK at 1.34e-07).test-llama-context --models: 139/139 (at 5df2bd1; not re-run at 1eeb32d).Three DGX Spark nodes, the Unsloth UD-IQ2_XXS GGUF (302.5 GB), served by the Spice runtime. 8 prompts × 200 tokens, pooled tok/s:
-sm layerBefore 6237114, a split target with the drafter aborted on its first request with
GGML_ASSERT(split_states_equal(src_ss[0], src_ss[2])).Replies on the same 8 prompts:
Margin walk at the first differing token (2026-10-30, same GGUF and nodes):
llama-server,-sm layer, no drafter, no prompt cache. It shares none of this PR's split rules.-sm layervs tensor split-sm layervs tensor split + DSparkEvery divergence is a choice between the oracle's top two or three tokens, a fraction of a nat apart. For example,
Message(−0.67) vsFinding(−1.11), andwith(−1.05) vsvia(−1.08).These positions flip on batch shape alone, without any split. At 4 of the 6 stock-vs-split positions, the oracle ranks stock's own token second. The oracle reads the shared text as one prompt batch, while stock generated it one token at a time, with the same build and the same layer split.
None of the walks found a continuation outside the oracle's top 3, or a margin above 0.44 nats.
Logit parity over wikitext-2 (2026-10-30, same GGUF and nodes).
llama-perplexityruns 40 × 512-token chunks of the wikitext-2 test set with-ngl 999 -fa on -c 512 -b 512 -ub 512. The fork base (spiceai-b11999at 2bedd1f,-sm layer) saved its logits with--kl-divergence-base, and every run below is scored against them with--kl-divergence:-sm layer-sm layer-sm tensorGGML_CUDA_DISABLE_FUSION=1-ub 256-fa offThe base scores PPL 7.142 ± 0.212. Re-running upstream b11999 against its own saved logits gives 0.000000, so the measurement itself repeats exactly.
-sm tensor, and outside a tensor split the SSMax graph is upstream's.-ub 256,-fa offand fusion off give 0.073–0.077 there. In every run with a nonzero mean, the median KLD is 0.0065–0.0071 and the 99.9th percentile 6.3–7.9, so the mean comes from a few tokens. The margin walk above found the same thing at the reply level.Why the SSMax order depends on the split mode. At 5df2bd1 the per-head order was used in every split mode, and
-sm layerscored 0.0762 against the base.llama-eval-callback, one 13-token prompt,-sm layer), all 5,699 named tensors were identical, the final logits included.nodes_fusedlineGGML_CUDA_DEBUGbuilds print, switched on in a lab-only build of each side). On the rpc-server holding layers 1–24, two MoE fusions ran differently over the 41 evaluations of each layer:ffn_moe_probstoffn_moe_weights_norm: softmax, top-k, normalize) ran in 41 of 41 evaluations at 5df2bd1 and in 1 of 41 on the base.ffn_moe_weightedtoffn_moe_out, 8 nodes) was fused in all 24 layers at 5df2bd1. On the base, 10 of the 24 used a 3-nodeADDfusion instead.ggml_cuda_check_fusion_memory_ranges). A graph with the same values but different nodes is allocated differently. Which check rejected each fusion on the base is code inspection only.