Repository navigation
[rl] GDN layer: run steps with drafts from TorchTitan's builder - #6433
felipemello1 wants to merge 3 commits into
Conversation
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.
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 5m 5s —— View job Verdict: Approve, with two optional cleanups. See the review |
There was a problem hiding this comment.
Verdict: Approve -- the layer uses vLLM's own GDN verify kernels on the builder's fixed buffers from #6432. Without drafts the path is unchanged, and I found no correctness problem. The remaining items are optional cleanups.
What this PR does. With num_speculative_tokens > 0, VLLMInnerGDN._forward sends each step to _forward_speculative.
- VERIFY runs vLLM's
causal_conv1d_updateand FLA'sfused_sigmoid_gating_delta_rule_updateon every row. A verify row reads the state its last step accepted and writes one state per draft position. - PACKED first runs Attention Gym's paged conv and chunk kernels on every token. It then runs the verify kernels on the first S tokens and uses
spec_token_maskto keep, for each token, the output of the kernel that owns its row.
__init__ still refuses drafts, so nothing in the tree reaches this code until #6287 removes that check.
Example. k = 3, max_num_seqs = 4 (so S <= 16). The step has rows [verify: 4 tokens, context 40, its last step accepted 2; prefill: 13 tokens].
before __init__ raises; _forward asserted spec_sequence_masks is None
after PACKED, 17 tokens, S = 16
prefill conv + chunk kernels on all 17 tokens; the verify row's interval has the
null slot, so tokens 0-3 get zeros
verify conv + GDN on tokens 0-15: row 0 reads conv rows 1-3 and the SSM state in
its 2nd slot, then writes 4 SSM states to its slots 1-4; the prefill tokens
4-15 have the null slot
output tokens 0-3 come from the verify kernels, tokens 4-16 from the chunk kernel
Should consider
torchtitan/rl/generator/vllm/attention/gdn.py:398-412: the VERIFY and PACKED branches repeat the samecausal_conv1d_updatecall. One sequence can cover both (inline).torchtitan/rl/generator/vllm/attention/gdn.py:68-69(and lines 10-11): the class and module docstrings now say verify rows run vLLM's kernels. But__init__(lines 92-95) still raises "does not support speculative decoding", and its comment gives a reason that is no longer true: "Attention Gym currently mutates one slot". Until #6287 lands, change that comment to say the check stays only until the engine wiring lands, e.g.# TODO: lifted by #6287.
Details
- Gate: this enables MTP on GDN models. #6287 is the consumer and carries the numbers: 1.66-2.14x decode, and trainer-vs-generator k3 2.61e-4 with MTP-3 vs 2.65e-4 with MTP off. It also rejects
debug.batch_invarianttogether with drafts, which this layer's speculative path doesn't honor. The layer reuses the kernels vLLM's native GDN runs instead of adding new ones. The SGLang counterpart (#6414) does the same with SGLang's verify kernels. - Overlap search:
gh pr list --search "MTP speculative"found only this stack (#6432, #6402, #6287, #6364, #6403, #6365, #6366) and the SGLang stack (#6414). None of them rewrites this function. - In-place conv in VERIFY:
mixed_qkvis not read afterinner_attention(models/common/attention/gdn.py:675-698), so writing over it is safe in eager mode. - Tests: each new GPU case guards something the others don't cover: rejected drafts (j < 4), row mixes against a step without drafts, packed-graph replay, and the uniform graph with zeroed padding. They are small (16 heads x 128).
Not verified: vLLM's source isn't available here. Two contracts rest on the author's GB300 run (38 passed): causal_conv1d_update and the FLA verify kernel skip rows whose slot is the null slot 0, and causal_conv1d_update accepts out=. CI has not run at this head.
Before merge: fill in the human-written summary.
| num_verify_tokens = spec_token_mask.shape[0] | ||
| # Writes only the verify rows' tokens, where the prefill conv wrote zeros. | ||
| causal_conv1d_update( | ||
| mixed_qkv[:num_verify_tokens], | ||
| conv_state, | ||
| conv_weight, | ||
| None, | ||
| "silu", | ||
| conv_state_indices=spec_slots[:, 0], | ||
| num_accepted_tokens=metadata.num_accepted_tokens, | ||
| query_start_loc=metadata.spec_query_start_loc, | ||
| max_query_len=spec_slots.shape[1], | ||
| validate_data=False, | ||
| out=conv_output[:num_verify_tokens], | ||
| ) |
There was a problem hiding this comment.
Should consider: this causal_conv1d_update call is the VERIFY branch's call (lines 373-384) again, with the same 9 arguments plus out=. The two branches differ only in what fills conv_output and output before the verify kernels run. In VERIFY, num_verify_tokens == num_tokens (the builder picks VERIFY only when num_tokens <= max_verify_tokens), so one sequence covers both:
num_verify_tokens = spec_token_mask.shape[0]
if metadata.execution_path is LinearAttentionExecutionPath.VERIFY:
conv_output = mixed_qkv # the conv update writes over its input
else:
conv_output = paged_causal_conv1d(...).squeeze(0)
causal_conv1d_update(mixed_qkv[:num_verify_tokens], ..., out=conv_output[:num_verify_tokens])
output = (
conv_output.new_zeros(num_tokens, self.local_num_v_heads, self.head_v_dim)
if metadata.execution_path is LinearAttentionExecutionPath.VERIFY
else self._forward_gdn(conv_output, a, b, ...)
)
verify_output = self._verify_gdn(conv_output[:num_verify_tokens], ...)
output[:num_verify_tokens] = torch.where(spec_token_mask[:, None, None], verify_output, output[:num_verify_tokens])That removes about 15 lines and leaves one place that encodes the verify-kernel arguments. Before adopting it, check one thing (unverified, I couldn't read vLLM's source here): passing out= aliased to the input x must behave like the default in-place write.
There was a problem hiding this comment.
Reply from claude: Kept the two calls. VERIFY runs on every decode step with drafts. The shared sequence would cost it 2 more kernels per GDN layer: a zeros buffer for output, and a masked copy back into it.
# VERIFY today: one torch.where
output = self._verify_gdn(conv_output, a, b, A_log, dt_bias, metadata)
return torch.where(spec_token_mask[:, None, None], output, 0)
# VERIFY with the shared sequence: new_zeros, where, and a copy into output[:num_verify_tokens]
output = conv_output.new_zeros(num_tokens, self.local_num_v_heads, self.head_v_dim)
verify_output = self._verify_gdn(conv_output[:num_verify_tokens], ...)
output[:num_verify_tokens] = torch.where(spec_token_mask[:, None, None], verify_output, output[:num_verify_tokens])|
Reply from claude: Fixed in cfaf638: the drafts refusal in # before
# vLLM speculative decoding retains one state per draft position and
# commits the accepted state; Attention Gym currently mutates one slot.
# after
# TODO: allow drafts once VLLMEngine sets them up (the MTP drafter and the runner's
# accepted counts); `_forward_speculative` already runs their steps. |
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 1m 7s —— View job Verdict: Approve -- see the review |
There was a problem hiding this comment.
Verdict: Approve -- since my last full review the only change in this PR's files is the __init__ comment fix (cfaf638), and both earlier items are settled.
What this PR does. With num_speculative_tokens > 0, VLLMInnerGDN._forward sends each step to _forward_speculative. That function runs one of two paths:
- VERIFY runs vLLM's verify conv and GDN kernels on every row.
- PACKED runs Attention Gym's prefill conv and chunk kernels on every token. It then runs the verify kernels on the first S tokens and keeps, for each token, the output of the kernel that owns its row.
__init__ still refuses drafts, so nothing in the tree reaches this path until #6287.
Example. k = 3, max_num_seqs = 4, rows [verify: 4 tokens, context 40, its last step accepted 2; prefill: 13 tokens].
before __init__ raises; _forward asserted spec_sequence_masks is None
after PACKED, 17 tokens, S = 16: tokens 0-3 come from the verify kernels (they read slot 2
and write slots 1-4); tokens 4-16 come from the chunk kernel
Earlier items
gdn.py:92-93stale reason for the refusal: resolved. It is now a TODO that names what still has to happen (the engine wiring).gdn.py:398-412duplicatedcausal_conv1d_updatecall: the author's reason holds. Sharing the sequence would add anew_zerosand a masked slice copy per GDN layer to VERIFY, which runs on every decode step with drafts. Keeping the two calls costs about 12 lines and saves those kernels on the hot path. Not re-raised.
Details
- Re-review scope:
git diff f676d62 9101c96over this PR's three files is empty. The merge only brings in base-branch changes (test_kv_offload.py). cfaf638 changes only the two comment lines. - Gate, overlap search, and test value are unchanged from the earlier review. The consumer and the numbers are in #6287. The layer reuses vLLM's own verify kernels instead of adding new ones.
Not verified: vLLM's source still isn't available here. Two kernel contracts rest on the author's GB300 run (38 passed): rows with null slot 0 are skipped, and causal_conv1d_update accepts out=. CI has not run at this head.
Before merge: fill in the human-written summary.
|
Superseded by #6475 |
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:
VLLMInnerGDNruns 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 ownsspeculative_config.Problem
kdrafts, 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.causal_conv1d_update, FLA'sfused_sigmoid_gating_delta_rule_update).Solution
_forward_speculativeruns the VERIFY or PACKED kernels above. No tensor size or Python branch depends on the mix of rows. Rows no sequence owns get zeros._verify_gdnruns vLLM's verify GDN kernel over every row, from the builder'sspec_*fields._forwardruns main's code.__init__keeps main's refusal of speculative decoding.Results
NOTE:
test_gdn_graph_metadata.pyruns in CI's RL 1 GPU job (A10G) when the PR has theciflow/rllabel. That job was green at the old head of "[rl] MTP on GDN models: FULL CUDA graphs for steps with prefill" (tagciflow/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
# TODOis in_verify_gdn)Test plan