Repository navigation
nemotron cuda: chunked prefill between other streams' rounds - #4700
Merged
Merged
Conversation
…' rounds serialChunks becomes a Pass whose next() runs one chunk: the whole pass loops it, and the new prefill_step calls it once a round, so both share one implementation. prefillFrom splits into begin, the segmented choice, the pass and firstToken for the same reuse. The lanes' prompt setup moves verbatim into cuda_lanes_fill.zig (whole and step; cuda_lanes.zig was at 598 lines). A step binds the stream's sequence, which restores its position, sampling, decision row and MTP head, sets the tap and prompt-row hooks for its one chunk, and on the last chunk takes the first token and the head's last row as the whole pass does. Image prompts (the tower keeps one row buffer an engine) and staggered-segment passes fill whole in their first step. A cancel between chunks keeps the interrupted prefix and drops the pass; release drops it too. test-nemotron-cuda-steps-host: an image prompt fills whole, each image through the tower once; a pass that cannot begin holds nothing; a cancel between chunks drops the pass.
…ted (REV59 1) The stepped pass stores fill_at after every chunk, but the backend did not declare reports_fill, so the lane host treated its progress as unreported (status, load ledger, remaining work, the prefill budget, srpt samples) and Drafted, which steps a target only when it reports its fill, would have run the whole pass under --drafter. The backend now declares it.
… the prefix (REV59 2) The lane host takes a cancel between two prompt calls itself: it calls the backend's cancel_prefill, if any, then releases the stream, and never steps the pass again. Nemotron CUDA kept an interrupted prefix only when a cancel landed inside a chunk, so a cancel between chunks (the common case under the host) lost it. cancel_prefill now binds the stream's sequence, where the prompt cache's save reads the state, and keeps the prefix where its last chunk ended; with no pass between chunks it keeps nothing.
… the end (REV59 3) A stream offered a kept state starts with fill_at at the kept row. When the restore failed, was refused or was skipped (prompt logprobs), open left it there, and only a stepped pass's unfinished chunks wrote it again, so the first chunk, a failure in it, a one-chunk pass or a whole pass reported rows never filled. open now sets it to the row its pass starts at, and the pass's end to the prompt's length.
… (REV59 4) The first cancel check was the pass's own, before its first chunk: by then a cancelled stream had taken a sequence, restored any kept prefix and, for an image prompt, run every image through the vision tower. The whole pass and the first step now refuse a cancelled stream before opening it.
… (REV59 5) Cuda gained a map of stepped passes standing between their chunks but its deinit never freed it, so an engine torn down after any stepped prompt leaked it. deinit now frees it. The host test's rig runs on a driver whose stream waits and host frees only count, so the real deinit runs.
…s its stream (REV59 6) Once a step opened a stream's lane (the own sequence, a paged lease or a new sequence), a failure in its pass left the lane in place: the lane host releases a failed stream itself, but Engine.fillStream releases only on a cancel, so its direct callers leaked the sequence. prefill_step now releases the stream, after its queued GPU work, on any error but a cancel (the cancel stays the host's, which keeps the interrupted prefix first); release is idempotent, so the host's own release finds nothing.
…the host bills it (REV59 7) The lane host sets settle_step on a stream whose prompt calls it times against decode's share (--decode-share, or past 32k rows by default), so a call's time must include its GPU work. A Nemotron chunk's kernels stay queued on the engine's stream when the call returns, so the call billed its launch time and the next decode round paid for the chunk. With settle_step, an unfinished chunk now waits for its stream before returning, as GLM's CUDA lanes do; without it nothing changes.
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.
Nemotron on CUDA fills a new prompt a chunk at a time between other streams' decode rounds, so a long prompt no longer stalls the replies already streaming. The engine's prompt loop becomes a resumable per-chunk call that holds the stream's prompt state (position, MTP absorb, taps, prompt logprobs, vision marks) across other streams' rounds, and both the whole pass and the new
prefill_stepuse it.reports_fillandcancel_prefillare declared, so drafting and a lane-host cancel between chunks behave as they do on the other chunked families.Served A/B against main on a GB10, Nemotron 3.5 Lightning 30B-A3B MLX 4-bit, three passes each, tokens equal in every cell: prompt 2K/8K/16K level (-0.3% to +1.0%), chat and code at 1/4/8 streams -1.4% to +2.7%.