Skip to content

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

Closed
felipemello1 wants to merge 2 commits into
felipemello1/gdn-builder-draftsfrom
felipemello1/mtp-uniform-verify
Closed

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

Conversation

@felipemello1

@felipemello1 felipemello1 commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

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)

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 26, 2026
@felipemello1
felipemello1 added this pull request to stack #6404 November 26, 2026 02:13
@felipemello1

Copy link
Copy Markdown
Contributor Author

@claude please review

@claude

claude Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 3m 2s —— View job


Approve -- please address the two small items before merging: fill in the human-written summary, and link #5956 in the TODO. Review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- please address the items below before merging. The fix sits in the right place: the runner's uniform-decode decision, through vLLM's own force_uniform_decode argument. It is small, and it costs nothing on steps where every row verifies.

What this PR does. With MTP drafts (k > 0), the V1 runner treats a step as uniform only when every row has exactly k decode drafts. Before, vLLM checked only the shapes (every row has 1 + k tokens). A prefill row of exactly 1 + k tokens passed that check and replayed the verify FULL graph, and that graph's GDN buffers still held the previous all-verify step's slots. vLLM writes num_decode_draft_tokens only on steps with drafts, so _prepare_inputs now resets it to -1 on steps without drafts. Otherwise the new check would read the previous step's counts.

Example. k = 3, 4 rows of 4 tokens, cuda_graph.mode FULL (FULL_AND_PIECEWISE with drafts):

draft counts           before                      after
[3, 3, 3, 3]           FULL verify graph           FULL verify graph (unchanged)
[3, 3, 3, -1]          FULL verify graph, GDN      PIECEWISE (FULL_DECODE_ONLY: eager)
                       reads stale slots
no drafts, after a     FULL verify graph (shape    PIECEWISE (the reset keeps the
verify step            passes)                     stale [3,3,3,3] from forcing uniform)

Must fix

  1. The PR description's "Summary (human-written)" section is empty. A human author has to fill it in; the agent text below it doesn't count.
  2. torchtitan/rl/generator/vllm/worker.py:232 -- the TODO has no link to the V2-runner migration (#5956). See the inline comment.
Details
  • Gate: the problem exists on the base branch (the new test fails there for both modes, per the description). It comes from vLLM V1's shape-only _is_uniform_decode. A fix in vLLM won't land, because V1 was removed and V2 already has decode_graph_eligible. A local override with a TODO is the right call.
  • Equivalence: when every row has k drafts, every row has 1 + k tokens, so forcing uniform never sends a step to the verify graph unless the shape check would also pass. Rows with fewer than k drafts (truncated by the token budget or near max_model_len) already failed the shape check, so nothing changes for them.
  • Dummy runs, capture, and an idle DP rank's dummy batch pass force_uniform_decode explicitly, so the is None guard leaves them alone. With DP, a non-uniform local decision only makes the cross-rank mode choice more conservative.
  • No host-device sync: the check is a NumPy comparison over num_reqs CPU ints.
  • k = 0 is unchanged: both branches are gated on uniform_decode_query_len > 1.
  • The new CPU test replaces GPUModelRunner._prepare_inputs with a stub that copies vLLM's write-only-with-drafts behavior. So the third assertion checks the override against that stub, not against vLLM. The vLLM _determine_batch_execution_and_padding and the dispatcher it runs are real, and it guards a silent state corruption, so it's worth its CI cost.

Not verified: whether vLLM's _build_attention_metadata passes num_decode_draft_tokens.cpu to GDNAttentionMetadataBuilder on steps without drafts. I couldn't read the installed vLLM source. If it does, the reset also changes what that builder sees on those steps: -1 instead of the previous step's counts. Worth one sentence in the description either way. No GPU tests were run. A maintainer still needs to review.

Comment thread torchtitan/rl/generator/vllm/worker.py Resolved
…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.
@felipemello1
felipemello1 removed this pull request from stack #6404 November 28, 2026 17:44
@felipemello1
felipemello1 changed the base branch from felipemello1/mtp-verify-steps to felipemello1/gdn-builder-drafts November 28, 2026 17:45
@felipemello1
felipemello1 force-pushed the felipemello1/mtp-uniform-verify branch from a286060 to 9f5c44c Compare November 28, 2026 17:45
@felipemello1
felipemello1 added this pull request to stack #6434 November 28, 2026 17:50
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude please review

@claude

claude Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 2m 11s —— View job


Approve: the earlier must-fix item (a link in the TODO) is resolved, and I found nothing new. Review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- the fix uses vLLM's own force_uniform_decode input to the runner's uniform-decode decision, and it adds no cost on steps where every row verifies. The earlier must-fix item (no link in the TODO) is fixed at HEAD.

What this PR does. With k > 0 drafts, a real step counts as uniform only when every row has exactly k decode drafts. Before, vLLM only checked shapes: every row has 1 + k tokens. _prepare_inputs now resets num_decode_draft_tokens to -1 on steps without drafts. vLLM writes that buffer only on steps with drafts, so without the reset, both the new check and the GDN builder would read the previous step's counts.

Example. k = 3, 4 rows of 4 tokens, FULL mode:

draft counts                     before                           after
[3, 3, 3, 3]                     uniform verify graph             uniform verify graph (unchanged)
[3, 3, 3, -1] (4-token prefill)  uniform graph -> builder raises  mixed FULL graph (FULL_DECODE_ONLY: eager)
no drafts, after a verify step   uniform graph (shapes pass)      mixed FULL graph

Earlier items:

  • Link in the TODO (worker.py:244-246): resolved, it now points to #5956 and names the _prepare_inputs reset.
Details
  • Gate: the bug comes from V1's shape-only uniform test, and vLLM main removed V1. V2 already handles this case with decode_graph_eligible. So a local override with a TODO pointing at the V2 migration (#5956) is the right layer. Overlap search ("force_uniform_decode", "worker.py uniform verify") found only stack siblings (#6364, #6403) and #5956, which rebases on this PR.
  • Equivalence: when every row has k drafts, every row has 1 + k tokens. So forcing uniform never picks the verify graph unless the shape test would also pass. Rows that the token budget truncates to fewer than k drafts already failed the shape test, so their path doesn't change.
  • _dummy_run (capture, warm-up, idle DP rank) passes force_uniform_decode itself, so the is None guard leaves it alone. dummy_run_uniform is read before the override, so builders still tell dummy runs apart from real steps.
  • The reset also fixes the builder's inputs. _build_with_drafts (linear_attention.py:331-366) classifies rows by num_decode_draft_tokens_cpu. If vLLM passed the stale buffer on a step without drafts, rows would be wrongly routed to the verify kernels, or the "drafts but no context" check would raise. After the reset it sees -1, the same as the None fallback.
  • No host-device sync: the check is a NumPy comparison over num_reqs CPU ints. k = 0 behaves as before, because both hunks are gated on uniform_decode_query_len > 1.
  • Tests: the new CPU test runs the real vLLM _determine_batch_execution_and_padding and dispatcher. It stubs only GPUModelRunner._prepare_inputs. The one-line uniform_decode_query_len = 1 additions in the two other tests are mechanical.

Not verified: I couldn't read the installed vLLM source here. These two claims are unchecked: that vLLM V1's _prepare_inputs writes num_decode_draft_tokens only on steps with drafts (the test stub copies this), and that it writes -1 past num_reqs. No GPU tests were run. A maintainer still needs to review.

Before merge: fill in the human-written summary.

@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude please review

@claude

claude Bot commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 1m 12s —— View job


Approve: nothing in the PR changed since my last review apart from the base-branch merge, and I found nothing new. Review

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verdict: Approve -- the PR's own code hasn't changed since my last review (11-28); the only new commit merges the base branch, and that merge leaves this PR's hunks the same.

What this PR does. With k > 0 drafts, a real step counts as uniform only when every row verifies exactly k drafts. vLLM V1's test only checks shapes: every row has 1 + k tokens. On steps without drafts, _prepare_inputs resets num_decode_draft_tokens to -1, so neither the new check nor the GDN builder reads the previous step's counts.

Example. k = 3, 4 rows of 4 tokens, FULL mode:

draft counts                     before                           after
[3, 3, 3, 3]                     uniform verify graph             uniform verify graph (unchanged)
[3, 3, 3, -1] (4-token prefill)  uniform graph -> builder raises  mixed FULL graph (FULL_DECODE_ONLY: eager)
no drafts, after a verify step   uniform graph (shapes pass)      mixed FULL graph

Earlier items: all resolved. The TODO at worker.py:267-269 links #5956 and names the _prepare_inputs reset.

Details
  • New since the last full review: 7f16db1, a merge of felipemello1/gdn-builder-drafts. I compared the PR diff before and after it. It is the same except for hunk offsets and the SchedulerOutput import, which the base now provides (worker.py:15). The base commit 869745f changes only the builder's TODO wording.
  • The gate and correctness analysis from the 11-28 review still holds. The bug comes from V1's shape-only uniform test, and V2's decode_graph_eligible handles this case, so a local override with a TODO pointing at #5956 is the right layer. Rows with k drafts always have 1 + k tokens, so the override never makes a step uniform when the shape test would fail. _dummy_run passes force_uniform_decode itself, so the is None guard leaves it alone. The check is a NumPy comparison on the host, with no device sync. k = 0 is unchanged, because both hunks are gated on uniform_decode_query_len > 1.
  • Overlap search ("force_uniform_decode", "uniform verify graph"): only stack siblings (#6432, #6433, #6364, #6403, #6365) and #5956, which rebases on this PR.

Not verified: I couldn't read the installed vLLM V1 _prepare_inputs, so I can't confirm it writes num_decode_draft_tokens only on steps with drafts (the test stub assumes it does). No GPU tests were run. A maintainer still needs to review.

Before merge: fill in the human-written summary.

@liangel-02

Copy link
Copy Markdown
Contributor

Superseded by #6474

@liangel-02 liangel-02 closed this Dec 1, 2026
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