Skip to content

[rl] GDN layer: run steps with drafts from TorchTitan's builder - #6475

Draft
liangel-02 wants to merge 3 commits into
liangel-02/mtp-uniform-verifyfrom
liangel-02/gdn-layer-drafts
Draft

liangel-02 wants to merge 3 commits into
liangel-02/mtp-uniform-verifyfrom
liangel-02/gdn-layer-drafts

Conversation

@liangel-02

Copy link
Copy Markdown
Contributor

Supersedes #6433 (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. this PR
  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: VLLMInnerGDN runs steps with MTP drafts from the GDN builder's metadata (PR 1). Every kernel runs every row, and rows it doesn't own get the null slot, so one graph per token count replays any mix of rows. The layer still refuses drafts in __init__: the MTP PR (4) lifts that refusal when the engine owns speculative_config.

The GDN layer runs verify rows on vLLM's verify GDN kernel, which keeps the state after each draft in its own slot so rejected drafts leave no trace, and one 32-token packed CUDA graph replays 4 row mixes bitwise equal to eager.

VLLMInnerGDN._forward_speculative, by the builder's execution path:
  VERIFY  every row verifies (or is a 1-token row after context): vLLM's verify conv + GDN kernels
  PACKED  any other step: Attention Gym's prefill conv + chunk kernels on every token,
          then vLLM's verify kernels on the first S = (1 + k) x max_num_seqs tokens;
          each token keeps the output of the kernels that own its row

Problem

  1. With k drafts, a verify row reads the state after its last accepted token. It must write one state per draft position, so a rejected draft leaves the accepted state intact.
  2. Attention Gym's GDN kernels keep one state per request, so main's layer refuses drafts.
  3. vLLM has verify kernels that keep one state per draft position (causal_conv1d_update, FLA's fused_sigmoid_gating_delta_rule_update).

Solution

  1. _forward_speculative runs the VERIFY or PACKED kernels above. No tensor size or Python branch depends on the mix of rows. Rows no sequence owns get zeros.
  2. _verify_gdn runs vLLM's verify GDN kernel over every row, from the builder's spec_* fields.
  3. Prefill rows run Attention Gym's paged conv and chunk kernels, as steps without drafts do.
  4. Unchanged: without drafts, _forward runs main's code. __init__ keeps main's refusal of speculative decoding.

Results

Numerics: verify rows run vLLM's GDN kernels; MTP off and the trainer run Attention Gym's.
GPU, one GB300, test_gdn_graph_metadata.py: 38 passed (27 from PR 1 + 11 here). Qwen3.5 GDN layer shapes, k = 3,
random weights:
  test_verify_rows_match_single_token_decodes        j = 1, 2, 4 accepted: outputs and kept states match j
                                                     single-token decodes without drafts
  test_speculative_step_matches_step_without_drafts  6 row mixes (decode, verify, prefill, trimmed drafts,
                                                     prefill with context): each row's output, SSM and conv
                                                     states match the same request in a step without drafts
  test_draft_steps_replay_one_packed_graph           one packed graph, 4 row mixes: bitwise vs eager
                                                     (output, conv state, SSM state)
  test_draft_verify_graph_follows_the_dummy_key      the uniform verify graph: bitwise vs eager; padding rows zero

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.

Follow up / TODO (the # TODO is in _verify_gdn)

  • Try vLLM's fused CUDA verify op, which also applies the gated norm: 3.27 ms per Qwen3.8-27B verify step in stock vLLM, vs 4.0 ms for this Triton kernel alone (GB300). Untested with this layer's layouts.

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         776 passed, 0 failed, 8 skipped on the pinned vLLM (9f03b510c), main merged in (PR 2: the same).
GPU                  test_gdn_graph_metadata.py: 38 passed
                     test_gdn_cudagraph.py: 4 passed (398 s), with "[models] GDN/KDA chunk kernels: always fused"
                     applied (GDN prefill on the fused kernels, which CI's A10G also takes)
pre-commit           all hooks pass (pyrefly and lychee skipped)

VLLMInnerGDN runs the builder's draft metadata: VERIFY steps on vLLM's verify kernels,
PACKED steps with verify rows first and prefill rows after, both inside FULL graphs.
The layer still refuses speculative decoding at construction; the MTP PR lifts that
refusal when the engine owns speculative_config. GPU tests compare verify rows with
single-token decodes and a step with drafts with one without, eager and replayed.
@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