Skip to content

logprobs on streamed chat completions and on /v1/completions (native CUDA server) - #645

Closed
plotarmordev wants to merge 3 commits into
ashhart:mainfrom
plotarmordev:feat/logprobs-stream
Closed

plotarmordev wants to merge 3 commits into
ashhart:mainfrom
plotarmordev:feat/logprobs-stream

Conversation

@plotarmordev

Copy link
Copy Markdown
Contributor

What this changes

Two of the parts #449 kept open, on the native CUDA server, on top of #572:

  • logprobs on streamed /v1/chat/completions. Each content chunk carries, in choices[0].logprobs.content, the rows of the answer tokens its delta.content completes; a token whose text isn't complete yet (a split UTF-8 character, or newlines after </think> before the answer starts) waits for the chunk that completes it, and the last chunk takes whatever is left. So the rows joined over a stream are exactly the whole reply's, answer-only with thinking on.
  • logprobs on /v1/completions, in the legacy form: the request's logprobs is the integer count of alternatives (0 to 20), and the reply has tokens, token_logprobs, top_logprobs (each alternative's text to its logprob) and text_offset, whole and streamed. It's built from the same rows as the chat form.

Tools, stop strings, structured output and a thinking budget stay refused with logprobs, as do the Responses route and the Metal engines. prompt_logprobs isn't part of this.

How:

  • server/logprobs.zig: answerStart (where the answer's rows begin, shared by the whole reply and the stream so both cut at the same token), Stream.delta (a content delta with the rows its streamed text now covers) and legacy (the completions form).
  • chat.zig: the rows are copied from the mailbox under its lock with each round's tokens (the engine thread appends to the mailbox while a stream reads); Generation.lp replaces the logprobs flag. The file stays at 600 lines.
  • openai.zig: a chunk moves its delta's logprobs to the choice; completions parse the integer logprobs (fields.legacyLogprobs) and write the legacy form; the completions stream lets a delta with rows through.

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.

  • Streamed chat against the whole reply, greedy unless stated, top_logprobs: 5 (17 of 17 checks):

    Request Rows streamed / chunks carrying them Streamed content = whole Streamed rows joined = whole rows Each chunk's rows end on text already sent
    prose, thinking off 77 / 33 yes yes yes
    "think, then answer with the letter", thinking on 1 / 1 (B) yes yes yes
    Japanese sentence and an emoji 11 / 6 yes yes yes
    sampled (T 0.8, seed 7, top_p 0.95) 85 / 35 yes yes yes
    "draft": false 77 / 77 yes yes yes

    Three at once (two streamed, one whole with "draft": false): each identical to its run alone.

  • /v1/completions with logprobs: 5, 64 tokens, on a prose, a code and a Japanese prompt (15 of 15): the streamed text and every legacy array equal the whole reply's; "draft": false gives the same; each greedy token is its row's best alternative; text_offset starts at 0 and grows by each token's length.

  • Speed: unchanged for requests without logprobs (no new kernel or engine work; the stream only formats rows the engine already returns). Not separately benchmarked for this change.

  • Tests run: zig build test 37/37 steps, 429/429 tests. Two new server tests: a streamed reply's rows joined over its chunks equal the whole reply's and spell its streamed content (thinking on, with the answer split across rounds after </think> and two newlines, and thinking off); /v1/completions gives the legacy arrays whole and streamed, with alternatives by text and the offsets. The refusal test now expects a stream to be served and a boolean logprobs on completions to be refused. The 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 (no Mac; Metal engines give no rows and refuse as before).

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; the engine side is logprobs and top_logprobs on the native CUDA server (Nemotron), from the verified target logits #572's, unchanged.)
  • No precision traded for speed. If the bits change, the description says which sums change and why. (Server formatting only.)
  • 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.

…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).
@plotarmordev

Copy link
Copy Markdown
Contributor Author

Brought up to date with 1.0.6 (d5126573) by a merge, with no force-push. The CHANGELOG entry now sits under Unreleased, and chat.zig stays at 600 lines: the tail's already-sent text folds into rest, with the same behaviour.

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 the changed files.
  • On a GB10: streamed chat 17/17 and /v1/completions 15/15, the same checks as before.
  • Beside a 1.0.6 build on the same GPU, structured-output and plain replies are token-identical (17/17), drafted equal to "draft": false.

@ashhart

ashhart commented Oct 12, 2026

Copy link
Copy Markdown
Owner

Thank you, @plotarmordev. This landed in 1.0.8 as your own commit (284daf125), rebased onto 1.0.6; the only conflict was the CHANGELOG. Our commit on top (5b02f8ca0) shortens two of the new doc comments to fit 120 columns and changes nothing else. We also merged this PR's head as it was then (a701d8c48, in dd310b96f). 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.

We gated it on a GB10 with Nemotron 3.5 Lightning (MLX 4-bit), against a build of the same tree without your two PRs and against the 1.0.6 release:

check result
streamed rows joined over the chunks == the nonstreamed reply's rows bit for bit on every prompt (story, code, seeded sampled, thinking), at top_logprobs 20 and 0, and on a resumed turn of a 7.2k-token conversation
a row never arrives before its text held on every chunk but the closing one, which sends what is left
thinking on the rows start at the answer: the prime-number prompt's single row is "B" at -0.0008, and a reply cut in its reasoning streams no rows
/v1/completions legacy form tokens spell the text and text_offset counts on, for logprobs 0, 5 and 20; the streamed parts joined (22 to 54 chunks) equal the whole reply
exactness with logprobs drafted rows == "draft": false rows; four logprob requests at once == each alone; the resumed turn's rows == a server with the prompt cache off
float64 reference (a gate-only build dumped every row's logits) 1,711 rows over 8 replies: chosen and alternative logprobs within 1.96e-6, ids exact
requests without logprobs the same tokens as 1.0.6 on all 29 replies of our served workload and 8/8 release prompts; decode and prompt speed within 0.5% of the base build, A B B A

The refusals still hold (tools, stop strings, structured output, a thinking budget, logprobs: true on /v1/completions, the Responses route), and a Metal server still answers every logprob request with a 400.

On speed, a 256-token greedy reply with top_logprobs: 20 decodes at 118.8 tok/s against 127.5 without (-6.9%), the same cost we measured when nonstreamed logprobs first landed (-7.0%).

@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#645 landed above as 284daf1 (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#645 landed above as 6f5863e (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