Skip to content

[rl] GDN builder: stage steps with drafts in fixed buffers - #6473

Draft
liangel-02 wants to merge 3 commits into
mainfrom
liangel-02/gdn-builder-drafts
Draft

liangel-02 wants to merge 3 commits into
mainfrom
liangel-02/gdn-builder-drafts

Conversation

@liangel-02

Copy link
Copy Markdown
Contributor

Supersedes #6432 (originally by felipemello1).

Summary (human-written)

Agent details

Stack, bottom to top:

  1. this PR
  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. "[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: TorchTitan's GDN metadata builder can now stage steps that carry MTP draft tokens. It writes them into fixed buffers, so FULL CUDA graphs can replay any mix of rows. No caller sets drafts yet: the GDN layer PR (3) runs these rows, and the MTP PR (4) turns drafts on. Steps without drafts run main's code.

TorchTitan's GDN builder stages a step with k = 3 MTP drafts in fixed 6-row buffers, where the verify kernels see the first 20 of 24 tokens and each kernel gets the null slot on rows it doesn't own, while vLLM's GDN builder sizes new tensors by the mix of rows.

k = 3 drafts, rows [verify 4, verify 4, 1-token resume, prefill 13], 24 padded tokens, at most 5 requests.
GDN's verify kernels see the first S = min(24, (1 + 3) x 5) = 20 tokens:
  query_start_loc          [0, 4, 8, 9, 22, 24, 24]   row 4: padding (null slot)
  spec_query_start_loc     [0, 4, 8, 9, 20, 20, 20]   the verify rows, clamped at S
  prefill_query_start_loc  [0, 9, 9, 9, 22, 24, 24]   rows 0-2 merged into one null interval
  VERIFY  uniform graph, uniform dummy run, or an eager step with no prefill row
  PACKED  any other step: prefill kernels on every token, verify kernels on the first S

Problem

  1. With k MTP drafts, each decode step verifies 1 + k tokens per request ("verify rows"). A step can also hold 1-token rows and prefill rows.
  2. TorchTitan's GDN builder knows only steps without drafts.
  3. vLLM's own GDN builder writes graph-safe buffers only when every row verifies. For any other step, it builds new tensors whose sizes depend on the mix of rows.
  4. So FULL CUDA graphs can't cover a step with drafts and a prefill row. In multi-turn agent loads, every new turn starts with a prefill row.

Solution

  1. TorchTitanLinearAttentionMetadataBuilder subclasses vLLM's GDNAttentionMetadataBuilder. vLLM's V1 runner passes draft and accepted counts only to known builder classes (GPUModelRunner._build_attention_metadata).
  2. _build_with_drafts stages each step with drafts in buffers sized for the largest step. A kernel gets the null slot (0) on rows it doesn't own, so no tensor size depends on the mix. update_block_table reuses one GDN group's metadata for the next, drafts included.
  3. Rows with context and at most 1 + k tokens lead every batch (batch-reorder threshold 1 + k), so the verify kernels read a fixed token prefix. FA4's builder asks for the same threshold. TorchTitanGPUModelRunner.calculate_reorder_batch_threshold raises if they disagree.
  4. The runner tells the builders which FULL graph a step replays (packed or uniform verify). It also says whether a dummy run stages a uniform batch: null slots, accepted counts of 1.
  5. Accepted counts come from the runner's num_accepted_tokens buffer, which vLLM refreshes on every step. vLLM passes them to builders only on steps with drafts.
  6. The builder raises instead of staging wrong state:
    • a row with drafts but no context (a 1-token prompt that vLLM padded with placeholder drafts);
    • a uniform verify graph that meets another row;
    • a verify row that ends past the S tokens.
  7. The MTP PR (4) adds the engine checks this builder relies on: VLLMEngine.add_requests rejects prompts under 2 tokens with drafts (this builder's raise is the backstop), and drafts at generator DP > 1 raise at engine start.
  8. Unchanged: without drafts, build runs main's code. __init__ now starts with vLLM's GDN builder __init__ (the new parent) in every GDN and KDA engine: 8 small buffers (the largest holds up to max_num_seqs * (1 + k) rows of 1 + k int32 slots) and a GDN prefill-backend lookup that reads hf_text_config.

Results

GPU, one GB300, test_gdn_graph_metadata.py: 27 passed (22 s).
  test_update_block_table_matches_build_with_drafts   "align" and "none", packed and verify: every field equal
                                                       to a fresh build, in the captured buffers
  test_runner_tells_builders_the_selected_graph        per graph mode and key: only GDN/KDA builders get the
                                                       packed and uniform flags
  test_draft_builder_rejects_rows_it_cannot_stage      the 3 raises above

You may ask: why a subclass of vLLM's builder? vLLM's V1 runner hands draft counts only to known builder classes. The TODO at the class says to drop it once vLLM passes the counts to any builder that asks. vLLM's V2 runner gates them by class too.

NOTE:

  • No consumer in the tree until the MTP PR (4). The stack lands together.
  • test_gdn_graph_metadata.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. The new test_draft_builder_rejects_rows_it_cannot_stage only regroups three raises those cases already checked.

Test plan

# RL CPU suite
pytest tests/rl/unit_tests/cpu
# 1 GPU (GB300)
pytest tests/rl/unit_tests/gpu/test_gdn_graph_metadata.py
pre-commit run --files <changed files>
RL CPU suite   774 passed, 0 failed, 8 skipped on the pinned vLLM (9f03b510c), main merged in (main: 774 passed).
GPU            test_gdn_graph_metadata.py: 27 passed
               TestBitwiseParityKimiK3DebugVarlen at the stack top: 4 passed (KDA layers on this builder, one GB300)
pre-commit     all hooks pass (pyrefly and lychee skipped)

TorchTitanLinearAttentionMetadataBuilder builds GDN metadata for steps with MTP drafts:
verify rows (1 + k tokens with context) go to GDN's verify kernels, the rest to the
prefill kernels, in fixed buffers that FULL graphs can replay.

- Rows of at most 1 + k tokens lead every batch (reorder threshold 1 + k); the runner
  checks it in calculate_reorder_batch_threshold.
- The runner tells the builders which graph a step replays (packed or uniform) and
  whether a dummy run stages a uniform batch (null slots, accepted counts of 1).
- Accepted counts come from the runner's buffer, which vLLM refreshes on every step.
- Rows with drafts but no context raise; so does a uniform graph that meets another row.

No caller sets drafts yet: the GDN layer runs these rows in the next PR, and MTP turns
them on after it.

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