Skip to content

server: n of 1 through 16 choices on chat and completions, each its own request on the one prompt - #3148

Merged
ashhart merged 6 commits into
mainfrom
lead/n-choices
Nov 22, 2026
Merged

ashhart merged 6 commits into
mainfrom
lead/n-choices

Conversation

@ashhart

@ashhart ashhart commented Nov 13, 2026

Copy link
Copy Markdown
Owner

Closes #3114.

Chat and completions take n from 1 to 16. Each choice is its own engine request on the one prompt, run at once and merged: choices[i] with its index, its own tensorfold block (seed, cached_tokens), stop sequence, loop-stop error and tool-call ids, and usage counting the prompt once. Choice 0 keeps the request's seed, so n: 1 replies are unchanged. Choice i draws with mix(seed ^ i), named in its tensorfold.seed, so any choice replays alone. Without a seed, one is drawn per request. Later choices resume the prompt the first fills.

An n request takes n places under --max-inflight and --max-inflight-per-key, all or none. When they don't fit, it gets today's 429 (Retry-After, max_inflight_exceeded or max_inflight_per_key_exceeded) and no choice reaches the engine; all n places are released together. /v1/responses and /v1/imprint still refuse n > 1 with main's 400. The --cortheon refusal applies only to chats Cortheon would take.

Tests: test-server-cpu 1343 pass, 7 skip (main 1330), with 8 of the 9 choices tests failing on main; an HTTP test with --max-inflight 2 (n=3 gets 429 and the engine is never called; n=2 holds two places and a plain request gets 429 until it ends) fails without the caps change; test-limit-pins-host 27, test-server-security 29, test-golden pass.

Device check pending (Qwen3.8-27B on an M5 and Qwen3.5 or Nemotron on a GB10, --prompt-cache-gib 8, n=3, T 0.7, seed 1234, a prompt over 3,000 tokens, whole and streamed): each choice's token hash equals a solo request with its reported seed, drafted and not; with no seed, choice i's seed equals mix(seed0 ^ i) and replays; n absent or 1 equals main; choices 1 to n-1 show cached tokens; an unrelated stream beside an n=3 request keeps its tokens.

…wn request on the one prompt

A request with n above 1 runs n replies at once, each the route's own whole reply or stream on its thread, and
merges them: choices[i] with its index, its own tensorfold block (seed, cached_tokens), stop_sequence, loop-stop
error and tool-call ids, and usage with the prompt counted once. Choice 0 keeps the request's seed, so n of 1 is
today's path byte for byte; choice i draws with mix(seed ^ i) in 63 bits, and a request that names no seed draws
one for all its choices. Later choices resume the prompt the first fills through the prefix wait and the prompt
cache. n above 1 with logprobs or a required tool call is refused, and on a --cortheon server so is a chat its turn
loop would take; anything else outside 1-16 gets "n must be an integer between 1 and 16". /v1/responses and
/v1/imprint serve one reply and keep refusing n other than 1, as before. Under --max-inflight and
--max-inflight-per-key an n-choice request holds n places: after its body is read it takes the other n - 1, all
or none, or answers the cap's own 429 before any choice starts.
Prompt lists and n choices fan one client reply over several engine
requests and merge them. Share that machinery instead of keeping a second
copy in choices.zig: prompt_list's Slot/Fan/Choice and its whole/mergeWhole/
streamed/stamp/count/usage helpers are now public, with two flags for what
differs. A merge takes prompt_logprobs from choice 0 for n choices (not for
a list) and counts the shared prompt once. choices.zig keeps only its seed,
its lease widening and its per-choice run. Keep both Plan fields and both
dispatch lines in openai.zig and refuse n above 1 with a list of prompts.
The prompt-list test keeps its n=2 refusal under the new message and drops
the single-prompt case, which n choices now serves. Note the feature under
Unreleased in CHANGELOG.md.
Match prompt-list dispatch: the request journal observes the one merged reply, while only an unfanned generation shares the mutable Trace for prepared settings and timings. This avoids concurrent choice writers and leaves n=1 journaling unchanged.
…at the fake serves n 1 through 16

test_serial_json_script_and_refusal_never_join posts a streamed request the fake refuses and checks that it never
claims the served-evidence pairing. It used n 2, which this PR's fake (refusal(), mirroring the server's new
1..16 range) now serves: the request went down the streamed path, claimed the pairing, and the mock's guard raised
"unrelated path joined the served-evidence rendezvous". The PR moved test_bench_conformance's refused example to
n 17 but not this one. It now posts n 17 and checks the whole 400 reply and its message, so the refusal it relies on
cannot quietly become a served request again; claim is still asserted never called.
@ashhart
ashhart merged commit 34af03a into main Nov 22, 2026
2 of 12 checks passed
@ashhart
ashhart deleted the lead/n-choices branch November 22, 2026 05:39
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.

n > 1 choices per request on chat and completions

1 participant