Skip to content

[rl] generator: vLLM 0.33 API fixes and TP padding in the model wrapper - #5498

Open
felipemello1 wants to merge 26 commits into
mainfrom
felipemello1/inference-graph-sizes/3-vllm-main-compat
Open

felipemello1 wants to merge 26 commits into
mainfrom
felipemello1/inference-graph-sizes/3-vllm-main-compat

Conversation

@felipemello1

@felipemello1 felipemello1 commented Oct 18, 2026 •

Copy link
Copy Markdown
Contributor

Summary (human-written)

By @wwwjn

  • vllm wrapper adaption to vllm 0.33.

  • For eager EP padding for router SP is still needed for our vllm wrapper, to keep eager decoding odd tokens working as before. (vLLM native model do this padding in model code self.experts, but for us, our training path will not hit this so it still make sense to put it in vllm wrapper)

    • The wrapper now pads eager steps to a multiple of TP when EP is on. Before, our V1 runner subclass did this by overriding vLLM's _pad_for_sequence_parallelism hook, before the model forward. vLLM 0.33 removed that hook, and the V2 runner never had it: it pads only to CUDA-graph sizes and leaves eager steps unpadded.
  • Another difference between V1 and V2 runner is: in V2, num_tokens_across_dp in forward context is not padded to TP degree when exchanging between DP ranks.

Agent details

TLDR: vLLM changed six things the generator uses outside its model runner (five in vLLM 0.33, the KV block size on vLLM main), and vLLM 0.33 removed the V1 runner's hook that padded eager steps to a multiple of TP. This PR adapts the generator to those changes and moves the TP padding into the model wrapper. Nothing here is V1 work: the vLLM 0.33 install above needs all of it with either runner, and the V2 port at the top of this stack builds on it.

TP 4, EP 4, eager decode of 3 tokens. Before, the pinned nightly's V1 runner pads the step to 4 rows. vLLM 0.33's V1 runner and the V2 runner have no such hook, so 3 rows don't split over 4 TP ranks and every rank crashes. This PR pads in the model wrapper, in the image-prompt forward too, marks the extra row as Dist-MoE padding and returns 3 rows. Below: the 7 vLLM API fixes, by where each breaks the generator.

The image predates two changes: the Scheduler.skipped_waiting fix moved to #5967 (with #6389's KV offload change), so this PR has six API fixes, and the block-size helper is registry.attention_kv_cache_block_size.

The bottom of a native stack, based on main. The PRs above it install vLLM 0.33.0, move the Dist-MoE padding mask and the V2 sampler patches, then port the generator to V2.

TP 4, EP 4, eager decode of 3 tokens
before:  the V1 runner pads the step to 4 tokens (_pad_for_sequence_parallelism)
after:   VLLMModelWrapper.forward pads input_ids and positions to 4 rows, marks row 3 as padding for Dist-MoE, and returns 3 rows

Problem

  1. Changed APIs. vLLM 0.33 removed PassConfig.enable_sp, FlashAttentionMetadata.use_cascade and the PretrainedConfig re-export. It also removed vllm.utils.torch_utils.is_quantized_kv_cache, which now lives only in vllm.v1.kv_cache_interface.
  2. Each one fails on vLLM 0.33: at import (PretrainedConfig, is_quantized_kv_cache), at config validation (PassConfig) or on the first forward (cascade).
  3. Two more. vLLM 0.33 passes the KV cache spec to get_supported_kernel_block_sizes, which our MLA backend doesn't take: DeepSeek V3 crashes at KV-cache init. vLLM main (0.34) also raises the default KV block size from 16 to 64. vLLM's flex backend tiles keys by the block size, so batch-invariant flex (trainer BLOCK_N pinned to 16) no longer matches the trainer: prefill logprob max delta 0.10 (TestBitwiseParityFlex, Qwen3-0.6B, V2 runner on vLLM main).
  4. Padding. With EP, the MoE splits its tokens evenly over TP. On the current pin, the V1 runner rounds eager steps up with _pad_for_sequence_parallelism. vLLM 0.33's V1 runner removed that hook, and the V2 runner never had it, so each eager step runs at its own size. A 3-token eager decode at TP4 EP4 then crashes all ranks.

Solution (each fix runs on the current pin and on vLLM 0.33)

  1. Delete InferenceParallelismConfig.enable_sequence_parallel (default False) and the PassConfig it turned on: vLLM 0.33 removed PassConfig.enable_sp, and SGLang already rejected the field. to_training() passes enable_sequence_parallel=False, since ParallelismConfig defaults it to True. No recipe sets it.
  2. Import PretrainedConfig from transformers, in the registry and in the image-prompt wrapper's test.
  3. Drop the cascade assert. Cascade attention is off by default on the pin and gone on main.
  4. Import is_quantized_kv_cache from vllm.v1.kv_cache_interface, which exists on both.
  5. The MLA backend's get_supported_kernel_block_sizes takes an optional KV cache spec.
  6. One block-size rule, registry.attention_kv_cache_block_size, next to vllm_attention_backend: BLOCK_N for pinned flex (nested in MLA too), 256 for FA2 as before, else vLLM's default. VLLMEngine (which generate.py builds through) and the bitwise parity test call it.
    • On SM90 and newer, the pin's default is already 16, so nothing changes.
    • On older GPUs (A100), three sizes change: VLLMEngine and generate.py with batch-invariant flex go 256 -> 16, and the parity test with unpinned flex goes vLLM's default -> 256, as in the engine.
  7. VLLMModelWrapper._pad_for_expert_sequence_parallel rounds the step's tokens and positions up to a multiple of TP when EP is on, and forward drops the extra rows from its output. Attention reads only the real rows (its metadata's token count). The Dist-MoE mask marks the extra rows as padding, and the Dist-MoE call size is the largest DP replica's token count rounded up to a multiple of TP, over TP (vLLM syncs the DP counts before the wrapper pads). It replaces TorchTitan's override of vLLM's _pad_for_sequence_parallelism, which vLLM 0.33 removed, and the GDN comments now point at this padding.
    • The image-prompt wrapper's forward (VLLMMultimodalModelWrapper) calls the same helper on inputs_embeds and its M-RoPE positions.
  8. Dist-MoE with TP > 1 needs EP > 1: wrapper init raises ValueError with both degrees otherwise. Dist-MoE splits each step's tokens over TP, but the wrapper pads to a multiple of TP only with EP. No recipe runs Dist-MoE at TP > 1 with EP 1.
  9. Unchanged: the V1 runner and VLLM_USE_V2_MODEL_RUNNER=0, the MoE, and capture sizes (still multiples of TP, so the wrapper never pads a graph).

Results

Numerics: bitwise parity tests pass (trainer == generator).

pinned nightly (V1 runner), GB300                  GPUs  ran on       result
tests/rl/unit_tests/cpu                            -     88d872bb3    566 passed, 7 skipped
Dist-MoE MXFP8 test under torchrun                 1     ee9b60f2b ‡  1 passed: a real Dist-MoE engine passes the EP check
Flex bitwise parity                                2     00c923460 †  3 passed
rl_h100: DeepSeek V3 (MLA), 3 steps                4     00c923460 †  passed
GPU unit tests, -m "not multi_gpu"                 1     7c745459e *  27 passed, 1 failed: the MXFP8 test needs torchrun (row 2)
uneven decode, TP4 EP4, eager                      4     7c745459e *  passed on 4 ranks
uneven decode, DP2 TP2 EP4, local copy             4     7c745459e *  passed on 4 ranks
MoE EP bitwise parity, DP2 TP2 EP4, local copy     4     7c745459e *  3 passed (see NOTE)

The rows ran on earlier heads of this PR (the sha column). Since then main was merged in (last: a75b09a), a code-style pass changed comments, two docstrings and one round-up helper, and a test now calls main's renamed BatchInvariantFlexTransform. The Test plan has the later runs.

‡ ee9b60f2b: an earlier head of this PR.

† 00c923460: also without the Dist-MoE EP check and one MLA comment. The check raises only for Dist-MoE at TP > 1 with EP 1, which no row runs.

* 7c74545: an earlier head of this PR, before the one block-size rule (no change on SM90 and newer) and later review fixes.

You may ask:

  • Is this V1 work? No. vLLM 0.33 already breaks every item above except the block size, whichever runner runs: the vLLM 0.33 install above needs this PR even without the V2 port.
  • Why move the padding here, not in the V2 port? vLLM 0.33's V1 runner already dropped its padding hook. Here, CI's RL GPU job checks it on today's pin (test_generator_uneven_decode.py, TP4 EP4 eager).
  • Why pad in the wrapper, not in the MoE? Only the generator needs it: the trainer's token counts already divide by TP. The V1 runner padded the whole model input the same way, so attention and linear attention already skip the extra rows.
  • Why keep VLLM_USE_V2_MODEL_RUNNER=0? On the current nightly, unset means V2, and the V1 subclasses would break. The V2 port drops it.

NOTE: 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, so the trainer's weights are copied into vLLM.

Follow up / TODO

  • Set sync_weights_from_trainer = True on TestBitwiseParityMoEEP so it runs as written, then add it to a CI job.

Test plan

  • python -m pytest tests/rl/unit_tests/cpu (includes the new test_attention_kv_cache_block_size_matches_pinned_flex_block_n and test_dist_moe_needs_ep_when_tp_splits_tokens)
  • The image-prompt padding test, in the CPU suite: test_vllm_multimodal_wrapper.py::test_forward_pads_the_step_for_expert_sequence_parallel
  • 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=4 -m pytest tests/rl/unit_tests/gpu/test_generator_uneven_decode.py
  • HF_ASSETS_PATH=<Qwen3-0.6B> torchrun --nproc-per-node=2 -m pytest tests/rl/unit_tests/gpu/test_bitwise_parity.py::TestBitwiseParityFlex
  • python -m tests.integration_tests.run_tests <out> --ngpu 4 --test_suite rl_h100 --test_name rl_grpo_deepseek_v3_debug
  • Local copies (4 GPUs):
    • test_generator_uneven_decode.py with the DP2 TP2 EP4 recipe, DP rank 0 decoding 2 tokens and rank 1 decoding 6;
    • TestBitwiseParityMoEEP with sync_weights_from_trainer = True.

At ae28a3a (the field deleted), tests/rl/unit_tests/cpu on the pinned nightly (x86_64 devserver): 856 passed, 2 skipped; the same 7 failures as on main.

At 3bd0dc0 (main 9a03490 merged in), tests/rl/unit_tests/cpu on the pinned nightly (x86_64 devserver): 857 passed, 2 skipped; its 7 failures fail on main there too (local Monarch RDMA and recipe setup).

At f37f26a (main a75b09a merged in), tests/rl/unit_tests/cpu on the pinned nightly: 708 passed, 7 skipped. Earlier runs:

Runs at ab47d00 (main b1c259c merged in), GB300, 2026-11-20:

check                                                GPUs  result
tests/rl/unit_tests/cpu, pinned nightly              -     684 passed, 7 skipped
tests/rl/unit_tests/cpu, vLLM 0.33.0                 -     682 passed, 8 skipped
GPU unit tests, -m "not multi_gpu", pinned nightly   1     27 passed

Merging main conflicted in 3 places: the SGLang engine (main's new HiCache check stays; the deleted SP check stays deleted), and the image-prompt forward and its test (main's forward_embeddings, plus this PR's TP padding).

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 18, 2026
@felipemello1
felipemello1 added this pull request to stack #5496 October 18, 2026 04:22
@felipemello1
felipemello1 force-pushed the felipemello1/inference-graph-sizes/3-vllm-main-compat branch 2 times, most recently from b4f5554 to 6aaa17b Compare November 6, 2026 01:43
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude please review

@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 3m 36s —— View job


Approve, with two small items to fix before merging: see the 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 six fixes are small, run on both vLLM versions, and delete more than they add. The only real logic change, moving the EP TP padding to after vLLM's dispatch, gives the same result as before. A maintainer still needs to review.

What this PR does. It drops the generator's dense-SP knob and its PassConfig. It pads EP steps to a multiple of TP after super()._determine_batch_execution_and_padding returns, instead of in _pad_for_sequence_parallelism, which vLLM main no longer calls. It also switches three imports or calls to APIs that exist on both versions: transformers.PreTrainedConfig, Scheduler.get_request_counts(), and the MLA hook with an optional act_dtype. Finally, it drops the cascade assert.

Example. Eager step, TP 4 + EP 4, 5 scheduled tokens:

before, pin:   vLLM calls _pad_for_sequence_parallelism(5) -> 8, then dispatch(8) -> eager, 8 rows
before, main:  the hook is never called -> 5 rows -> 5 % 4 != 0 in the MoE token split -> SIGABRT
after, both:   dispatch(5) -> eager, batch_descriptor.num_tokens 5 -> 8, num_tokens_across_dp [5, 3] -> [8, 4]

In a graph step the result is the same, because capture sizes are already filtered to TP multiples (config.py:145). So dispatch(5) and dispatch(8) both land on the same capture size, and the rounding is a no-op.

Must fix

  1. tests/rl/unit_tests/cpu/test_generator.py:973 -- test_inference_parallelism_disables_dense_sequence_parallelism now only checks a hardcoded constant. Delete it.
  2. The description says the worker counts waiting requests with Scheduler.get_request_counts(). The diff only changes session_kv_holder.py, and worker.py has no scheduler access. Fix the description.

Should consider

  • tests/rl/unit_tests/cpu/test_session_kv_holder.py:124 -- the stub now adds the two queues itself, so the skipped_waiting parametrize case only checks the stub. Collapse it to one waiting queue.
  • torchtitan/rl/generator/vllm/worker.py:106 -- the class docstring still says "sequence-parallel padding". The runner now pads only for expert parallelism.
Details
  • Gate: the problem is real (every start fails on vLLM main), the fix sits at the right layer (the vLLM subpackage), and nothing else changes. Net LoC is +14, and that comes from the rewritten padding test and docstring.
  • Pin double-padding: the pin's base _pad_for_sequence_parallelism now runs without the override. It pads only when pass_config.enable_sp is set, which is off by default and no longer set by the generator, so the pin still pads only once, here.
  • DP: round_up is applied elementwise to num_tokens_across_dp on every rank. Each rank's own entry still matches its batch_descriptor.num_tokens, and all ranks agree on the vector. num_tokens_across_dp is a host tensor, so the rounding adds no device sync.
  • Dist-MoE: set_num_valid_tokens still gets the unpadded count before any padding, so the extra TP-rounding rows are masked off like the other padding.
  • Cascade: as far as I can tell, FlashAttentionMetadata keeps the full query_start_loc, seq_lens and block table when cascade is on. So the non-cascade path stays correct without the assert, and cascade would only cost speed.
  • The MLA act_dtype=None branch is a two-version shim, with a TODO pointing to vllm-project/vllm#57678. That's acceptable while torchtitan supports both versions.

Not verified: the vLLM source isn't installed in this checkout. These claims come from the PR's GPU and CPU results, not from reading vLLM: that the pin's get_request_counts() counts skipped_waiting, and that vLLM main sizes its inputs from batch_descriptor.num_tokens.

assert compilation_config.pass_config.sp_min_token_num == 1


def test_inference_parallelism_disables_dense_sequence_parallelism():

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.

Now that to_training() hardcodes enable_sequence_parallel=False (parallelism.py:43), this test only checks a constant. No input can change the result, so it can't catch a regression. Delete it along with the other dense-SP tests.

running=running,
waiting=waiting,
skipped_waiting=skipped_waiting,
get_request_counts=lambda: (len(running), len(waiting) + len(skipped_waiting)),

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 stub now adds waiting and skipped_waiting together itself. So the skipped_waiting case of test_a_waiting_turn_gets_room_when_held_sessions_fill_the_pool (line 312) checks the stub's own arithmetic. It no longer checks the holder or vLLM. The holder only sees num_waiting, so both parametrize cases test the same thing.

The real assumption is that the pin's Scheduler.get_request_counts() counts skipped_waiting, and this test can't check it. Drop the skipped_waiting param and the parametrize, and keep one waiting queue.

@felipemello1
felipemello1 force-pushed the felipemello1/inference-graph-sizes/3-vllm-main-compat branch from 6aaa17b to 04a50c9 Compare November 6, 2026 01:59
@felipemello1

Copy link
Copy Markdown
Contributor Author

Reply from claude: @claude please review again. Head ff4567a (rebased on #5383's new head, then this fix commit).

  • Must fix 1: deleted test_inference_parallelism_disables_dense_sequence_parallelism.
  • Must fix 2: the description now says only session_kv_holder.py calls get_request_counts().
  • The holder stub has one waiting queue; the skipped_waiting case is gone.
  • The runner docstring says expert-parallel padding.
    CPU suite: 559 passed on the pin and on vLLM main.

@claude

claude Bot commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Claude finished @felipemello1's task in 48s —— View job


Approve: all four items from the last review are fixed at ff4567a, and the new commit adds no new problems. See the 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 -- All four items from the last review are fixed at ff4567a, and the new commit adds no new problems. A maintainer still needs to review.

Earlier items, checked at HEAD

  • Must fix 1, resolved: test_inference_parallelism_disables_dense_sequence_parallelism is deleted. InferenceParallelismConfig is still imported and used in other tests in test_generator.py.
  • Must fix 2, resolved: the description now says only session_kv_holder.py calls get_request_counts().
  • Should consider, resolved: _holder in test_session_kv_holder.py has one waiting queue, and the skipped_waiting parametrize case is gone.
  • Should consider, resolved: the TorchTitanGPUModelRunner docstring (worker.py:106) now says expert-parallel padding.

What changed since the last review. The fix commit touches only the three files above (+6/-16). After the rebase on #5383, the _determine_batch_execution_and_padding override, the MLA hook, the config, the registry and the holder changes match what I reviewed before.

Details
  • I checked every remaining enable_sequence_parallel reference in torchtitan/rl, tests/rl and torchtitan_recipes. The ones in dapo_math.py, alphabet_sort.py, test_vllm_wrapper.py, test_bitwise_parity.py, controller.py and model_wrapper.py all read the trainer's ParallelismConfig, so none of them break now that the field is gone from InferenceParallelismConfig.
  • Nothing under torchtitan/rl or tests/rl still references _pad_for_sequence_parallelism, use_cascade, skipped_waiting or enable_sp.

Not verified: the GPU results (they come from the PR description). Whether the pin's Scheduler.get_request_counts() counts skipped_waiting is also unverified, because the vLLM source isn't in this checkout.

@felipemello1
felipemello1 force-pushed the felipemello1/inference-graph-sizes/3-vllm-main-compat branch from ff4567a to a083233 Compare November 6, 2026 02:09
@felipemello1
felipemello1 force-pushed the felipemello1/inference-graph-sizes/3-vllm-main-compat branch 2 times, most recently from 6378194 to 9c99e44 Compare November 6, 2026 14:31
Base automatically changed from felipemello1/gen-perf/4-vllm-capture-sizes to main November 6, 2026 14:31
@felipemello1
felipemello1 force-pushed the felipemello1/inference-graph-sizes/3-vllm-main-compat branch from 9c99e44 to 81d1c7d Compare November 6, 2026 14:31
@felipemello1
felipemello1 removed this pull request from stack #5496 November 8, 2026 22:07
@felipemello1
felipemello1 force-pushed the felipemello1/inference-graph-sizes/3-vllm-main-compat branch from 81d1c7d to cadd040 Compare November 8, 2026 22:08
@felipemello1 felipemello1 changed the title [rl] generator: run on vLLM main as well as the current pin [rl] generator: vLLM-main API fixes and TP padding in the model wrapper Nov 8, 2026
@felipemello1
felipemello1 changed the base branch from main to felipemello1/vllm-v2/1-hybrid-page-size November 8, 2026 22:08
@felipemello1
felipemello1 added this pull request to stack #5957 November 8, 2026 22:08
wwwjn pushed a commit that referenced this pull request Dec 1, 2026
…round (#6389)

<!-- Write this yourself, not with an AI tool. 2-5 sentences: the
problem, why
     this approach, and what you checked yourself. -->
upgrade vlllm to 0.33.0 (the last v1 stable version) and address this
issue vllm-project/vllm#69805

vLLM 0.33.0 fixes
[vllm-project/vllm#69805](vllm-project/vllm#69805):
`kv_connector_no_forward` now calls `wait_for_save`, so Mooncake submits
finish-time saves scheduled on a step without a forward. On the pinned
nightly (`9f03b510c`) it passes `wait_for_save=False`, which is why
`worker.py` overrides it. This PR moves the KV offload code to vLLM 0.33
and drops that override.

**Depends on #5498 and #5967** (felipemello1), which move the generator
to vLLM 0.33.0; land this after them. Until then this PR's CI runs on
the pinned nightly, where these changes fail.

- `kv_offload_scheduler.py`, `session_kv_holder.py`: vLLM 0.33 replaced
`skipped_waiting` with `kv_holding_waiting`, which it always drains
before `waiting`. Rename the queue, and delete the
`_select_waiting_queue_for_scheduling` override: there is no longer a
choice between two queue heads to tie-break.
- `worker.py`: delete the `kv_connector_no_forward` override and its
TODO; delete its unit test in `test_mooncake_coordination.py`.
- Tests (mechanical): fill in the `Scheduler` state 0.33 reads
(`_kv_fetch_stages`, `deferred_loads`, ...) in the hand-built test
schedulers. In `test_kv_offload.py`, on 0.33 the first request's tail no
longer saves on an idle step, so the check that a finish-time save
without forward ran now covers the whole test instead of the first
request.

main vs this PR on top of #5967. Stock Qwen3-0.6B AlphabetSort GRPO
recipe (TP4 generator + 2-GPU trainer, B200), 12 steps, mean of steps
3-12, 3 runs each:

| | main (vLLM nightly 11-07, torch 11-07) | this PR (vLLM 0.33.0, torch
11-24) | change |
|---|---|---|---|
| generator inter-token latency (ms) | 4.64 | 4.80 | +3% |
| generator decode time per request (ms) | 143.6 | 149.5 | +4% |
| step wall time (s) | 2.64 | 2.64 | 0% |
| trainer tokens/s (full step) | 2110 | 2165 | +3% |

Per-run inter-token latency: main 4.53 / 4.68 / 4.70, PR 4.96 / 4.85 /
4.58; the runs overlap, so the generator difference is within noise and
step time is unchanged. These measure the vLLM/torch upgrade (#5967) as
much as this PR.

With #5498 and #5967 applied, on vLLM 0.33.0 + torch 2.16.0.dev20261124:
- `tests/rl/unit_tests/cpu`: 738 passed except
`test_vllm_multimodal_wrapper.py::test_controller_requires_a_vision_processor_exactly_for_multimodal_models`
(needs `math_verify`, not installed locally); `test_dapo_math.py` /
`test_geometry3k.py` not collected for the same reason.
- `tests/rl/unit_tests/gpu/test_kv_offload.py`: 3 passed (the 8-GPU
`dp2` case not run).
- `generate.py` with vLLM, and with SimpleCPU offload: same text as
main.
- Mooncake Store end to end (2 generators x TP2,
`save_decode_cache=True`, 4 steps): one master on the controller host, 4
segments mounted, ~350 keys loaded per generator, 0 failed loads or
saves.

(cherry picked from commit 8ab41b4)
return h
return h[:num_tokens]

def _pad_step_to_tp(

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.

Previously we do the padding arround model_wrapper forward when EP, why we need this now?

@wwwjn wwwjn Dec 1, 2026 •

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.

Basically it is our original _pad_for_sequence_parallelism, but the original name is a name from vllm and we override it. However, vllm delete the function we override, so we rename the function _pad_for_expert_sequence_parallel and this is only used for eager router SP

wwwjn added 2 commits December 1, 2026 11:46
…rallel

It pads to a multiple of expert_sequence_parallel_size, which is TP only with EP; with TP alone it does nothing. The name also avoids the tp abbreviation and sits next to the vLLM method it replaces (_pad_for_sequence_parallelism).
Comment thread torchtitan/rl/generator/parallelism.py Resolved
Comment thread torchtitan/rl/generator/vllm/engine.py Outdated
# FA2 requires block_size to be a multiple of 256
if not has_cuda_capability(9, 0):
engine_kwargs["block_size"] = 256
block_size = vllm_block_size(model)

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.

Why adding this helper function?

wwwjn added 4 commits December 1, 2026 12:13
It returns the KV cache block size the attention kernel needs (flex's pinned BLOCK_N, FA2's 256), or None for vLLM's default; 'block size' alone could also mean the kernel's BLOCK_N.
… in the model wrapper

main's wrapper imported no vLLM math helpers. The Dist-MoE call size is round_up(num_tokens, tp) // tp: pad to a multiple of TP, then split. Plain // would round down and undersize the call for vLLM's unpadded DP counts (test case [5, 3] at TP 4 -> 2).
…lel; VLLMEngine rejects it

Keep the field (default False) and SGLangEngine's check as on main. vLLM 0.33 removed PassConfig.enable_sp, so VLLMEngine raises ValueError when it is set instead of ignoring it.
@wwwjn
wwwjn marked this pull request as ready for review December 1, 2026 20:38
@pytorch-bot pytorch-bot Bot added ciflow/b200 Trigger B200 CI ciflow/fake-pg Run 1-GPU Fake PG integration tests labels Dec 1, 2026
@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 2m 30s —— View job


Approve -- please address the items below before merging: the enable_sequence_parallel field now accepts only False, so delete it, and the description still describes the skipped_waiting fix that the main merge dropped. See the 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 commits since my last full review (ab47d00) are two renames, round_up for the Dist-MoE call size, comment edits, and merges of main. None of them changes behavior, but they leave a config field with no usable value and a description that no longer matches the diff. A maintainer still needs to review.

What changed since the last review.

  • 48fafc9: renames _pad_step_to_tp to _pad_for_expert_sequence_parallel, which answers @wwwjn's padding thread.
  • ab7b766: renames vllm_block_size to attention_kv_cache_block_size.
  • b16a7d4: the Dist-MoE call size is now round_up(n, tp) // tp, the same value as the earlier cdiv.
  • 3bd0dc0: restores InferenceParallelismConfig.enable_sequence_parallel, and VLLMEngine now raises when it is set.
  • 3f3a462: a merge of main that takes main's session_kv_holder.py.

Example. The behavior is the same as at the last approval. TP 4, EP 4, 3-token eager decode:

vLLM passes 3 rows -> _pad_for_expert_sequence_parallel -> 4 rows, mask [F,F,F,T]
Dist-MoE call size: round_up(4, 4) // 4 = 1; DP 2 with counts [5, 3]: round_up(5, 4) // 4 = 2
returns h[:3]

Must fix

  1. torchtitan/rl/generator/vllm/engine.py:280 -- both engines now reject enable_sequence_parallel=True, so the field accepts only False. Delete it, as @wwwjn agreed on parallelism.py:27. In to_training(), pass False explicitly, because ParallelismConfig defaults it to True. Full explanation in the inline comment.
  2. The PR description no longer matches the diff:
    • Problem 1-2 and Solution 4 say this PR replaces Scheduler.skipped_waiting with get_request_counts(). Merge 3f3a462 took main's session_kv_holder.py, which still reads scheduler.skipped_waiting at :152, and the rename to kv_holding_waiting is now in #5967. Remove that item, fix the "seven things" count, and say that #5967 handles the queue rename.
    • The Test plan names test_forward_pads_the_step_to_a_multiple_of_tp. The test is now called test_forward_pads_the_step_for_expert_sequence_parallel.
    • Solution 1 needs rewording once item 1 is fixed.
Details
  • @wwwjn's question on engine.py ("Why adding this helper function?") has no reply in its thread. Solution 7 in the description answers it, and the answer holds:

    • attention_kv_cache_block_size has two callers, engine.py:481 and test_bitwise_parity.py:243. Before, they used different rules: the test skipped 256 for flex, and the engine didn't.
    • The new pinned-flex rule (BLOCK_N) is needed on vLLM main, where the default block size becomes 64.
    • It sits next to vllm_attention_backend, which reads the same attention config.

    A short reply in that thread would close it.

  • @wwwjn's padding thread: resolved by the rename and the _pad_for_expert_sequence_parallel docstring (model_wrapper.py:485), which says why the V1 hook had to move.

  • b16a7d4: the asserts that TP divides the call size are gone. For DP 1, the wrapper pads to TP. For DP > 1, the round-up covers vLLM's unpadded DP counts. The init check (model_wrapper.py:386) bans the one case where the padding multiple isn't TP (Dist-MoE, TP > 1, EP 1).

  • Overlap search (vLLM 0.33, model_wrapper, session_kv_holder): #5967 (the vLLM 0.33 install, which now carries the skipped_waiting rename), #5971, #5972 and #5956 (the rest of this stack). None of them rewrites this PR's code.

Not verified: the GPU results in the description. As in earlier reviews, also not verified: that vLLM's KV writers size their writes by slot_mapping rather than by key.

Comment thread torchtitan/rl/generator/vllm/engine.py Outdated
Comment on lines +280 to +282
if parallelism.enable_sequence_parallel:
# vLLM 0.33 removed its dense sequence-parallel pass (PassConfig.enable_sp).
raise ValueError("VLLMEngine does not support sequence parallelism")

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.

With this check, both GenerationEngine implementations reject InferenceParallelismConfig.enable_sequence_parallel=True: here, and SGLangEngine at sglang/engine.py:238. So False is the only value the field accepts. It is a knob no setting can use, and design.md says to delete unused fields. @wwwjn also agreed on parallelism.py:27 that deleting it is fine, since no recipe sets it. 3bd0dc0 brought the field back, and its message gives no consumer that needs it.

Fix (about -15 lines):

  • delete the field (parallelism.py:27);
  • in to_training(), pass enable_sequence_parallel=False explicitly. ParallelismConfig defaults it to True (config/parallelism.py:96), so dropping the line alone would turn SP sharding on in the generator model;
  • delete this check and the SGLang one;
  • delete test_vllm_engine_rejects_sequence_parallelism.

No other InferenceParallelismConfig(...) in torchtitan, tests or torchtitan_recipes passes the field.

Both engines rejected True (vLLM 0.33 removed its dense sequence-parallel
pass, and SGLang never had one), so False was the field's only valid value.
to_training() passes enable_sequence_parallel=False explicitly, since
ParallelismConfig defaults it to True. No recipe or test set the field.
@wwwjn wwwjn changed the title [rl] generator: vLLM 0.33 API fixes and TP padding in the model wrapper [WIP] [rl] generator: vLLM 0.33 API fixes and TP padding in the model wrapper Dec 2, 2026
@wwwjn

wwwjn commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

from claude: replies to this round's review threads (posted here because a pending review on this PR blocks in-thread replies):

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


Approve: ae28a3a deletes enable_sequence_parallel as asked and the description now matches the diff, so nothing is left to fix. See the 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 -- ae28a3a deletes InferenceParallelismConfig.enable_sequence_parallel the way the last review asked, and the description now matches the diff. Nothing is left to fix. A maintainer still needs to review.

What changed since the last review. One commit, ae28a3a (+3/-32):

  • It deletes the field.
  • It deletes the VLLMEngine and SGLangEngine checks that rejected True, and test_vllm_engine_rejects_sequence_parallelism.
  • to_training() now passes enable_sequence_parallel=False explicitly, with a comment saying why.

Example.

InferenceParallelismConfig(tensor_parallel_degree=4).to_training().enable_sequence_parallel
  before ae28a3a:  self.enable_sequence_parallel -> False (the field's default; True raised in both engines)
  after:           False (hardcoded); without it, ParallelismConfig's default True would shard the generator model for SP
InferenceParallelismConfig(enable_sequence_parallel=True)
  before: ValueError from the engine;  after: TypeError at construction (slotted kw_only dataclass, no such field)

Earlier items, checked at HEAD

  • Must fix 1 (delete the field): resolved. No InferenceParallelismConfig(...) in torchtitan, tests or torchtitan_recipes passes it. Every remaining enable_sequence_parallel reads the trainer's ParallelismConfig (controller.py:576, test_bitwise_parity.py:124, test_vllm_wrapper.py:121, the recipes) or reads to_training() (generator/model.py:104).
  • Must fix 2 (description): resolved. The skipped_waiting item is gone and #5967 is named as its home. The count is six. The Test plan names test_forward_pads_the_step_for_expert_sequence_parallel. Solution 1 describes the deletion.
  • @wwwjn's threads (parallelism.py:27, engine.py helper, padding rename): all answered at HEAD. The human-written summary is filled in.
Details
  • Gate: unchanged from the earlier approvals. Every fix is needed on vLLM 0.33 whichever runner runs, the fixes sit in the vLLM subpackage, and the PR is net negative LoC.
  • Overlap search (enable_sequence_parallel generator, vLLM 0.33): #5967, #5972 and #5956 (the rest of this stack), and the MTP stack (#6473-#6479), which edits engine.py, registry.py, worker.py and gdn.py on its own base. None of them rewrites this PR's code, but whichever stack lands second will have merge conflicts.

Not verified: the GPU results in the description. As in earlier reviews, also not verified: that vLLM's KV writers size their writes by slot_mapping rather than by key.

@wwwjn wwwjn changed the title [WIP] [rl] generator: vLLM 0.33 API fixes and TP padding in the model wrapper [rl] generator: vLLM 0.33 API fixes and TP padding in the model wrapper Dec 2, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

2 participants