Skip to content

prompt_logprobs on /v1/completions for the CUDA lanes (#449) - #647

Closed
plotarmordev wants to merge 6 commits into
ashhart:mainfrom
plotarmordev:feat/prompt-logprobs
Closed

plotarmordev wants to merge 6 commits into
ashhart:mainfrom
plotarmordev:feat/prompt-logprobs

Conversation

@plotarmordev

Copy link
Copy Markdown
Contributor

What this changes

prompt_logprobs on nonstreamed /v1/completions, on the native CUDA server: the next part #449 kept open. It is stacked on #645 (its first commit is #645's), so please review #645 first; this PR's own change is the last commit.

The shape follows vLLM and @Bizuayeu's spec in #399, which @jetnet asked for in #298: prompt_logprobs: k (0 to 20) gives choices[0].prompt_logprobs, null for the first prompt token, then per prompt token an object keyed by token id whose first key is the prompt token itself, followed by the k best tokens, each {logprob, rank, decoded_token}. The prompt token's rank is vLLM's: every vocabulary token at or above its logit, itself included, so a tie counts against it; the best tokens are ranked by place.

What refuses it, so a client never gets a silent empty list (your point on #298): chat, streaming, and any engine whose lanes backend doesn't produce prompt rows (Info.prompt_logprobs, from the backend's prompt_rows). A request with it never resumes a cached prefix, because every row has to go through the head.

How:

  • logprob_rows.cuh: the row gains one word, the pick's rank, counted over the vocabulary only when asked (rank); generation rows pass false and write 0.
  • cuda_engine.zig: PromptRows. When a prompt pass carries it, each chunk's rows (already in p_hidden) go through the head 16 at a time into the logits scratch, and logprobRows reads them against the next prompt tokens. That pass takes the serial chunk path rather than staggered segments.
  • cuda_lanes.zig: prefillFn installs the hook for that one pass, with its own small mapped buffer so a prompt pass never writes over another stream's pending window rows, and the rows land in Stream.prompt_rows.
  • lane_host.zig: skips the prompt-cache lookup for these requests, keeps them off the lone driver, and emits .prompt_logprobs right after .prefilled.
  • Server: fields.promptLogprobs, logprobs.promptValue, and Input/Reply fields. chat.zig was at 600 lines, so its private Mailbox moved, unchanged apart from the new event, to server/mailbox.zig.

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 branch on a6aa4782 built with zig build native -Dnvcc=… -Dsm=121 in the NGC PyTorch 26.07 container, built-in kernels, --context 16384 --parallel 4.
  • Served checks, 24 of 25 passed. The one miss is explained below.
    • Rows well formed: null first, prompt token first, ranks consistent with the best tokens' places including ties, logprobs ≤ 0, for k = 0, 5 and 20 and for a 5000-token prompt (3 chunks).
    • A one-token prompt gives [null].
    • Chunk and group edges: the rows of prefixes of 17, 2047, 2049 and 3000 tokens equal the 5000-token prompt's rows at the same positions (max |Δ| 0.0000).
    • Drafts: "draft": false and a repeat give identical rows.
    • Concurrency: four at once, mixing prompt-row requests with requests streaming generation logprobs, equal their runs alone, both kinds.
    • A request with the field reports 0 cached tokens and prefills from 0; its generated text equals the same request without the field. Replies that didn't ask carry no prompt_logprobs.
    • Chat and streamed requests with the field get HTTP 400.
  • Teacher-forced against generation rows: generate 24 greedy tokens C after a prompt P with logprobs, then send P+C with prompt_logprobs. On a prose and a code prompt, every generated token ranks 1 (or ties for it) in the prompt pass. Over the 48 positions, |prompt logprob − generation logprob| has median 0.000, 25 exactly equal, p90 0.034 and max 0.114. The first generated token is read from the prompt pass's last row in both cases, and it agrees to 0.000. Larger gaps show up only at uncertain positions (generation logprob around −0.5 to −1.3). I read this as the decode/verify kernels and the prefill kernels rounding bf16 differently, not as this change: the prompt rows equal the prefill path's own rows across every chunk shape tried. My script's 0.05 gate failed on the prose prompt because of this; I'm reporting the distribution rather than moving the gate.
  • Tests run:
    • zig build test: 37/37 steps, 429/429.
    • Server tests: 121/121 and 100/100. One new test: the vLLM shape (null first, the prompt token first with its rank, the best token after it, the prompt token alone when it is the best), a one-token prompt, no field when not asked, and HTTP 400 for chat, streaming, k = 21, a boolean, and an engine without prompt rows.
    • Frozen server goldens: 309 of 319 equal, 0 unexpected differences, the same as main.
    • zig fmt --check clean on the changed files.
  • Not run, and why:
    • Metal: I have no Mac; Metal engines refuse the field.
    • Prompt speed with the field: not measured. It costs one head pass per prompt row.
    • Prompt and decode speed without it: not re-benchmarked. Those requests take the unchanged path apart from an orelse on the prompt pass and one extra word per generation row.
    • token_sha against logprobs on streamed chat completions and on /v1/completions (native CUDA server) #645's binary: not run; only with and without the field on this binary.

Checklist

  • Every token still goes through the lane rounds. No serial path, and nothing that needs drafts off. (Generation stays on the lanes; these requests skip the lone driver. Their prompt pass runs the serial chunk grid, not staggered segments.)
  • Drafted output equals "draft": false, a resumed prompt equals a fresh one, and concurrent equals solo. (Prompt rows checked for all three; these requests never resume.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (No sums change; generation rows gain a zero word.)
  • Prompt processing is no slower than the last release. (Unchanged path without the field, but not re-measured; see Not run.)
  • 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.

…CUDA server)

A stream's content chunks carry the logprob rows of the answer tokens their text completes (rows copied from the
mailbox with each round's tokens), so the rows joined over a stream are the whole reply's, answer-only with
thinking on. /v1/completions takes the legacy integer logprobs (0-20) and answers in the legacy form (tokens,
token_logprobs, top_logprobs, text_offset), whole and streamed. Tools, stop strings, structured output and a
thinking budget stay refused with logprobs. Refs ashhart#449.
The CHANGELOG entry moves under Unreleased; chat.zig stays at 600 lines (the tail's sent text folds into rest).
The prompt-rows pass moves to cuda_prompt_rows.zig and the prefill rate to lane_host_status.zig, so cuda_engine.zig and lane_host.zig stay within 600 lines.
@plotarmordev

Copy link
Copy Markdown
Contributor Author

Brought up to date with 1.0.6 by a merge on top of #645's, with no force-push. To stay within 600 lines:

  • The prompt-rows pass moved into cuda_prompt_rows.zig.
  • The prefill-rate update moved into lane_host_status.zig, beside the other rate counters.

prompt_logprobs requests also keep 1.0.6's lesson-route gate on staggered segments.

Re-checked at this head:

  • zig build test: 452/452.
  • Server tests: 129/129 and 104/104.
  • Frozen goldens: 309/319, 0 unexpected differences.
  • zig fmt and lean_check are clean.
  • On a GB10: the prompt_logprobs checks give the same 24/25 as before. The one miss is the known decode-versus-prompt rounding gap, the same max 0.114.
  • The logprobs and top_logprobs on the native CUDA server (Nemotron), from the verified target logits #572 chat-row checks pass 24/24.
  • Beside a 1.0.6 build on the same GPU, 17/17 replies are token-identical, structured output included.

@ashhart

ashhart commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Thank you, @plotarmordev. prompt_logprobs landed in 1.0.8 as your own commit (370069e67), rebased onto 1.0.6. We also merged this PR's head as it was then (a4770b8b8, in 35a8f8bc9). Your branch has since merged 1.0.6 and main, so its head isn't in 1.0.8's history and GitHub won't mark this PR merged. Those merges bring nothing 1.0.8 lacks beyond CHANGELOG wording and your own versions of our lean-pass moves, so I'm closing this with thanks.

The rebase overlapped with three things, and we kept both sides each time. Structured output (1.0.6) verifies windows through verifyMasked, so your false rank flag now rides on that call. The prompt-cache lookup takes 1.0.6's decoded spans beside your prompt_logprobs == null guard. Living Weights can end a prompt chunk early at a lesson's decision row, and your head pass follows the chunks as they come. With Living Weights in, cuda_engine.zig came to 613 lines and lane_host.zig to 602, past our 600-line limit. Our commit 5b02f8ca0 moves your PromptRows and the head loop, unchanged, into families/nemotron/cuda_prompt_rows.zig, trims two lines from lane_host.zig, and shortens five comments to 120 columns. It lists you as co-author because it moves your lines. Moving the mailbox out of chat.zig was the right call; that file sat at 551 lines.

We gated it on a GB10 with Nemotron 3.5 Lightning (MLX 4-bit). A gate-only build dumped the logits your head pass produced, and we checked every prompt row against float64:

check result
prompt rows against float64 2,985 rows (prompts of 18, 39 and 2,931 tokens, each at prompt_logprobs 0, 5 and 20): logprobs within 2.05e-6, bit-equal to f32(logit) - f32(lse)
rank equal to the float64 count of tokens at or above the prompt token on every row (rank 1 on 2,081 of the 2,930 long-prompt rows); the best tokens' ids in order and ranked by place
decoded_token the tokenizer's text on every entry
exactness prompt rows equal with drafts on and "draft": false, and beside logprobs; replies equal the same request without prompt_logprobs; the same request twice gives equal rows and resumes nothing
concurrency two prompt_logprobs requests (2,931 and 39 tokens) beside two chats: all four equal their runs alone
the reply's own tokens sent back as a prompt the prompt row for the reply's first token equals the reply's first row bit for bit. Later rows compare the prompt pass with decode windows of the same tokens: chosen logprob within 0.19 (mean 0.024 and 0.007 on two prompts), and the greedy token ranks 1 in 123 of 126 rows
requests without prompt_logprobs the same tokens as 1.0.6 everywhere we looked (29 served replies, 8 release prompts, 17 exactness pairs); decode and prompt speed within 0.5% of the base build, A B B A

On cost, prompt_logprobs: 20 on the 2,931-token prompt took 0.83 s where the same prompt without it took 0.44 s, with the prompt cache off for both. Chat, a streamed completion and values outside 0-20 get a 400, as does a Metal server.

Thanks as well to @Bizuayeu for the spec in #399 and to @jetnet for asking in #298.

@ashhart ashhart closed this Oct 12, 2026
BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
The prompt pass's rows move out of cuda_engine.zig (613 lines with Living Weights) into cuda_prompt_rows.zig, the
long comments fit 120 columns, and lane_host.zig stays at 600 lines (runLone no longer repeats admitOne's start
time; one single-use alias goes). No behaviour changes.

Co-authored-by: plotarmordev <[email protected]>
BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
ashhart#647 landed above as 370069e (the author's commit, rebased onto this candidate). This keeps the PR's own head commit in the history, with no change to the tree.
BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
The two lines name their PRs, say what a GB10 measured, and credit the author.
BobClawblaw pushed a commit to BobClawblaw/TensorFold that referenced this pull request Oct 12, 2026
….8 candidate

CHANGELOG: ashhart#645 and ashhart#647 stay under Unreleased; 1.0.7's section is the release's.
@ashhart ashhart mentioned this pull request Oct 14, 2026
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
The prompt pass's rows move out of cuda_engine.zig (613 lines with Living Weights) into cuda_prompt_rows.zig, the
long comments fit 120 columns, and lane_host.zig stays at 600 lines (runLone no longer repeats admitOne's start
time; one single-use alias goes). No behaviour changes.

Co-authored-by: plotarmordev <[email protected]>
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
ashhart#647 landed above as fdca11b (the author's commit, rebased onto this candidate). This keeps the PR's own head commit in the history, with no change to the tree.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
The two lines name their PRs, say what a GB10 measured, and credit the author.
BlivionIaG pushed a commit to BlivionIaG/TensorFold that referenced this pull request Oct 20, 2026
….8 candidate

CHANGELOG: ashhart#645 and ashhart#647 stay under Unreleased; 1.0.7's section is the release's.
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