fix(cuda-graph): keep replay metadata dynamic across tensor-parallel ranks - #540
Open
junjiewang253-ctrl wants to merge 2 commits into
Open
Conversation
junjiewang253-ctrl
marked this pull request as ready for review
August 15, 2026 10:23
junjiewang253-ctrl
requested review from
a team
and
a lite review from Copilot
August 15, 2026 10:23
There was a problem hiding this comment.
Pull request overview
This PR addresses correctness issues when using CUDA Graphs for static-KV decode with tensor-parallelism by ensuring decode metadata remains device-dynamic at replay time and by preventing TP row-parallel outputs from being consumed before their asynchronous all-reduce completes.
Changes:
- Add a CUDA-Graph recording path in static attention that uses graph-safe KV update + paged-attention ops with device-resident (dynamic) metadata.
- Gate static batching graph compilation on supported device/layout/dtype/KV-quant settings, and initialize replay metadata tensors as I32 device tensors (including block tables).
- Synchronize the current stream after TP RowParallel
compute_linear_allreduce()before returning the output.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/static/test_static_graph_dynamic_metadata.py | Adds focused unit tests that assert graph recording forwards device-dynamic metadata into graph-safe ops and that replay inputs are copied into device-resident tensors. |
| csrc/layers/linear/linear.cpp | Ensures TP RowParallel forward waits for async all-reduce completion via stream synchronization. |
| csrc/layers/attention/backends/static_attn.hpp | Declares a private forward_graph_ helper for the graph-recording attention path. |
| csrc/layers/attention/backends/static_attn.cpp | Implements the graph-recording attention path using kv_caching_ and paged_attention_ with device-resident metadata. |
| csrc/engine/compiler/static_batching_compiler.cpp | Adds support checks for static graph attention and initializes/updates replay metadata tensors to remain device-dynamic. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
junjiewang253-ctrl
force-pushed
the
fix/cuda-graph-static-kv-replay
branch
from
August 15, 2026 17:30
565238d to
9410531
Compare
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.
Summary
Keep static-KV decode metadata device-dynamic during CUDA Graph replay and ensure tensor-parallel row reductions complete before downstream work consumes their output.
Root cause
CUDA Graph capture parsed KV offsets and attention shapes on the host, freezing capture-time decode decisions. Replay could therefore reuse stale KV and attention metadata. On the current upstream tensor-parallel path, RowParallel also returned the result of an asynchronous all-reduce without waiting for stream completion, which could let ranks advance out of phase during graph-enabled decode.
Fix
compute_linear_allreduce()completes and before returning its output.CUDA Graph remains opt-in; this change does not modify the default enable policy.
Correctness
Fresh current-upstream builds were validated with the same 12 exact prompts in each cell:
Overall: 6/6 valid cells, 72/72 token-exact, with zero request errors, timeouts, OOMs, output collapse, loops, or abnormal lengths.
A targeted ablation reproduced the TP2 Graph ON hang without the RowParallel synchronization, while the synchronization overlay completed 12/12 exact requests. The committed candidate then passed the full six-cell matrix.
Build and tests
Limitations