Skip to content

llama: argmax output, the picks of a split output head without its logits (DeepSeek-V4.1) - #30

Merged
lukekim merged 46 commits into
spiceai-b11999from
lukim/b11999-dsv41-argmax-output
Nov 4, 2026
Merged

lukekim merged 46 commits into
spiceai-b11999from
lukim/b11999-dsv41-argmax-output

Conversation

@lukekim

@lukekim lukekim commented Nov 3, 2026 •

Copy link
Copy Markdown

Builds on #27 (the DSpark drafter's vocabulary split), whose ops and rows views it reuses.

What

Under a tensor split, DeepSeek-V4.1's output head (Q6_K, 5120 x 129280) is mirrored. Every device computes all 129280 rows of it for each verification batch, and the host copies the logits back (4 x 129280 floats a step) and takes each row's first max for a greedy pick.

With the argmax output on, a DeepSeek-V4.1 context instead does what the DSpark drafter does since #27:

  • each device computes only its rows of the head, as a view of the copy it already holds (ggml_backend_meta_rows);
  • each output row's pick comes from one (value, index) pair per device: ARGMAX_PART, a gather, then ARGMAX_MERGE;
  • only the picks come back to the host.

API (llama.h):

  • llama_set_argmax_output(ctx, bool) turns the mode on or off. It is part of the graph parameters, so a change rebuilds the graph.
  • llama_get_argmax_ith(ctx, i) returns output row i's pick. That is the greedy sampler's pick: the lowest index on a tie, and token 0 when the row's first logit is a NaN. It is the raw logits' first max, so no sampler bias (suppressed tokens, a logit bias) applies.
  • The logits of such a decode are not computed: llama_get_logits, llama_get_logits_ith and llama_get_unsampled_logits_ith (llama: read a row no backend sampler sampled with one synchronize #25) return NULL for it.
  • Wherever the head stays whole, the logits are computed as usual and llama_get_argmax_ith takes their first max on the host. A row a backend sampler sampled is refused.

The head stays whole in these cases:

  • there is no tensor split;
  • LoRA is in use;
  • LLAMA_TENSOR_LOGITS_GATHER is set;
  • a device would get no rows;
  • the head is not on a meta device (an override that places it elsewhere);
  • a backend sampler is attached, since it samples from the logits;
  • the context is a pooled embedding context, whose graph skips the head (build_logits);
  • a device of the split cannot run ARGMAX_PART or ARGMAX_MERGE (Metal, also behind an RPC server), so they would run on the CPU after the split product had been copied there. The probe is llama: split the DSpark drafter's head by vocabulary rows under a tensor split #27's, now shared with the DSpark drafter's head as llama_dev_runs_argmax_split;
  • a ubatch has no outputs.

Who turns it on. There is no environment variable or other knob. The caller decides per request: spiced will turn it on for requests whose sampling chain is the greedy sampler alone, and read every pick through llama_get_argmax_ith, the first token after the prompt and every verification row included. llama-server does not use it.

Evidence

All runs use DeepSeek-V4.1 UD-Q2_K_XL with its DSpark Q8_0 drafter, tensor-split across three DGX Sparks (GB10) over RPC and served by spiced. Each arm is one binary built from the fork tree the lab serves plus this branch; the arms differ only in whether spiced turns the argmax output on for greedy requests. The bench is bench_sym: 8 prompts x 200 tokens, greedy.

A/B. Sessions ran X, argmax, argmax, X, each with one run set aside and two counted, so 4 counted runs per arm.

arm tok/s, 4 counted runs mean
argmax output off (X) 46.61, 46.77, 46.73, 46.60 46.68
argmax output on 48.92, 48.88, 48.99, 48.88 48.92 (+4.8%)

In every run of both arms, warmups included, the drafts and accepted counts matched the reference run step by step (599 steps, 985 of 1797 drafted tokens accepted), and the replies matched 8 of 8.

Spans. From one nsys capture of the head per arm, medians per step:

arm verification span head kernel drafter span
X 48.995 ms mul_mat_vec_q Q6_K cols4, grid 64640: 2.850 ms 4.438 ms
argmax output 46.790 ms grid 21547: 0.93 ms 4.391 ms

ARGMAX_PART over the 4 rows takes 9.4 µs and ARGMAX_MERGE 1.3 µs.

Every pick checked. A lab build kept the whole head's logits beside the split head's picks and compared every pick with the logits' first max. Over one bench run (at most 1814 picks: every first token after a prompt, every accepted draft and every bonus token), it found 0 mismatches. That check mode is not part of this PR.

Rebuilds when the mode flips. Greedy and sampled requests alternated, timed with LLAMA_DECODE_TIMING=1.

  • The mode flip adds no rebuild: both arms rebuild the verification graph once per request (8 in 8), because the prompt graph already displaces it.
  • The split head's rebuild costs more: 65.4 ms median against 53.9 ms (build 12.5 against 10.5 ms, submit 54.4 against 50.5 ms). That is about +11 ms once per greedy request, against about −2.5 ms on each of its steps.
  • The steady verification decodes' host time inside llama_decode was 1.95 ms median (p99 3.22) against 1.77 ms (p99 3.47).

Tests.

  • test-argmax-split adds the target's verification head shape: Q6_K, 5120 x vocabulary, 4 columns, split by the same rows. It checks the split product bit for bit against the whole one, and the picks against the first max.
    • On CUDA0 (GB10) at TEST_VOCAB=129280: 124 ok, 0 FAIL. The 4-column Q6_K head, split two and three ways, differs from the whole product in 0 of 517120 values
    • With argmax_part_combine's tie order inverted, it fails: 27 FAIL lines, e.g. pairs row 1: pick 999, want 31. Restored, it passes.
    • On the Mac CPU at the default vocabulary, every case passes.
  • test-backend-ops on CUDA: ARGMAX_PART 4/4 and ARGMAX_MERGE 3/3 passed.
  • llama: split the DSpark drafter's head by vocabulary rows under a tensor split #27's test-argmax-malformed on this tree passes on the Mac CPU and on the GB10 host's CPU (exit 0, 0 FAIL).
  • The CUDA tests above and one spiced session ran on this branch's tree as of the merge of spiceai-b11999, before the last two commits. The session had the argmax output on for greedy requests. Its result: 48.89 and 48.90 tok/s over two counted bench_sym runs (46.87 in the run set aside). Replies matched the reference run 8 of 8, and drafts and accepted counts matched it step by step (599 steps, 985 of 1797 accepted).
  • A session on the final production code (f85628e; later commits change only tests/), run the same way: 48.99 and 48.88 tok/s counted (47.13 set aside). Replies were 8/8 equal to the reference run, and drafts and accepted counts identical step by step. The head still splits on GB10: a same-rig control with the head whole measured 46.84–46.85 the same day. It checks the last two commits on GB10. They change what a failed decode leaves readable and add the whole-head guards. The guards must still let the head split over the GB10 RPC servers, and the DSpark drafter now takes its probe from the shared function.

Notes and limitations

  • No new ops or kernel entry points. Nothing under ggml/ changes. The head is built with llama: split the DSpark drafter's head by vocabulary rows under a tensor split #27's ggml_argmax_part and ggml_argmax_merge and runs on their kernels, so llama: split the DSpark drafter's head by vocabulary rows under a tensor split #27's shape validation (a node whose destination does not fit is refused with GGML_ASSERT, covered by test-argmax-malformed) applies to it unchanged.
  • The model-backed check needs two devices. test-llama-archs checks the argmax output on every tensor split. It needs at least two devices that run ARGMAX_PART and ARGMAX_MERGE to split the head, such as two local RPC servers (--rpc). CI runs test-llama-archs only to generate models. On a single GPU the head stays whole and only the fallback is checked.
  • DeepSeek-V4.1 only. Other models' heads are a plain product too. A central version in build_logits would cover GLM and Qwen, but needs their own A/B, so it is a follow-up.
  • The spiced side lands separately, after spiced moves to this fork's tree. It sets the mode internally, for greedy-only requests on a split model, so no user ever sets it.

Test plan

  • test-argmax-split: CPU (Mac), and CUDA (GB10) at the default vocabulary and at 129280. It fails with the tie order inverted.
  • test-backend-ops for both ops on CUDA.
  • test-llama-archs argmax output check (Mac), tiny DeepSeek-V4.1 over two local RPC servers:
    • CPU servers: the head splits, and the check passes with LLAMA_TENSOR_BACKEND_SAMPLING unset, 0 or 1.
    • Metal servers: the head stays whole, and the check passes.
    • Every architecture without --rpc: all 548 configurations pass.
    • It also checks a failed decode. An abort callback stops a mode-off decode (returns 2) after an argmax-output decode; no logits may be readable then, and the next successful decode must make them readable again. Without the readiness reset in c97df24, it fails: logits from before the argmax-output decode are readable after the aborted one.
    • It also checks that a pooled (MEAN) embedding context computes the same embedding with the mode on as off. Without the pooled-embedding guard, that decode's graph had 10 result_output_rows and 10 ARGMAX_* nodes (GGML_SCHED_DEBUG=2); with it, none.
    • Without the Copilot fixes: it fails with backend sampler, row 127: sampled -1, first max 20 and embedding context, row 124: no logits with the mode off. On Metal servers the head split and GGML_SCHED_DEBUG=2 placed ARGMAX_PART and ARGMAX_MERGE on the CPU.
  • The A/B, spans, pick check and rebuild runs above.
  • A bounded Codex adversarial pass over this diff: on the final diff, no critical or high findings. It found one medium, fixed in the last commit: after an argmax-output decode, a decode with the mode off set the logits readable as it started, so if it failed, llama_get_logits returned the buffer as it was before the argmax-output decode. It also found one low, the unsampled getter's comment, fixed in the same commit
  • CI: not run. Upstream's workflows on 21b07bb (CI (cpu), run 41574454415; Models Backend Check, run 41574454337) queued for runner labels this fork has none of and were cancelled after 24 h, as on Tensor split for Mistral Large 4 and its DSpark drafter #20. No check is required on this fork, so the tests above are this PR's gate.

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.
…sor 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.
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.
… 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.
…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.
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.
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.
… 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.
…ab-split

# Conflicts:
#	tests/CMakeLists.txt
… 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.
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.
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.
…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.
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.
…nd 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.
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.
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.
…gh 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.
…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).
…ackend-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.
…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.
… 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.
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.
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.
… 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.
Copilot AI balanced review requested due to automatic review settings November 3, 2026 02:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The argmax branch bypasses attached backend samplers, leaving sampled-token and candidate results unavailable even for a greedy sampling chain.

3 open issues
What changed in this PR

Adds an opt-in argmax output mode for DeepSeek-V4.1, reusing #27's split-head operations to return greedy token picks without copying full logits to the host.

Changes:

  • Splits eligible output heads by vocabulary rows and merges per-device argmax results.
  • Adds public controls and getters, with output synchronization, reordering, and logits availability tracking.
  • Extends split-head tests to cover the four-column verification shape.
File Description
tests/​test-argmax-split.cpp Adds four-column Q6_K split-head coverage.
src/​models/​deepseek41.cpp Builds the split-head argmax path with whole-head fallbacks.
src/​llama-graph.h Tracks argmax results and includes the mode in graph reuse checks.
src/​llama-graph.cpp Clears argmax results when resetting graph state.
src/​llama-cparams.h Adds the internal argmax output flag.
src/​llama-context.h Declares argmax accessors and output state.
src/​llama-context.cpp Handles pick retrieval, copy-back, reordering, and logits availability.
include/​llama.h Exposes and documents the argmax output API.

Review effort: Balanced

Comment thread src/models/deepseek41.cpp Resolved
Comment thread src/llama-context.cpp Resolved
Comment thread src/models/deepseek41.cpp Resolved
… 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.
Copilot AI balanced review requested due to automatic review settings November 3, 2026 03:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Pooled-embedding and argmax-only paths perform unnecessary vocabulary-wide work, while sampling tests mishandle disabled sampling and split logits, causing failures or suite aborts.

2 open issues
2 previously missed issues

In code that hasn't changed since last review

Medium severity Avoid reordering logits when only argmax picks are ready

src/​llama-context.cpp:2727

Argmax-only output still incurs the full-logits reorder above: output_reserve() allocates the logits buffer in non-embedding contexts, so logits.size > 0 remains true even when logits_ready is false. For interleaved multi-sequence batches reordered by split_equal(), reading the picks therefore swaps 129280 stale floats per row swap in addition to these two token IDs. Gate the logits reorder on logits_ready so argmax-only reordering stays proportional to the number of picks.

Medium severity Skip argmax output for pooled embedding requests

src/​models/​deepseek41.cpp:976

With embeddings enabled and pooling other than NONE, this branch expands the output head and argmax even though build_logits() normally skips the head for pooled embeddings. Leaving argmax output enabled therefore adds a vocabulary-wide projection for every input token to requests that only need embeddings. Exclude pooled embedding contexts from this branch.

3 resolved since last review

Review effort: Balanced

Comment thread tests/test-llama-archs.cpp Resolved
Comment thread tests/test-llama-archs.cpp Resolved
…icks 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.
Copilot AI balanced review requested due to automatic review settings November 3, 2026 03:38
@lukekim

lukekim commented Nov 3, 2026

Copy link
Copy Markdown
Author

Both issues the last review listed as previously missed are fixed in f85628e.

Skip argmax output for pooled embedding requests (src/models/deepseek41.cpp). head_vocab_parts now keeps the head whole in a pooled embedding context, and build_logits then drops it. Run: a pooled (MEAN) embedding decode with the mode on, over two CPU RPC servers with GGML_SCHED_DEBUG=2, counting graph nodes during that decode alone:

  • without the guard: 10 result_output_rows nodes and 10 ARGMAX_PART/ARGMAX_MERGE nodes;
  • with it: 0 and 0, with no result_output either.

test-llama-archs now also requires that pooled embedding context's embedding to be identical with the mode on and off.

Avoid reordering logits when only argmax picks are ready (src/llama-context.cpp). output_reorder moves the logits only when they are readable (logits_ready); after an argmax-output decode only the picks move. Unverified, code inspection only: this is a perf change, and nothing I ran reorders outputs. The picks' own swap is unchanged.

Runs on f85628e:

  • test-llama-archs -a deepseek41 --rpc over CPU RPC servers: OK (split), all passed, with LLAMA_TENSOR_BACKEND_SAMPLING unset and set to 1.
  • The same over Metal RPC servers: OK (whole), all passed.
  • Every architecture, without --rpc: all 548 test(s) passed.
  • Mac ctests (argmax, meta-gather, rpc-nccl, logits-argmax, backend-sampler): 8/8 passed.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Human assessment is needed because the added tests cover only successful decodes, leaving the stale-logits failure-state fix and recovery behavior without automated regression coverage.

No open issues 🎉

2 resolved since last review

Review effort: Balanced

…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.
Copilot AI balanced review requested due to automatic review settings November 3, 2026 03:49
@lukekim

lukekim commented Nov 3, 2026

Copy link
Copy Markdown
Author

On the last review's note that the tests covered only successful decodes, leaving the stale-logits failure-state fix without regression coverage: 21b07bb adds that case to test-llama-archs.

With the head split, an abort callback stops a decode with the mode off (llama_process returns 2, after the outputs were reserved). The decode before it was an argmax-output decode. After the aborted decode, llama_get_logits must return NULL, because the buffer still holds logits from before the argmax-output decode. The next decode must then succeed with logits whose first maxes match a reference decode.

Runs, tiny DeepSeek-V4.1 over two CPU RPC servers (test-llama-archs -a deepseek41 -s 42 --rpc …):

  • with c97df24's readiness reset reverted to logits_ready = !cparams.argmax_output:
    argmax output: failed decode: logits from before the argmax-output decode are readable after the aborted one
    Summary: 4 test(s) executed, 1 failed
    
  • on 21b07bb: OK (split), all 4 passed, with LLAMA_TENSOR_BACKEND_SAMPLING unset and set to 1. Over Metal RPC servers: OK (whole), passed. Every architecture without --rpc: all 548 passed.

21b07bb changes only tests/.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

The final GB10 CUDA/RPC validation is still pending, so human review must confirm that the guards and shared capability probe preserve target-head splitting and DSpark output validity on deployment backends.

No open issues 🎉

Review effort: Balanced

@lukekim

lukekim commented Nov 3, 2026

Copy link
Copy Markdown
Author

GB10 hardware result for the final production code. This is f85628e; 21b07bb after it changes only tests/.

Setup: DeepSeek-V4.1 UD-Q2_K_XL with its DSpark Q8_0 drafter, tensor-split across three DGX Sparks (GB10) over RPC and served by spiced, with the argmax output on for greedy requests. bench_sym, 8 prompts x 200 tokens, greedy. One run is set aside and two are counted.

run tok/s replies vs reference drafts and accepted counts vs reference
set aside 47.13 8/8 equal identical (599 steps, 985/1797 accepted)
counted 48.99 8/8 equal identical
counted 48.88 8/8 equal identical

The head still splits on GB10. These runs are at the level of this PR's A/B above (48.92 mean). That A/B had the head whole at 46.68, and today's same-rig control with the head whole measured 46.84–46.85 (4 counted runs per arm). So the capability probe and the new whole-head guards (backend sampler, pooled embeddings) leave the target head split on these devices. The DSpark drafter now takes the shared probe and drafts exactly as before.

@lukekim

lukekim commented Nov 3, 2026

Copy link
Copy Markdown
Author

Five output rows: the split head's picks equal the whole head's, end to end. This PR's tests cover up to 4 columns: test-backend-ops runs ARGMAX_PART at 1 and 3 rows and ARGMAX_MERGE at 1, 4 and 64, and test-argmax-split runs 1–4 columns. A verification batch of 5 rows (a draft of 4) had not been checked. We ran it on DeepSeek-V4.1 UD-Q2_K_XL with its DSpark Q8_0 drafter, tensor-split across three DGX Sparks (GB10) over RPC and served by Spice. bench_sym: 8 prompts × 200 tokens, greedy, drafting 4 tokens per step.

run argmax output replies equal to the argmax-on draft-4 run drafts and accepted counts
warmup + 2 counted off (whole head, host first max) 8/8, 8/8, 8/8 identical step by step: 554 steps, 1023 of 2216 drafted tokens accepted
2 sessions × (warmup + 2 counted) on 8/8 in every run, against each other identical

So at 5 columns the split head's ARGMAX_PART/ARGMAX_MERGE picks are exactly the whole head's first max on every verification row of these runs. Drafting 4 instead of 3 changes the replies of 5 of the 8 prompts compared with a draft of 3, and does so with the whole head as well. That comes from the 5-row verification batch's own numerics, not from this PR. Drafting 4 is also slower on this setup (47.73 against 48.90 tok/s), so Spice keeps drafting 3. With the argmax output on, a draft of 4 runs at 47.73 tok/s against 45.64 with it off (+4.6%).

Fork tree: f85628e, the same production code as the GB10 check above (21b07bb after it changes only tests/).

@lukekim lukekim self-assigned this Nov 3, 2026
@lukekim

lukekim commented Nov 4, 2026

Copy link
Copy Markdown
Author

On Copilot's review of 21b07bb: the GB10 validation it calls pending ran on the final production code (f85628e; the commit after it changes only tests/). spiced served DeepSeek-V4.1 + DSpark with the argmax output on for greedy requests: 48.99 and 48.88 tok/s counted. Replies were 8/8 equal to the reference run, and drafts and accepted counts identical step by step. A same-rig control with the head whole measured 46.84–46.85, so the head still splits over the GB10 RPC servers with the new guards. The description's Evidence section has it, and its CI line now says why upstream's jobs show as cancelled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants