Repository navigation
llama: read a row no backend sampler sampled with one synchronize - #25
Conversation
…pler sampled with one synchronize
There was a problem hiding this comment.
🟡 Changes recommended
The getter’s invalid-ID behavior is misdocumented: it aborts in builds without NDEBUG rather than returning NULL, requiring a documentation correction or non-aborting validation.
1 open issue
What changed in this PR
This PR reduces synchronization overhead in the DSpark draft-token path by combining backend-sampling checks and full-logits access into one public getter.
Changes:
- Adds
llama_get_unsampled_logits_ith, which synchronizes once and rejects backend-sampled rows. - Updates
common_sampler_row_argmaxto use the new getter. - Extends existing tests to check plain and backend-sampled rows.
| File | Description |
|---|---|
tests/test-backend-sampler.cpp |
Adds assertions for the new getter's row handling. |
src/llama-context.cpp |
Implements the single-synchronization getter. |
include/llama.h |
Declares and documents the public API. |
common/sampling.cpp |
Replaces multiple public getter calls with the new API. |
Review effort: Balanced
…as llama_get_logits_ith's
|
Spark A/B of this getter, chain-226 (2026-11-02,
|
…a.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.
…gits (DeepSeek-V4.1) (#30) * ggml: reduce meta-backend gathers exactly in the CUDA all-reduces A gather (ggml_backend_meta_gather) moves values rather than summing partial results: every device but one adds zeros. The CUDA internal all-reduce rounded every F32 tensor through BF16 (GGML_CUDA_AR_BF16_THRESHOLD defaults to 1), and the direct NCCL all-reduce and the opt-in BF16 NCCL wire did the same from 32768 elements, so a gathered tensor came back rounded: logits, and token ids above 256 (64122 came back as 64000). The RPC comm path already kept gathers in F32. The check moves to ggml-impl.h as ggml_is_meta_gather, and all four reductions keep a gather in its own type. test-meta-gather-exact gathers a product split across two copies of one device and compares it bit for bit with the whole product, logits and token ids above 100000. * llama: split the DSpark drafter's head by vocabulary rows under a tensor split On DeepSeek-V4.1 the DSpark drafter's output head (the target's Q6_K output.weight) and its Markov transition (markov_w2, BF16) are mirrored, so every device of a tensor split computes all 129280 rows. Each device now multiplies a view of its own rows of the copy it already holds (ggml_backend_meta_rows, no second copy of the weights), and the draft chain takes each position's first max from one (value, index) pair per device (ggml_argmax_part, gathered, then ggml_argmax_merge): the lowest index on a tie, and token 0 when the row's first logit is a NaN, as the greedy sampler picks. The rows the host reads are one-hot at the pick. Without a tensor split the graph is unchanged. test-argmax-split checks the split product bit for bit against the whole one and the picks against a CPU reference, with ties across and inside devices. * tests: test-backend-ops cases for ARGMAX_PART and ARGMAX_MERGE Rows whose every value appears twice, so each row's max ties and the first index must win, at the drafter's shapes (43094 and 129280 columns); pairs with few distinct values and the -1 sentinel for the merge. * ggml: append ARGMAX_PART and ARGMAX_MERGE to the op enum and move the RPC protocol to 9.0.0 Inserted after TOP_K_MASK, the two ops renumbered UNARY and every op after it. RPC sends ops by number and its handshake compares only the major and minor, so a peer built before them connected to one built after and ran the other's ops as different ones: on loopback an old server crashed (abort) on a new client's first graph, and a new server segfaulted on an old client's. Appended, they leave every older op's number alone, and with the major at 9 the two refuse each other at connect (RPC server version mismatch) before any graph runs. * llama: keep the DSpark head whole when a tensor split gives a device no rows A device with no rows of the split computes nothing, so its ggml_argmax_part pair was left unwritten: on the CPU meta backend, with the logits below 0, the merge picked the stale (0, 0) pair (token 0 where the first max was 5946, 12356 or 169). dspark_vocab_parts keeps the head whole when any device's share is empty, ggml_backend_meta_rows returns a view of the whole matrix in that case, and the meta split of ggml_argmax_part asserts that every device has rows. test-argmax-split adds the first and the last device empty under negative logits, Q6_K and BF16, and runs every split twice on the same buffers with other inputs. * tests: run test-argmax-split through the default all-reduce The test set GGML_CUDA_ALLREDUCE=none, which hid that the CUDA internal all-reduce rounded the gathered pairs through BF16. With gathers exact there, two copies of a CUDA device now reduce through it and three through the butterfly. * llama: keep the DSpark head whole for a draft of more than one sequence With several sequences each draft position's view of the head steps over the other sequences' rows, a strided view of a row-split tensor that the meta backend cannot split: building the graph aborted (ggml-backend-meta.cpp handle_view). dspark_vocab_parts splits the head for one sequence only. test-argmax-split builds the Markov head's graph for one sequence over a row-split head and for two over the whole head, picks against the first max of the whole computation. * rpc: agree on the BF16 NCCL wire only between ranks that keep gathers exact With gathers kept F32 on the BF16 wire, a rank of this build and one from before would both enable the wire (the agreement byte carried the wish, not the exception) and then run a large gather as ncclFloat on one rank and ncclBfloat16 on the other. A rank now asks for the BF16 wire with a new bit (RPC_NCCL_WIRE_BF16_EXACT) and never sends the old one, so an older rank reads no wish and stays on F32, and this rank enables the wire only when both ranks set the new bit. The agreement lives in nccl-wire.h; test-rpc-nccl-wire checks every pair of builds and wishes in both rank orders. * rpc: take the exact-gathers capability from the backend, and agree on the wire by wish bit The agreement bit said what the server could do, but a gather is reduced by the backend, which the server loads separately (GGML_BACKEND_DL). A new server with an old CUDA backend sent the exact bit and rounded gathers anyway. - A server now sends RPC_NCCL_WIRE_BF16_EXACT only when its backend exports ggml_backend_cuda_nccl_comm_set_wire_bf16_exact, and RPC_NCCL_WIRE_BF16 for a wish otherwise, as servers did before. - The wire is BF16 only when both ranks send the same wish bit: gathers stay F32 when both sent the exact bit, and are rounded on both ranks when both sent the old one (a pair with an older server or backend keeps the wire it had). - The CUDA backend keeps gathers F32 on the BF16 wire only after set_wire_bf16_exact; set_wire_bf16 rounds them, as an older backend does. - The server's word, agreement and setter call live in nccl-wire.h, and test-rpc-nccl-wire runs them for every ordered pair of ranks: old or new server, old or new backend, with or without GGML_NCCL_WIRE_BF16. * tests: run test-meta-gather-exact on every CPU and GPU device found It ran on the CPU unless TEST_DEVICE named a device, so a CI or local run on a GPU machine never reached a GPU's all-reduce. Now it runs on every CPU and GPU device, or on TEST_DEVICE alone when that is set. * ggml: a gather is exact in value, and a -0.0 comes back as +0.0 The comments said a gather was exact, but each device adds its slice to the others' zero padding, and -0.0 plus a zero is +0.0. Argmax picks are unaffected: a first max compares -0.0 and +0.0 as equal, so a tie still resolves by index. test-meta-gather-exact now gathers a split tensor of signed zeros among other values and compares it by value, and prints how many -0.0 came back +0.0. * tests: a NaN at the start of a later device's rows is skipped on the split path test_pairs checked a NaN as the row's first value on one backend, where every pair's origin is 0. On a meta device the check that makes a first NaN token 0 must apply only to the device whose rows start at 0: test_meta_nan puts a NaN at each later device's first row, with the max in the last row, in the first device's rows, or nowhere (every other row -inf), over two and three devices. * tests: skip a device that cannot run test-meta-gather-exact's ops On the macOS CI runner the Metal device has no simdgroup reductions, so it cannot run the F32 product, and the meta backend, which does not fall back to another device, aborted on it. A device is now skipped, with the op it lacks, when it does not support the product, the gather or the add the meta backend reduces with. TEST_DEVICE still fails when the device it names is skipped. * tests: check gathers against their slices, pin the CUDA reductions, and model pre-wish ranks test-meta-gather-exact: - Each gathered product is compared bit for bit with the split product read back slice by slice, as each device computed it, instead of with a whole product a backend may sum in another order. - The directly populated tensor of signed zeros grows to 65536 elements, above the direct NCCL all-reduce's 32768, with values BF16 cannot represent. - The registered test pins GGML_CUDA_AR_BF16_THRESHOLD=1 and unsets GGML_CUDA_ALLREDUCE (the platform default), and two more runs pin GGML_CUDA_ALLREDUCE=internal and =nccl. The NCCL run needs a build with NCCL and a second GPU, since NCCL takes one rank per GPU, and skips a CUDA device otherwise. test-rpc-nccl-wire: - Servers and backends from before the wire was negotiated join the model: 324 ordered pairs. - When the build has a CUDA backend with NCCL, it must export both wire setters, which a new server reads as the capability. The setters' own effect needs an NCCL communicator and stays unverified here. * ggml: keep a meta-backend gather's all-reduce at the gather The meta backend delays a partial sum's all-reduce past a following product by a mirrored tensor, and merges two branches' reductions into one of their sum. For a gather that moved the reduction to a node without the gather marker, so a CUDA reduction that keeps gathers in F32 rounded it to BF16 after all: gather -> mul(mirrored) -> relu, say. A gather's reduction is now never delayed, and never merged with another branch's. test-meta-gather-exact adds that graph: relu(gather * ones), compared by value with its slices. * sycl: reduce meta-backend gathers in F32 The SYCL all-reduce of two devices compressed every F32 tensor of 32768 elements and more to BF16, gathers included. A gather now takes the F32 path whatever its size, as in the CUDA reductions. Compiles in CI; unverified at runtime, with no SYCL device at hand. * tests: pair a CUDA device with a second GPU whenever it reduces through NCCL With GGML_CUDA_ALLREDUCE unset, Linux builds with NCCL reduce through it by default, and the default run paired a device with itself, which NCCL refuses (one rank per GPU). The test now resolves the reduction as the CUDA backend does before choosing the second device. * ggml: rows views at an offset, and argmax over whole rows, on a meta backend - A rows view of a mirrored matrix that is itself a view at a row offset aborted in the generic view-offset scaling, which asserts a split source. A rows view now skips it and takes the offset plus the rows of the devices before it. - ARGMAX_PART over whole rows split across the devices (axis 1) asserted a split along the row. It now keeps the rows' split, each device indexing its rows from 0, and ARGMAX_MERGE maps an axis-1 split of its pairs to its picks' only axis, instead of keeping axis 1 on a 1-D result, which failed the share assertion. - test-argmax-split checks both, over two and three devices, and runs at a 4096-token vocabulary unless TEST_VOCAB says otherwise (TEST_VOCAB=129280 for the drafter's shapes, several GiB on the CPU). * tests: compare ARGMAX_PART and ARGMAX_MERGE results exactly in test-backend-ops The pairs of a part with more than one slot carry (-inf, -1) padding, so the default nmse was NaN, which never exceeds max_err: a backend returning a wrong pair passed. Both cases now count the values that differ, an infinity matching only itself and a NaN only a NaN. * llama: keep the DSpark head whole with suppressed tokens or a weight off the meta device - A drafter vocabulary with suppressed tokens sends the draft rows through the sampler, whose logit bias runs before its pick: a one-hot row whose winner is suppressed would leave it nothing, where the whole row has the next-best token. Defensive guard, from code inspection only: no model at hand has suppressed tokens. - The split needs both the head and the Markov transition on the drafter's meta device, so that each device holds them and computes its rows. A weight placed elsewhere (an override that keeps the head on the CPU, say) now keeps the head whole. * tests: probe every op test-meta-gather-exact runs, on both devices of an NCCL pair The support probe checked the product, the gather and the add, but the graph also runs a broadcast product and a relu, and the second GPU of an NCCL pair was never probed. A device that cannot run one of them is now skipped, with the op it lacks, instead of failing inside the graph. * tests: check every pair test_pairs reads, not only the pick The NaN, infinity and signed-zero rows checked only the merged pick, so a part that wrote (+inf, 0) instead of (NaN, 0) for a first NaN would pass: both pick token 0. Every pair, padding included, is now compared with the reference bit for bit, a NaN matching a NaN. * ggml: ggml_backend_meta_rows requires a matrix with contiguous rows The rows view is built with ggml_view_2d, which takes rows of contiguous elements, so a transposed matrix was read with other strides than it has: [1 2 2 3 3 4] for a transpose holding [1 4 2 5 3 6]. It now asserts contiguous rows. * tests: on the CPU, check F32 split picks against what the devices computed CI's x86 CPU runners failed test-argmax-split: split 1365/1365/1366, the F32 split product differed from the whole product in 6376 of 8192 values, in the last bits, while Q6_K, BF16 and even splits were equal. The CPU's F32 product there depends on how many rows a device computes. For F32 on a CPU device the picks are now checked against the first max of the gathered split product (and the biased one, now gathered too), and the difference from the whole product is reported rather than failed. Every other type and device still has to match the whole product bit for bit, which the drafter's Q6_K head and BF16 Markov transition do on CUDA and the CPU. * llama, rpc: keep the DSpark head whole on a device that cannot run ARGMAX_PART or ARGMAX_MERGE RPC answered every op as supported, so under a tensor split over RPC servers backed by Metal the drafter split its head by rows and sent ARGMAX_PART to servers that abort on it ("unsupported op" in ggml-metal-ops.cpp). - Each RPC server now says in its HELLO (the response's spare byte, now op_caps) whether every backend it serves runs ARGMAX_PART and ARGMAX_MERGE over F32. An RPC device answers supports_op for those two ops from that bit, so a server that does not set it, as one built before it, is taken not to run them. - dspark_vocab_parts asks the meta device each weight is on (which asks each of its devices) whether it runs both ops, and keeps the head whole when it does not. This covers local devices without them as well as RPC ones. - test-rpc-argmax-split starts two RPC servers on one device (RPC_TEST_DEVICE, CPU by default) and checks that each RPC device and a meta device over the two answer as that device does locally, and that the picks of a head split across them, or kept whole when they cannot run the ops, are the first max of the whole head. * tests: pair a ROCm device with a second GPU when it reduces through RCCL test-meta-gather-exact paired a device with a second GPU only when its registry was named "CUDA", so on a ROCm build, which reduces through RCCL (NCCL's interface) the way a CUDA build reduces through NCCL, it paired the device with itself: RCCL then fails to initialize on one GPU, the comm falls back to the internal all-reduce, and the RCCL path is never exercised. Every build of the CUDA backend (CUDA, ROCm, MUSA) now takes that path, and the second GPU comes from the same backend's registry. * ggml: views and reshapes of a rows view keep each device's rows on a meta backend A view of a view is a view of its source, so a view or reshape of a rows view pointed at the mirrored matrix, and only the rows view itself took each device's row offset. An identity view or a reshape then had every device read the first rows again (gathered, the rows of the second device repeated the first's), and a view at an offset aborted in the generic view-offset scaling, which needs a split source. Every split view of a mirrored tensor now takes the offset the rows view took: the view's own offset plus the parts of the devices before it along its split axis, which covers the rows view and any view or reshape of it. A stride beyond the split axis, which the per-device strides would scale, is refused. test-argmax-split checks an identity view, a view of half of each row, a view from row 250 and a reshape of a rows view, each gathered against the rows it views, and a product with the identity view against the rows view's own product and pick. * llama: argmax output, the picks of a split output head without its logits (DeepSeek-V4.1) Under a tensor split the target's output head is mirrored: every device computes all 129280 rows of it for the verification batch, and the host copies the logits back and takes their first max for a greedy pick. With the argmax output on (llama_set_argmax_output), a DeepSeek-V4.1 context instead computes each device's rows of the head (a view of the copy it holds, ggml_backend_meta_rows) and takes the picks from one (value, index) pair per device (ARGMAX_PART, a gather, ARGMAX_MERGE), as the DSpark drafter does. llama_get_argmax_ith returns the pick: the greedy sampler's, the lowest index on a tie and token 0 when the row's first logit is a NaN. - The logits of such a decode are not computed: llama_get_logits_ith and llama_get_logits return NULL for it. - The head stays whole, and the picks come from the logits' first max on the host, without a tensor split, with LoRA, with LLAMA_TENSOR_LOGITS_GATHER, when a device would get no rows, or when the head is not on a meta device. - The mode is part of the graph parameters, so changing it rebuilds the graph. - test-argmax-split adds the target's verification head shape: Q6_K, 5120 x vocabulary, 4 columns. * ggml: ARGMAX_PART and ARGMAX_MERGE kernels refuse a destination that does not fit An RPC server deserializes a client's nodes without ggml_argmax_part's and ggml_argmax_merge's checks, and the kernels checked only their source: ARGMAX_PART wrote a pair into a destination of one value, or into rows the destination does not have, and ARGMAX_MERGE wrote one pick per source row into a shorter destination. The CPU kernels and the CUDA launchers now assert what the constructors build before writing anything: a matrix source; for ARGMAX_PART, an F32 contiguous matrix destination of an even width of at least two with one row per source row; for ARGMAX_MERGE, an even pairs width and a contiguous I32 vector of one pick per source row. GGML_ASSERT, as the neighbouring kernels (count_equal, the CUDA argmax) check their shapes, since a CPU op has no error to return and an RPC server asserts on a failed graph anyway. test-argmax-malformed builds such nodes by hand and computes each in a child process on the CPU backend, with the destination followed by canaries in memory shared with the parent: each malformed node must abort with every canary intact, and two well-formed nodes must compute their picks. * llama: name every logits getter the argmax output leaves NULL llama_get_unsampled_logits_ith, which #25 added, reads through llama_get_logits_ith and so returns NULL after an argmax-output decode as well; say so beside llama_get_logits and llama_get_logits_ith. * llama: keep the logits unreadable after an argmax-output decode until a decode succeeds A decode with the argmax output off set the logits readable as it started, so one that failed after an argmax-output decode exposed the logits buffer as that earlier decode had found it: logits from before it. It now keeps them as they were, readable only if the last decode that succeeded left them so, until it succeeds itself. llama_get_unsampled_logits_ith's comment names the argmax output among the cases that return NULL. * llama: keep the argmax output's head whole where it cannot split, and reserve an embedding context again on a mode change - With a backend sampler attached, the split head left no logits for it to sample from: build_sampling returned at once, and the sampler's token read LLAMA_TOKEN_NULL. head_vocab_parts keeps the head whole then, so the sampler runs and llama_get_argmax_ith refuses the row it sampled, as documented. - On a device that cannot run ARGMAX_PART or ARGMAX_MERGE (Metal, also behind an RPC server), the scheduler ran both on the CPU after copying the split product there. head_vocab_parts probes both ops on the head's meta device, through llama_dev_runs_argmax_split, which the DSpark drafter's head (dspark_vocab_parts) now shares. - In an embedding context the scheduler's reserve decides whether the output buffer holds logits from the graph it reserved with; reserved with the mode on and the head split, the context had no logits once the mode was off. set_argmax_output reserves again when the mode changes in an embedding context. test-llama-archs checks the argmax output on every tensor split, on new contexts, against the first max of a mode-off decode of the same batch: every pick (every token an output, and the last four), the split head's logits unreadable, a greedy backend sampler still sampling (with LLAMA_TENSOR_BACKEND_SAMPLING), and an embedding context's logits after the mode is off. Over two local RPC servers, a DeepSeek-V4.1 head splits on CPU servers and stays whole on Metal ones. * llama: keep the head whole for pooled embeddings, and move only the picks after an argmax-output decode - A pooled embedding context's graph skips the head (build_logits), but the argmax output's split head was expanded in the model graph, so it computed a vocabulary-wide projection and the picks for every token of a request that needed only its embedding. head_vocab_parts keeps the head whole there, and build_logits then drops it. - output_reorder swapped every reordered row's logits even when the decode left none (the argmax output); it now moves the logits only when they are readable. test-llama-archs: the backend sampler case reads LLAMA_TENSOR_BACKEND_SAMPLING as the runtime does (on when a non-zero number) and runs only when the argmax output split the head, whose logits are mirrored as backend sampling needs (a head split by vocabulary aborts the sampler's ARGMAX); a pooled embedding context must compute the same embedding with the mode on as off. * tests: check the argmax output's readiness across a failed decode in test-llama-archs With the head split: a decode with the mode off that an abort callback stops (returns 2) after an argmax-output decode must leave no logits readable, since the buffer still holds logits from before the argmax-output decode, and the next decode that succeeds must make them readable again, with the reference's first maxes. Without the readiness reset of c97df24 (logits_ready = !argmax_output as the decode starts), the case fails: logits from before the argmax-output decode are readable after the aborted one.
…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.
…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
llama_get_unsampled_logits_ith(ctx, i)reads the full logits row of the ith output with one synchronize. It returns NULL when a backend sampler sampled the row, since the host then has only its candidates, and for an invalid id.common_sampler_row_argmax, the DSpark drafter's pick from #23, now calls it.Why it matters on a split model. Every public row getter (
llama_get_sampled_token_ith,_logits_ith,_probs_ith,llama_get_logits_ith) starts withllama_context::synchronize(). On a tensor-split model that waits on every RPC dispatcher:rpc_dispatcher::synchronizequeues a no-op message and waits for it. Checking a row for backend sampling and then reading it took four synchronizes per pick. The new getter checks with the context's own unsynchronized accessors after a single synchronize.Evidence
Spark A/B, chain-225 (2026-11-01, 21:57–22:58Z). DeepSeek-V4.1 UD-Q2_K_XL + DSpark (n_max 3) on three DGX Sparks, tensor split, served by
spiced. Sessions ran A B C C B A, with 8 prompts × 200 tokens per run and four counted runs per arm:macOS, Apple M3 Max, Metal, at 49f5f8c, from a clean build dir with
-DGGML_CCACHE=OFF -DGGML_METAL=ON -DGGML_RPC=ON -DBUILD_SHARED_LIBS=OFF:test-backend-sampleronQwen3-0.6B-Q8_0.gguf: all 23 default tests pass.test_row_argmaxnow also asserts thatllama_get_unsampled_logits_ithreturnsllama_get_logits_ith's row on a plain row, and NULL on a backend-sampled row (top-k + greedy, and top-k alone).test-logits-argmax: 6812 rows match.test-samplingexits 0.test-speculative-rejection-sampling:All tests passed.test-llama-archs:Summary: all 548 test(s) passed.llama_get_unsampled_logits_ith,test_row_argmaxfails:test-backend-sampler.cpp:473: GGML_ASSERT(llama_get_unsampled_logits_ith(test_ctx.ctx.get(), idx) == nullptr) failed, exit 134. Restored, it passes.The runtime picks this up with spiceai/spiceai#15922, which moves its pin to the merge of this PR and switches
Context::logitsto the new getter.