Repository navigation
Enable CUDA Graph for continuous rollouts - #8732
Open
nathon-lee wants to merge 11 commits into
Open
nathon-lee wants to merge 11 commits into
nathon-lee wants to merge 11 commits into
Conversation
Signed-off-by: nathon-lee <leejianwoo@gmail.com>
Cache continuous-rollout CUDA graph state across matching generate calls. Rebuild the graph when the model parameters or static decode shape changes, and reset static buffers and KV cache rows before reuse. Use eager attention and a preallocated additive causal mask during capture to avoid Transformers capture-time mask allocations. Relax cache-class detection for models that support the cache interface without declaring the private capability flag. Add coverage for eager-attention capture, graph reuse, weight invalidation, and current StaticCache update semantics. Signed-off-by: nathon-lee <leejianwoo@gmail.com>
Signed-off-by: nathon-lee <leejianwoo@gmail.com>
Use the preallocated additive causal mask to make CUDA Graph capture safe without overriding the model attention implementation. This preserves default SDPA behavior and restores eager/graph token parity for pretrained GPT-2. Update graph-capture coverage to verify the configured attention implementation remains unchanged. Signed-off-by: nathon-lee <leejianwoo@gmail.com>
Populate continuous rollout cache statistics after CUDA Graph decoding so callers do not receive stale eager-path metrics. Cover graph cache capacity, peak usage, decode steps, and trimming metrics. Signed-off-by: nathon-lee <leejianwoo@gmail.com>
Validate fixed-slot CUDA Graph options before capture and cover unsupported decode alignment, cache trimming, and insufficient cache capacity. Signed-off-by: nathon-lee <leejianwoo@gmail.com>
Add CUDA rollout coverage for pretrained Hugging Face models behind DEEPSPEED_PRETRAINED_ROLLOUT_MODEL so regular CI does not download weights. Validate eager and CUDA Graph parity across prompts and verify graph reuse. Signed-off-by: nathon-lee <leejianwoo@gmail.com>
nathon-lee
marked this pull request as ready for review
October 10, 2026 09:52
nathon-lee
requested review from
loadams,
tjruwase and
tohtana
as code owners
October 10, 2026 09:52
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c280ea3b13
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Route dummy writes for non-decoding graph slots to a scratch cache position so refilled prompts retain their prefetched KV state. Add CUDA coverage for a slot refill while another request continues decoding. Signed-off-by: nathon-lee <leejianwoo@gmail.com>
Reject flash_attention_2 before continuous CUDA Graph capture because the fixed replay path requires a four-dimensional additive attention mask. Document the restriction and cover the configuration error. Signed-off-by: nathon-lee <leejianwoo@gmail.com>
Reject models that explicitly lack cache-class support before the continuous CUDA Graph path creates static cache state. Add regression coverage for the graph-specific validation path. Signed-off-by: nathon-lee <leejianwoo@gmail.com>
This branch has not been deployed
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.
Enable CUDA Graph for continuous rollouts
Summary
Enable experimental CUDA Graph decode replay for greedy Hybrid Engine rollouts that use
SamplingConfig.continuous_batch_size.DeepSpeedStaticCacherows.tensor addresses and a fixed batch shape.
dtype, batch capacity, prompt width, or cache shape changes.
operations that are not CUDA-graph-safe while preserving the model's configured attention implementation.
retired rows before reuse.
Requirements and limitations
CUDA Graph capture currently requires CUDA inputs, greedy decoding, one sample per prompt, equal padded prompt
widths,
align_decode_fronts=False, andenable_cache_trimming=False. The graph path rejects aligned decode frontsand cache trimming explicitly because those modes move cache rows or columns, whereas a captured graph requires fixed
physical addresses.
Models that explicitly report no cache-class support remain rejected. Models with unknown support use the legacy
prefill path and should be validated against eager generation before production use.
Validation
On an NVIDIA RTX A4500 with PyTorch 2.9.1+cu128 and Transformers 4.57.1, locally initialized small GPT-2 and Llama
models produced token-identical eager and CUDA Graph outputs. Two different GPT-2 prompts reused one capture
(
capture_count=1).The same validation ran with public
openai-community/gpt2pretrained weights in FP16. Two fixed-length,left-padded prompts with seeds 1234 and 1235 produced token-identical eager and CUDA Graph outputs, including
attention masks, while reusing one capture (
capture_count=1).Performance
The former synthetic continuous-rollout sample included graph capture in every rollout and is not representative of
the reused steady-state path. Production benchmarking should report both first-call latency, which includes capture,
and steady-state reuse separately.
For a local sanity check on the RTX A4500, a randomly initialized medium GPT-2 model with BF16 disabled, batch size
1, prompt length 32, response length 32, two warmup calls, and five steady-state measurements produced:
This is a local synthetic sanity check, not a production-model result. Production-model measurements should use fixed
prompts and report first-call and steady-state results independently.
CC @delock @minjiaz @PKUWZP