Skip to content

[rl] MTP on GDN models: FULL CUDA graphs for steps with prefill - #6478

Draft
liangel-02 wants to merge 3 commits into
liangel-02/mtp-verify-stepsfrom
liangel-02/mtp-full-graphs-prefill
Draft

liangel-02 wants to merge 3 commits into
liangel-02/mtp-verify-stepsfrom
liangel-02/mtp-full-graphs-prefill

Conversation

@liangel-02

Copy link
Copy Markdown
Contributor

Supersedes #6403 (originally by felipemello1).

Summary (human-written)

Agent details

Stack, bottom to top:

  1. "[rl] GDN builder: stage steps with drafts in fixed buffers"
  2. "[rl] MTP: replay the verify CUDA graph only when every row verifies"
  3. "[rl] GDN layer: run steps with drafts from TorchTitan's builder"
  4. "[rl] MTP speculative decoding in the vLLM generator"
  5. "[rl] MTP verify steps: run verify rows on FA4's decode kernel"
  6. this PR
  7. "[rl] vLLM generator: fp8 KV cache through FA4's fp8 forward, MTP verify steps included"

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).

Before this PR, drafts needed FULL_DECODE_ONLY, so steps with prefill and the MTP drafter ran eagerly, and this PR replays one FULL mixed graph for those steps and vLLM's breakable piecewise graphs for the drafter (earlier runs: 1,387 vs 1,305 output tok/s against piecewise graphs for steps with prefill, +6.3%, Qwen3.8-27B, 26 sessions, one GB300).

k = 3 drafts:              FULL_DECODE_ONLY (below this PR)   FULL (this PR)
every row verifies         FULL verify graph                  FULL verify graph
step with prefill          eager                              FULL mixed graph (GDN packed path)
MTP drafter                eager                              piecewise graphs, attention eager

Problem

  1. With drafts, a step can hold verify rows (1 + k tokens), 1-token rows and prefill rows.
  2. The MTP PR (4) refuses FULL with drafts, so drafts run FULL_DECODE_ONLY: steps with prefill run eagerly.
  3. vLLM's V1 runner captures drafter graphs only while the target captures piecewise graphs. Under a FULL target, the drafter runs eagerly.
  4. vLLM's graph-memory estimate charges FULL graphs like a mixed graph. Main keeps decode graphs out of the estimate, since they are small. With drafts, decode graphs are verify graphs (1 + k tokens per row), and they are not small.

Solution

  1. VLLMCudaGraphConfig: FULL with drafts is vLLM's FULL.
  2. For FULL with drafts, VLLMEngine._setup sets VLLM_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.
  3. TorchTitanEagleProposer.dummy_run captures the drafter's graphs at start-up under a FULL target.
  4. capture_model raises instead of replaying wrong state:
    • a requested FULL that vLLM lowered (it does when an attention backend lacks AttentionCGSupport.ALWAYS);
    • a drafter that is not breakable.
      No mode puts GDN inside piecewise target graphs: TorchTitan compiles with CompilationMode.NONE, so vLLM lowers to FULL_DECODE_ONLY or NONE.
  5. The verify graphs stay in vLLM's graph-memory estimate. Left out, 145 of them put the capture 0.79 GiB over the estimate (Qwen3.8-27B, k = 3, GB300).
  6. The MTP PR's refusal of FULL with drafts goes.
  7. Unchanged: runs without drafts. With drafts, FULL_DECODE_ONLY and NONE.

Results

Numerics: FULL graphs replay bitwise vs eager (engine test with M-invariant GEMMs).

test_gdn_cudagraph.py::test_gdn_full_runner_matches_eager[drafts], Qwen3.5-0.8B, k = 3, one GB300: passed
  FULL vs eager: token ids, logprobs and GDN states bitwise equal
  FULL replays every step kind: prefill, mixed and verify; a mixed step takes the packed graph
  a verify-graph replay where a row accepted 2+ tokens (it reads its state past slot 0)
  every drafter graph captured at start-up (none captured while serving)
Earlier runs: Qwen3.8-27B, fp8 KV cache, k = 3, one GB300, cuda_graph FULL, one run per arm, output tok/s.
"MTP-3 piecewise" is an earlier version of the stack, where steps with prefill replayed piecewise graphs:
load                            no MTP    MTP-3 piecewise    MTP-3 FULL (this PR)
26 multi-turn sessions          1,028     1,305              1,387 (+6.3%)
128 sessions, KV cache full     1,766     1,397              1,458 (+4.4%)
start-up graph capture, 26 sessions:   55 s, 3.99 GiB  ->  75 s, 5.26 GiB
  • Acceptance length is equal across the MTP arms (2.40 vs 2.40, 2.19 vs 2.18), so the gain is per step.
  • No run compares FULL with FULL_DECODE_ONLY, what the PRs below run, on one base. Two earlier runs, 26 sessions: FULL_DECODE_ONLY 1,008 -> piecewise 1,106 tok/s (bf16 KV), and piecewise 1,305 -> FULL 1,387 (fp8 KV, the table).

You may ask:

  • Why not vLLM's FULL_AND_PIECEWISE for steps with prefill? GDN and attention would run eagerly between the pieces, and vLLM would also capture about 155 piecewise target graphs (estimated). FULL beat it by 6.3% above.
  • Why not vLLM's V2 model runner, which graphs mixed steps? TorchTitan runs the V1 runner (TorchTitanGPUWorker.init_device raises on V2). "[rl] generator: run on vLLM's model runner V2 (vLLM 0.34)" rebases on this stack.

NOTE:

  • The throughput numbers ran an earlier version of this stack's FULL path with an fp8 KV cache, on a base that also carried other unmerged PRs; both arms shared it. Not re-measured on this stack; bf16 KV not measured.
  • The GPU run above applies "[models] GDN/KDA chunk kernels: always fused" (open), so GDN prefill runs the fused kernels. On GB300, the default warpdrive kernel fails to build with cutlass DSL 4.7.1. Warpdrive runs only on SM100/SM103, so CI's A10G takes the fused kernels anyway.
  • test_gdn_cudagraph.py runs in CI's RL 1 GPU job (A10G) when the PR has the ciflow/rl label. That job was green at the old head of "[rl] MTP on GDN models: FULL CUDA graphs for steps with prefill" (tag ciflow/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 # TODO at its site)

  • Drop the import check in _enable_breakable_cuda_graphs once the vLLM pin reaches v0.33+, which decides graph breaks at call time. Keep the variable until vLLM honors an explicit CompilationConfig.use_breakable_cudagraph.
  • Drop the dummy_run override with the move to vLLM's V2 model runner.
  • List test_gdn_cudagraph.py in the B200 RL workflow once the fused-kernel PR lands.

Test plan

pytest tests/rl/unit_tests/cpu
pytest tests/rl/unit_tests/gpu/test_gdn_graph_metadata.py tests/rl/unit_tests/gpu/test_gdn_cudagraph.py   # 1 GPU (GB300)
pre-commit run --files <changed files>
RL CPU suite   788 passed, 0 failed, 8 skipped on the pinned vLLM (1.0.0.dev20261107; PR 5: the same), main merged in.
GPU            at the stack top (PR 7 on this PR): test_gdn_graph_metadata.py 38 passed (31 s);
               test_gdn_cudagraph.py (with the fused-kernel PR) 5 passed (497 s)
               VLLMEngine through its entry point (Qwen3.5-0.8B, k = 3, FULL, fp8 KV, one GB300): starts with
               breakable graphs on and FULL kept; 8 requests, 4 arriving next to verify rows, all finish
pre-commit     all hooks pass (pyrefly and lychee skipped)

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.
…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.
@pytorch-bot pytorch-bot Bot added the ciflow/rl label Dec 1, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Dec 1, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/rl CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants