Repository navigation
[rl] MTP on GDN models: FULL CUDA graphs for steps with prefill - #6403
felipemello1 wants to merge 3 commits into
Conversation
|
@claude please review. Also find opportunities, if any, to reduce the amount of lines or to break this pr further. If its not possible or unreasonable, it is ok. |
|
Claude finished @felipemello1's task in 8m 8s —— View job Needs discussion -- see the review on this PR. It proposes a split (A: GDN drafts on the TorchTitan builder, which changes numerics; B: FULL graph mode, bitwise) and ~60 lines of trims. |
There was a problem hiding this comment.
Verdict: Needs discussion -- I found no confirmed bug. The trimmed-draft path relies on a vLLM runner contract I couldn't verify. Whether to split the PR at its numerics seam is the author's and maintainers' call.
What this PR does. It replaces the GDN-with-drafts path (vLLM's GDN builder plus an eager graph break) with TorchTitanLinearAttentionMetadataBuilder staging every step in fixed buffers. Every kernel runs every row, with the null slot (0) on the rows it doesn't own, so one FULL graph per token count replays any mix of verify, 1-token and prefill rows. cuda_graph.mode="FULL" with drafts becomes vLLM's FULL instead of FULL_AND_PIECEWISE. The drafter keeps breakable piecewise graphs, now captured at start-up by TorchTitanEagleProposer.dummy_run.
Example. k = 3, max_num_seqs 5, one step with rows [verify 4, verify 4, 1-token resume, prefill 13] padded to 24 tokens:
before: piecewise graph; GDN and attention eager; index_select/index_copy_ splits rows
after: PACKED graph, S = min(24, 4 x 5) = 20
prefill conv + chunk on all 24 tokens (rows 0-2 = one null interval, slot 0)
verify conv + GDN on tokens 0-19 (rows 3+ have slot 0, so the kernels skip them)
out[:20] = where(spec_token_mask, verify_out, chunk_out)
Must fix
- PR description: "Summary (human-written)" is empty. The author has to write it (CONTRIBUTING.md, "AI-assisted contributions").
linear_attention.py:335-343: steps with every draft trimmed readrunner_num_accepted_tokens, and the only test sets that buffer by hand. Cite the vLLM line that refreshes it on every step, or copy the counts in the runner (inline).
Should consider
gdn.py:365: unreachableRuntimeError; make it an assert (inline).linear_attention.py:79: KDA now runsGDNAttentionMetadataBuilder.__init__, and no GPU test starts a KDA engine (inline).test_gdn_graph_metadata.py:924-938: the NaN-poison probe is fragile and already covered; delete it (inline).test_gdn_cudagraph.py:55-67: the fp8 engine case runs in no CI job (inline).linear_attention.py:472,488:_check_uniform_rowsand_check_verify_kernel_rows_fiteach have one caller. Inline them into_build_with_drafts(design.md: no single-call-site functions).
Questions
worker.py:414TorchTitanEagleProposer.dummy_runforcesuse_cudagraphswhenever vLLM captures, including FULL_DECODE_ONLY targets, where the drafter isn't breakable. Does vLLM's drafter then stay eager there, as before? If unsure, gatecaptureonisinstance(self.model, BreakableCUDAGraphWrapper).
Reducing lines / splitting the PR
Split (feasible, optional). The PR has two separable changes:
| PR | Contents | Numerics | Approx. size |
|---|---|---|---|
| A: GDN drafts on the TorchTitan builder | builder subclass, _build_with_drafts, _update_block_table_with_drafts, new _forward_speculative (VERIFY/PACKED), FA4 reorder threshold 1 + k, runner flags, 1-token rejection, DP > 1 ban, layer tests |
changes (Attention Gym conv for prefill rows; verify kernels for 1-token rows after context) | ~550 code + ~350 test |
| B: FULL instead of FULL_AND_PIECEWISE | VLLMCudaGraphConfig mode, drafter dummy_run capture, capture_model checks, memory-estimate change, deleting the eager break, engine test drafts case |
bitwise vs A's eager path | ~150 code + ~150 test |
A keeps _forward_speculative_eager / eager_break_during_capture, which are already on the base, so its piecewise steps still run GDN eagerly with metadata. B deletes them. This puts the numerics change and the drift numbers in A, and the graph-mode change and the +6.3% in B. The cost: A still needs its own GPU validation, and A alone gives no throughput gain. If the stack is reviewed as a whole anyway, keeping it as one PR is reasonable.
Smaller trims (~60 lines total): the NaN probe (-15), the fp8 engine case (-20), the gdn.py check as an assert (-3), and inlining the two _check_* helpers (-6). The two new graph tests in test_gdn_graph_metadata.py duplicate ~20 lines of capture setup (two layers, a cloned kv_cache, warm-up plus torch.cuda.graph). A shared _capture_gdn_graph(layer, metadata, static_tokens, weights) would remove that.
Not worth cutting: the start-up checks in capture_model / calculate_reorder_batch_threshold. Each guards a failure that would otherwise be silent (GDN inside a piecewise capture replays zeros; a wrong reorder threshold puts verify rows past S). The run-merging in _build_with_drafts also stays: without it, the chunk kernel would see one null sequence per verify row (up to max_num_seqs) instead of one per run.
Gate notes. The problem is real and measured (+6.3% / +4.4% output tok/s). GDN integration inside vLLM belongs to torchtitan's generator. Private vLLM dependencies (V1 builder-class dispatch, _init_reorder_batch_threshold, drafter capture) carry TODOs pointing at the V2 runner. The design is generator-only by nature (inference CUDA graphs), so question 7 doesn't apply.
Not verified: vLLM kernel and runner contracts (whether the conv and verify kernels skip slot 0, whether num_accepted_tokens is refreshed every step, drafter capture under FULL_DECODE_ONLY); vLLM sources weren't available in this run, and nothing ran on GPU. A maintainer still needs to review.
cuda_graph.mode="FULL" with MTP drafts maps to vLLM's FULL: verify-only steps replay the uniform verify graph, steps with prefill the packed mixed graph. The drafter replays breakable piecewise graphs (VLLM_USE_BREAKABLE_CUDAGRAPH). capture_model refuses piecewise modes and a lowered FULL, the graph-memory estimate keeps verify graphs charged, and the drafter captures under a FULL target.
dc7d9c3 to
3c1f835
Compare
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 4m 31s —— View job Approve, with two small fixes to make before merging. See the review on this PR. |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. After the split, this PR is only the graph-mode change. The silent failure modes it opens (GDN inside a piecewise graph, vLLM lowering FULL, a drafter that isn't breakable) now raise at start-up. What remains is mechanical.
What this PR does. It drops the ValueError for cuda_graph.mode="FULL" with drafts. With FULL and drafts, VLLMEngine sets VLLM_USE_BREAKABLE_CUDAGRAPH=1, and raises if vLLM's attention op was imported before that. TorchTitanEagleProposer.dummy_run captures the drafter's piecewise graphs at start-up. capture_model raises on the graph modes that would replay wrong state. Verify graphs stay in vLLM's graph-memory estimate.
Example. Qwen3.5 with k = 3 and cuda_graph.mode="FULL":
before: VLLMEngine.Config.__post_init__ raises; use FULL_DECODE_ONLY -> steps with prefill and the drafter run eagerly
after: verify-only step -> FULL verify graph; step with prefill -> FULL mixed graph (packed path, PR 1)
drafter -> breakable piecewise graphs captured at start-up, attention eager
vLLM lowers FULL (a backend without ALWAYS support) -> RuntimeError at capture_model
Must fix
config.py:189--uses_breakable_cuda_graphshas one caller. Inline it atengine.py:354(inline).test_generator.py:1571-- the new assertion only reads back the mode it just set, and the mapping it checks is unchanged on the base branch. Delete it (inline).
Should consider
engine.py:354-- the env var is set in the middle of theValueErrorchecks. Move the call into_setup(inline).worker.py:138-150-- the mode check can likely be a single condition (inline, unverified).worker.py:443-- gate the forced drafter capture onisinstance(self.model, BreakableCUDAGraphWrapper)(inline). This was the open question from the last review.
Questions
- Has a
VLLMEngine(e.g.generate.pyor an RL recipe) withnum_speculative_tokens > 0and FULL started at this head?test_gdn_cudagraph.pysetsVLLM_USE_BREAKABLE_CUDAGRAPH=1at process start and drivesLLMEnginedirectly, so no test runs_enable_breakable_cuda_graphs. If the top-level vLLM imports inengine.pyalready import vLLM's attention module, every such engine raises at init. That failure is loud, but it would block the feature from its real entry point.
Details
Earlier review (2026-11-26). Must-fix 2, the accepted-count contract, now has a citation (worker.py:168, GPUModelRunner._prepare_inputs). The split it proposed (A: builder, B: graph mode) is done: this PR is B, and the builder, layer and test_gdn_graph_metadata.py changes moved down the stack. The should-consider items on gdn.py, linear_attention.py and the NaN probe went with them and weren't re-checked here. The fp8 engine case is gone from test_gdn_cudagraph.py.
Gate. The problem is real: with drafts, every new turn's prefill step runs eagerly under FULL_DECODE_ONLY. The measured gain (+6.3% / +4.4% output tok/s) comes from an earlier version of the stack, as the description says. The change is generator-only by nature. The private vLLM dependencies (drafter capture in V1's _dummy_run, the import-time graph break) have TODOs pointing at #5956 and the v0.33 pin.
Overlap search. Searched open PRs for "breakable cuda graph", "MTP drafter" and "worker.py vllm cudagraph". Found #5956 (V2 runner, rebases on this stack), #6287, #6364 and #6366 (the stack itself), and the SGLang breakable-graph PRs #6415, #6200 and #6425 (a different engine). None rewrites this code.
Net LoC. +227/-41, of which about 106 is the GPU test's drafts case. The trims above save about 15 lines.
Not verified: vLLM's EagleProposer.dummy_run behaviour with use_cudagraphs=True on an unwrapped drafter, and whether engine.py's imports load vLLM's attention op early (vLLM sources weren't available; nothing ran on GPU). A maintainer still needs to review.
Before merge: fill in the human-written summary.
| # TODO: drop with the move to vLLM's V2 model runner (pytorch/torchtitan#5956); V1's | ||
| # GPUModelRunner._dummy_run captures drafter graphs only for piecewise targets | ||
| # ("Eagle currently only supports PIECEWISE cudagraphs"). | ||
| capture = is_graph_capturing and not self.speculative_config.enforce_eager |
There was a problem hiding this comment.
This is still open from the last review. capture forces use_cudagraphs=True for every graph-capturing target, FULL_DECODE_ONLY included, but there the drafter isn't breakable and the comment above doesn't apply. Whether vLLM's EagleProposer.dummy_run then pads or dispatches differently for an unwrapped drafter is unverified. FULL_DECODE_ONLY is the default mode with drafts in the PRs below, and the GPU test here runs only eager and FULL. Tie the forcing to the condition the comment describes, which is also the one capture_model checks:
| capture = is_graph_capturing and not self.speculative_config.enforce_eager | |
| capture = is_graph_capturing and isinstance(self.model, BreakableCUDAGraphWrapper) |
If that change is wrong, please say what vLLM does with use_cudagraphs=True on an unwrapped drafter.
There was a problem hiding this comment.
Reply from claude: Kept: under FULL_DECODE_ONLY the forcing changes nothing, because the drafter has no graphs to replay there. At our pin (vLLM 9f03b510c):
- The drafter's dispatcher gets PIECEWISE keys only if the target's mixed mode is PIECEWISE or FULL. Under FULL_DECODE_ONLY the mixed mode is NONE, so it gets NONE keys (
vllm/v1/spec_decode/llm_base_proposer.py:431-440). dummy_runthen dispatches withvalid_modes=Noneinstead of{NONE}(:1803-1806). With only NONE keys, both give NONE, and the drafter runs eagerly.
…er the checks capture_model's mode check keeps one condition: with drafts, a requested FULL must stay FULL. TorchTitan compiles with CompilationMode.NONE, so vLLM never resolves a mode with piecewise target graphs.
|
Reply from claude: Yes. A |
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 1m 40s —— View job Approve -- see the review on this PR. |
There was a problem hiding this comment.
Verdict: Approve -- every item from the 11-28 review is resolved at a535ef9, and the new commit adds no must-fix problems.
What this PR does. It lifts the ban on cuda_graph.mode="FULL" with MTP drafts. VLLMEngine._setup turns on vLLM's breakable CUDA graphs, which the drafter uses, and raises if vLLM's attention op was imported too early. TorchTitanEagleProposer.dummy_run captures the drafter's piecewise graphs at start-up. capture_model raises if vLLM lowers a requested FULL or the drafter isn't breakable. Verify graphs stay in vLLM's graph-memory estimate.
Example. Qwen3.5 with k = 3, cuda_graph.mode="FULL":
before: Config.__post_init__ raises -> FULL_DECODE_ONLY: steps with prefill and the drafter run eagerly
after: verify-only step -> FULL verify graph; step with prefill -> FULL mixed graph (packed path)
drafter -> breakable piecewise graphs, captured at start-up
vLLM lowers FULL, or the attention op was imported before the env var -> RuntimeError at start-up
Earlier items (11-28 review)
uses_breakable_cuda_graphsinlined: resolved (engine.py:382).- Read-back assertion in
test_generator.py: resolved (deleted). - Env var set mid-validation: resolved (moved to
_setup, after every check). - Mode check as one condition: resolved (
worker.py:163-171). The vLLM citation (compilation.py:1152-1155,:1424-1425) supports it. - Drafter-capture gate: kept. The author's argument holds. Under FULL_DECODE_ONLY the drafter's dispatcher has only NONE keys (
llm_base_proposer.py:431-440), so forcinguse_cudagraphsstill dispatches to NONE. - Real entry point: answered with a
VLLMEnginerun (k = 3, FULL, 8 requests next to verify rows).
Should consider
worker.py:259-262-- the comment rewrite dropped the sentence that says why filtering the profiling keys is safe (inline).
Details
Re-review scope. I re-read the full diff at a535ef9, not just the fix commit: _enable_breakable_cuda_graphs, _setup, capture_model, initialize_kv_cache, dummy_run, the config and engine docstrings, and the drafts case in test_gdn_cudagraph.py. The test subprocess already sets VLLM_USE_BREAKABLE_CUDAGRAPH=1 at start (test_gdn_cudagraph.py:72, unchanged), so the test doesn't run _enable_breakable_cuda_graphs. The author's manual VLLMEngine run covers that path, and if it breaks, capture_model raises at start-up rather than failing silently.
Overlap search. I searched open PRs for "breakable cuda graph" and "worker.py drafter dummy_run". I found #5956 (V2 runner, rebases on this stack), #6364 (below this PR), and the SGLang breakable-graph PRs #6415, #6200 and #6425 (a different engine). None of them rewrites this code.
Not verified: the vLLM line citations in the author's replies (I don't have vLLM's sources here), and nothing ran on a GPU. A maintainer still needs to review.
Before merge: fill in the human-written summary.
| # vLLM's graph-memory estimate, taken out of the KV cache, charges every FULL graph like the second largest | ||
| # (a mixed graph). 1-token decode graphs take far less (Qwen3-8B TP2: 11 added 0.03 GiB to 1.57), so profile | ||
| # only the mixed graphs. Verify graphs (1 + k tokens per row) stay charged: left out, 145 of them put the | ||
| # capture 0.79 GiB over the estimate (Qwen3.8-27B, k = 3, GB300). |
There was a problem hiding this comment.
This rewrite dropped the sentence that says why filtering the keys is safe: "vLLM drops these profiling keys afterwards; the real call rebuilds them, decode keys included (test_generator_dp_cudagraph.py checks a decode graph still replays)." Without it, a reader can't tell whether the real capture loses its decode graphs. Since it isn't related to drafts, consider restoring it after the new verify-graph sentence.
|
Superseded by #6478 |
Summary (human-written)
Agent details
Stack, bottom to top:
The stack lands after the vLLM 0.33 PRs ("[rl] generator: vLLM 0.33 API fixes and TP padding in the model wrapper", "[rl] Install vLLM 0.33.0 on the torch nightly"). "[rl] generator: run on vLLM's model runner V2 (vLLM 0.34)" rebases on it.
TLDR:
cuda_graph.mode="FULL"now works with MTP drafts. Steps that mix prefill rows and verify rows replay one FULL CUDA graph, using the GDN builder's packed path (PR 1). The MTP drafter replays vLLM's breakable piecewise graphs. Below this PR, drafts need FULL_DECODE_ONLY, which runs every step with prefill eagerly. In multi-turn agent loads, every new turn starts with such a step. Earlier runs: +6.3% output tok/s over piecewise graphs for those steps (Qwen3.8-27B, 26 sessions, NOTE).Problem
Solution
VLLMCudaGraphConfig: FULL with drafts is vLLM's FULL.VLLMEngine._setupsetsVLLM_USE_BREAKABLE_CUDAGRAPH=1(_enable_breakable_cuda_graphs), after the config checks and before vLLM registers the model. vLLM makes its attention op a graph break only if the variable is set when it imports the op, so the engine checks the op and raises if it isn't one.TorchTitanEagleProposer.dummy_runcaptures the drafter's graphs at start-up under a FULL target.capture_modelraises instead of replaying wrong state:AttentionCGSupport.ALWAYS);No mode puts GDN inside piecewise target graphs: TorchTitan compiles with
CompilationMode.NONE, so vLLM lowers to FULL_DECODE_ONLY or NONE.Results
You may ask:
TorchTitanGPUWorker.init_deviceraises on V2). "[rl] generator: run on vLLM's model runner V2 (vLLM 0.34)" rebases on this stack.NOTE:
test_gdn_cudagraph.pyruns in CI's RL 1 GPU job (A10G) when the PR has theciflow/rllabel. That job was green at the old head of "[rl] MTP on GDN models: FULL CUDA graphs for steps with prefill" (tagciflow/rl/6403), which had these cases. There they skip only without CUDA or the model path, which the workflow sets, so they most likely ran. Its log was not read. Not run there at this head yet. A TODO at the test says to add it to the B200 RL workflow once the fused-kernel PR lands.Follow up / TODO (each has a
# TODOat its site)_enable_breakable_cuda_graphsonce the vLLM pin reaches v0.33+, which decides graph breaks at call time. Keep the variable until vLLM honors an explicitCompilationConfig.use_breakable_cudagraph.dummy_runoverride with the move to vLLM's V2 model runner.test_gdn_cudagraph.pyin the B200 RL workflow once the fused-kernel PR lands.Test plan