Skip to content

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

Closed
felipemello1 wants to merge 3 commits into
mainfrom
felipemello1/gdn-builder-drafts
Closed

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

Conversation

@felipemello1

@felipemello1 felipemello1 commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

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.
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Nov 28, 2026
@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 6m 12s —— View job


Needs discussion -- review posted (correctness depends on vLLM kernel and runner behavior I couldn't read; the subclass TODO needs an upstream vLLM issue link).

@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: Needs discussion -- the staging logic holds up on its own terms, but whether it is correct depends on vLLM kernel and runner behavior I couldn't read (vLLM isn't installed here). One TODO also needs an upstream link.

What this PR does. When MTP drafts are on (use_spec_decode), TorchTitan's GDN builder takes a new path, _build_with_drafts. It sorts rows on the CPU into verify-kernel rows (rows with drafts, and 1-token rows after context) and prefill-kernel rows. It writes both into buffers sized for the largest step, with the null slot 0 on rows a kernel doesn't own. That keeps every tensor shape fixed, so one FULL graph (packed or uniform verify) can replay any mix of rows. The runner now also tells the builders whether a uniform graph is being replayed and whether a dummy run is uniform, and hands them its accepted-count buffer. Without drafts, nothing changes. Nothing sets drafts until #6287.

Example (from the docstring: k = 3, capacity 5, 24 padded tokens, so S = 20):

rows                     verify 4 | verify 4 | 1-token resume | prefill 13 | pad
spec_query_start_loc     [0, 4, 8, 9, 20, 20, 20]  -> row 3 gets 11 tokens on the verify kernels, null slot
prefill_query_start_loc  [0, 9, 9, 9, 22, 24, 24]  -> rows 0-2 merged into one null interval
before: vLLM's GDN builder makes mix-dependent tensors -> no FULL graph for this step
after:  fixed buffers -> packed FULL graph replays it

Must fix

  1. linear_attention.py:88 -- the subclass is a workaround for vLLM V1's isinstance gate, and its TODO links a torchtitan PR, not a vLLM issue. It also makes every KDA engine run GDN's __init__. Details inline.

Should consider

  • worker.py:199 -- read force_uniform_decode from kwargs instead of changing the signature and re-passing None to vLLM. Details inline.

Questions

  • Null-slot rows in the verify kernels. In the example, row 3 hands the verify kernels an 11-token interval but only 4 slot columns. Do fused_sigmoid_gating_delta_rule_update and causal_conv1d_update return early on a row whose slot is 0, before any per-token ssm_state_indices[row, t] load or store? If they only check idx >= 0 per token, rows longer than 1 + k inside S read the next rows' slots, and late rows read past spec_state_indices_tensor. The conv update could also overwrite the prefill conv's output for those tokens. If the skip isn't guaranteed, clamp spec_query_start_loc at the end of the last verify row (known on the CPU) instead of at S. That gives the later non-verify rows zero-length intervals, with no shape change.
  • Does the V2 runner in #5956 pass num_accepted_tokens / num_decode_draft_tokens_cpu to non-GDN builders? If so, the subclass has a known end date. If not, an upstream issue is the only exit.
Details
  • Overlap search: "GDN", "MTP", "linear_attention.py". Found the rest of this stack (#6433, #6402, #6287, #6364, #6403, #6365) and #5956 (V2 runner), which rewrites _determine_batch_execution_and_padding and the builder flags. Per the description, #5956 rebases on this stack, so they are coordinated.
  • Value: the stack's measurement is in #6403: +6.3% / +4.4% output tok/s for FULL over piecewise (Qwen3.8-27B, one run per arm, on an earlier version of the stack). That's acceptable for a stack that lands together. Citing it in this PR would help a reader.
  • Checked: the buffer sizes for PACKED (num_rows = capacity + 1, which fits the num_reqs_capacity + 2 offsets), the run-merging in prefill_query_start_loc, dummy-run staging, the order in which paths are picked, and that update_block_table keeps the captured buffers. No D2H syncs: classification uses *_cpu tensors and async_tensor_h2d.
  • _update_block_table_with_drafts works out which rows are real from != 0 on the first group's slots. That's sound only because slot 0 is vLLM's null block and is never handed out.
  • The FA4 builder moves from reorder_batch_threshold = 1 to _init_reorder_batch_threshold(1, supports_spec_as_decode=True). Without drafts this is the same. With drafts, the leading single-token split in FA4 no longer fires behind verify rows (the comment at attention.py:266 says so). #6364 addresses that.

Not verified: the vLLM behaviors listed above, that vLLM's runner refreshes num_accepted_tokens.gpu in batch order on every step, and that None is the parent's default for force_uniform_decode. These depend on vLLM source, which isn't available here.

Before merge: fill in the human-written summary.

Comment on lines +88 to +90
# TODO: with the move to vLLM's V2 model runner (pytorch/torchtitan#5956), drop the subclass if V2
# passes draft counts to any builder that asks. V1 passes them only to known builder classes
# (GPUModelRunner._build_attention_metadata).

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.

Must fix. This subclass exists only to get past vLLM V1's isinstance(builder, GDNAttentionMetadataBuilder) gate in GPUModelRunner._build_attention_metadata. That is a workaround for a vLLM gap, and CLAUDE.md principle 3 asks for a TODO that links an upstream issue. This TODO links a torchtitan PR instead (#5956, which is the open V2-runner PR, not an issue). The workaround also has a cost on main: every KDA engine now runs vLLM's GDN __init__ (spec buffers that get replaced, plus a GDN prefill-backend lookup that reads hf_text_config). The tests have to stub model_config for it (test_gdn_graph_metadata.py:705).

Fix: open a vLLM issue asking the runner to pass draft and accepted counts to any builder that declares it wants them (for example a class attribute), and link it here. #5956 is already open, so the TODO can also say whether V2 passes these counts today. If it does, the condition can be dropped.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reply from claude: Fixed in 869745f: the TODO says what vLLM must change, and that both of vLLM's runners gate the counts by builder class. A vLLM feature request is drafted for Felipe; the TODO links it once it's open.

V2 gates the same way, so the move to V2 alone doesn't end the subclass. MambaHybridAttnMetadata.get_extra_attn_kwargs passes the counts only to vLLM's 4 builder classes (vLLM main 63bcaee474, vllm/v1/worker/gpu/model_states/mamba_hybrid.py:54-66).

KDA engines still start with the GDN parent __init__: TestBitwiseParityKimiK3DebugVarlen (Kimi K3 debug model, its KDA layers on TorchTitan's builder) passes 4 of 4 at the stack's top, on one GB300.

# TODO: drop the subclass once vLLM passes the draft and accepted counts to any builder that
# asks for them. Both of vLLM's runners pass them only to vLLM's own builder classes: V1 in
# GPUModelRunner._build_attention_metadata, V2 in MambaHybridAttnMetadata.get_extra_attn_kwargs
# (vLLM main). No vLLM issue filed yet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Reply from claude: Still open, on purpose. The PR's author reviews each vLLM feature request on his own fork before he files it on vllm-project/vllm. This request is drafted but not open yet. The TODO gets its link once it is open.

Comment thread torchtitan/rl/generator/vllm/worker.py Resolved
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: Both questions, answered from vLLM 9f03b510c (our pin).

  1. Null-slot rows: both verify kernels return on slot 0 before any per-token load or store, so a row's interval length doesn't matter.
    • causal_conv1d_update: the kernel loads the row's slot and returns on the null block (vllm/model_executor/layers/mamba/ops/causal_conv1d.py:834-839), before it reads query_start_loc (:842).
    • fused_sigmoid_gating_delta_rule_update: the kernel loads the slot at the row's accepted offset and returns if it is <= 0 (vllm/third_party/flash_linear_attention/ops/fused_sigmoid_gating.py:103-115), before its token loop (:122).
  2. V2 passes the counts only to vLLM's own builder classes too (the TODO thread has the line), so the subclass stays until vLLM changes.

@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 52s —— View job


Needs discussion -- the subclass TODO still has no vLLM issue link, the cited vLLM behavior still needs someone to check it at the pin, and there's a new question about out-of-bounds gathers in "align" mode: review posted.

@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: Needs discussion -- one must-fix is still open: the vLLM workaround's TODO has no upstream issue link. The PR is also only correct if vLLM's kernels and runner behave as the author's citations say, and someone who can read vLLM at the pin has to confirm that. I couldn't (vLLM isn't available here).

What this PR does. When MTP drafts are on, the GDN/KDA metadata builder takes a new path, _build_with_drafts. On the CPU it splits rows into verify-kernel rows (rows with drafts, and 1-token rows after context) and prefill-kernel rows. It writes both into buffers sized for the largest step, and gives each kernel the null slot 0 on rows it doesn't own. Tensor shapes then don't depend on the mix of rows, so one packed or uniform FULL graph can replay any step. The runner now tells the builders whether a uniform graph replays and whether a dummy run is uniform, and hands them its accepted-count buffer. Steps without drafts run the same code as on main. Nothing turns drafts on until #6287.

Example (k = 3, capacity 5, 24 padded tokens, S = 20):

rows                     verify 4 | verify 4 | 1-token resume | prefill 13 | pad
spec_query_start_loc     [0, 4, 8, 9, 20, 20, 20]   verify kernels; rows 3+ get null slots
prefill_query_start_loc  [0, 9, 9, 9, 22, 24, 24]   rows 0-2 merged into one null interval
before: vLLM's GDN builder builds tensors sized by the row mix -> no FULL graph for this step
after:  fixed buffers -> the packed FULL graph replays it

Since the last review (869745f)

  • Resolved: the null-slot question. The author cites both verify kernels returning on slot 0 before any per-token load or store (causal_conv1d.py:834-839, fused_sigmoid_gating.py:103-115 at 9f03b510c). Unverified by me.
  • Resolved: the V2 runner question. V2 also gates the counts by builder class (mamba_hybrid.py:54-66), so moving to V2 doesn't remove the subclass. The TODO now says so.
  • Resolved (should-consider): worker.py:233, the named force_uniform_decode parameter. #6402 sets this value on real steps, so the override has to pass its own value to vLLM. The author also cites vLLM's default being None.

Must fix

  1. Still open: linear_attention.py:401 -- the TODO for the subclass workaround says "No vLLM issue filed yet." CLAUDE.md principle 3 asks a workaround for an upstream gap to link an upstream issue. File the drafted vLLM feature request and put its URL in the TODO before merging. This is a mechanical edit.

Questions

  • linear_attention.py:423-426 (and :579-582): the gather reads block-table columns state_block_column .. state_block_column + k for every row, prefill rows included, before torch.where masks them. In "align" mode, a row whose running-state column is among the last k columns would gather out of bounds, which is a device-side assert. The max_seq_len check at :201 only bounds the running column. Does vLLM's mamba block table with num_speculative_blocks always leave k columns past the last running column in "align" mode (unverified)? If not, the smallest fix is to clamp the index at block_table.shape[1] - 1, since non-verify rows are masked anyway. A verify row that hits the clamp would then be a real bug to raise on. Before this stack, "align" + drafts couldn't be reached, so no existing test covers it. The new test's tables (8 columns, last running column 4) don't reach the edge.
Details
  • Commits since the last full review: 869745f (the TODO text only) and a merge of main. The merge doesn't touch the PR's logic (gh pr diff against main is otherwise unchanged).
  • Overlap search: "linear_attention", "GDN builder". Found the rest of this stack (#6433, #6402, #6403, #6287, #6364, #6365), #5956 (V2 runner; the description says it rebases on this stack), #6415 (SGLang, a separate generator), and #6294 (models/common/attention/linear_attention.py, not the RL builder). No conflicting rewrite.
  • Re-checked at HEAD: PACKED buffer sizes (num_rows = capacity + 1 against query_start_loc's capacity + 2), dummy-run staging (all rows go to the prefill kernels with dummy slots and accepted counts of 1), the uniform-graph raise (a uniform descriptor needs every row at 1 + k tokens, so a step whose drafts were all trimmed can't get there), and D2H syncs (classification uses *_cpu and numpy; H2D goes through async_tensor_h2d).
  • KDA engines now run vLLM's GDN __init__ as well. The author reports TestBitwiseParityKimiK3DebugVarlen 4/4 at the stack top.

Not verified: the vLLM source lines cited in the replies (kernel early returns, the V1/V2 builder-class gates, num_accepted_tokens.gpu refreshed in batch order on every step), and the block-table width in "align" mode with drafts.

Before merge: fill in the human-written summary.

@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: I checked every vLLM behavior this PR cites at TorchTitan's pin, and each one holds. The "align" gather stays in bounds, so the code doesn't change. Two lines of the PR text were wrong, and I fixed them.

The pin: scripts/install_rl_env.sh installs vllm==1.0.0.dev20261107, built from vLLM 9f03b510c. The installed wheel's files are the same as that commit's files, so the links below show the exact code that runs.

1. The cited behaviors

  • causal_conv1d_update loads the row's slot and returns on the null block before it reads query_start_loc: causal_conv1d.py#L830-L843.
  • fused_sigmoid_gating_delta_rule_update loads the slot at the row's accepted offset and returns if it is <= 0, before its token loop: fused_sigmoid_gating.py#L103-L122.
    • That check runs only when initial_state and ssm_state_indices are set (#L17-L19). The GDN layer PR passes both.
  • V1 passes the draft and accepted counts only on steps with drafts, and only to its own 4 builder classes: gpu_model_runner.py#L2527-L2545.
  • V2 gates them by class too: mamba_hybrid.py#L52-L74.
  • num_accepted_tokens is refreshed in batch order on every step, before the drafts branch at :2244. There are two paths:

2. "align" gathers stay in bounds. vLLM gives each mamba block-table row k spare columns past the last running column:

  1. In "align" mode, a row is cdiv(max_len, block_size) + num_speculative_blocks wide (kv_cache_interface.py#L1047-L1055). The runner passes max_len = max_model_len (gpu_model_runner.py#L7273-L7288).
  2. A GDN layer's num_speculative_blocks is k (abstract.py#L79-L85).
  3. With drafts, the scheduler keeps every request within max_model_len (scheduler.py#L668-L675). TorchTitanGPUModelRunner._dummy_run caps capture requests there too.
  4. So the last column the gather reads is (seq_len - 1) // block_size + k, which is at most cdiv(max_model_len, block_size) - 1 + k, the row's last column.

vLLM's own GDN builder makes the same gather, on every row, in "align" mode (gdn_attn.py#L222-L227, which calls utils.py#L1155-L1180).

A CPU check built a real MambaSpec at the pin and ran this builder's gather at seq_len = max_model_len:

block 1664, max_model_len 65536, k 3:  row width 43, last column read 42: in bounds
block   16, max_model_len    64, k 3:  row width  7, last column read  6: in bounds
in all 5 shapes, the first out-of-bounds seq_len is cdiv(max_model_len, block) x block + 1, past max_model_len

You're right that the max_seq_len check bounds only the running column. The spare columns cover the rest for every length vLLM schedules.

3. PR text

before: The TODO at the class says to drop the subclass with the move to vLLM's V2 runner, if V2 passes the counts to any builder that asks.
after:  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.

before: a few int32 buffers of `max_num_seqs * (1 + k)` entries and a GDN prefill-backend lookup
after:  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`

Still open: the TODO's upstream link (see its thread).

@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 8s —— View job


Needs discussion: the subclass TODO still needs its vLLM issue link, and someone who can read vLLM at the pin should check the author's citations. Review posted.

@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: Needs discussion -- no code has changed since my last review (869745f). The one must-fix left is the TODO's missing vLLM issue link. The vLLM behavior the PR depends on is now cited with permalinks at the pin, but I still can't read vLLM here, so someone who can should check those links before this merges.

What this PR does. When MTP drafts are on, the GDN/KDA metadata builder uses _build_with_drafts. On the CPU it sorts rows into verify-kernel rows and prefill-kernel rows. It writes both into buffers sized for the largest step, and gives the null slot 0 to every row a kernel doesn't own. One packed or uniform FULL graph can then replay any mix of rows. Steps without drafts run main's code.

Example (k = 3, capacity 5, 24 padded tokens, S = 20):

rows                     verify 4 | verify 4 | 1-token resume | prefill 13 | pad
spec_query_start_loc     [0, 4, 8, 9, 20, 20, 20]   verify kernels; rows 3+ get null slots
prefill_query_start_loc  [0, 9, 9, 9, 22, 24, 24]   rows 0-2 merged into one null interval
before: vLLM's GDN builder builds tensors sized by the row mix -> no FULL graph for this step
after:  fixed buffers -> the packed FULL graph replays it

Since the last review

  • No new commits. The author replied with vLLM permalinks at 9f03b510c and fixed two lines of the description.
  • Answered: the question about out-of-bounds gathers in "align" mode. The argument holds, given the cited facts. A mamba block-table row is cdiv(max_model_len, block_size) + k columns wide, and a GDN layer's num_speculative_blocks is k. The scheduler keeps every request within max_model_len, and the runner caps its dummy runs there too (worker.py:191-197). So the last column read is (max_model_len - 1) // block_size + k, the row's last column. The arithmetic checks out. The vLLM facts it rests on are unverified by me.

Must fix

  1. Still open: linear_attention.py:88-91. The TODO for the subclass workaround says "No vLLM issue filed yet." It's a mechanical edit: link the issue once it's filed. Filing it later isn't an argument against the finding, so it stays a must-fix until the link is in the TODO.

Should consider

  • linear_attention.py:201-211 (existing code, not in the diff): the max_seq_len check bounds only the running column, while the new draft gather reads k more columns. With drafts, checking against (block_table_tensor.shape[1] - self.num_spec) * block_size would guard the bound the gather actually relies on. A wrong layout would then raise a clear ValueError instead of a device-side assert. This is a one-line change.
Details
  • I tried to read vLLM at 9f03b510c to check the citations. The vLLM package isn't installed in this job, and reading other repos isn't permitted here.
  • The overlap search from the last review still applies: the rest of this stack (#6433, #6402, #6403, #6287, #6364, #6365) and #5956 (V2 runner, which rebases on this stack). No conflicting rewrite.

Not verified: the vLLM lines the author cited. These are the kernels' early return on slot 0, the V1/V2 builder-class gates, num_accepted_tokens being refreshed in batch order on every step, and the mamba block-table width in "align" mode.

Before merge: fill in the human-written summary.

@liangel-02

Copy link
Copy Markdown
Contributor

Superseded by #6473

@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