You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
speculative: read a DSpark draft token as its row's largest logit - #23
A DSpark draft token is read from its logits row instead of through the CPU sampler chain, when that is the same token. The drafter takes the first candidate its per-sequence CPU chain leaves. That chain is top-k(10) and a final pick, so its first candidate is the row's largest logit. The chain gets there by copying the row into a 12-byte candidate per vocabulary token (129,280 for DeepSeek-V4.1) and partially sorting it. common_sampler_row_argmax (new in common/sampling.{h,cpp}, with the pure common_logits_argmax and the chain check common_sampler_top1_is_argmax) reads the row in place, in two passes the compiler vectorizes: the largest logit that is not a NaN, then the first token that has it. That is the greedy sampler's pick, NaNs included.
A single scan that keeps the running maximum is slower than the chain on Apple M3 Max (below), because every logit waits on the previous compare.
When it applies. The CPU chain must be top-k and its final pick alone, which the drafter checks once, when it builds the chains (common_sampler_top1_is_argmax). A vocabulary that suppresses tokens adds a logit bias ahead of top-k, and such a chain keeps the old path. With the parameters the drafter sets, no grammar or reasoning budget runs ahead of the chain.
A row a backend sampler sampled keeps the old path. The CPU holds only that sampler's candidates for such a row. common_sampler_row_argmax returns LLAMA_TOKEN_NULL for it, and the drafter then samples as before. idx must be an output row of the last decode, as for llama_get_logits_ith. With SPLIT_MODE_TENSOR, set_sampler refuses the drafter's backend chain ("backend sampling not supported with SPLIT_MODE_TENSOR; using CPU") unless LLAMA_TENSOR_BACKEND_SAMPLING=1, so every row of a tensor-split drafter takes the new path.
Ties. On an exact tie for the largest logit, the scan takes the lowest token id, as the greedy sampler does. Top-k's std::partial_sort leaves tied candidates in an unspecified order. A draft token only proposes: the target's verification decides the reply either way.
The draft loop otherwise runs as before. It still calls common_sampler_accept, and the chain is reset at each draft. The final dist pick, which the drafter never read, no longer draws for these rows.
Why not sample on the backend under SPLIT_MODE_TENSOR instead. Upstream refuses every backend sampler with SPLIT_MODE_TENSOR. This fork lets one through only behind LLAMA_TENSOR_BACKEND_SAMPLING=1, because the meta backend's per-row ops (top-k) assert when the vocabulary axis of the sampled logits is split. So that path works only when the output head is mirrored, which is a per-model property (DeepSeek-V4 mirrors its head; most models split it). Making it the default would mean deciding that per model, and attaching a chain also makes the context reserve its graphs again. The scan here has no precondition beyond the chain's shape.
Tests added.
tests/test-logits-argmax.cpp (ctest label main) compares common_logits_argmax with llama_sampler_init_greedy on 6812 rows. The rows cover lane and block edges, ties, NaNs, infinities and signed zeros, plus full 129,280-logit rows. It passed on CI ubuntu arm64 at 21d331e.
test_row_argmax in tests/test-backend-sampler.cpp needs a model. On a plain row it checks the pick against a greedy chain's llama_sampler_sample, and on a backend-sampled row it checks for LLAMA_TOKEN_NULL.
test_top1_is_argmax in the same file checks common_sampler_top1_is_argmax, which the drafter now calls to test its chain's shape. The drafter's parameters pass. A logit bias, top_k = 0, an extra sampler, a grammar and a reasoning budget are each rejected.
At faa6d7c on Metal with Qwen3-0.6B, both model tests and the full test-backend-sampler pass. Each of the three new tests fails under a mutation of what it guards (comment).
Evidence
Spark A/B of this PR's code, end to end, with the runtime half (spiceai/spiceai#15911) (2026-11-01, details). DeepSeek-V4.1 UD-Q2_K_XL with a DSpark drafter (n_max 3), on three DGX Sparks with a tensor split, served by spiced, 8 prompts × 200 tokens per run, sessions B A A B, two counted runs each:
Arm A: spiced 23bacc2008 + the lab's llama.cpp ef88449.
Result: B 42.38–42.73 tok/s against A 42.08–42.49 (n=4 counted runs each), a mean of 42.52 against 42.21: +0.31 tok/s (+0.7%) with both halves on.
Both B sessions (42.61, 42.43) beat both A sessions (42.30, 42.13), and replies were 8/8 identical to A in all 12 runs.
Prototype, for context: an earlier prototype of both halves, toggled behind environment switches in one session, measured +2.6%. That number is the prototype's, not this code's.
Likely cause of the difference, code inspection only: each llama.cpp row getter (llama_get_sampled_token_ith, _logits_ith, _probs_ith, llama_get_logits_ith) starts with llama_context::synchronize(), which on a split model waits on every RPC dispatcher. The prototype read the row with one getter. This code first checks that no backend sampler sampled the row, which takes four getters per pick. That leaves it most of the waits llama_sampler_sample makes. A follow-up measures this and, if it holds, cuts the waits.
macOS, Apple M3 Max, Metal, at 81bb557 (the scan has been moved to common/sampling.cpp since, unchanged), built from a clean build dir with -DGGML_CCACHE=OFF -DGGML_METAL=ON -DGGML_RPC=ON -DBUILD_SHARED_LIBS=OFF:
test-llama-archs: Summary: all 548 test(s) passed.
test-sampling: passes.
test-speculative-rejection-sampling (on the test-llama-archs -a llama -s 999 target): All tests passed.
The same replies and the same drafts, end to end. No test in this repo drives the DSpark draft loop, so llama-server ran a tiny random-weight Mistral Large 4 target (as test-llama-archs writes it) with a tiny random-weight DSpark drafter for it. Each run was 4 greedy completions × 128 tokens, at this PR's base (f3bce26) and at this PR:
split over three local rpc-servers (-sm tensor)
one device (MTL0)
drafter's CPU chain
yes: set_sampler: backend sampling not supported with SPLIT_MODE_TENSOR; using CPU
no: the drafter samples on the backend
token ids, 4 × 128, base vs this PR
identical
identical
drafted / accepted per prompt, base vs this PR
identical (372/1, 375/0, 375/0, 375/0)
identical
In-situ differential check. A build with temporary instrumentation (not in this PR) also ran the old path at every draft position where the new one answered. Over the split run, the two picked the same token at 1509 of 1509 positions. On one device the new path never answered, because every row was backend-sampled, so those rows took the old path.
The check catches a wrong pick. With the scan pointed at the neighbouring output row, it reported 1474 of 1512 positions different. Prompt 0 then accepted 0 drafts instead of 1. The replies stayed the same, because the target verifies every draft.
Pick cost on one 129,280-logit row, Apple M3 Max, -O3. This is a scratch bench, not part of the PR. The old path goes through libllama (llama_sampler_apply on a [top-k(10), dist] chain after filling the candidates). The new path is this PR's scan, extracted verbatim from common/speculative.cpp. Each path ran 64 rows of N(0, 3) logits × 160 reps, n = 10,240 picks per path, with the arm order alternating every rep. Both runs:
path
p99 µs
p99.9 µs
old: candidates + top-k
69.7 / 63.3
73.6 / 66.6
one scan, running max in a register
166.9 / 151.6
173.4 / 165.0
one scan, compare against logits[best] (the lab prototype)
132.5 / 120.5
143.1 / 130.0
this PR: two passes
19.0 / 17.0
21.4 / 18.9
Each of the four paths picked the greedy sampler's token on all 64 full rows.
This PR's scan matched the greedy sampler on 20,000 short rows drawn from {-inf, -1, -0, 0, 0.5, 1, inf, NaN}, where most rows tie.
On this CPU, both single scans are slower than the old path. On the Sparks the prototype's single scan was faster than the old path (above). The two-pass scan is the fastest of the four on this Mac, and its effect on the Sparks is still to be measured.
The runtime picks this up with a later llama-cpp-src pin bump. spiceai/spiceai pins this fork at spiceai-b11803 today, so nothing changes in the runtime until a bump to a commit that has this one.
The DSpark drafter takes the first candidate its CPU sampler chain leaves. When that chain is top-k and its final
pick alone (no logit bias ahead of it), the first candidate is the row's largest logit, so the drafter now reads it
from the row instead of copying the row into a candidate per vocabulary token and partially sorting it. A row a
backend sampler sampled still goes through the chain.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The new row scan and DSpark fast path lack checked-in regression tests for boundary cases, ties, NaNs, and backend-sampled-row fallback, leaving future token-selection changes unprotected.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Add regression tests for row scan and DSpark fallback
common/speculative.cpp:995
The new row scan and DSpark fast path have no checked-in regression tests, so the temporary differential checks will not catch future changes to token selection or fallback behavior. Please add persistent comparisons against the greedy sampler for row lengths around the 16-lane and 64-token boundaries, ties, and NaNs, plus coverage for the backend-sampled-row fallback. Other helpers in this file already have automated coverage in tests/test-arg-parser.cpp.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
The seeded-coverage assertion fails valid argmax results and release CTest runs, while non-output-row probes abort in debug builds instead of returning LLAMA_TOKEN_NULL.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The promised LLAMA_TOKEN_NULL fallback for non-output rows instead reaches a logits getter that aborts in debug builds, so the contract or lookup needs correction.
Re the request for checked-in regression tests (Copilot review on b3aa7f2): addressed in 55f4e84 and 21d331e.
The scan moved to common_logits_argmax / common_sampler_row_argmax in common/sampling.{h,cpp}. speculative.cpp calls it.
tests/test-logits-argmax.cpp (ctest label main) compares the scan with llama_sampler_init_greedy. It covers rows of 1, 2, 3, 15-17, 31-33, 63-65, 127-129, 200 and 1000 logits drawn from {-inf, -1, -0, 0, 0.5, 1, inf, NaN}, half of them with the maximum planted once or twice at random places. It adds explicit tie, NaN-first and signed-zero rows, and 8 full 129,280-logit rows. CI ran it on ubuntu arm64 at 21d331e: 6812 rows matched.
test_row_argmax in tests/test-backend-sampler.cpp covers a row with no backend sampler, which must match a greedy chain's llama_sampler_sample over 8 decode steps. It also covers a backend-sampled row (top-k + greedy attached), which must give LLAMA_TOKEN_NULL. That test needs a model, so CI does not run it. It has not run yet because a build hold on my machine is in effect. I will run it, and show both new tests failing under a mutation, once the hold lifts.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because the published review omits findings about untested top-k-only fallback behavior and a documented NaN contract that contradicts the implementation.
Re Copilot's review of 0478580, which names an untested fallback for a chain that is not top-k alone, and a NaN contract the code contradicts. Both are addressed in faa6d7c:
The NaN wording was wrong and is fixed. The header said "a NaN never wins", but the code (like the greedy sampler) returns token 0 when logits[0] is a NaN. common_logits_argmax now documents "the first max on a tie, and token 0 when logits[0] is a NaN, else never a NaN". test-logits-argmax already checks {NAN, 5.0f} against llama_sampler_init_greedy.
The chain-shape check is now a tested function.common_sampler_top1_is_argmax in common/sampling.cpp returns false for a grammar, a reasoning budget, top_k <= 0, or any chain other than top-k plus its final pick. The drafter calls it. test_top1_is_argmax in test-backend-sampler.cpp checks it on Qwen3-0.6B: the drafter's parameters are accepted (the vocabulary suppresses no tokens), while a user logit bias, top_k = 0, an extra temperature sampler, a grammar and a reasoning budget are each rejected.
Runs at faa6d7c on macOS (Apple M3 Max, Metal), from a clean build dir with -DGGML_CCACHE=OFF, against Qwen3-0.6B-Q8_0.gguf:
test-logits-argmax: common_logits_argmax matches the greedy sampler on 6812 rows (530 picks past logit 63).
test-backend-sampler --test test_row_argmax and --test test_top1_is_argmax: exit 0. The full test-backend-sampler (23 default tests): exit 0.
test-llama-archs: Summary: all 548 test(s) passed. test-sampling exit 0. test-speculative-rejection-sampling: All tests passed.
Tiny DSpark end to end, split over three local rpc-servers and on one device: token ids and drafted/accepted counts identical to the base f3bce26. The in-situ check build picked the same token at 1509 of 1509 draft positions, so the fast path still runs.
Each new test fails when what it guards is broken. Each mutation was applied, rebuilt, run and reverted:
mutation in common/sampling.cpp
result
pass 2 takes the last match in the block
test-logits-argmax: Assertion failed: (false), function check, file test-logits-argmax.cpp, line 35.
Re Copilot's review of faa6d7c, which says the greedy-based backend case bypasses the sampled-logits guard, so DSpark's top-k-only fallback is never exercised. That's correct, and it is addressed in 0805c8d.
The gap. The case attached top-k plus greedy, which picks a token on the backend. common_sampler_row_argmax therefore returned at its sampled-token check, and the sampled-logits check never ran.
What changed.test_row_argmax now also attaches top-k(10) alone, the chain the DSpark drafter attaches. For each chain it first checks the setup it means to test: llama_get_sampled_token_ith != LLAMA_TOKEN_NULL holds exactly when the chain picks, and llama_get_sampled_logits_count_ith == 10. Only then does it check that common_sampler_row_argmax returns LLAMA_TOKEN_NULL.
The run, at 0805c8d on macOS Metal with Qwen3-0.6B-Q8_0.gguf: test-backend-sampler --test test_row_argmax exits 0, and the full test-backend-sampler (23 default tests) exits 0.
It fails when the guard is broken. With only the sampled-logits check removed from common_sampler_row_argmax, it fails: test-backend-sampler.cpp:472: GGML_ASSERT(common_sampler_row_argmax(test_ctx.ctx.get(), idx) == LLAMA_TOKEN_NULL) failed, exit 134. That is the top-k-alone iteration, since the picking chain's row returns at the sampled-token check that is still in place. With the check restored it passes.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The two-pass scan lacks benchmarks on the intended DGX Spark tensor-split workload, and gains from a different prototype plus platform-dependent performance rankings leave regression risk unresolved.
Spark A/B of the final code (2026-11-01, bash ~/evidence/argmax-ab/chain-221.sh on the lab's bench node, holding the lab lock, 19:36–20:45Z)
Workload: the same as the prototype A/B. DeepSeek-V4.1 UD-Q2_K_XL with its DSpark drafter (n_max 3), on three DGX Sparks with a tensor split, served by spiced; bench_spiced runs 8 prompts × 200 tokens. The workload needs the lab's goal-stack fork (ef88449), so both arms build on it:
arm
spiced
llama.cpp
binary sha256
A
23bacc2008e3 (the trunk commit ggml-org#15911 merged at 94315e6b)
94315e6bf190 (ggml-org#15911's head then; 7ba7fee1, pushed since, merges trunk 8d579949 and has the same diff)
ef88449 + #23's diff f3bce26..0805c8d. Every file it touches is identical at ef88449 and f3bce26, and B's copies were checked byte-equal to 0805c8d's
4e7624fd…abbba460
Both arms use the lab's spiced recipe, [patch] to the fork path and GGML_RPC_GET_ASYNC/SET_ASYNC. Each session is one model load; sessions ran B A A B. In each session the first bench (W) is set aside and two more (a, b) are counted.
run
pooled tok/s
per prompt min / median / max (n=8)
replies equal to A1a
B1a / B1b
42.73 / 42.48
34.87, 34.91 / 41.41, 41.00 / 55.74, 55.63
8/8, 8/8
A1a / A1b
42.49 / 42.10
35.37, 34.44 / 41.01, 40.63 / 54.75, 55.01
8/8, 8/8
A2a / A2b
42.17 / 42.08
35.20, 34.96 / 40.79, 40.49 / 55.63, 54.09
8/8, 8/8
B2a / B2b
42.38 / 42.48
34.73, 34.81 / 40.82, 41.23 / 55.31, 55.69
8/8, 8/8
B is faster by +0.31 tok/s (+0.7%). The counted runs average 42.52 for B (range 42.38–42.73, n=4) against 42.21 for A (42.08–42.49, n=4). Both B sessions (42.61, 42.43) are faster than both A sessions (42.30, 42.13). The set-aside first benches agree (B 41.48 / 41.28, A 40.63 / 41.06).
Replies are 8/8 identical to A1a in all 12 runs.
The final code gains about a quarter of the prototype's +2.6%. That one-session A/B toggled environment switches, with no reload between arms.
Hypothesis for the gap (code inspection only, not measured yet):
Every row getter in llama.cpp (llama_get_sampled_token_ith, _logits_ith, _probs_ith, llama_get_logits_ith) starts with llama_context::synchronize(). On this split model that waits on each RPC dispatcher (rpc_dispatcher::synchronize pushes a no-op message and waits for it).
The prototype read the row with one getter. The final code guards against backend-sampled rows first, so it makes four getter calls per pick. Trunk's llama_sampler_sample makes five, and the drafter's common_sampler_sample about six.
The final code therefore saves the candidate fill and sort, but only one or two of those waits per pick, where the prototype saved four or five.
A third arm with the guards removed would test this.
…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#25spiceai/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#25spiceai/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#25spiceai/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#25spiceai/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
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 this changes
A DSpark draft token is read from its logits row instead of through the CPU sampler chain, when that is the same token. The drafter takes the first candidate its per-sequence CPU chain leaves. That chain is top-k(10) and a final pick, so its first candidate is the row's largest logit. The chain gets there by copying the row into a 12-byte candidate per vocabulary token (129,280 for DeepSeek-V4.1) and partially sorting it.
common_sampler_row_argmax(new incommon/sampling.{h,cpp}, with the purecommon_logits_argmaxand the chain checkcommon_sampler_top1_is_argmax) reads the row in place, in two passes the compiler vectorizes: the largest logit that is not a NaN, then the first token that has it. That is the greedy sampler's pick, NaNs included.A single scan that keeps the running maximum is slower than the chain on Apple M3 Max (below), because every logit waits on the previous compare.
common_sampler_top1_is_argmax). A vocabulary that suppresses tokens adds a logit bias ahead of top-k, and such a chain keeps the old path. With the parameters the drafter sets, no grammar or reasoning budget runs ahead of the chain.common_sampler_row_argmaxreturnsLLAMA_TOKEN_NULLfor it, and the drafter then samples as before.idxmust be an output row of the last decode, as forllama_get_logits_ith. WithSPLIT_MODE_TENSOR,set_samplerrefuses the drafter's backend chain ("backend sampling not supported with SPLIT_MODE_TENSOR; using CPU") unlessLLAMA_TENSOR_BACKEND_SAMPLING=1, so every row of a tensor-split drafter takes the new path.std::partial_sortleaves tied candidates in an unspecified order. A draft token only proposes: the target's verification decides the reply either way.common_sampler_accept, and the chain is reset at each draft. The finaldistpick, which the drafter never read, no longer draws for these rows.Why not sample on the backend under
SPLIT_MODE_TENSORinstead. Upstream refuses every backend sampler withSPLIT_MODE_TENSOR. This fork lets one through only behindLLAMA_TENSOR_BACKEND_SAMPLING=1, because the meta backend's per-row ops (top-k) assert when the vocabulary axis of the sampled logits is split. So that path works only when the output head is mirrored, which is a per-model property (DeepSeek-V4 mirrors its head; most models split it). Making it the default would mean deciding that per model, and attaching a chain also makes the context reserve its graphs again. The scan here has no precondition beyond the chain's shape.Tests added.
tests/test-logits-argmax.cpp(ctest labelmain) comparescommon_logits_argmaxwithllama_sampler_init_greedyon 6812 rows. The rows cover lane and block edges, ties, NaNs, infinities and signed zeros, plus full 129,280-logit rows. It passed on CI ubuntu arm64 at 21d331e.test_row_argmaxintests/test-backend-sampler.cppneeds a model. On a plain row it checks the pick against a greedy chain'sllama_sampler_sample, and on a backend-sampled row it checks forLLAMA_TOKEN_NULL.test_top1_is_argmaxin the same file checkscommon_sampler_top1_is_argmax, which the drafter now calls to test its chain's shape. The drafter's parameters pass. A logit bias,top_k = 0, an extra sampler, a grammar and a reasoning budget are each rejected.test-backend-samplerpass. Each of the three new tests fails under a mutation of what it guards (comment).Evidence
Spark A/B of this PR's code, end to end, with the runtime half (spiceai/spiceai#15911) (2026-11-01, details). DeepSeek-V4.1 UD-Q2_K_XL with a DSpark drafter (n_max 3), on three DGX Sparks with a tensor split, served by
spiced, 8 prompts × 200 tokens per run, sessions B A A B, two counted runs each:f3bce26..0805c8dapplied.llama_get_sampled_token_ith,_logits_ith,_probs_ith,llama_get_logits_ith) starts withllama_context::synchronize(), which on a split model waits on every RPC dispatcher. The prototype read the row with one getter. This code first checks that no backend sampler sampled the row, which takes four getters per pick. That leaves it most of the waitsllama_sampler_samplemakes. A follow-up measures this and, if it holds, cuts the waits.macOS, Apple M3 Max, Metal, at 81bb557 (the scan has been moved to
common/sampling.cppsince, unchanged), built from a clean build dir with-DGGML_CCACHE=OFF -DGGML_METAL=ON -DGGML_RPC=ON -DBUILD_SHARED_LIBS=OFF:test-llama-archs:Summary: all 548 test(s) passed.test-sampling: passes.test-speculative-rejection-sampling(on thetest-llama-archs -a llama -s 999target):All tests passed.The same replies and the same drafts, end to end. No test in this repo drives the DSpark draft loop, so
llama-serverran a tiny random-weight Mistral Large 4 target (astest-llama-archswrites it) with a tiny random-weight DSpark drafter for it. Each run was 4 greedy completions × 128 tokens, at this PR's base (f3bce26) and at this PR:-sm tensor)set_sampler: backend sampling not supported with SPLIT_MODE_TENSOR; using CPUPick cost on one 129,280-logit row, Apple M3 Max,
-O3. This is a scratch bench, not part of the PR. The old path goes through libllama (llama_sampler_applyon a [top-k(10), dist] chain after filling the candidates). The new path is this PR's scan, extracted verbatim fromcommon/speculative.cpp. Each path ran 64 rows of N(0, 3) logits × 160 reps, n = 10,240 picks per path, with the arm order alternating every rep. Both runs:logits[best](the lab prototype)The runtime picks this up with a later
llama-cpp-srcpin bump. spiceai/spiceai pins this fork atspiceai-b11803today, so nothing changes in the runtime until a bump to a commit that has this one.