Repository navigation
Nemotron CUDA: keep prompt states where messages end, staged inside a chunk without an extra pass - #721
Nemotron CUDA: keep prompt states where messages end, staged inside a chunk without an extra pass#721plotarmordev wants to merge 2 commits into
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.
|
Thanks for taking #670 on. One gap: with the rules now |
|
Thanks for running I'd keep the floor out of this pull request and send it as a follow-up once this lands. That keeps this one to the two changes the receipt covers, and leaves the floor's value to be settled beside #669, which reasons about the same floor for the planned families. I measured it on this branch's second commit, with a local switch for the floor: 1,024 on both Sparks, 0 on one. Eight conversations of 0.5k to 3.8k tokens, six turns each:
Your 0.12 s first-turn cost fits what I'd expect from this branch: only a lone keep in a chunk is staged, so a chunk holding several keeps still ends at the first. Staging every keep in a chunk would remove that cost, and I'd pair it with the floor in the follow-up. |
|
Closing this as superseded by 1.0.8. #670's change, prompt states that keep and resume at any row, with a keep inside a chunk costing no prompt call ( #720 and #723 stay open. I'm merging 1.0.8 into both and will re-measure them on it, with The Grill behind the speed receipts. |
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.
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.
|
Thank you, @plotarmordev, and agreed: 1.0.8's in-chunk keeps from #670 cover what this PR did, so closing it was right. Your test for it landed in 1.0.9. On a GB10 (sm_121) it passes on both Nemotron checkpoints, MLX 4-bit and NVFP4, at 3,073, 4,096, 4,097 and 8,193 tokens, the last one running one row into a third 4,096-row pass. |
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.
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.
What this changes
Nemotron on CUDA keeps a conversation's prompt state where its messages end, and keeps it without an extra prompt pass. Two commits:
planned/grid(.{ .lookahead = 1 });cuda_prompt_grid.zigtakes the keeps (end,lastStart,resumableat any row inside the prompt); the lanes read the last chunk's hidden row fromlastStart. Newtf-cuda-test prompt-cuts MODEL IDS_FILE: a 9,000-token pass keeping at 1, 777, 2047, 2048, 2049, n-33 and n-1, and passes resumed from each kept state, against one uncut pass (caches and states, the head's caches, the last logits and hidden row).Buffers.snapshotFrom); the chunk's KV rows past the keep ride along and are written again before any pass reads them. A chunk holding several keeps still ends at the first. A later turn, which keeps where its messages end a few tokens before the prompt's end, now prefills in one pass instead of two.Receipt
Environment: two DGX Sparks (GB10, sm_121, driver 580.173.02, CUDA 13),
TensorFold/NVIDIA-Nemotron-3.5-Lightning-30B-A3B-MLX-4bit@d9d758fb, one7c523eb,zig build native -Dnvcc=… -Dsm=121, built-in kernels,--context 16384 --parallel 4.Exactness:
"draft": false: all 11 positions equal the uncut run (token_shaand the 20-alternative logprob rows).prompt-cutspasses after each commit (the second exercises cut and staged keeps). It fails, as it should, when a local change makes the scan'sdtclamp depend on the chunk's rows.token_shaand logprob rows) equal the cache-off server's (--prompt-cache-gib 0,e7c523eb) after each commit, on both Sparks, two sessions each.Prompt speed, the same conversations (each later turn's
prefill_seconds, median of 60):e7c523ebEvery turn resumed at the same token in commit 1 and commit 2.
Decode speed: unchanged (no change to windows or rounds).
Memory: one stage buffer, the size of one sequence's Mamba states and conv rows.
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:tf-cuda-test prompt-cutsafter each commit (above).Not run, and why: Metal (unchanged). The NVFP4 checkpoint, RTX cards (no hardware here).
--segmentsabove 1 only runs a pass that keeps nothing, so it is unchanged.Checklist
"draft": false, a resumed prompt equals a fresh one, and concurrent equals solo.prompt-cutsneeds the model and a GPU; the grid test's expectations follow the new cuts.)