Skip to content

logprobs and top_logprobs on the native CUDA server (Nemotron), from the verified target logits - #572

Merged
ashhart merged 1 commit into
ashhart:mainfrom
plotarmordev:feat/cuda-logprobs
Oct 10, 2026
Merged

ashhart merged 1 commit into
ashhart:mainfrom
plotarmordev:feat/cuda-logprobs

Conversation

@plotarmordev

Copy link
Copy Markdown
Contributor

What this changes

logprobs and top_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": false give the same rows. With thinking on, rows start after the first </think> and the newlines the text drops, so logprobs.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 with logprobs, 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_logprobs is 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.rows beside emitted(); conclude gives 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_host sends a logprobs event before each tokens event.
  • Server: probabilityOptions accepts logprobs when the engine (Info.logprobs) and the tokenizer's exact token bytes (core: expose exact token-local tokenizer bytes #532's tokenBytes) give them; finish cuts the answer's rows and writes OpenAI's {token, logprob, bytes, top_logprobs}, bytes keeping 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 on 297ec2cd built with zig build native -Dnvcc=… -Dsm=121 in the NGC PyTorch 26.07 container, the built-in kernels. The branch is now on 0d83398b, rebased with only the CHANGELOG to merge: the commits since are Metal Nemotron and one startup error line in server/main.zig, and the CPU tests below pass on it.

  • Exactness, served, --context 16384 --parallel 4, 24 of 24 checks:

    Check Result
    greedy, thinking off, top_logprobs: 20, 64 tokens one row a token; rows' bytes spell content; each pick is its own row's best token; best 20 descending
    the same with "draft": false same token_sha, identical rows
    thinking on, "think, then answer with the single letter" rows cover the answer B only; content[0] = B (-0.268), alternatives The (-1.643), 3 (-3.268); identical with "draft": false
    sampled (T 0.8, seed 7, top_p 0.95), drafts on and off same token_sha, identical rows (raw distribution, not T 0.8)
    the three above at once (shared rounds) each identical to its run alone
    stream, tools, stop, Responses with logprobs 400
  • Against the raw logits: tensorfold prefill … --dump of 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:

    TheGrill cell main this branch, logprobs off
    portable-v1 count C1: decode, tok/s (median of 24 waves) 341.5 340.7
    portable-v1 count C1: first token, ms (median) 59.3 59.1
    ladder chat-lru C1: aggregate tok/s (median of 8) 195.5 194.6
    ladder C2 284.1 282.5
    ladder C4 429.9 428.1
    ladder C8: levels (acquisitions of 8) 423–424 (4), 533 (4) 421 (2), 518–531 (6)

    Within 0.6% everywhere. An earlier A/B on 78ee0f42 had 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 logprobs refuses streaming, so this replays the same TheGrill cells (messages, 400 tokens, greedy, thinking off, concurrency) non-streamed, with logprobs: true, top_logprobs: 20 or without, alternated on one server, 3 trials each. Every wave's tokens are the same on and off.

    Cell off, tok/s on, tok/s
    portable-v1 count C1 325.0 269.2 −17.2%
    ladder chat-lru C1 194.6 179.5 −7.8%
    ladder C2 279.7 269.0 −3.8%
    ladder C4 434.7 410.2 −5.6%
    ladder C8 421.2, 421.4, 529.9 463.8 – 464.6 level-mixed

    The 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 count prompt) and smaller as streams share a round. A 256-token prose reply with top_logprobs: 20 decoded at 121.0 tok/s against 127.4 without (−5%; −9% on the earlier base's captured kernels). Requests without logprobs run no extra kernel.

  • Tests run: zig build test 260 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 with top_logprobs 0, 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 as main. zig fmt --check passes on the changed files except lane_host.zig, whose one-line test { … } at its end fails the same way on main.

  • Not run, and why: Metal (no Mac; Metal engines give no first row, so Info.logprobs stays false and they refuse as before). Prompt speed: the prompt pass is unchanged without logprobs; with them one row is read after it.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off.
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Drafted and concurrent rows checked above; resumed prompts are not on main for CUDA yet.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (Tokens unchanged; the rows are new outputs.)
  • Prompt processing is no slower than the last release.
  • The description says which platforms I ran, Metal M1 to M5 and CUDA, and which I could not. (CUDA GB10 only.)
  • New tests fail before the change, pass after it, and skip cleanly without their dependency.
  • Comments and docstrings are one line. No measurements or history in the source.
  • No personal data, machine names, internal hosts or local paths. No AI attribution lines.

…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.
@ashhart
ashhart merged commit 18874cb into ashhart:main Oct 10, 2026
1 of 2 checks passed
@ashhart

ashhart commented Oct 10, 2026

Copy link
Copy Markdown
Owner

Thank you, @plotarmordev. This is merged into main (18874cb) with your commit as it was, and it ships in the next
release. Reading the rows from the verified target logits right after each forward, and cutting the answer's rows
where the text is cut, is what #449 asked for, and your receipt made it easy to check.

We gated it on a GB10. With logprobs off, nothing moved: 29 of 29 served replies (greedy and seeded sampled, drafted
and "draft": false, three conversations at once, turns resumed from the CUDA prompt cache) and the four release
prompts give the same tokens as 1.0.4 and main, and decode is within 0.35% of main when both builds use the same
measured window costs. With logprobs on, every reply's tokens match the same request without them. The rows are
identical bit for bit with "draft": false, with four streams sharing rounds, and when a 7,200-token conversation's
second turn resumes from a kept prompt state, which landed in main after your branch. We also dumped the target
logits from a test build and checked 1,750 rows against a float64 log-softmax. The top 20 came out in the same
order, ties to the lower id, and the largest difference was 2.0e-6.

Three small commits of ours follow yours, two of them for Mac-only code that a Linux build never compiles.
a941d95 passes the new rows argument in adoptPrefilled, which the Mac's Qwen3.8-27B lane decode calls, so the
Metal server builds. 128fed5 moves
the row kernel's device code to logprob_rows.cuh and the reply's logprobs object to server/logprobs.zig, line for
line, because sample.cu, lanes/engine.zig and server/chat.zig had passed our 600-line limit. You're its co-author.
137f571 adds the new logprobs event to seven test switches that only build on a Mac.

Thanks also to @DakotaTexas for the spec in #449.

BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
…r (Nemotron), from the verified target logits

Thanks @plotarmordev. Refs ashhart#449.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
… 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.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
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]>
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
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.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants