Repository navigation
Nemotron CUDA: prefill each reply in the background for the next turn - #723
Conversation
…messages end A prompt pass cuts a chunk at each keep, since a row's bits do not depend on where its chunk is cut, so the prompt cache keeps states at the history's end instead of the 2,048-row grid point below it. tf-cuda-test prompt-cuts checks a pass cut on and off the grid, and passes resumed from each cut, against one uncut pass.
…the chunk there The Mamba scan runs to the keep, its state and the conv rows a cut would leave are copied aside, and the scan runs on with the same bits; the keep's saved state takes those planes in place of the live ones. A chunk with several keeps still ends at the first. A conversation's later turn now prefills in one pass.
…ws only A state kept after at tokens copies each layer's first at KV rows instead of the whole window's, and the cache counts it at that size; the rows past it, which no pass reads before writing them, stay as they are on restore. prompt-cuts fills those rows before each restore.
The Nemotron CUDA store is warm and its host takes warm turns: after a reply, the conversation, the reply and the next turn's opening are prefilled in a background pass that steps aside at a chunk boundary for a foreground request. A warm pass of a family keyed past its state keeps one row before its end, however near it resumed, through its marks.
ashhart#721 and ashhart#722 were superseded by 1.0.8 (ashhart#670: states keep and resume at any row, kept states hold the prompt's rows); this merge takes 1.0.8's prompt states and keeps only this PR's change on top.
|
Brought up to date with 1.0.8 ( Re-checked at this head on a GB10, against a 1.0.8 build, in two sessions:
Not re-run on 1.0.8: the 0.05 s gap case and the ~30 ms cost when a message arrives the instant a reply lands. The CHANGELOG entry gives those from the 1.0.7 receipt. |
The contributor's commit landed above on 1.0.8's prompt states. The head also holds ashhart#721's and ashhart#722's commits, whose changes 1.0.8 had already made in its own form and whose tests landed above; this keeps the head in the history with no change to the tree.
…st windows as measured
|
Thank you, @plotarmordev. Prefilling the reply in the background is what makes a conversation's next turn cheap on CUDA, as it already is on the Macs. It landed in 1.0.9 under your name ( What we measured on a GB10 (sm_121):
Before the release we changed when the pass runs ( The batch waited a day on a speed check of ours, and the cause was ours too. After the merge, a served A/B read prose greedy 1.5% slower. Both builds make the same draft decisions on the same window-cost table, so the difference came from the table the draft-depth rule reads, and our calibration had timed its windows over the MTP head's own drafts, which loop and read too cheap. That is fixed in our commit after yours ( |
The contributor's commit landed above on 1.0.8's prompt states. The head also holds ashhart#721's and ashhart#722's commits, whose changes 1.0.8 had already made in its own form and whose tests landed above; this keeps the head in the history with no change to the tree.
…st windows as measured
What this changes
On top of #722 (its three commits come first here; this pull request adds the last one). Nemotron on CUDA takes warm turns, as the Qwen3.8-27B does: after a reply, the conversation, the reply and the next turn's opening are prefilled in a background pass, so the next turn resumes past the reply and prefills only its new message.
native/cuda.zig: the Nemotron store's rules are warm, and the host reportswarm_turns.core/prompt_cache.zig: a warm pass (its history the whole prompt) of a family keyed past its state keeps one row before its end, however near it resumed;core/lane_host.zigkeeps a warm pass's end itself only for a family that keys no lookahead (the 27B, unchanged). A test expectation covers the new mark.cuda_lanes.zig: the prompt's cancel check also asksStream.yields(), so a background pass steps aside at its next chunk when a request arrives.Trade-off: a message sent the instant its reply lands waits behind that reply's background pass, which has already begun: about 30 ms later than without this change. From a 0.15 s gap on, the next turn starts about twice as fast (below).
Receipt
Environment: as Nemotron CUDA: keep prompt states where messages end, staged inside a chunk without an extra pass #721 (two DGX Sparks, GB10, driver 580.173.02, Nemotron 3.5 Lightning MLX-4bit @
d9d758fb, one7c523eb),--context 16384 --parallel 4.Exactness: six conversations of six turns over 5k to 10k-token documents with 200-token replies: all 36 replies equal the cache-off server's on both Sparks, and equal across every gap below, two sessions each.
Time to first token of the later turns (the server's
time_to_first_token, queue wait included; medians per turn, 30 turns a session):I also tried letting a background pass wait 25 ms before it starts so an instant message goes first; it was worse (a skipped background pass leaves the next turn resuming further back), so it is not here.
Decode speed: unchanged.
Tests run:
zig build test39/39 steps, 451/451 tests;zig build test-cuda-host24/24 steps; the server tests 127/127 and 104/104 (zig/tests/server/zig_test.sh); the frozen server goldens 309 of 319 equal, 0 unexpected differences, as onmain;zig fmt --checkclean on the changed files;lean_check.py534 problems, as onmain. GPU: the conversations above; no new GPU test.Not run, and why: Metal (its stores are not warm; the core change only touches warm stores with a lookahead). The NVFP4 checkpoint, RTX cards (no hardware here).
Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.