Skip to content

[rl] generator: run on vLLM's model runner V2 (vLLM 0.34) - #5956

Open
felipemello1 wants to merge 40 commits into
felipemello1/vllm-v2/2-sampler-patchesfrom
felipemello1/vllm-v2/3-v2-runner
Open

felipemello1 wants to merge 40 commits into
felipemello1/vllm-v2/2-sampler-patchesfrom
felipemello1/vllm-v2/3-v2-runner

Conversation

@felipemello1

@felipemello1 felipemello1 commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human-written)

By @wwwjn
Some changes in V1 -> V2 runner that we adopted:

  • Implement TorchTitanGPUModelRunner
  • v1: Cudagraph Dispatcher -> v2: Cudagraph manager
  • Tell GDN / KDA kernel which cudagraph is currently replaying: Use input_batch.max_query_len to infer the reply cudagraph type that is the same when capture
  • V2 sampler using a new triton kernel, so our golden loss changed

Agent 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.

Which FULL graph each batch replays on vLLM's V2 runner. Stock V2 replays a packed mixed graph for decodes while GDN/KDA build single-token metadata. This PR adds decode graphs and tells GDN/KDA when the replayed graph is packed.

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_version to 0.34.0 (install_rl_env.sh, and validate_release_gpu.yml twice), the first release without the V1 runner: neither change works alone. Please add the ciflow/rl and ciflow/b200 tags before merging. They no longer run the H100 and B200 GRPO suites (see NOTE).

                          V1 runner (before)                       V2 runner (this PR)
FULL decode graphs        TorchTitanCudagraphDispatcher             TorchTitanCudaGraphManager
GDN/KDA replayed graph    runner override                           TorchTitanGPUModelRunner.prepare_inputs
runner install            module-attribute swap                     Worker._make_model_runner

Problem

  1. The generator subclasses vLLM's V1 runner, worker and CUDA-graph dispatcher, and forces V1 with VLLM_USE_V2_MODEL_RUNNER=0.
  2. vLLM 0.34 deleted the runner and the dispatcher, and refuses to start with that variable set to 0.
  3. V2 has no mode with FULL graphs for both mixed and decode steps: in FULL, 4 decodes replay the 4-token mixed graph. GDN/KDA then run their packed kernels for decodes. FA4 decode attention runs 1.3-2.0x longer in a mixed graph than in a decode graph, from 32 sequences at head dim 64 and from 64 at head dim 128 (GB300, 16-token pages).
  4. V2 tells the attention builders only the graph mode, not which graph replays. GDN/KDA must build the path the graph was captured with.

Solution

  1. TorchTitanCudaGraphManager: under FULL, also capture the decode graphs vLLM builds for FULL_DECODE_ONLY. vLLM's own dispatch already tries decode graphs first. vLLM builds its manager in initialize_kv_cache with 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.
  2. TorchTitanGPUModelRunner.prepare_inputs: on a FULL mixed-graph replay of a hybrid model, set InputBatch.max_query_len to 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_len is vLLM's own field for a graph that promises a longer query; vLLM sets it only for adaptive verification today (TODO).
    • An idle DP rank's FULL dummy run skips 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_loc in update_block_table).
  3. GDN/KDA share 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 raises RuntimeError naming it.
  4. Dist-MoE init raises if VLLM_MOE_SKIP_PADDING=0: V2 then stops rewriting the forward context's padding mask, which Dist-MoE reads.
  5. vLLM 0.34's APIs: capture sizes use the split fields (token counts for mixed graphs, request counts up to max_num_seqs for 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's release_session_cache looks blocks up by ID.
  6. Deleted: the V1 runner overrides (_dummy_run, the capture-memory filter, the replayed-graph hook), the dispatcher, and the VLLM_USE_V2_MODEL_RUNNER=0 lines.
    • keep_prefix_cached_image_data and 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.
    • The worker's _maybe_get_memory_pool_context override: the engine sets enable_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.)
  7. _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).
    • FA2 (GPUs older than SM90) and ROCm: 256-token kernel pages, which the engine used to set as the block size. registry.attention_kv_cache_block_size is now flex_attention_kv_cache_block_size and returns only pinned flex's BLOCK_N.
  8. 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.
  9. On XPU the generator now uses vLLM's own worker (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.
  10. Unchanged: graph modes, attention backends apart from the FA3 page size, the session KV holder, weight sync.

Results

Numerics (GB300): bitwise parity tests pass (trainer == generator: Varlen, Flex, Qwen3.5 debug, Kimi K3, MoE EP).
                  Kimi K3 batch-invariant RL: logprob diff max 0 at steps 1-3.

vLLM main at cf5cea2da (an ancestor of v0.34.0, 41 commits before it), V2 runner, GB300
check                                              GPUs  result
test_gdn_cudagraph.py (GDN FULL vs eager)          1     4 passed (regular and batch-invariant)
RL smoke: Qwen3.5 debug, 5 steps, temperature 0.8  2     exit 0; new weights every step; logprob diff max 0.00986
Flex bitwise parity                                2     3 passed
rl_h100: Kimi K3 batch-invariant, 3 steps          4     logprob diff max 0
GPU unit tests, -m "not multi_gpu"                 1     29 passed, 1 failed: the MXFP8 test needs torchrun (next row)
Dist-MoE MXFP8 test under torchrun, FULL graphs    1     1 passed
Kimi K3 bitwise parity                             1     4 passed
NONE mode with local compile, dense and MoE        1     eager vs compiled: 24/24 requests match; no recompile-limit error
uneven decode, TP4 EP4, eager                      4     passed on 4 ranks
uneven decode, DP2 TP2 EP4, local copy             4     passed on 4 ranks
Dist-MoE DP2 TP2 EP4, FULL graphs, uneven DP load  4     passed on 4 ranks
MoE EP bitwise parity, local copy                  4     3 passed (see NOTE)
Varlen bitwise parity                              2     3 passed
Qwen3.5 debug bitwise parity                       2     5 passed
DP decode graphs with a prefilling peer            2     passed
DP linear attention with FULL graphs               2     passed
rl_h100: DeepSeek V3, 3 steps                      4     passed

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:

  • Why not 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.
  • Why not also run on vLLM 0.33? Its V2 graph manager has a different internal API (one decode_query_len, no decode_max_reqs or _decode_descs), and it lacks the split capture-size fields. That would be a second implementation, deleted at the 0.34 bump.
  • Batch-invariant mode, a decode next to a 1-token first step? A prefix-cached copy of a prompt (its first step is 1 token over cached context) counts as a decode in vLLM, so the batch replays a decode graph (vLLM 0.34.0 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:

  • At 00da2cb, GB300's DP linear attention test failed: warpdrive's GDN prefill kernel asserted invalid packed cu_seqlens in an idle rank's dummy replay of a mixed graph. Later GDN groups read the previous step's offsets (Solution 2). Before 6b83b0e, the prepare_attn hook 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_run fails without it.
  • The local GPU rows ran on GB300. CI's A10G, H100 and B200 jobs are the first runs of vLLM 0.34.0 on x86_64.
  • vLLM 0.34 raises the default KV block size from 16 to 64. H100 varlen attention and compressed MLA now use 64-token pages outside batch-invariant mode (GB300 FA4 uses 128). A hybrid model's block is rounded up to hold its linear-attention state: Kimi K3's went from 240 tokens (vLLM 0.33.0) to 256.
  • At 1496fc9, CI's H100 Kimi K3 parity failed decode vs 2nd-pass prefill: max_delta 3.89e-02, 95 of 128 logprobs differ. 33 match, as many as see at most 96 keys, FA3's key tile without TMA. A 256-token page is a multiple of 128, so FA3 gave the 192-token prefill 128-key TMA tiles. Batch-invariant FA3 now uses 16-token kernel pages. CI's H100 Kimi K3 parity passes at 9aa2faf, 0c6b961 and 7445dcb: 4 passed, decode vs prefill included.
  • Main already has a gap on H100 at head dim 192 (Kimi K3's MLA). Batch-invariant trainer and generator logprobs differ there: main's H100 CI logs bit_wise/logprob_diff/max 0.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 _FlashAttentionPageSize and BITWISE_PARITY.md now name it.
  • The A10G RL loss guard compares losses exactly (--assert-equal) against tests/assets/losses/rl_grpo_cuda.txt. V2 draws each token with its own seeded Gumbel-max kernel (V1 used torch's exponential_ 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.
  • First CI run on vLLM 0.34.0 (738de7c): RL CPU failed 6 new graph-manager tests, because a host with no GPU gets a vLLM platform with no CUDA graph pool; the tests now stub it.
  • RL B200's Dist-MoE DP2 TP2 EP4 flavor fails on one CI runner, whatever the PR: DP adjusted local rank 3 is out of bounds for 3 devices at vLLM engine init. Main at 4122eaf failed this way on dgxb200-06-1002 and passed on dgxb200-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).
  • PR CI no longer runs the 3-step H100 and B200 GRPO suites (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 on ciflow/rl. The H100 and B200 GRPO rows in the Test plan ran at 0c6b961, before that merge.
  • XPU: not run (no XPU hardware here), and the V2 runner has never run on XPU. As on main, XPU also needs vLLM's XPU platform to accept flex attention; vLLM 0.34.0 still rejects it (vllm/platforms/xpu.py:264-268). A CPU check with the device type forced to XPU: TORCHTITAN_WORKER_CLS is "auto", which vLLM's XPU platform resolves to its XPUWorker (vllm/platforms/xpu.py:450-451).
  • TestBitwiseParityMoEEP fails at setup on main too, before any generator code. Its recipe's hf_assets_path is the relative tests/assets/tokenizer, which the checkpointer rejects, and that folder has no weights. No CI job runs it. The row above ran a local subclass with sync_weights_from_trainer = True.

Follow up / TODO

  • Set sync_weights_from_trainer = True on TestBitwiseParityMoEEP so it runs as written, then add it to a CI job.
  • vLLM changes that delete workarounds here (each TODO names its own):
    • a CUDA-graph mode with FULL graphs for both mixed and decode batches: deletes TorchTitanCudaGraphManager;
    • a method a subclass can override to build the runner's graph manager: deletes the manager rebuild;
    • vLLM setting max_query_len for FULL mixed-graph replays: deletes the prepare_inputs override;
    • a graph-memory estimate that charges each FULL graph at its own size: lets the manager install before the estimate.
  • H100 at head dim 192: one FA3 key tile for trainer and generator (TODO in _FlashAttentionPageSize). Then assert bit_wise/logprob_diff/max == 0 in batch-invariant integration tests, and raise the Kimi K3 parity test's prompt length above 96.
  • Time FULL against FULL_AND_PIECEWISE (breakable graphs) on an RL step.
  • Run GRPO on Intel XPU with the V2 runner: main's XPU support was checked on the V1 runner only.
  • Share one CPU helper for TorchTitanCudaGraphManager between test_generator.py and test_gdn_graph_metadata.py.

Test plan

  • python -m pytest tests/rl/unit_tests/cpu tests/rl/unit_tests/gpu/test_gdn_graph_metadata.py
  • python -m pytest tests/rl/unit_tests/gpu -m "not multi_gpu" -rs
  • torchrun --nproc-per-node=1 -m pytest tests/rl/unit_tests/gpu/test_generator_dist_moe_mxfp8.py
  • torchrun --nproc-per-node=1 -m pytest tests/rl/unit_tests/gpu/test_bitwise_parity.py::TestBitwiseParityKimiK3DebugVarlen
  • HF_ASSETS_PATH=<Qwen3-0.6B> torchrun --nproc-per-node=2 -m pytest tests/rl/unit_tests/gpu/test_bitwise_parity.py::TestBitwiseParityVarlen, then ::TestBitwiseParityFlex
  • torchrun --nproc-per-node=2 -m pytest tests/rl/unit_tests/gpu/test_bitwise_parity.py::TestBitwiseParityQwen35DebugVarlen
  • torchrun --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_graphs
  • torchrun --nproc-per-node=4 -m pytest tests/rl/unit_tests/gpu/test_generator_uneven_decode.py
  • python -m tests.integration_tests.run_tests <out> --ngpu 4 --test_suite rl_h100
  • Local scripts: NONE mode with local compile, eager vs compiled (1 GPU); uneven decode at DP2 TP2 EP4 (4 GPUs); Dist-MoE at DP2 TP2 EP4 with FULL graphs and uneven DP load (4 GPUs); TestBitwiseParityMoEEP with sync_weights_from_trainer = True (4 GPUs); a 5-step RL smoke, a 2-GPU copy of rl_grpo_qwen3_5_debug_varlen with FULL graphs.

GB300 (fair-cw), torch 2.17.0.dev20261201, vLLM 0.34.0, 2026-12-01:

check                                                        GPUs  result
At 00da2cb16:
GPU unit tests, -m "not multi_gpu"                           1     25 passed, 1 failed: the MXFP8 test needs torchrun (next row)
Dist-MoE MXFP8 test under torchrun                           1     1 passed
Kimi K3 bitwise parity                                       1     4 passed
MLA backends                                                 1     1 passed
Varlen bitwise parity                                        2     3 passed
Flex bitwise parity                                          2     3 passed
uneven decode, TP4 EP4, eager                                4     1 passed
rl_h100: Kimi K3 batch-invariant and DeepSeek V3, 3 steps    4     passed (Kimi K3 logprob_diff/max 0 every step)
0.6B dense batch-invariant RL, trainer TP2 + generator TP2,
  5 steps (4-GPU copy of rl_grpo_0_6b_tp4_batch_invariant)   4     logprob_diff/max 0 every step
At b76a3a821 (the DP dummy-run fix):
DP linear attention with FULL graphs                         2     1 passed (failed at 00da2cb16, see NOTE)
DP decode graphs with a prefilling peer                      2     1 passed
Qwen3.5 debug bitwise parity                                 2     5 passed
Qwen3.5 debug batch-invariant RL, TP2, 5 steps               4     logprob_diff/max 0 every step

At b76a3a8, tests/rl/unit_tests/cpu on 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):

check                                                        GPUs  result
At 7445dcb74, CPU:
tests/rl/unit_tests/cpu                                      -     706 passed, 7 skipped
At c501023ac (main 65e88e902: warpdrive GDN/KDA prefill on Blackwell), GB300:
test_gdn_cudagraph.py (regular: warpdrive; batch-invariant:
  fused)                                                     1     4 passed
Kimi K3 bitwise parity                                       1     4 passed
Qwen3.5 debug bitwise parity                                 2     5 passed
CI at 7445dcb74, H100 (rl-kimi-k3 job):
Kimi K3 bitwise parity                                       1     4 passed
DP decode graphs with a prefilling peer                      2     1 passed
DP linear attention with FULL graphs                         2     1 passed
CI at 0c6b961ca, H100 (rl-kimi-k3 job):
rl_h100: Kimi K3 batch-invariant and DeepSeek V3, 3 steps    4     passed
CI at 0c6b961ca, B200 (rl-b200 job):
rl_b200: Kimi K3 batch-invariant, DeepSeek V3, 3 steps       4     passed (Kimi K3
                                                                   logprob_diff/max 0)
rl_b200: Dist-MoE TP2 EP4 (trainer FSDP2, generator DP2)     8     passed
At 7e7626890 (same code as 9aa2faf4b), GB300:
Kimi K3 bitwise parity                                       1     4 passed
Kimi K3 decode vs prefill, FA3's batch-invariant page
  choice with FA4 kernels                                    1     passed (kernel pages 16;
                                                                   seq 0 stopped at 6 tokens,
                                                                   seqs 1-2 compared 128 each)
Rows at 1496fc9f1 (main b1c259cd3; later: the main merge and the FA3 page size):
graph-manager and padding test files on vLLM's no-GPU
  platform (what CPU CI gets)                                -     74 passed
test_gdn_cudagraph.py (regular and batch-invariant)          1     4 passed
GPU unit tests, -m "not multi_gpu", MXFP8 test deselected    1     29 passed
Qwen3.5 debug bitwise parity                                 2     5 passed
GPU rows at 737e798b7 (later commits: docstrings, comments, asserts, the shared padding helper, the CPU-test stub, the golden):
Varlen bitwise parity                                        2     3 passed
DP decode graphs with a prefilling peer                      2     1 passed
DP linear attention with FULL graphs                         2     1 passed
B200 unit tests (Kimi K3 parity, MXFP8 under torchrun, MLA
  backends, Dist-MoE recipe)                                 1     8 passed
uneven decode, TP4 EP4, eager                                4     1 passed
Flex bitwise parity (at 462605eb2)                           2     3 passed

@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude please review

@claude

claude Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

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.

@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: 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

  1. PR description -- the "Summary (human-written)" section is empty. The author needs to fill it in before merge (CONTRIBUTING, "AI-assisted contributions").
  2. 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_metadata turns 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 decode CudaGraphManager doesn't forward varlen_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_profiling returns before model_state.cudagraph_manager is set (worker.py:126). If vLLM's estimate capture ever calls prepare_attn with FULL for a hybrid model, it raises AttributeError on the unset annotation.
  • worker.py:131 discards the manager vLLM just built, and worker.py:61 builds one more manager just to read its candidates. Does either constructor allocate device state? Does anything else built in GPUModelRunner.initialize_kv_cache keep 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.

Comment thread torchtitan/rl/generator/vllm/worker.py Outdated
Comment on lines +48 to +49
TODO: drop this class once vLLM captures FULL decode graphs next to FULL mixed
graphs without piecewise compilation.
graphs.

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.

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.

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: 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 to ModelState.prepare_attn.

Filing these upstream is the author's call, so the TODOs carry no links.

Comment on lines +225 to +226
if self.prefix not in attn_metadata:
return mixed_qkv.new_zeros(output_shape)

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.

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.

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 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_run passes skip_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.

Comment thread torchtitan/rl/generator/vllm/worker.py Outdated
Comment on lines +61 to +68
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,
)

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.

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).

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 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.

@felipemello1
felipemello1 force-pushed the felipemello1/vllm-v2/3-v2-runner branch from 924ded0 to b1839d2 Compare November 8, 2026 22:44
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: answers to the two questions in the review.

(a) Extensible KV cache off.
No run covered the extensible KV cache off. Every RL run logged "Extended KV cache", and TorchTitan never sets num_gpu_blocks_override or kv_cache_memory_bytes. By reading vLLM main, the AttributeError can't happen:

  • With it off, profile_cudagraph_memory calls initialize_kv_cache(..., is_profiling=True) (cudagraph_utils.py:1129), where we return before setting the manager, and then captures.
  • Capture calls prepare_attn with CUDAGraphMode.NONE (cudagraph_utils.py:966-968), and we read cudagraph_manager only for FULL.
  • FULL replays start after the real initialize_kv_cache, which sets it.

(b) Device state and references to vLLM's manager.
Neither manager allocates device memory. CudaGraphManager.__init__ stores config, descriptor tables and the shared global graph-pool handle (cudagraph_utils.py:166-234). Graphs are captured later, and only by the installed manager. In initialize_kv_cache (model_runner.py:637-830), only FastPrefillHelper keeps vLLM's manager (:805-807), and only with kv_sharing_fast_prefill, which no TorchTitan model uses. The speculator builds its own manager from the mode (:821). The ubatch runner is built before the manager (:760). The dispatch path reads self.cudagraph_manager at call time (:1878-1879).

@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude please review again. Fixes are in the new commits; each of your comments has a reply in its thread.

@claude

claude Bot commented Nov 8, 2026 •

Copy link
Copy Markdown
Contributor

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

@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: 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 no TorchTitanLinearAttentionMetadata is present, and anything else raises. The CPU tests cover both layers.
  • worker.py:68: the inner FULL_DECODE_ONLY manager now gets varlen_decode, as the rebuild at :145 does.
  • Question on the extensible KV cache being off: answered. The estimate captures through prepare_attn with CUDAGraphMode.NONE, so the unset cudagraph_manager is 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 with kv_sharing_fast_prefill, which no TorchTitan model uses.

Must fix (still open)

  1. PR description: the "Summary (human-written)" section is still empty. The author fills it in (CONTRIBUTING, "AI-assisted contributions").
  2. 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.

felipemello1 added a commit that referenced this pull request Nov 8, 2026
…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]>
@felipemello1
felipemello1 force-pushed the felipemello1/vllm-v2/3-v2-runner branch from b1839d2 to 84307fb Compare November 8, 2026 23:05
@felipemello1
felipemello1 removed this pull request from stack #5957 November 8, 2026 23:54
@felipemello1
felipemello1 force-pushed the felipemello1/vllm-v2/3-v2-runner branch from 84307fb to 227158b Compare November 8, 2026 23:54
@felipemello1
felipemello1 added this pull request to stack #5965 November 8, 2026 23:54
@felipemello1
felipemello1 removed this pull request from stack #5965 November 9, 2026 03:04
@felipemello1
felipemello1 changed the base branch from felipemello1/inference-graph-sizes/3-vllm-main-compat to felipemello1/rl/vllm-033-override November 9, 2026 03:04
@felipemello1
felipemello1 added this pull request to stack #5968 November 9, 2026 03:04
@felipemello1
felipemello1 force-pushed the felipemello1/vllm-v2/3-v2-runner branch from 227158b to ea18a30 Compare November 9, 2026 03:07
@felipemello1
felipemello1 removed this pull request from stack #5968 November 9, 2026 03:49
@felipemello1
felipemello1 force-pushed the felipemello1/vllm-v2/3-v2-runner branch from ea18a30 to af6111f Compare November 9, 2026 03:50
@wwwjn wwwjn changed the title [rl] generator: run on vLLM's model runner V2 (vLLM 0.34) [WIP] [rl] generator: run on vLLM's model runner V2 (vLLM 0.34) Dec 2, 2026
…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.
@wwwjn

wwwjn commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

from claude: @claude review

@claude

claude Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @wwwjn's task in 5m 39s —— View job


Approve -- please address the items before merging (the PR description still describes the deleted TorchTitanHybridModelState; 6b83b0e replaced it with a prepare_inputs override): review. A maintainer still needs to review.

@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: 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) sets InputBatch.max_query_len to the graph's captured value. The GDN/KDA builder's own max_query_len == 1 rule then picks the captured path. This deletes replays_packed_graph, last_dispatched_descriptor, TorchTitanHybridModelState and the get_model_state_cls override.
  • 533ad4e: the FA2 256-token rule moves from the engine's block_size to _FlashAttentionPageSize. attention_kv_cache_block_size becomes flex_attention_kv_cache_block_size.
  • 499fb73: release_session_cache reads 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

  1. 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 to ModelState.prepare_attn: deletes TorchTitanHybridModelState", and the human summary ("Use ModelState.prepare_attn") all need updating. They should name TorchTitanGPUModelRunner.prepare_inputs setting InputBatch.max_query_len, with its TODO ("vLLM sets max_query_len for 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_inputs runs 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 captured max_query_len? The old prepare_attn hook 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_len too. Under FULL replay the kernel launches come from capture, so only tensors the builders compute change. MLA's _build_decode recomputes the longest query from query_start_loc_cpu (mla.py:111-118), and a max_query_len of n stays under its 512 decode threshold, or falls back to the real query lengths above it. The varlen impl reads max_query_len only in Python, and Python doesn't run on replay.
  • Overlap: the MTP stack (#6473-#6479) edits worker.py and linear_attention.py on 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-b200 failure 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.

Comment on lines +91 to +92
if flash_impl is None:
return [MultipleOf(256)]

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.

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:

Suggested change
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).

@wwwjn wwwjn changed the title [WIP] [rl] generator: run on vLLM's model runner V2 (vLLM 0.34) [rl] generator: run on vLLM's model runner V2 (vLLM 0.34) Dec 2, 2026
@wwwjn
wwwjn marked this pull request as ready for review December 2, 2026 02:08
@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Dec 2, 2026
@github-actions
github-actions Bot requested review from liangel-02 and pzhan9 December 2, 2026 02:08
@wwwjn wwwjn changed the title [rl] generator: run on vLLM's model runner V2 (vLLM 0.34) [WIP] [rl] generator: run on vLLM's model runner V2 (vLLM 0.34) Dec 2, 2026
@wwwjn

wwwjn commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

from claude: replies to the last review (posted here because a pending review on this PR blocks in-thread replies):

  • attention.py:92, ROCm: ROCm doesn't change. The removed check was has_cuda_capability(9, 0), which is False on ROCm (torch.version.hip is None, torchtitan/tools/utils.py:35), so the engine already set block_size=256 there. add9b61 says so in the docstring's FA2 row.
  • Description: updated for prepare_inputs / InputBatch.max_query_len, 533ad4e (FA2 pages on the backend) and 499fb73 (block-ID cache).
  • DP dummy step: it doesn't go through prepare_inputs. vLLM 0.34 builds it with InputBatch.make_dummy and prepare_attn(..., for_capture=True) for a FULL replay (vllm/v1/worker/gpu/model_runner.py:2035-2045), which calls the builders' build_for_cudagraph_capture. Ours builds with stage_packed=True, staging the packed path's buffers as well as the single-token ones, so either captured path reads valid inputs.
  • _dup_ids[key] includes the first block ID: BlockHashToBlockMap.insert seeds it with _cache[key] on the first duplicate (self._dup_ids.setdefault(key, {block_id: None})[block.block_id] = None, vllm/v1/core/block_pool.py:82).

@wwwjn

wwwjn commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

from claude: @claude review

@claude

claude Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

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.

@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: 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 _FlashAttentionPageSize table (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 was has_cuda_capability(9, 0), and that check returns False whenever torch.version.hip is set (torchtitan/tools/utils.py:31-37). So on main the engine already set block_size=256 on 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_inputs setting InputBatch.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_attn mechanism.
  • 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_dummy and prepare_attn(..., for_capture=True), which calls build_for_cudagraph_capture. Ours stages both paths' buffers (stage_packed=True).
  • Question on _dup_ids: answered. BlockHashToBlockMap.insert seeds _dup_ids[key] with the first block ID, so release_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

  1. worker.py (the TorchTitanCudaGraphManager class TODO, the two TODOs in initialize_kv_cache, and the prepare_inputs TODO) and attention.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.

@wwwjn wwwjn changed the title [WIP] [rl] generator: run on vLLM's model runner V2 (vLLM 0.34) [rl] generator: run on vLLM's model runner V2 (vLLM 0.34) Dec 2, 2026
…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.
@wwwjn

wwwjn commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

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 min(num_tokens, max_num_reqs) requests, often one token each, so the metadata is single-token while a mixed graph replays, and update_block_table copied the packed offsets to later groups only for packed metadata. On GB300, warpdrive's check caught it in test_vllm_dp_linear_attention_full_graphs at 00da2cb (invalid packed cu_seqlens); it passed at cec6892, before 6b83b0e. b76a3a8 carries the staged offsets in the metadata (packed_query_start_loc) and later groups stage them whenever the first group did; a new CPU test fails without it. GB300 at b76a3a8: the DP test, Qwen3.5 parity and Qwen3.5 batch-invariant RL (logprob diff 0) pass. Description updated.

@wwwjn

wwwjn commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

from claude: @claude review

@claude

claude Bot commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @wwwjn's task in 1m 33s —— View job


Approve -- please address the item before merging (the vLLM/FA3-workaround TODOs still have no upstream issue links; b76a3a8's DP dummy-run fix is correct): review. A maintainer still needs to review.

@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: 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_loc is set whenever _stage_decode_split runs. That covers a packed build and also a stage_packed capture or dummy build, even when that build is single-token.
  • linear_attention.py:327-340: update_block_table now restages query_start_loc and the decode split whenever the first group staged them. Before, it did this only when execution_path is PACKED. The returned non_spec_query_start_loc still 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)

  1. The vLLM/FA3-workaround TODOs have no upstream issue links. They are in worker.py (TorchTitanCudaGraphManager, both initialize_kv_cache TODOs, prepare_inputs) and attention.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_drafts next to this update_block_table. Whichever PR lands second has to keep the packed_query_start_loc restaging 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_loc views the first builder's own query_start_loc. Nothing writes that buffer between that group's build and the later groups' update_block_table in 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.

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/b200 Trigger B200 CI ciflow/fake-pg Run 1-GPU Fake PG integration tests 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.

3 participants