Repository navigation
[rl] MTP: replay the verify CUDA graph only when every row verifies - #6402
felipemello1 wants to merge 2 commits into
Conversation
|
@claude please review |
|
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 |
There was a problem hiding this comment.
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
- 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.
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 hasdecode_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_decodeexplicitly, so theis Noneguard 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_reqsCPU ints. - k = 0 is unchanged: both branches are gated on
uniform_decode_query_len > 1. - The new CPU test replaces
GPUModelRunner._prepare_inputswith 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_paddingand 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.
…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.
a286060 to
9f5c44c
Compare
|
Reply from claude: @claude please review |
|
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 |
There was a problem hiding this comment.
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_inputsreset.
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) passesforce_uniform_decodeitself, so theis Noneguard leaves it alone.dummy_run_uniformis 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 bynum_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 theNonefallback. - No host-device sync: the check is a NumPy comparison over
num_reqsCPU ints. k = 0 behaves as before, because both hunks are gated onuniform_decode_query_len > 1. - Tests: the new CPU test runs the real vLLM
_determine_batch_execution_and_paddingand dispatcher. It stubs onlyGPUModelRunner._prepare_inputs. The one-lineuniform_decode_query_len = 1additions 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.
|
Reply from claude: @claude please review |
|
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 |
There was a problem hiding this comment.
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 offelipemello1/gdn-builder-drafts. I compared the PR diff before and after it. It is the same except for hunk offsets and theSchedulerOutputimport, which the base now provides (worker.py:15). The base commit869745fchanges 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_eligiblehandles 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_runpassesforce_uniform_decodeitself, so theis Noneguard 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 onuniform_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.
|
Superseded by #6474 |
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: 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.
Problem
kdrafts, each decode step verifies 1 + k tokens per row. FULL and FULL_DECODE_ONLY replay a FULL "uniform" graph for these steps.Solution
_determine_batch_execution_and_paddingpasses vLLM'sforce_uniform_decode: True only when every row has k drafts. vLLM uses it in place of its shape test._prepare_inputsresetsnum_decode_draft_tokensto -1 on steps without drafts. vLLM writes it only on steps with drafts, so it would keep the last step's counts.force_uniform_decode.Results
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:
test_draft_builder_rejects_rows_it_cannot_stage) covers what the wrong choice would hit.Test plan