Skip to content

[rl] MTP: replay the verify CUDA graph only when every row verifies - #6474

Draft
liangel-02 wants to merge 2 commits into
liangel-02/gdn-builder-draftsfrom
liangel-02/mtp-uniform-verify
Draft

liangel-02 wants to merge 2 commits into
liangel-02/gdn-builder-draftsfrom
liangel-02/mtp-uniform-verify

Conversation

@liangel-02

Copy link
Copy Markdown
Contributor

Supersedes #6402 (originally by felipemello1).

Summary (human-written)

Agent details

Stack, bottom to top:

  1. "[rl] GDN builder: stage steps with drafts in fixed buffers"
  2. this PR
  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. "[rl] MTP on GDN models: FULL CUDA graphs for steps with prefill"
  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: With MTP drafts, vLLM replays the uniform "verify" CUDA graph for any step whose rows all have 1 + k tokens. A prefill row of exactly 1 + k tokens passes that test. The verify graph runs only GDN's verify kernels, so the GDN builder (PR 1) raises on such a step. Now the runner calls a step uniform only when every row verifies k drafts.

Before this PR, a step with 3 verify rows and one 4-token prefill row replayed the verify graph and made the GDN builder raise, and this PR checks each row's draft count so that step replays the mixed graph (FULL) or runs eagerly (FULL_DECODE_ONLY).

# vLLM's test (GPUModelRunner._is_uniform_decode): shapes only
uniform = max_query_len == 1 + k and num_tokens == (1 + k) * num_reqs
# this PR (TorchTitanGPUModelRunner._determine_batch_execution_and_padding): every row verifies k drafts
force_uniform_decode = bool((self.num_decode_draft_tokens.np[:num_reqs] == k).all())

Problem

  1. With k drafts, each decode step verifies 1 + k tokens per row. FULL and FULL_DECODE_ONLY replay a FULL "uniform" graph for these steps.
  2. vLLM picks that graph by shape only: every row has 1 + k tokens. A step with a prefill row of exactly 1 + k tokens passes.
  3. The uniform graph runs only GDN's verify kernels. The GDN builder (PR 1) raises "A uniform verify graph met row ..." on such a step, so the engine stops. vLLM's own GDN builder instead replays stale slots and can overwrite another request's state, silently.
  4. How often real runs hit it was not measured: every row of a step must have exactly 1 + k tokens.

Solution

  1. _determine_batch_execution_and_padding passes vLLM's force_uniform_decode: True only when every row has k drafts. vLLM uses it in place of its shape test.
  2. _prepare_inputs resets num_decode_draft_tokens to -1 on steps without drafts. vLLM writes it only on steps with drafts, so it would keep the last step's counts.
  3. Unchanged: steps where every row verifies still replay the verify graph. Without drafts (k = 0), nothing changes. Dummy runs and capture still pass their own force_uniform_decode.

Results

New CPU test, k = 3, 4 rows of 4 tokens, vLLM graph mode FULL / FULL_DECODE_ONLY:
                                                        FULL                FULL_DECODE_ONLY
draft counts [3, 3, 3, 3]                               FULL, uniform       FULL, uniform
draft counts [3, 3, 3, -1] (a 4-token prefill row)      FULL, mixed graph   NONE (eager)
a step without drafts, after an all-verify step         FULL, mixed graph   NONE (eager)

You may ask: why not fix vLLM? vLLM's V2 model runner already keeps steps with a prefill row off decode graphs (decode_graph_eligible). TorchTitan runs the V1 runner, and vLLM main deleted it, so a fix there would not land. The TODO at the override says to drop it with the move to V2.

NOTE:

  • The test checks the graph choice. The GDN builder's raise (PR 1's test_draft_builder_rejects_rows_it_cannot_stage) covers what the wrong choice would hit.
  • No consumer in the tree until the MTP PR (4).

Test plan

pytest tests/rl/unit_tests/cpu
pytest tests/rl/unit_tests/cpu/test_generator.py::test_runner_replays_the_verify_graph_only_when_every_row_verifies
pytest tests/rl/unit_tests/gpu/test_gdn_graph_metadata.py   # 1 GPU (GB300)
pre-commit run --files <changed files>
RL CPU suite   776 passed, 0 failed, 8 skipped on the pinned vLLM (9f03b510c), main merged in (PR 1: 774 passed).
GPU            test_gdn_graph_metadata.py: 27 passed
pre-commit     all hooks pass (pyrefly and lychee skipped)

…y row verifies

vLLM calls a step uniform when every row has 1 + k tokens, so a 1 + k token prefill row
could replay the uniform verify graph, which runs only GDN's verify kernels. The runner
now asks for the uniform graph only when every row verifies k drafts, and resets vLLM's
draft counts on steps without drafts.
@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