Repository navigation
server: kept_probs, each token's post-filter probabilities beside its logprobs - #3207
Merged
Merged
Conversation
ashhart
force-pushed
the
lead/kept-probs
branch
3 times, most recently
from
November 15, 2026 21:47
1ecb2e3 to
456d597
Compare
ashhart
force-pushed
the
lead/kept-probs
branch
4 times, most recently
from
November 21, 2026 20:01
0802098 to
68b05a2
Compare
ashhart
force-pushed
the
lead/kept-probs
branch
3 times, most recently
from
November 26, 2026 15:57
c15ca35 to
9720636
Compare
…m its logprob row An opt-in `kept_probs: true` on chat (with logprobs) and completions (with a logprobs count) adds, for each reply token, the probabilities over the tokens the sampler keeps after temperature, top_k, top_p and min_p, renormalized. The server computes them on the host with the sampler's own cut (`sampling.kept`, moved out of `chooseOrdered` unchanged) and asks the engine for all 20 alternatives, while `top_logprobs` still prints the count asked for. A sampled request needs top_k from 1 to 20 so the kept set fits the row; other top_k values and nonzero penalties are refused with HTTP 400. Tokens and every other field are unchanged with the option on or off. Fixes #3182
ashhart
force-pushed
the
lead/kept-probs
branch
from
November 28, 2026 05:30
9720636 to
0ee0b0d
Compare
ashhart
added a commit
to joshuaswarren/TensorFold
that referenced
this pull request
Nov 28, 2026
ashhart
added a commit
that referenced
this pull request
Nov 28, 2026
ashhart
added a commit
to Bizuayeu/TensorFold
that referenced
this pull request
Nov 28, 2026
ashhart
added a commit
that referenced
this pull request
Nov 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
Adds an opt-in
kept_probs: trueto/v1/chat/completions(withlogprobs: true) and/v1/completions(with alogprobscount). Each reply token also carries the probabilities the sampler drew it from: the tokens left after temperature,top_k,top_pandmin_p, in the row's order, renormalized to sum to 1. Chat adds akept_probslist of{token, prob}to eachlogprobs.contententry; completions add akept_probslist besidetop_logprobs, one list per token. A greedy request reports its one token at probability 1.The server computes the set on the host from the logprob row it already receives, with the sampler's own cut: the top_p and min_p step moves unchanged out of
chooseOrderedintosampling.kept, which both the draw andkept_probscall. With the option on, the engine is asked for all 20 alternatives;top_logprobsstill prints the count the client asked for.A sampled request needs
top_kfrom 1 to 20, so the kept set always fits inside the 20-alternative row. Any othertop_k(including none), a nonzeropresence_penaltyorfrequency_penalty, orkept_probswithout logprobs returns HTTP 400 with the reason. The set comes from the rows' 32-bit values, so a token within about 1e-6 of a cut can land on the other side of it;docs/api.mdsays so.Why replies are unchanged
The option changes only what the server prints. The engine sees the same request apart from a larger logprobs count, which only sizes the logprob row; the sampler reads the same logits with the same seed, so tokens are untouched. With the option off, the request and every printed field are as before.
Tests (host, no GPU)
kept_probs.zig: the kept set by hand (top_k, top_p's cumulative cut, min_p's floor, temperature); a top_k the row can't hold is an error, never a truncated set; 20,000 host draws per configuration land in the set at their reported frequencies; from rows built off full-vocabulary logits, every draw of the host sampler and of both GPU sampler references lands in the set, a top_k cut between tied logits keeps the lower id, and the full-row GPU rule keeps exactly as many tokens; refusals for top_k 0, 21 and 50 and for penalties.logprobs_test.zig: chat and completions, whole and streamed, option on and off: with ids, clocks and the runtime block fixed andkept_probsremoved, every body and stream event is byte-identical; the streamed kept sets joined over the chunks equal the whole reply's; greedy keeps one token at 1; a completion with no tokens carries an empty list; the HTTP 400 cases.zig build test-server-cpu,test-logprob-offers-host,test-shared-lane-regressions-host(with the sampler identity tests),test-request-seeds-hostandtest-lane-api-hostpass;zig fmt --checkis clean; the lean checker's count equals main's.Still owed
A served check: the same sampled chat with and without
kept_probs(whole, streamed, and on/v1/completions) must give equaltoken_sha256andtop_logprobs; each token must be in its own kept set with probabilities summing to 1; decode speed with the option on and off should be within noise.Fixes #3182