Repository navigation
server: resume the streamed-reply scans where they stopped - #5987
joshuaswarren wants to merge 2 commits into
Conversation
|
GREEN on c22fd48 Verified against head c22fd48. The resumable scan is correct, not just faster:
Evidence: measured with The +106/-0 reply_stops.zig is the scan module; reply_text.zig delegates. Scope matches the claim; no lab names. Reviewer-Model: GLM (w7J) |
Synthena Initial Review — Performance receipt required (
|
|
Re-ran Handler ms for the ~32k-token synthetic reply, stride 1:
Reproduces the ~2200+ ms to ~180-290 ms claim. kimi's control reads 130 -> 146 ms on this box, which looks like noise but is worth noting. Request-arena numbers are unchanged across the board. |
|
Thanks @joshuaswarren. Every commit here is included unchanged in #5994, so we will review and test them together there and close this PR when #5994 lands.
|
Each chunk of a streamed reply re-ran the whole-reply scans: the stop string search, the MiniMax call-block search, the think close rewrite and the split's opener finds all walked the full decode buffer again, so a long thinking reply cost quadratic request-thread time. The decode buffer only grows, so their found offsets cannot move: keep each scan's frontier and first-found offset on the generation, resume the searches there, and reuse the rewritten close offset once its token lands. Streamed frames are unchanged: 32k-token thinking replies through bench-stream-scan drop from 2.2-2.4 s of handler time to 0.2-0.26 s per route, with the same frame and token counts.
c22fd48 to
c0b30b8
Compare
|
Thanks, @joshuaswarren. The shared scan work is present in #5994 as agreed. Comparing both applications on the same main confirms that the chat/split scan files match, with #5994 carrying the additional stop and logprob fixes. We will keep the combined review and host validation there, then close this duplicate after the combined change lands. No separate receipt, device run or author revision is needed here.
|
|
Closing as agreed: every commit here landed unchanged in #5994, which merged 2026-12-05T06:48:36Z. Verified on current main (038b7a6): the resumable scan (Stops.Scan scanned frontier, stream_scan_stages.zig, reply_text.zig) is identical to this PR; the remaining diffs on reply_stops/logprob_parts/root/chat_generation are #5994's additional stop and logprob fixes on top. |
No issue: this is a measured host-side performance fix, not a new family, backend or arithmetic change. Found with
zig build bench-stream-scan, which replays captured SSE chunks through the real streamcommitpath.On a 30k-token streamed reply the per-chunk handler cost grows linearly with reply length: every chunk re-searches the whole accumulated text for stop strings, the think close tag and call openers, the MiniMax block opener, and re-runs
closeAfterRewriteon the frozen prefix. At 30k tokens that is ~130-180 us a chunk; over a 32k-token synthetic reply the stream handler wall time is ~2.2-2.4 s against ~135 ms forkimi/chat, which already tracks its own incremental state.This change keeps the same answers and only resumes each search where the last chunk left off:
zig/src/server/reply_stops.zig(new file;Stopsmoved out ofreply_text.zigto keep it under the lean 600-line limit):Stops.Scanmemoizes the first stop-string match offset and resumes the search atscanned - (longest_stop - 1), so a stop that would begin in already-checked text is still found.zig/src/server/reply_text.zig:SplitScan+ an optionalscanparameter onsplitThinkingAtmemoizes the spelled close-marker offset and the first call-opener offset in the stripped text, with the resume frontier backed off by the longest needle. Disabled when any needle is empty (findTagreturnsfromthere).Incremental.closeOfwas already memoized.zig/src/server/chat_generation.zig: per-Generationstop_scan/split_scanstate;rewrite_closememoizescloseAfterRewriteonce the original close is.token(its offset cannot move);mini_open/mini_scannedrun an incremental search for the]<]minimax[><tool_call>opener, and while it is absentdsmlis skipped sotextstays the untouched decode buffer; a pointer check gates whethersplit_scanis safe to use on the same bytes.stops.matchedstill runs only at finish; every othersplitThinkingAtcaller (logprob parts, stream-scan stages, finish path) passesnulland gets the unmemoized behavior.Measurements
x86_64 Linux, EPYC 7443P, zig 0.17.0, ReleaseSafe (
-Dstream-scan-optimize=safe, the server build mode).zig build bench-stream-scan, stride 1, ~32k-token synthetic replies through the real route code. Basec3e546800, headc22fd4876. Alternating builds, token and frame counts identical between arms.Handler wall time for the full stream:
Per-chunk cost at 30k tokens: qwen/chat ~130-180 us -> 8.6 us; none/chat ~137 us -> 5.6 us. kimi/chat is flat before and after (it has its own incremental path) and is the control.
Checks on this head
zig build test-server-cpu: 2302 tests pass, including 2 new equivalence tests (a resuming stop scan finds and holds the same visible prefix; resuming split searches return the same streamed split a fresh search does).zig fmt --check build.zig zig,git diff --check: clean.Not covered
atc overlap --jsonon basec3e546800: pull-file data was unavailable; the flagged overlaps belong to my older open PR gpu: raise the Vulkan Qwen3.5 context ceiling to 8192 keys #3417 and none of them touchchat_generation.zig,reply_text.zigorreply_stops.zig.