Repository navigation
logprobs and top_logprobs on the native CUDA server (Nemotron), from the verified target logits - #572
Conversation
…from the verified target logits Each committed token's log probability under the target's raw distribution (temperature 1) with up to 20 alternatives (logit descending, ties by the lower id), computed on the GPU right after each forward from the target logits (sample.cu tf_logprob_rows), so drafts on and "draft": false give the same rows. With thinking on, the rows cover the answer only: after the first </think> and the newlines the text drops; a reply cut inside its reasoning has none (spec: @DakotaTexas, ashhart#449). Streaming, tools, stop strings, structured output and a thinking budget stay refused with logprobs; Metal engines, Responses and legacy completions keep refusing.
|
Thank you, @plotarmordev. This is merged into main (18874cb) with your commit as it was, and it ships in the next We gated it on a GB10. With logprobs off, nothing moved: 29 of 29 served replies (greedy and seeded sampled, drafted Three small commits of ours follow yours, two of them for Mac-only code that a Linux build never compiles. Thanks also to @DakotaTexas for the spec in #449. |
…r (Nemotron), from the verified target logits Thanks @plotarmordev. Refs ashhart#449.
… the row argument ashhart#572 gave Stream.commit the tokens' logprob rows. adoptPrefilled, which only the Mac's Qwen3.8-27B lane decode calls, still passed two arguments, so `zig build native` and the macOS release archive stopped compiling. It now commits no rows, and refuses a stream that asked for logprobs, because another driver's prompt pass gives no first row.
ashhart#572 took sample.cu to 667 lines, lanes/engine.zig to 601 and server/chat.zig to 647. The moves are line for line: - the logprob row's device code goes to zig/kernels/cuda/logprob_rows.cuh with its own constants, and sample.cu includes it and keeps the tf_logprob_rows entry point, so the fatbin set stays the same; - the chat reply's logprobs object and the request's logprob checks go to server/logprobs.zig; - the lane core asks for the first row through Backend.firstRow. Two doc comments past 120 columns are shorter. The lean check counts 509 problems, as on main. Co-authored-by: plotarmordev <[email protected]>
ashhart#572 added `.logprobs` to engine_api.Event. Seven exhaustive switches in Mac-only tests did not name it: the serial host's, cache_mode_host_test's, the third in lane_host_reuse_test.zig, and the Qwen3.8-27B served, drafted-served and reuse programs. `zig build test` on a Mac stopped compiling them. Each now ignores the event, as their engines give no rows.
What this changes
logprobsandtop_logprobs(0 to 20) on the native CUDA server for Nemotron 3.5 Lightning, nonstreamed/v1/chat/completions, as you laid out in #449. Each reply token's row comes from the verified target logits at temperature 1, before any sampling filter, so drafts on and"draft": falsegive the same rows. With thinking on, rows start after the first</think>and the newlines the text drops, sologprobs.content[0]is the first answer token, and a reply cut inside its reasoning has none. Streaming, tools, stop strings, structured output and a thinking budget stay refused withlogprobs, as in 0.6.6; Metal engines, Responses and legacy completions keep refusing. The spec is @DakotaTexas's. Refs #449, #298 (generated-token logprobs only;prompt_logprobsis not part of this).How:
sample.cu:tf_logprob_rows, one 1,024-thread block a row: log-sum-exp over the bf16 row, the pick's logit, and the k best (logit descending, ties by the lower id) by k exact passes. Fixed reduction trees, so a row never depends on timing.cuda_lanes.zig: for a stream that asked, the kernel runs right after each forward on the window's logits (and once after prefill on the prompt's last row), into host-mapped memory read after the stream's existing synchronize.lanes:Stream.rowsbesideemitted();concludegives each committed token its path row's row; a logprob stream takes verify windows rather than the pipelined one-token rounds, and the lone driver doesn't take it.lane_hostsends alogprobsevent before eachtokensevent.probabilityOptionsaccepts logprobs when the engine (Info.logprobs) and the tokenizer's exact token bytes (core: expose exact token-local tokenizer bytes #532'stokenBytes) give them;finishcuts the answer's rows and writes OpenAI's{token, logprob, bytes, top_logprobs},byteskeeping a partial UTF-8 sequence.Receipt
Environment: one DGX Spark (GB10, sm_121, driver 580.173.02, CUDA 13),
TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit@d9d758fb, this change on297ec2cdbuilt withzig build native -Dnvcc=… -Dsm=121in the NGC PyTorch 26.07 container, the built-in kernels. The branch is now on0d83398b, rebased with only the CHANGELOG to merge: the commits since are Metal Nemotron and one startup error line inserver/main.zig, and the CPU tests below pass on it.Exactness, served,
--context 16384 --parallel 4, 24 of 24 checks:top_logprobs: 20, 64 tokensbytesspellcontent; each pick is its own row's best token; best 20 descending"draft": falsetoken_sha, identical rowsBonly;content[0]=B(-0.268), alternativesThe(-1.643),3(-3.268); identical with"draft": falsetoken_sha, identical rows (raw distribution, not T 0.8)stream,tools,stop, Responses withlogprobsAgainst the raw logits:
tensorfold prefill … --dumpof the first reply row, recomputed in float64 (log-sum-exp, the best 20): the same 20 tokens in the same order, largest log probability difference 1.4e-7.Speed, logprobs off, this branch against
main(297ec2cd), TheGrill 0.5.0 (grill-perf baseline, client on the same host, portable-v1 and the concurrency-ladder-v1 selection, 600 s and 2,400 s allowances, 8 acquisitions each), each server alone with--context 16384 --parallel 8 --no-thinking:maincountC1: decode, tok/s (median of 24 waves)countC1: first token, ms (median)chat-lruC1: aggregate tok/s (median of 8)Within 0.6% everywhere. An earlier A/B on
78ee0f42had the branch 0.2% ahead on the same cells, so I read this as run-to-run spread; at C8 both builds alternate between the same two throughput levels, so its median follows how many acquisitions land on each.Speed, logprobs on against off, on this branch: TheGrill streams and sends no extra request fields, and
logprobsrefuses streaming, so this replays the same TheGrill cells (messages, 400 tokens, greedy, thinking off, concurrency) non-streamed, withlogprobs: true, top_logprobs: 20or without, alternated on one server, 3 trials each. Every wave's tokens are the same on and off.countC1chat-lruC1The cost is the kernel's passes over the vocabulary, one a requested alternative, for every row a round verifies, so it is largest when drafts are long (the
countprompt) and smaller as streams share a round. A 256-token prose reply withtop_logprobs: 20decoded at 121.0 tok/s against 127.4 without (−5%; −9% on the earlier base's captured kernels). Requests withoutlogprobsrun no extra kernel.Tests run:
zig build test260 of 260 (28 steps, which now include the server tests); the server tests alone (zig/tests/server/zig_test.sh) 95 of 95, four new: the answer cut after</think>and its newlines with the end token left out, a reply cut in its reasoning, thinking off withtop_logprobs0, and the refusals; the lanes engine test checks every row against the fake target's row at that token's history, drafted, plain, shared, sampled and through the thinking budget's forced close. The frozen server goldens: 309 of 319 equal, 0 unexpected differences, the same asmain.zig fmt --checkpasses on the changed files exceptlane_host.zig, whose one-linetest { … }at its end fails the same way onmain.Not run, and why: Metal (no Mac; Metal engines give no first row, so
Info.logprobsstays false and they refuse as before). Prompt speed: the prompt pass is unchanged without logprobs; with them one row is read after it.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Drafted and concurrent rows checked above; resumed prompts are not onmainfor CUDA yet.)