Repository navigation
[rl] generator: run on vLLM's model runner V2 (vLLM 0.34) - #5956
felipemello1 wants to merge 40 commits into
Conversation
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 4m 39s —— View job Approve -- please address the items before merging (empty human-written summary, upstream issue links on the vLLM-workaround TODOs): review. A maintainer still needs to review. |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. This port is required: vLLM main deleted the V1 runner, worker and dispatcher that the generator subclassed. The V2 replacement is smaller than what it replaces, and it keeps the same graph behavior. A maintainer still needs to review it, and merging waits for a nightly that includes vLLM PR 63373.
What this PR does. The generator moves onto vLLM's V2 model runner, which is now the only one. Its FULL mode still gets separate FULL decode graphs. TorchTitanCudaGraphManager adds FULL_DECODE_ONLY's decode candidates and rebuilds vLLM's manager after initialize_kv_cache. TorchTitanHybridModelState.prepare_attn tells the GDN/KDA builders which graph is about to replay. The hand-written padding count for Dist-MoE gives way to vLLM's ForwardContext.is_padding. In batch-invariant mode, the prompt-logprob and temperature Triton kernels are also replaced with PyTorch ops.
Example. FULL mode, mixed graphs [1, 2, 8, 16] tokens, decode graphs [1, 2] requests:
step V2 stock FULL this PR
2 decodes 2-token mixed (packed) 2-request decode graph, single-token path
3 decodes 8-token mixed (packed) 8-token mixed, builders told "packed"
3 decodes, batch-invariant 8-token mixed (packed) eager, decode kernels
prefill of 5 tokens 8-token mixed 8-token mixed
Must fix
- PR description -- the "Summary (human-written)" section is empty. The author needs to fill it in before merge (CONTRIBUTING, "AI-assisted contributions").
worker.py:48-- none of the three upstream-workaround TODOs (worker.py:48,worker.py:125,linear_attention.py:352) links an upstream issue. All three rely on vLLM private APIs (_init_candidates,_decode_descs,_capture_descs, rebuilding the manager). (inline)
Should consider
gdn.py:225/kda.py:227--prefix not in attn_metadataturns a missing-metadata bug on a real step into silent zero output. Return zeros only when the dict holds no linear-attention metadata at all, and assert otherwise. (inline)worker.py:61-- the inner decodeCudaGraphManagerdoesn't forwardvarlen_decode, but the rebuild at :139 does. Either forward it in both places or in neither. (inline)
Questions
- Did any run cover the extensible KV cache off? That is the only path where
is_profilingreturns beforemodel_state.cudagraph_manageris set (worker.py:126). If vLLM's estimate capture ever callsprepare_attnwithFULLfor a hybrid model, it raisesAttributeErroron the unset annotation. worker.py:131discards the manager vLLM just built, andworker.py:61builds one more manager just to read its candidates. Does either constructor allocate device state? Does anything else built inGPUModelRunner.initialize_kv_cachekeep a reference to the original manager, for example a speculator?
Not verified: no vLLM install was available, so I couldn't check any claim about vLLM V2 internals (the dispatch/prepare_attn call order under DP sync, the is_padding length, MLA's max_query_len cap). I relied on the author's GB300 runs for those. The DP + batch-invariant + prefilling-peer case, which the old dispatcher handled through valid_modes, is covered by test_vllm_dp_decode_graphs_with_prefilling_peer.
| TODO: drop this class once vLLM captures FULL decode graphs next to FULL mixed | ||
| graphs without piecewise compilation. | ||
| graphs. |
There was a problem hiding this comment.
This workaround overrides vLLM's private _init_candidates, and it reads _decode_descs and _capture_descs off a throwaway CudaGraphManager. Its TODO has no upstream issue link, and neither do the TODOs at worker.py:125 (the graph-memory estimate) and linear_attention.py:352 (passing the replayed graph to the builders). CLAUDE.md principle 3 asks for a link on every workaround for an upstream gap. These three private-API dependencies will break silently at a future nightly, and without links nobody can tell when they become deletable. Please file the vLLM issues listed in the follow-ups and link them here, at :125 and at linear_attention.py:352 before merging.
There was a problem hiding this comment.
Reply from claude: Each TODO now names the vLLM change that deletes it (b1839d2):
worker.py:48: a CUDA-graph mode with FULL graphs for both mixed and decode batches (vLLM's FULL has no separate decode routine), or FULL_AND_PIECEWISE being as fast on RL steps.worker.py:125: a graph-memory estimate that charges each FULL graph at its own size, plus a manager factory method, which deletes the rebuild.linear_attention.py:352: the replayed graph's descriptor passed toModelState.prepare_attn.
Filing these upstream is the author's call, so the TODOs carry no links.
| if self.prefix not in attn_metadata: | ||
| return mixed_qkv.new_zeros(output_shape) |
There was a problem hiding this comment.
Before this change, a real step without metadata for this layer raised KeyError. Now it silently returns zeros. Example: a prefix mismatch, or a vLLM change that drops a linear-attention group from attn_metadata. Every GDN layer would then output 0 and generation would carry on with garbage. kda.py:227 has the same problem, and there it leaves output_THK unwritten.
The profile run is the only expected case, and in that run no linear-attention layer has metadata. Restricting the skip to that case costs one check:
if self.prefix not in attn_metadata:
# The profile run builds no linear-attention metadata at all.
assert not any(
isinstance(m, TorchTitanLinearAttentionMetadata) for m in attn_metadata.values()
), f"no attention metadata for {self.prefix}"
return mixed_qkv.new_zeros(output_shape)This is an invariant whose failure would otherwise be silent (principle 8), so the check is worth its line. Unverified: I couldn't confirm against vLLM main that the profile run really builds no metadata for any linear layer.
There was a problem hiding this comment.
Reply from claude: Fixed in a87c97e. A missing layer now returns zeros only when the dict holds no TorchTitanLinearAttentionMetadata at all. Otherwise it raises RuntimeError naming the prefix, in both GDN and KDA, and the CPU tests cover both. I checked vLLM main (cf5cea2da3):
profile_runpassesskip_attn=True(vllm/v1/worker/gpu/model_runner.py:1078-1081), so its metadata is None.- Only the kernel-autotune dummy runs (
is_profile=True,vllm/model_executor/warmup/kernel_warmup.py:456-460) drop every MambaSpec group (model_runner.py:2010-2018).
So in vLLM's own runs, a layer is missing only when every linear-attention layer is missing.
| decode_graphs = CudaGraphManager( | ||
| self.vllm_config, | ||
| self.device, | ||
| CUDAGraphMode.FULL_DECODE_ONLY, | ||
| decode_query_lens=self.decode_max_reqs, | ||
| lora_capture_cases=self.lora_capture_cases, | ||
| ubatch_runner=self.ubatch_runner, | ||
| ) |
There was a problem hiding this comment.
The rebuild at :132-141 forwards varlen_decode so that the manager matches vLLM's, but this inner decode manager doesn't forward it. If varlen_decode affects the decode descriptors, then FULL's decode graphs would differ from the ones vLLM's own FULL_DECODE_ONLY would build. If it doesn't affect them, then forwarding it at :139 serves no purpose. Pick one and do the same in both places: forward varlen_decode=self.varlen_decode here, or drop it from both. Unverified (I couldn't inspect vLLM's CudaGraphManager signature).
There was a problem hiding this comment.
Reply from claude: Fixed in b1839d2: the inner FULL_DECODE_ONLY manager now gets varlen_decode too, so both managers take vLLM's arguments. It does affect decode descriptors: with it, decode graphs become token-keyed varlen graphs (vllm/v1/worker/gpu/cudagraph_utils.py:313-330) instead of _decode_descs. vLLM sets it from adaptive_verification is not None (model_runner.py:801), which needs speculative decoding. The generator never enables that, so it is False in every run here.
924ded0 to
b1839d2
Compare
|
Reply from claude: answers to the two questions in the review. (a) Extensible KV cache off.
(b) Device state and references to vLLM's manager. |
|
Reply from claude: @claude please review again. Fixes are in the new commits; each of your comments has a reply in its thread. |
|
Claude finished @felipemello1's task in 56s —— View job Approve -- please address the items below before merging: both should-consider items are fixed. The empty human-written summary and the missing upstream issue links on the vLLM-workaround TODOs are still open. Review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The two new commits fix both should-consider items. The two must-fix items from the last review are still open, and both are for the human author. A maintainer still needs to review, and merging still waits for a nightly that includes vLLM PR 63373.
Example (what a87c97e changes). A hybrid model with GDN layers gdn.0 and gdn.1, on a real step where attn_metadata has gdn.0 but not gdn.1:
before (previous head) a87c97e
kernel-autotune run (no linear- gdn.1 -> zeros gdn.1 -> zeros
attention metadata at all)
real step, only gdn.1 missing gdn.1 -> zeros (silent) RuntimeError("No attention metadata for gdn.1 ...")
Resolved since the last review
gdn.py:225/kda.py:227: the silent zero output on a real step. The skip now applies only when noTorchTitanLinearAttentionMetadatais present, and anything else raises. The CPU tests cover both layers.worker.py:68: the innerFULL_DECODE_ONLYmanager now getsvarlen_decode, as the rebuild at :145 does.- Question on the extensible KV cache being off: answered. The estimate captures through
prepare_attnwithCUDAGraphMode.NONE, so the unsetcudagraph_manageris never read. - Question on device state and stale references: answered. Neither constructor allocates device memory. The only component that keeps vLLM's manager is
FastPrefillHelper, and only withkv_sharing_fast_prefill, which no TorchTitan model uses.
Must fix (still open)
- PR description: the "Summary (human-written)" section is still empty. The author fills it in (CONTRIBUTING, "AI-assisted contributions").
worker.py:48,worker.py:127,worker.py:135,linear_attention.py:352: each TODO now names the vLLM change that would delete it, which helps. None links an upstream issue, though, and they cover private-API dependencies (_init_candidates,_decode_descs,_capture_descs, the manager rebuild). The reply is right that agents don't file issues. CLAUDE.md principle 3 still asks for the link, so the human author needs to file the vLLM issues and add the links before merge.
Not verified: no vLLM install was available. I relied on the author's citations to vLLM main for two claims: that only the is_profile kernel-autotune dummy runs drop every MambaSpec group, and that DP idle dummy runs build metadata for either all linear-attention layers or none.
…K3) (#5955) ## Summary (human-written) <!-- Write this yourself, not with an AI tool. 2-5 sentences: the problem, why this approach, and what you checked yourself. --> ## Agent details **TLDR:** Kimi K3 batch-invariant RL crashes at KV-cache init on GB300 with the current nightly, so main's `rl_grpo_kimi_k3_debug_batch_invariant` test is red. vLLM sizes Kimi K3's attention page with K's head size for V too, then refuses to split the padded block. The unequal-K/V attention backend now reports V's head size. This PR alone turns the test green. Bottom of a 3-PR stack, based on main: #5955 (this) -> #5498 -> #5956. ```text Kimi K3 RL test, bytes per KV block (from vLLM's error) before: block stride 638976 (V counted at K's head size) != real page 532480 -> crash at KV-cache init after: page estimate = real page -> runs, trainer vs generator logprob diff 0 ``` **Problem** 1. **vLLM's estimate.** For a hybrid model, vLLM sizes the attention page from a spec without `head_size_v` (`vllm/platforms/interface.py:854-863` on the pinned nightly, `:1037-1048` on vLLM main), so V gets K's head size. vLLM's DiffKV backends don't correct it in `customize_spec`. 2. **Smaller V.** Kimi K3's full attention has a smaller V head, so its real page is smaller than the estimate. The block stride is padded. 3. **Now a crash.** #5870 changed batch-invariant FA4 kernel blocks from `MultipleOf(16)` to exactly `[16]`, so vLLM must split each KV block, and it refuses to split a padded block. 4. **Who hits it.** Only batch-invariant Kimi K3: `uses_compressed_mla_cache` keeps materialized K/V (the unequal-K/V backend) only in batch-invariant mode. It crashes at KV-cache init on GB300, on the current nightly and on vLLM main. **Solution** 1. `TorchTitanVarlenInnerAttentionDiffKVBackend.customize_spec` sets `head_size_v` to the layer's V head size, then calls vLLM's. vLLM's page estimate then equals the real page. This is the order vLLM's own fix uses. 2. vLLM's DiffKV backends keep V's head size on the class (`set_head_size_v`), so this assumes one V head size per process, as vLLM does. Kimi K3 has one. 3. A TODO names the vLLM change that deletes this override: vLLM's DiffKV backends setting `head_size_v` in `customize_spec`. A vLLM-side fix is drafted at felipemello1/vllm#2. 4. Unchanged: every other attention backend, and models whose K and V head sizes are equal. **Results** ```text Numerics: Kimi K3 batch-invariant RL, trainer vs generator logprob diff max 0 at steps 1-3. pinned nightly, GB300 GPUs ran on result tests/rl/unit_tests/cpu - 69cc40a54 568 passed, 7 skipped Kimi K3 batch-invariant RL, 3 steps (rl_h100) 4 69cc40a54 passed; logprob diff max 0 at steps 1-3 058306e passed; logprob diff max 0 at steps 1-3 without fix * crash at KV-cache init Kimi K3 bitwise parity (B200 CI's test) 1 with fix * 4 passed ``` Rows ran at 69cc40a54, this PR's code before the rebase. The stack was then rebased onto main 7d88c59, which adds one FSDP commit that touches none of these files. 058306e is this PR's first commit alone: `replace` after vLLM's `customize_spec` instead of before. Both give the same spec, because vLLM's base `customize_spec` returns the spec unchanged. \* Ran with the next PR's API fixes underneath. They don't touch the attention page code. NOTE: - This changes Kimi K3's KV block size on every GPU. vLLM sizes the block from the per-token attention page, which drops from 2 x K to K + V head bytes. Tested on GB300 only. - B200 CI runs the Kimi K3 parity test only with the `ciflow/b200` tag. H100 CI never splits blocks, so it never hit the crash. **Test plan** - `python -m pytest tests/rl/unit_tests/cpu` - `torchrun --nproc-per-node=1 -m pytest tests/rl/unit_tests/gpu/test_bitwise_parity.py::TestBitwiseParityKimiK3DebugVarlen` - `python -m tests.integration_tests.run_tests <out> --ngpu 4 --test_suite rl_h100 --test_name rl_grpo_kimi_k3_debug_batch_invariant` --------- Co-authored-by: Felipe Mello <[email protected]>
b1839d2 to
84307fb
Compare
84307fb to
227158b
Compare
227158b to
ea18a30
Compare
ea18a30 to
af6111f
Compare
…tBatch.max_query_len A FULL mixed-graph replay must build the GDN/KDA path its graph was captured with, and vLLM captures a mixed graph with max_query_len equal to its token count. TorchTitanGPUModelRunner.prepare_inputs now sets InputBatch.max_query_len (vLLM's field for a graph that promises a longer query than the batch has) from the descriptor vLLM passes it, for hybrid models only. The builders' own max_query_len == 1 rule then picks the captured path. This replaces TorchTitanHybridModelState, the builders' replays_packed_graph flag and the manager's last_dispatched_descriptor, which relied on dispatch running before prepare_attn in the same step.
|
from claude: @claude review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The main new commit, 6b83b0e, replaces TorchTitanHybridModelState with a prepare_inputs override. The override no longer depends on dispatch running before prepare_attn, and the PR gets smaller. The description still describes the deleted mechanism, though. A maintainer still needs to review.
What changed since the last review (7445dcb -> 6b83b0e).
- 6b83b0e: on a FULL mixed-graph replay in a hybrid model,
TorchTitanGPUModelRunner.prepare_inputs(worker.py:143-183) setsInputBatch.max_query_lento the graph's captured value. The GDN/KDA builder's ownmax_query_len == 1rule then picks the captured path. This deletesreplays_packed_graph,last_dispatched_descriptor,TorchTitanHybridModelStateand theget_model_state_clsoverride. - 533ad4e: the FA2 256-token rule moves from the engine's
block_sizeto_FlashAttentionPageSize.attention_kv_cache_block_sizebecomesflex_attention_kv_cache_block_size. - 499fb73:
release_session_cachereads vLLM 0.34's block-ID cache (_cache/_dup_ids). - The rest are merges from the PRs below in the stack.
Example. Hybrid model, FULL mode, mixed graphs [1, 2, 8, 16] tokens, decode graphs [1, 2] requests:
step before (prepare_attn flag) 6b83b0e (InputBatch.max_query_len)
3 decodes in the 8-token graph replays_packed_graph -> packed 8 -> packed
2 decodes, decode graph 1 -> single-token unchanged (1)
1-token mixed graph 1 -> single-token 1 -> single-token
eager step / non-hybrid model batch's own batch's own
DP re-dispatch before the step read the last dispatch no dependency on order
Must fix
- PR description: it still describes the deleted mechanism. Solution 2, the V1/V2 table row "GDN/KDA replayed graph ->
TorchTitanHybridModelState.prepare_attn", the Follow-up item "descriptor passed toModelState.prepare_attn: deletesTorchTitanHybridModelState", and the human summary ("UseModelState.prepare_attn") all need updating. They should nameTorchTitanGPUModelRunner.prepare_inputssettingInputBatch.max_query_len, with its TODO ("vLLM setsmax_query_lenfor FULL mixed-graph replays"). The description also doesn't mention 533ad4e (the FA2 rule on the backend, including ROCm, see inline) or 499fb73. The Results and Test plan predate all three commits.
Should consider
attention.py:91-92: ROCm now gets 256-token pages as well (inline).- Still open from earlier rounds: none of the vLLM-workaround TODOs links an upstream issue, including the new one in
prepare_inputs.
Questions
prepare_inputsruns on real steps. When a DP rank with no requests replays a FULL mixed graph to match its peers, does vLLM 0.34's dummy run build its metadata through a path that already carries the capturedmax_query_len? The oldprepare_attnhook covered both kinds of step.test_vllm_dp_linear_attention_full_graphs(H100 job, queued) should show it.simple_cpu_offload_connector.py:75: does_dup_ids[key]include the first block ID, which_cache[key]holds? If it lists only the duplicates, the first copy's aliases are never released.
Details
- In a hybrid model, the full-attention builders see the larger
max_query_lentoo. Under FULL replay the kernel launches come from capture, so only tensors the builders compute change. MLA's_build_decoderecomputes the longest query fromquery_start_loc_cpu(mla.py:111-118), and amax_query_lenof n stays under its 512 decode threshold, or falls back to the real query lengths above it. The varlen impl readsmax_query_lenonly in Python, and Python doesn't run on replay. - Overlap: the MTP stack (#6473-#6479) edits
worker.pyandlinear_attention.pyon vLLM 0.33. Its description says this PR rebases on it. Searched: "vLLM 0.34", "worker.py TorchTitanGPUModelRunner". - CI at 6b83b0e: B200 Kimi K3 parity passes (4 passed). The
rl-b200failure is an HF 429 in the SGLang step. RL GPU Unit Tests (test_gdn_cudagraph.py,test_gdn_graph_metadata.py, Qwen3.5 parity) and the H100 DP tests are queued. Those jobs are what check 6b83b0e on GDN.
Not verified: no vLLM install was available. That leaves unchecked that prepare_inputs runs before the metadata build, that BatchExecutionDescriptor.max_query_len exists, and that vLLM captures a mixed graph with max_query_len == num_tokens.
| if flash_impl is None: | ||
| return [MultipleOf(256)] |
There was a problem hiding this comment.
This also changes ROCm, and neither the commit nor the docstring mentions it. get_cuda_flash_attention_impl() returns None whenever torch.version.hip is set (torchtitan/tools/utils.py:48-49). So ROCm varlen now gets MultipleOf(256) pages. Before this, the removed has_cuda_capability(9, 0) check was True on current AMD GPUs (MI300 reports (9, 4), MI350 (9, 5)), so ROCm got vLLM's default block size. ROCm still runs this backend outside batch-invariant mode (controller.py:556 only rejects batch-invariant).
What changes on ROCm: KV blocks become at least 256 tokens (vLLM 0.34's default is 64). That makes prefix-cache reuse coarser and can leave up to 255 KV slots unused per sequence. If torch's ROCm flash path doesn't need 256-token pages, keep the old behavior:
| if flash_impl is None: | |
| return [MultipleOf(256)] | |
| if flash_impl is None and torch.version.hip is None: | |
| return [MultipleOf(256)] |
If ROCm does need them, say so in the docstring table (the FA2 row currently reads as CUDA SM80 only).
|
from claude: replies to the last review (posted here because a pending review on this PR blocks in-thread replies):
|
|
from claude: @claude review |
|
Claude finished @wwwjn's task in 1m 32s —— View job Approve -- please address the item before merging (the vLLM/FA3-workaround TODOs need upstream issue links, or an explicit maintainer override; the description and ROCm items from the last review are resolved): review. A maintainer still needs to review. |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. The commits since the last review (6b83b0e -> add9b61) change only a docstring in this PR's diff. They resolve the last review's must-fix (the stale description) and its ROCm comment. A maintainer still needs to review.
What changed since the last review.
- add9b61: the
_FlashAttentionPageSizetable (attention.py:49-50) now says ROCm gets 256-token pages, as it did before. My last inline comment on this was wrong. The removed check washas_cuda_capability(9, 0), and that check returns False whenevertorch.version.hipis set (torchtitan/tools/utils.py:31-37). So on main the engine already setblock_size=256on ROCm, and ROCm doesn't change. - 40ae78a / 727aeb1: a merge from the PR below in the stack (it rebinds vLLM's sampler kernels in
batch_invariance.py). No file in this PR's diff changes. - The description and the human-written summary now describe
TorchTitanGPUModelRunner.prepare_inputssettingInputBatch.max_query_len. They also cover 533ad4e (FA2 pages on the backend) and 499fb73 (the block-ID cache).
Example. Page sizes by device, before and after 533ad4e + add9b61:
device main (engine block_size) this PR (_FlashAttentionPageSize)
SM80 (FA2) 256 MultipleOf(256)
ROCm 256 (cap check is False) MultipleOf(256)
H100 FA3, batch-inv. vLLM default 16
GB300 FA4 128 / 16 if batch-inv. unchanged
Resolved since the last review
- The PR description no longer describes the deleted
TorchTitanHybridModelState/prepare_attnmechanism. attention.py:93(ROCm): no behavior change, as explained above, and the docstring now says so.- Question on the DP dummy step: answered. vLLM 0.34 builds the dummy step with
InputBatch.make_dummyandprepare_attn(..., for_capture=True), which callsbuild_for_cudagraph_capture. Ours stages both paths' buffers (stage_packed=True). - Question on
_dup_ids: answered.BlockHashToBlockMap.insertseeds_dup_ids[key]with the first block ID, sorelease_session_cache(simple_cpu_offload_connector.py:75) visits every copy. On a hash with no duplicates, it falls back to(first_block_id,).
Must fix
worker.py(theTorchTitanCudaGraphManagerclass TODO, the two TODOs ininitialize_kv_cache, and theprepare_inputsTODO) andattention.py(the two FA3 TODOs): none links an upstream issue. CLAUDE.md principle 3 requires the link for every upstream workaround, and these depend on private vLLM APIs (_init_candidates,_decode_descs,_capture_descs, the manager rebuild), which a vLLM bump can break silently. Earlier rounds left this for the maintainer to decide. "Not now" doesn't clear a written rule, though, so I'm listing it again: file the vLLM / FA3 issues and add the links, or get an explicit maintainer override (@claude override).
Not verified: I had no vLLM install. The vLLM 0.34 claims (make_dummy / for_capture, block_pool.py:82) rest on the author's citations. The first GPU check of 6b83b0e on GDN is still the CI run of the RL GPU unit tests and the H100 DP tests.
…LL dummy run At DP>1, an idle rank's dummy step can replay a FULL mixed graph. vLLM pads the dummy to min(num_tokens, max_num_reqs) requests, often one token each, so the builders see max_query_len 1 and build single-token metadata. The first group's build_for_cudagraph_capture stages the packed buffers anyway (stage_packed), but update_block_table copied the query offsets to later groups only for packed metadata. Their packed graph then read the previous step's offsets: warpdrive's check_packed_offsets asserted "invalid packed cu_seqlens" in test_vllm_dp_linear_attention_full_graphs on GB300. The metadata now carries the staged packed offsets (packed_query_start_loc), and update_block_table stages them whenever the first group did. Before 6b83b0e the prepare_attn hook marked these dummy builds packed, so the bug did not show.
|
from claude: correction to my DP dummy-step answer above. Only the first GDN/KDA group's capture build stages both paths. vLLM pads an idle rank's dummy to |
|
from claude: @claude review |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. b76a3a8 fixes a real bug that 6b83b0e introduced: an idle DP rank's dummy step left stale packed offsets in later GDN/KDA groups. The fix is in the right place and is small: one metadata field and one changed branch in update_block_table. It adds no new problems. A maintainer still needs to review.
What changed since the last review (add9b61 -> b76a3a8).
linear_attention.py:54,304:TorchTitanLinearAttentionMetadata.packed_query_start_locis set whenever_stage_decode_splitruns. That covers a packed build and also astage_packedcapture or dummy build, even when that build is single-token.linear_attention.py:327-340:update_block_tablenow restagesquery_start_locand the decode split whenever the first group staged them. Before, it did this only whenexecution_path is PACKED. The returnednon_spec_query_start_locstill follows the metadata's own path.- c7a80e1 and the 00da2cb merge come from the PR below in the stack (
batch_invariance.py). They change no file in this PR's diff.
Example. DP2, FULL, mixed graphs [1, 2, 4, 8] tokens. Rank 1 is idle and replays the 2-token mixed graph as a dummy of 2 one-token requests, for GDN groups A (first) and B:
before b76a3a8 b76a3a8
A: build_for_cudagraph_capture single-token, packed staged same, packed_query_start_loc set
B: update_block_table decode offsets only query_start_loc <- [0, 1, 2, 2], decode split restaged
B's packed graph reads last step's query_start_loc this step's offsets
real packed step (any DP) copies non_spec offsets same values, via packed_query_start_loc
real single-token step no restage no restage (field is None)
The restaging order is correct: _stage_state_indices runs first, so _stage_decode_split copies this group's slots, and it clamps the offsets only after they are copied in. test_update_block_table_stages_packed_buffers_of_a_dummy_run guards this, and with FLA kernels (H100 CI) the failure would otherwise be silent, so the test earns its place.
Must fix (still open)
- The vLLM/FA3-workaround TODOs have no upstream issue links. They are in
worker.py(TorchTitanCudaGraphManager, bothinitialize_kv_cacheTODOs,prepare_inputs) andattention.py(the two FA3 TODOs). CLAUDE.md principle 3 requires the links. Fix: file the issues and link them, or a code owner overrides (@claude override).
Should consider
- MTP stack overlap: #6473 adds
_update_block_table_with_draftsnext to thisupdate_block_table. Whichever PR lands second has to keep thepacked_query_start_locrestaging on every path that can replay a packed graph from a dummy build.
Details
- Search terms: "linear_attention update_block_table", "vLLM 0.34". Found the MTP stack #6473-#6479 (already known; it rebases on this PR) and nothing else that touches
update_block_table. packed_query_start_locviews the first builder's ownquery_start_loc. Nothing writes that buffer between that group'sbuildand the later groups'update_block_tablein the same step. The next single-token, non-staged build leaves the field None, so a stale view can't carry over.- The human-written summary is now filled in, and the description's Solution 2 and NOTE describe b76a3a8.
Not verified: no GPU or vLLM install. The claim that vLLM 0.34 pads an idle rank's dummy to min(num_tokens, max_num_reqs) one-token requests rests on the author's reading. The GB300 DP test at b76a3a8 is the check of record.
Summary (human-written)
By @wwwjn
Some changes in V1 -> V2 runner that we adopted:
input_batch.max_query_lento infer the reply cudagraph type that is the same when captureAgent details
TLDR: vLLM 0.34 removed its V1 model runner. The generator now runs on the V2 runner, and RL installs vLLM 0.34.0. It keeps FULL CUDA graphs for mixed steps plus separate FULL graphs for decode steps. Trainer-vs-generator parity stays bitwise in batch-invariant mode on GB300.
The image's code box shows an earlier mechanism. GDN/KDA now read the replayed graph's query length from
InputBatch.max_query_len(Solution 2); which graph each batch replays is unchanged.The top of a native stack. The PRs below land the pieces that also run on vLLM 0.33: the Dist-MoE padding mask from vLLM's forward context, and the batch-invariant patches for V2's sampler. This PR also sets
vllm_versionto 0.34.0 (install_rl_env.sh, andvalidate_release_gpu.ymltwice), the first release without the V1 runner: neither change works alone. Please add theciflow/rlandciflow/b200tags before merging. They no longer run the H100 and B200 GRPO suites (see NOTE).Problem
VLLM_USE_V2_MODEL_RUNNER=0.Solution
TorchTitanCudaGraphManager: under FULL, also capture the decode graphs vLLM builds forFULL_DECODE_ONLY. vLLM's own dispatch already tries decode graphs first. vLLM builds its manager ininitialize_kv_cachewith no factory, so the runner rebuilds it there with the arguments read off vLLM's manager. vLLM's memory estimate stays on vLLM's own manager. The worker builds the runner in_make_model_runner.TorchTitanGPUModelRunner.prepare_inputs: on a FULL mixed-graph replay of a hybrid model, setInputBatch.max_query_lento the query length vLLM captured that graph with (max_query_len or num_tokens). GDN/KDA take the single-token path only when it is 1, as at capture.max_query_lenis vLLM's own field for a graph that promises a longer query; vLLM sets it only for adaptive verification today (TODO).prepare_inputs. vLLM pads it to one-token requests, so GDN/KDA build single-token metadata while a mixed graph replays. The first group's capture build stages the packed buffers anyway (stage_packed); later groups now stage them too (packed_query_start_locinupdate_block_table).get_linear_attention_metadata: it returns None only when no linear-attention layer has metadata, as in vLLM's kernel-autotune dummy runs. Otherwise a layer without metadata raisesRuntimeErrornaming it.VLLM_MOE_SKIP_PADDING=0: V2 then stops rewriting the forward context's padding mask, which Dist-MoE reads.max_num_seqsfor decode graphs; the sizes don't change), and MLA's post-load hook takes no argument. vLLM 0.34's prefix-cache map holds block IDs (duplicates in_dup_ids), so the CPU offload connector'srelease_session_cachelooks blocks up by ID._dummy_run, the capture-memory filter, the replayed-graph hook), the dispatcher, and theVLLM_USE_V2_MODEL_RUNNER=0lines.keep_prefix_cached_image_dataand its test: its TODO asked to delete it on V2. vLLM 0.34's scheduler re-sends a resumed request in full, like a new one, so a preempted image request no longer resumes without its image data._maybe_get_memory_pool_contextoverride: the engine setsenable_cumem_allocator=False, so vLLM returns a no-op context for every tag. (vLLM's sleep mode would turn the allocator back on; no recipe or test sets it.)_FlashAttentionPageSize(was_FA4PageSize): batch-invariant FA3 on H100 gets exactly 16-token kernel pages, as batch-invariant FA4 on GB300 already did. With vLLM 0.34's larger pages, FA3 sums a long prefill's keys in 128-key tiles and decode's in 96-key tiles (see NOTE).registry.attention_kv_cache_block_sizeis nowflex_attention_kv_cache_block_sizeand returns only pinned flex'sBLOCK_N.gpu_memory_limit's docstring says the rest of the GPU must hold what weight sync allocates through torch after the engine starts, one FSDP group at a time: the group's shards, plus FSDP's all-gather buffer (the whole group) when the FSDP degree is above 1. vLLM 0.34 sizes the KV cache from measured memory, then caps torch's allocator at what torch holds after warmup, plus about that rest.worker_cls="auto"). Main's XPU worker (main a75b09a) subclassed the V1 runner to reuse TorchTitan's overrides. On V2 those overrides only add FULL decode graphs, and XPU runs without CUDA graphs.Results
The GPU rows ran before the split, on the same code, on vLLM main cf5cea2da. The Test plan has the runs on vLLM 0.34.0. Some ran on local commits from before the last review rounds, which changed where the graph manager reads its arguments (same values), names, error checks and comments. The Kimi K3 RL row ran the whole path at the end.
You may ask:
FULL_AND_PIECEWISE? On mixed steps it runs attention outside the graph, through breakable CUDA graphs. This PR keeps today's FULL behavior: mixed steps replay one FULL graph. Comparing the two on an RL step is a follow-up.decode_query_len, nodecode_max_reqsor_decode_descs), and it lacks the split capture-size fields. That would be a second implementation, deleted at the 0.34 bump.vllm/v1/worker/gpu/model_runner.py:1426-1438). Only a fresh 1-token prompt counts as prefill: then vLLM replays the packed mixed graph. Packed kernels are not guaranteed bitwise equal to the decode kernels;test_gdn_cudagraph.py's batch-invariant arm happened to match for that step. RL prompts are never 1 token.NOTE:
invalid packed cu_seqlensin an idle rank's dummy replay of a mixed graph. Later GDN groups read the previous step's offsets (Solution 2). Before 6b83b0e, theprepare_attnhook marked these dummy builds packed. H100 CI runs FLA kernels, which don't check the offsets. b76a3a8 fixes it;test_update_block_table_stages_packed_buffers_of_a_dummy_runfails without it.bit_wise/logprob_diff/max0.089, 0.097 and 0.13 for Kimi K3 at steps 1-3; B200 logs 0. FA3's tile table likely explains it: the trainer's unpaged FA3 call gets 128-key tiles and the generator's paged calls 96. This PR keeps it at about 0.1: its H100 CI logs 0.090, 0.14 and 0.11 at 9aa2faf, and 0.064, 0.11 and 0.082 at 0c6b961. Its rollouts differ from main's (V2 samples other tokens), so the steps don't compare one to one. vLLM 0.33.0 at 240-token pages also used 96-key tiles. The parity test can't see it: its prompts are 64 tokens. A TODO in_FlashAttentionPageSizeandBITWISE_PARITY.mdnow name it.--assert-equal) againsttests/assets/losses/rl_grpo_cuda.txt. V2 draws each token with its own seeded Gumbel-max kernel (V1 used torch'sexponential_noise), so the rollouts change from step 1. This PR commits the losses the guard printed on CI as the new golden. The PR below (vLLM 0.33.0, V1 runner, same torch nightly) passed the old golden in the same CI run. At 1496fc9 the guard (RL Integration Tests) passes with the new golden:All losses match.DP adjusted local rank 3 is out of bounds for 3 devicesat vLLM engine init. Main at 4122eaf failed this way ondgxb200-06-1002and passed ondgxb200-07-1002. Since 11-17, RL B200 failed 19 of 20 first-attempt jobs on runner 06 (the one pass didn't run this flavor) and passed 21 of 21 on runner 07. On this PR it failed at 738de7c (runner 06) and passed at 1496fc9 (runner 07).rl_h100,rl_b200): since main ccb2b1c, merged in here, they run daily on main or by manual dispatch. The A10G RL suite still runs onciflow/rl. The H100 and B200 GRPO rows in the Test plan ran at 0c6b961, before that merge.vllm/platforms/xpu.py:264-268). A CPU check with the device type forced to XPU:TORCHTITAN_WORKER_CLSis"auto", which vLLM's XPU platform resolves to itsXPUWorker(vllm/platforms/xpu.py:450-451).TestBitwiseParityMoEEPfails at setup on main too, before any generator code. Its recipe'shf_assets_pathis the relativetests/assets/tokenizer, which the checkpointer rejects, and that folder has no weights. No CI job runs it. The row above ran a local subclass withsync_weights_from_trainer = True.Follow up / TODO
sync_weights_from_trainer = TrueonTestBitwiseParityMoEEPso it runs as written, then add it to a CI job.TorchTitanCudaGraphManager;max_query_lenfor FULL mixed-graph replays: deletes theprepare_inputsoverride;_FlashAttentionPageSize). Then assertbit_wise/logprob_diff/max == 0in batch-invariant integration tests, and raise the Kimi K3 parity test's prompt length above 96.TorchTitanCudaGraphManagerbetweentest_generator.pyandtest_gdn_graph_metadata.py.Test plan
python -m pytest tests/rl/unit_tests/cpu tests/rl/unit_tests/gpu/test_gdn_graph_metadata.pypython -m pytest tests/rl/unit_tests/gpu -m "not multi_gpu" -rstorchrun --nproc-per-node=1 -m pytest tests/rl/unit_tests/gpu/test_generator_dist_moe_mxfp8.pytorchrun --nproc-per-node=1 -m pytest tests/rl/unit_tests/gpu/test_bitwise_parity.py::TestBitwiseParityKimiK3DebugVarlenHF_ASSETS_PATH=<Qwen3-0.6B> torchrun --nproc-per-node=2 -m pytest tests/rl/unit_tests/gpu/test_bitwise_parity.py::TestBitwiseParityVarlen, then::TestBitwiseParityFlextorchrun --nproc-per-node=2 -m pytest tests/rl/unit_tests/gpu/test_bitwise_parity.py::TestBitwiseParityQwen35DebugVarlentorchrun --nproc-per-node=2 -m pytest tests/rl/unit_tests/gpu/test_generator_dp_cudagraph.py::test_vllm_dp_decode_graphs_with_prefilling_peer, then::test_vllm_dp_linear_attention_full_graphstorchrun --nproc-per-node=4 -m pytest tests/rl/unit_tests/gpu/test_generator_uneven_decode.pypython -m tests.integration_tests.run_tests <out> --ngpu 4 --test_suite rl_h100TestBitwiseParityMoEEPwithsync_weights_from_trainer = True(4 GPUs); a 5-step RL smoke, a 2-GPU copy ofrl_grpo_qwen3_5_debug_varlenwith FULL graphs.GB300 (fair-cw), torch 2.17.0.dev20261201, vLLM 0.34.0, 2026-12-01:
At b76a3a8,
tests/rl/unit_tests/cpuon vLLM 0.34.0: 779 passed, 8 skipped;test_gdn_graph_metadata.py: 20 passed, 1 skipped. At 533ad4e (FA2 pages on the attention backend), A100: Varlen bitwise parity 3 passed, Qwen3.5 debug bitwise parity 5 passed.Runs on vLLM 0.34.0, 2026-11-20 and 21: local rows on torch 2.16.0.dev20261119, CI rows on dev20261120. After 9aa2faf the commits change docstrings, merge main (last: a75b09a) and select vLLM's own worker on XPU (Solution 9). The GRPO rows ran at 0c6b961 (see NOTE):