Repository navigation
[rl] Generator: default vLLM's max_num_batched_tokens to vllm serve's per-GPU value - #5952
felipemello1 wants to merge 18 commits into
Conversation
…ks for the GPU With max_num_batched_tokens unset, the generator ran vLLM's 2048 fallback on every GPU: LLMEngine.from_engine_args uses UsageContext.ENGINE_CONTEXT, which vLLM's per-GPU defaults table skips. Unset now resolves to the `vllm serve` value from that table (16384 on B200/GB300, 8192 on H100/H200, 2048 on A100 and smaller GPUs), capped at max_num_seqs * max_model_len as vLLM caps its own default. SGLang picks the same values on H100/H200 and >= 160 GB GPUs. The engine and the FULL CUDA graph capture cap take the same resolved value. Explicit values are unchanged. The Muse Spark 816B DAPO recipe pins 2048, because its Dist-MoE scratch grows with the budget.
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 3m 34s —— View job Approve, but please address the items in the review first. Review: #5952 (review) |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The root cause is real (LLMEngine.from_engine_args uses ENGINE_CONTEXT, which falls back to 2,048). The fix is small and resolves the budget once, so the engine, the FULL capture cap and the Dist-MoE scratch all see the same value. A maintainer still needs to review, since this changes the generator's default perf and memory on H100 and B200/GB300.
What this PR does. When Generator.Config.max_num_batched_tokens is None, the new resolve_max_num_batched_tokens reads vLLM's own per-GPU table (EngineArgs.get_batch_defaults, the OPENAI_API_SERVER entry). It caps that value at max_num_seqs * max_model_len, like vllm serve does, and always passes the result to EngineArgs. get_vllm_compilation_config now requires the budget, and the _DEFAULT_MAX_NUM_BATCHED_TOKENS fallback is deleted. The Muse Spark 816B recipe pins 2,048 so its Dist-MoE scratch stays the same size.
Example.
Qwen3.5-9B generator, max_num_batched_tokens unset, FULL graphs, max_num_seqs=512, max_model_len=65536
main: H100 -> EngineArgs has no budget -> vLLM picks 2048; capture cap 2048
this PR: H100 -> 8192 passed to EngineArgs; capture cap 8192
GB300 -> 16384 for both; Dist-MoE scratch (model_wrapper.py:536 reads scheduler_config) grows to match
A10G -> 2048 (RL golden on A10G unchanged)
max_num_seqs=1, max_model_len=1024 on GB300 -> min(16384, 1024) = 1024
Must fix
- PR description -- "Summary (human-written)" is empty. The author has to fill it in. Agents don't.
Should consider
torchtitan/rl/generator/vllm/config.py:32-- the docstring andgenerator.py:130copy vLLM's tier table, which goes stale on the next vLLM bump (see inline).torchtitan/rl/generator/vllm/config.py:28--tensor_parallel_sizeonly affects vLLM's CPU backend, but every caller has to pass it (see inline).
Details
- Gate. The problem is real on main, and torchtitan is the right layer: the capture sizes are built before
EngineArgs, so passingusage_context=OPENAI_API_SERVERwould leave mixed steps above 2,048 running eager, as the description says.EngineArgs.get_batch_defaultsis a public staticmethod, so no private-API TODO is needed. No overlapping PR changes the default. The two open PRs the description names touch the same lines but don't supersede this one. - Callsites. Every path that builds the vLLM engine resolves the budget:
VLLMEngine._build_engine_args,generate.pyand thetest_bitwise_parity.pyhelper. Dist-MoE sizing readsvllm_config.scheduler_config.max_num_batched_tokens, so it follows the resolved value. The DeepEP recipes (alphabet_sort.pyandsearch_r1.py) size their buffers from an explicit budget and are unchanged.add_extra_vllm_engine_argsstill rejectsmax_num_batched_tokensinextra_engine_args. - Numerics. Rollout chunking changes on H100 and SM100 for recipes that leave the budget unset, so generator logprobs there aren't bitwise identical to main unless batch-invariant mode is on. The only RL golden runs on A10G, which stays at 2,048, so no golden needs regenerating.
- Memory. The description measures FULL-graph pool growth (~1.5 GiB) and a 1-2% KV cut. One unset recipe is
rl_grpo_qwen35_35b_a3b_terminal_bench(eager, all-to-all MoE, needs >80 GB GPUs), and it now profiles at 16,384 tokens per step. Its peak activation memory during the profile run wasn't measured. - Test.
test_unset_max_num_batched_tokens_uses_vllm_serve_defaultguards the table key and themax_num_seqs * max_model_lencap. Both would silently regress to 2,048 without it, and it runs on CPU. The edits to the other tests are mechanical (the new required argument).
Not verified: that the installed vLLM's get_batch_defaults has the >=160 GB tier and applies the max_num_seqs * max_model_len cap in vllm serve (vLLM isn't installed in this runner), and the GPU and CI results in the description.
| ``vllm serve`` reads vLLM's per-GPU table (``EngineArgs.get_batch_defaults``) and caps the | ||
| value at ``max_num_seqs * max_model_len``. The table today: | ||
| >= 160 GB (B200, GB300) -> 16384 | ||
| >= 70 GB, not A100 (H100) -> 8192 | ||
| other GPUs (A100, A10G) -> 2048 |
There was a problem hiding this comment.
Should consider: the PR reads the table from vLLM at runtime because "vLLM's table changes", but this docstring copies the tiers (and Generator.Config.max_num_batched_tokens in generator.py:130 says "16384 on GB300"). Both go stale on the next vLLM bump, and nothing will flag it. Either note which vLLM version the numbers come from ("as of vLLM X.Y"), or drop the numbers here and keep one example in the PR description.
There was a problem hiding this comment.
Reply from claude: Done in ee5973a. The docstring table now says "as of vLLM 0.32" (checked against v0.32.0:vllm/engine/arg_utils.py), and Generator.Config.max_num_batched_tokens no longer quotes a number: it points to resolve_max_num_batched_tokens.
There was a problem hiding this comment.
Reply from claude: Kept the three rows and the "as of vLLM 0.32" date in 4eadb08. The docstring now says the table is keyed on total device memory plus an A100 name check, and that GPUs below compute capability 9.0 (FA2) and ROCm keep 2048. Generator.Config still quotes no number.
| *, | ||
| max_num_seqs: int, | ||
| max_model_len: int, | ||
| tensor_parallel_size: int, |
There was a problem hiding this comment.
Should consider: the docstring says tensor_parallel_size matters only on vLLM's CPU backend. The generator can't run there (it uses CUDA attention backends and checks has_cuda_capability). Every caller (engine.py, generate.py, test_bitwise_parity.py) still has to thread TP through. If you'd rather keep it to match vllm serve, which passes pipeline_parallel_size * tensor_parallel_size, that's fine, but then say so in the docstring. Otherwise, drop the parameter and call EngineArgs.get_batch_defaults(world_size=1) with a one-line comment. That's minor, about -6 LoC.
There was a problem hiding this comment.
Reply from claude: Dropped tensor_parallel_size in ee5973a. The helper calls EngineArgs.get_batch_defaults(world_size=1) with a one-line comment (world_size only scales the CPU backend, which the generator never uses), and the 3 callers no longer pass TP.
…the table to vLLM 0.32 world_size scales vLLM's batch-default table only on its CPU backend, which the generator never uses. Name the vLLM version the docstring table comes from, and keep the numbers out of Generator.Config.
|
Claude finished @felipemello1's task in 42s —— View job Approve, but please address the items in the review first. Both earlier suggestions are resolved in ee5973a, and the "Summary (human-written)" section is still empty. Review: #5952 (review) |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. ee5973a resolves both should-consider items from the last review and adds no new problems. A maintainer still needs to review, because this changes the generator's default perf and memory on H100 and B200/GB300.
Re-review of ee5973a.
- Resolved: the tier table in
torchtitan/rl/generator/vllm/config.py:32is now labeled "as of vLLM 0.32", andGenerator.Config.max_num_batched_tokens(generator.py:129) no longer quotes a number. - Resolved:
tensor_parallel_sizeis gone.resolve_max_num_batched_tokenscallsEngineArgs.get_batch_defaults(world_size=1)and has a one-line comment explaining why. I checked all three callers (vllm/engine.py:277,generate.py:170,test_bitwise_parity.py:260), and none passes TP anymore. The CPU test's monkeypatch (test_generator.py:694) takesworld_sizeas a keyword, which matches the new call.
Must fix
- PR description -- "Summary (human-written)" is still empty. The author has to fill it in. Agents don't.
Not verified: that vLLM 0.32's get_batch_defaults takes a world_size keyword, and the tier values (vLLM isn't installed in this runner). The CPU test mocks the function, so it won't catch a renamed parameter. The GPU CI runs on ciflow/rl and ciflow/b200 will.
…string on device memory - Log the budget when it comes from vLLM's table, the one fact vLLM can't print. - The table keys on total device memory for any GPU vendor; FULL graph sizes are built before the engine, which is why torchtitan reads it instead of passing a usage context. - FULL docstring: vLLM switches to FULL_DECODE_ONLY when an attention backend graphs only uniform decode batches (MLA). - max_num_seqs property: fix the comment on the budget, TODO for FA2 GPUs that resolve > 2048. Co-authored-by: Claude <[email protected]>
…0 keep 2048 FA2 writes out of bounds past 64 tokens per profile request, and the controller's max_num_seqs floor assumes a 2048 budget when unset. vLLM's table gives an A800 80 GB 8192; FA2 GPUs now keep main's 2048 (A10G, A100 and L40S already get it). The test covers the FA2 case. Co-authored-by: Claude <[email protected]>
… not always vllm serve's The resolver keeps 2048 on FA2 GPUs and ROCm, so 'what vllm serve picks' no longer holds there. The TODO says dropping the FA2 branch also moves ROCm to vLLM's table. Co-authored-by: Claude <[email protected]>
…fault-batched-tokens
|
Reply from claude: @claude please review 4eadb08. Changes since your last review:
|
|
Claude finished @felipemello1's task in 1m 21s —— View job Approve. Please fill in the "Summary (human-written)" section before merging. 4eadb08 adds no new problems. Review: #5952 (review) |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. 4eadb08 adds the FA2/ROCm 2,048 branch, the startup log line and the MLA docstring note, and none of them introduces a new problem. A maintainer still needs to review, because this changes the generator's default perf and memory on H100 and B200/GB300.
Re-review of 4eadb08.
- FA2/ROCm branch (
torchtitan/rl/generator/vllm/config.py:47):has_cuda_capabilityreturns False on ROCm (torch.version.hip is None,torchtitan/tools/utils.py:35), so MI300X/MI350X also keep 2,048, as the docstring says. The TODO links the FA2 issue, matching the controller's TODO. - Controller invariant (
controller.py:479):max_num_seqs_per_generator_dp_rankstill assumes 2,048 when the budget is unset. The resolved budget ismin(table >= 2048, max_num_seqs * max_model_len), andmax_num_seqs <= 2048, somax_num_seqs <= max_num_batched_tokensstill holds on every GPU. The FA2 floor (budget / 64) is only needed below SM90, and there the budget stays 2,048, so the floor is still correct. - Callsites after the merge with main: all three engine builders (
vllm/engine.py:295,generate.py:170,test_bitwise_parity.py:251) resolve the budget and pass it toget_vllm_compilation_config. Dist-MoE sizing (model_wrapper.py:345) readsscheduler_config, so it follows the resolved value. No_DEFAULT_MAX_NUM_BATCHED_TOKENSoror 2048fallback remains outside the controller. - Test: the new
(False, 16384, 2048)case patcheshas_cuda_capabilityon the config module, which is the name the resolver looks up. So it guards the FA2 branch.
Must fix
- PR description -- "Summary (human-written)" is still empty. The author has to fill it in. Agents don't.
Not verified: the vLLM get_batch_defaults(world_size=...) signature and tier values (vLLM isn't installed in this runner; the CPU test mocks it), and the GPU results in the description. ciflow/rl and ciflow/b200 will exercise the real call.
| (prefill + decode, summed over the batch). ``None`` (default) leaves the | ||
| engine's own default in place.""" | ||
| (prefill + decode, summed over the batch). ``None`` (default): the engine's default | ||
| for this GPU. For vLLM, see ``resolve_max_num_batched_tokens``.""" |
There was a problem hiding this comment.
lets make this also be the same for sglang
There was a problem hiding this comment.
Reply from claude: SGLang already does this. When the field is unset, torchtitan passes no chunked_prefill_size, so SGLang picks its own value for the GPU. The docstring now says that for both engines. One difference: SGLang splits its default over its DP ranks, so at DP4 on a GB300 each rank gets 4,096. A set value is per DP rank in both engines.
There was a problem hiding this comment.
Reply from claude: Follow-up in 9b205ba. Unset now means the same in both engines: the engine's own per-device default, per DP rank. SGLang divides its default over DP ranks, so at DP > 1 SGLangEngine._build_server_args asks SGLang's resolver for its per-rank share and multiplies it back by DP. On a GB300 at DP 2 that is 16,384 per rank (was 8,192). DP 1 is unchanged.
There was a problem hiding this comment.
Reply from claude: Update, replacing my 9b205ba follow-up: 41476c6 reverts the SGLang DP-split change, so the SGLang engine matches main. Unset means each engine's own default for the GPU. vLLM uses it on each DP rank; SGLang splits its default over its DP ranks, as the field's docstring says. A set value is per DP rank in both engines. Undoing the split meant reading SGLang's default back only to pass it in again.
| engine_kwargs["max_num_seqs"] = max_num_seqs | ||
| if gen_config.max_num_batched_tokens is not None: | ||
| engine_kwargs["max_num_batched_tokens"] = gen_config.max_num_batched_tokens | ||
| max_num_batched_tokens = resolve_max_num_batched_tokens( |
There was a problem hiding this comment.
i dont see why we have this code repeated here and in vllm
There was a problem hiding this comment.
Reply from claude: Fixed in c6f49ec. generate.py had a copy of VLLMEngine's whole engine-args build (#5951 and #5488 each had to edit both). build_engine_args is now a public static method, and generate.py calls it. It only turns the tokenizer back on, because it prints text. Ran on 1 GB300: it generates the sorted names.
| # Dist-MoE scratch grows with the step budget: 2 GiB per GPU at 2,048 tokens, | ||
| # 16 GiB at 16,384 (the GB300 default), taken from the KV cache. | ||
| # TODO: measure 16,384 against the KV cache it costs. | ||
| max_num_batched_tokens=2048, |
There was a problem hiding this comment.
lets just test and remove this change.
There was a problem hiding this comment.
Reply from claude: Not done yet. The test needs the 816B weights and 4 GB300 hosts for the generator alone (DP4 x TP4, EP16). At 16,384 its Dist-MoE scratch grows from 2.0 to 16.0 GiB per GPU, and that memory comes out of the KV cache. The pin stays until that run happens.
There was a problem hiding this comment.
Reply from claude: Removed in 8bd2f70, as you asked: the recipe now takes the default (16,384 on GB300). Not run. Its Dist-MoE scratch grows from 2 to 16 GiB per GPU, taken from the KV cache; the body NOTE says so.
| max_num_batched_tokens: Max tokens scheduled per engine step, or None for the | ||
| engine's default. | ||
| engine's default for this GPU. |
There was a problem hiding this comment.
i find this a bit deceiving, because we dont use vllms default, which would actually be 16k for gb300. We set our own undocumented global constant default
There was a problem hiding this comment.
Reply from claude: Fixed in c6f49ec. Unset now means vLLM's own pick. resolve_max_num_batched_tokens asks vLLM's config builder (create_engine_config(UsageContext.OPENAI_API_SERVER)), so a GB300 gets 16,384. The one exception is now written in Generator.Config.max_num_batched_tokens: below compute capability 9.0, or off CUDA, it asks for LLMEngine's default, 2,048 (the FA2 bug; the TODO links it). This docstring points there.
There was a problem hiding this comment.
Reply from claude: Follow-up in 9b205ba: the exception in my previous reply is gone. Unset takes vLLM's own value on every device. Only FlashAttention-2 GPUs cap it, at 64 x max_num_seqs (the bug's limit). This docstring now says "per DP rank" and points to Generator.Config.max_num_batched_tokens.
There was a problem hiding this comment.
Reply from claude: Update: the FlashAttention-2 cap in my last reply is gone (41476c6). Unset takes vllm serve's value on every device. On FlashAttention-2 GPUs, resolve_scheduler_limits raises max_num_seqs instead.
| budget is ``generator.max_num_batched_tokens``, or 2048 when unset: the smallest value in | ||
| vLLM's table, and what FA2 GPUs keep (``resolve_max_num_batched_tokens``). |
There was a problem hiding this comment.
There is no such a thing as 2k if unset. If unset, we default to resolve_max_num_batched_tokens
There was a problem hiding this comment.
Reply from claude: Fixed in c6f49ec. The docstring now says each generator picks the budget for its GPU. The controller runs before any generator, so it can't know that value. Its clamp uses 2,048 as a lower bound, the smallest default vLLM picks on CUDA, so max_num_seqs <= max_num_batched_tokens still holds.
There was a problem hiding this comment.
Reply from claude: Follow-up in 98d4aa7: the controller no longer has a 2,048. It only computes concurrency (2x each DP rank's share, rounded up to a power of two). The two vLLM rules it used to apply with an assumed budget (max_num_seqs <= budget, and the FlashAttention-2 floor of budget / 64) moved to fit_max_num_seqs, which the vLLM engine calls after it resolves the budget.
There was a problem hiding this comment.
| ) -> int: | ||
| """Return ``max_num_batched_tokens``, or a default for this GPU when it is None. | ||
|
|
||
| ``vllm serve`` reads vLLM's table (``EngineArgs.get_batch_defaults``), keyed on total device |
There was a problem hiding this comment.
can we make this work for sglang as well? should we?
There was a problem hiding this comment.
Reply from claude: No code change for SGLang (see the generator.py thread): it already uses its own default. I don't think we should compute SGLang's value ourselves. "Unset" means what each engine's server picks.
There was a problem hiding this comment.
Reply from claude: Follow-up in 9b205ba: yes, done (see the generator.py thread). SGLang needs no budget up front: it sizes its prefill graphs from its own chunk. The only change is undoing its DP split. The divide-or-not runs in the body measured that at 1.23x prefill and 1.72x mixed-step prefill.
There was a problem hiding this comment.
Reply from claude: Update to my 9b205ba follow-up: the SGLang change is reverted in 41476c6 (see the generator.py thread). The rule is shared: the Generator.Config.max_num_batched_tokens field. The code differs because vLLM needs the value before the engine exists (the FULL graph list and two max_num_seqs rules), while SGLang sizes its prefill graphs from its own chunk.
| table as of vLLM 0.32: | ||
| >= 160 GiB (B200, GB300) -> 16384 | ||
| >= 70 GiB, not A100 (H100) -> 8192 | ||
| other GPUs (A100, A10G) -> 2048 |
There was a problem hiding this comment.
what if someone uses it with intel, amd, tpu, etc? Please make this clear.
Can we import vllms internal resolver here? i would prefer
i believe you told me that we cannot leave it to vllm, because we need the value for our cudagraph. So lets get the value from vllm, use here, and then pass. Same for sglang i guess? but iirc, they are the same?
There was a problem hiding this comment.
Reply from claude: Fixed in c6f49ec. We now take the value from vLLM's resolver, through its public config builder: EngineArgs(**engine_kwargs).create_engine_config(usage_context), then scheduler_config.max_num_batched_tokens (0.05 s on a GB300). The resolver itself (_set_default_max_num_seqs_and_batched_tokens_args) is private, and it needs configs that only create_engine_config builds. We build the CUDA graph sizes from that value and pass it to the engine. Extra engine args such as performance_mode now reach vLLM's rules too.
Platforms, as the docstring says: CUDA with compute capability >= 9.0 gets vllm serve's value. Everything else (older CUDA, ROCm, XPU, TPU, CPU) gets LLMEngine's 2,048, as on main.
SGLang: no change needed. Its table matches vLLM's on H100 (8,192) and GB300 (16,384).
There was a problem hiding this comment.
Reply from claude: Follow-up in 9b205ba, replacing my previous answer. Every platform now gets vllm serve's value. vLLM keys it on device memory on CUDA, ROCm (through amdsmi) and XPU, so an MI300X gets 16,384. TPU and CPU follow vLLM's own rules. The old "below SM90 or off CUDA -> 2,048" branch is gone.
The one exception is the FlashAttention-2 bug, now capped at its real limit: 64 x max_num_seqs, on CUDA below SM90. A10G CI stays at 2,048.
Not run on AMD: torchtitan's varlen generator can't run on ROCm today.
Why we still read the value up front: torchtitan lists FULL graphs up to the budget before the engine exists. On vLLM 0.34's V2 runner that is no longer needed (TODO in the code).
There was a problem hiding this comment.
Reply from claude: Update: since 41476c6, unset takes vllm serve's value on every platform, with no FlashAttention-2 cap. On FlashAttention-2 GPUs the bug now raises max_num_seqs to at least max_num_batched_tokens // 64 instead (only CUDA below SM90 since 0940851; XPU skips it). One function, resolve_scheduler_limits, returns both numbers.
# Conflicts: # tests/rl/unit_tests/cpu/test_generator.py # torchtitan/rl/generator/vllm/engine.py
…py reuses VLLMEngine.build_engine_args resolve_max_num_batched_tokens(engine_kwargs) builds EngineArgs(**engine_kwargs) and reads create_engine_config(UsageContext.OPENAI_API_SERVER).scheduler_config.max_num_batched_tokens, so vLLM's own rules apply (per-GPU table, max_num_seqs * max_model_len cap, extra engine args such as performance_mode). Below compute capability 9.0 and off CUDA it asks for ENGINE_CONTEXT (2048), as on main (FA2 TODO). Resolution runs after extra_engine_args. generate.py calls VLLMEngine.build_engine_args instead of a copy. Docstrings in Generator.Config, GenerationEngine and the controller say what an unset budget means.
|
Reply from claude: @claude please review c6f49ec, which addresses the maintainer's threads 12-18.
|
|
Claude finished @felipemello1's task in 2m 59s —— View job Approve -- please address the items below before merging. The description's human-written summary is still empty, and the 816B recipe still pins 2,048 (thread 14). Review: #5952 (review) |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. c6f49ec resolves threads 12, 13, 15, 16, 17 and 18 and adds no new problems. Thread 14 (the 816B pin) is still open. A maintainer still needs to review, because this changes the generator's default perf and memory on H100 and B200/GB300.
What changed in c6f49ec. resolve_max_num_batched_tokens(engine_kwargs) no longer reads vLLM's table itself. It builds a throwaway EngineArgs(**engine_kwargs).create_engine_config(usage_context) and reads scheduler_config.max_num_batched_tokens. It runs after extra_engine_args and before the FULL capture sizes are built. VLLMEngine.build_engine_args is now a public staticmethod, and generate.py calls it instead of keeping its own copy (-51 lines there).
Example.
FULL graphs, max_num_batched_tokens unset, extra_engine_args={}
GB300 (SM100): create_engine_config(OPENAI_API_SERVER) -> 16384 -> EngineArgs and capture cap 16384
A10G (SM86): create_engine_config(ENGINE_CONTEXT) -> 2048 -> same as main
set to 4096: no probe build -> 4096
extra_engine_args={"compilation_config": ...} -> still ValueError ("use VLLMEngine.Config.cuda_graph")
Must fix
- PR description: the "Summary (human-written)" section is still empty. The author has to fill it in. Agents don't.
torchtitan_recipes/rl/dapo_math.py:375(thread 14): felipemello1 asked to "test and remove this change", and the 2,048 pin is still there. Either do the 4-host run and delete the 4 lines, or say on the thread that the pin (with its TODO) stays in this PR.
Details
- Thread status at HEAD. 12 (SGLang in
Generator.Config): answered, and the docstring now covers both engines. 13 (generate.pyduplication): fixed. 15 (the "undocumented constant"): fixed, since the value now comes from vLLM's config builder, and the FA2/off-CUDA 2,048 is documented inGenerator.Configwith the TODO link. 16 (controller): the docstring says each generator picks its own budget and the clamp uses 2,048 as a lower bound. 17 and 18 (SGLang, other platforms, vLLM's resolver): fixed, and the private_set_default_max_num_seqs_and_batched_tokens_argsisn't called. - Ordering.
add_extra_vllm_engine_argsnow runs beforecompilation_configand the budget are set. Both keys are inconfig_field_by_engine_arg(vllm/engine.py:80-85), so a user still can't set them through extras.seedandmm_processor_cache_gbare set before the extras, as before. - Controller invariant.
max_num_seqs_per_generator_dp_rankreturns at mostmin(max_num_seqs, 2048). Both usage contexts resolve to at leastmin(2048, max_num_seqs * max_model_len), so vLLM'smax_num_seqs <= max_num_batched_tokenscheck still holds. If an extra arg ever pushes vLLM's pick below that, vLLM's own scheduler-config check would raise. It wouldn't be silent. generate.py. It now also gets the generator'sscheduling_policy="priority",logprobs_mode="processed_logprobs",prefix_cache_retention_interval=Noneandenable_cumem_allocator=False. That is the point of sharing the builder. Requests without a priority use 0, so the single-request flow is unchanged. Settingskip_tokenizer_init = Falseafter the build is fine, because the budget doesn't depend on it.- Test.
test_unset_max_num_batched_tokens_uses_vllm_defaultguards the capability -> usage-context choice and checks that the value reaches both the engine args and the FULL capture cap. vLLM now owns themax_num_seqs * max_model_lencap, so dropping that case from the CPU test is right.
Not verified: vLLM isn't installed in this runner. So I couldn't confirm that the probe create_engine_config leaves the objects it shares with the real EngineArgs unchanged (attention_config, dict-valued extras such as speculative_config), or that vLLM applies the max_num_seqs * max_model_len cap. The GB300 runs in the Test plan and ciflow/rl / ciflow/b200 exercise the real call.
|
Claude finished @felipemello1's task in 43s —— View job Approve. Please fill in the "Summary (human-written)" section before merging. 8bd2f70 closes thread 14 and adds no new problems. Review: #5952 (review) |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. 8bd2f70 deletes the 4-line max_num_batched_tokens=2048 pin and its TODO from the 816B recipe, which closes thread 14. torchtitan_recipes/ now matches main, and the commit adds no new problems. A maintainer still needs to review, because this changes the generator's default perf and memory on H100 and B200/GB300.
Re-review of 8bd2f70.
- Resolved (thread 14):
torchtitan_recipes/rl/dapo_math.pyis no longer in the PR diff.muse_spark_816b_a42b_dapo_math_gb300_configleaves the budget unset (dapo_math.py:364-379), so on GB300 it resolves throughresolve_max_num_batched_tokensto vLLM'svllm servevalue, like every other unset recipe. The description's NOTE says the same thing: its Dist-MoE scratch grows from 2 to 16 GiB per GPU, the memory comes out of the KV cache, and it was not run. - No other files changed since c6f49ec, so the rest of the previous review still holds.
Must fix
- PR description: the "Summary (human-written)" section is still empty. The author has to fill it in. Agents don't.
Details
- Thread 14 asked to "test and remove". The pin is removed, but the 816B generator hasn't run at 16,384. That recipe has FULL graphs,
gpu_memory_limit=0.9, and Dist-MoE scratch withscratch_capacity_factor=16.0, so it now profiles with about 14 GiB more scratch per GPU. If the KV cache left over is too small, vLLM fails at startup with a clear error rather than giving wrong results. So this is a perf and memory question for whoever runs the recipe next, not a correctness risk, and the description already discloses it.
Not verified: the 816B generator's KV cache size and throughput at 16,384 on GB300 (it needs 4 hosts).
…e default on every platform, per DP rank vLLM: always take vllm serve's value from vLLM's config builder (vLLM keys it on device memory on CUDA, ROCm and XPU). Before, only CUDA with compute capability >= 9.0 got it; every other GPU, ROCm included, was forced to 2048. FlashAttention-2 GPUs now cap it at 64 * max_num_seqs, the limit of flash-attention#3117, instead of falling back to 2048. SGLang: at DP > 1, SGLang splits its per-GPU default over attention-DP ranks (4096 per rank at DP 4 on a GB300). Ask SGLang's resolver for that share and undo the split, so an unset value is per DP rank in both engines, like a set one.
|
Reply from claude: @claude please review 9b205ba. Changes since your last review:
|
|
Claude finished @felipemello1's task in 2m 50s —— View job Approve. Please fill in the "Summary (human-written)" section before merging. 9b205ba adds no correctness problems. I left one should-consider inline: the FA2 cap also applies on XPU. Review: #5952 (review) |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. 9b205ba makes "unset" mean the same thing in both engines: the engine's own per-device default, per DP rank. It also replaces the blanket 2,048 fallback with a FlashAttention-2 cap at the bug's real limit. Neither change adds a correctness problem. A maintainer still needs to review, because this changes the generator's default perf and memory on H100, B200/GB300 and, now, ROCm.
What changed since 8bd2f70.
- vLLM:
resolve_max_num_batched_tokensasks forOPENAI_API_SERVERon every platform. Only CUDA below SM90 then caps the value at64 * max_num_seqs. - SGLang: at DP > 1 with the budget unset,
_build_server_argsbuilds a probeServerArgsfrom the same kwargs (extras included), reads the resolved per-rankchunked_prefill_size, and multiplies it back by DP.
Example.
budget unset, controller max_num_seqs = 64
A10G (SM86): vllm serve 2048 -> min(2048, 64*64) = 2048 (as main)
A800 80 GB: vllm serve 8192 -> min(8192, 64*64) = 4096 (main: 2048)
MI300X: vllm serve 16384 -> 16384 (main: 2048)
generate.py on SM86, max_num_seqs=1 -> 64 (main: 2048; disclosed)
SGLang, GB300, DP2 unset: probe resolves 8192/rank -> 16384 -> chunked_prefill_size 32768 -> 16384/rank (main: 8192/rank)
Must fix
- PR description: the "Summary (human-written)" section is still empty. The author has to fill it in. Agents don't.
Should consider
torchtitan/rl/generator/vllm/config.py:51: the FA2 cap also applies on XPU/CPU/TPU, not just CUDA below SM90 as the docstring says. Details and a suggested fix are inline.
Details
- Controller invariant. With the budget unset, the controller clamps
max_num_seqsto [32, 2048] (controller.py:578-586). On FA2 GPUs the resolved budget ismin(vllm_default, 64 * max_num_seqs), which is >= 2048 whenever vLLM's default is. vLLM'smax_num_seqs <= max_num_batched_tokenscheck still holds on every path, including64 * max_num_seqs >= max_num_seqsforgenerate.py'smax_num_seqs=1. The updated docstring and comment atcontroller.py:559and:584match this. - The two FA2 guards don't overlap. The controller's floor (
budget / 64) covers set budgets, and the resolver's cap covers unset ones, where vLLM may pick more than 2,048 (A800). Neither one makes the other redundant. - SGLang.
chunked_prefill_sizeis in_TORCHTITAN_SERVER_ARGS, soextra_server_argscan't set it, and the probe resolves SGLang's own default. At DP 1 the branch is skipped and nothing changes from main. A set value is still multiplied by DP as before. - Callsites.
VLLMEngine.build_engine_args,generate.py(throughbuild_engine_args) andtest_bitwise_parity.py:251-258all resolve the budget beforeget_vllm_compilation_config, which now requires it. No_DEFAULT_MAX_NUM_BATCHED_TOKENSfallback is left. - Test. The new ROCm case (
hip="7.0", SM90 False -> 4096) guards thetorch.version.hip is Nonehalf of the condition, and the SM86 case guards the cap. - TODO at
config.py:43links #5956 (the V2-runner port, open). That PR is in-repo, so the link is fine.
Not verified: SGLang's ServerArgs.resolve_once() / resolved_dict() API and whether a second resolution has side effects (SGLang isn't installed here). Also not verified: vLLM's XPU/ROCm memory table and the GPU results in the description. The B200 SGLang DP 2 parity classes exercise the SGLang probe.
| ) | ||
| vllm_serve_default = vllm_config.scheduler_config.max_num_batched_tokens | ||
| max_num_batched_tokens = vllm_serve_default | ||
| if torch.version.hip is None and not has_cuda_capability(9, 0): |
There was a problem hiding this comment.
Should consider: this condition is also true off CUDA. On XPU, torch.version.hip is None and has_cuda_capability returns False because torch.cuda.is_available() is False (torchtitan/tools/utils.py:33). So the FA2 cap applies there too. The docstring (line 37) and the PR's "every platform gets vllm serve's value" both say it applies only on CUDA below SM90. Example: on XPU at max_num_seqs=64, a 16,384 default becomes 4,096. The generator probably can't run on XPU today, so this mostly makes the code disagree with its docstring. Smallest fix: limit the cap to CUDA. The FA2 test case then also needs torch.cuda.is_available patched to True.
| if torch.version.hip is None and not has_cuda_capability(9, 0): | |
| if torch.cuda.is_available() and torch.version.hip is None and not has_cuda_capability(9, 0): |
The other option is to keep the code and have the docstring say "CUDA below compute capability 9.0, and non-CUDA non-ROCm devices".
There was a problem hiding this comment.
Reply from claude: Fixed in 0940851. The GRPO-on-XPU PR landed on main, so XPU now reaches this code. The floor now runs only when device_type == "cuda" and the GPU is below SM90. XPU runs only flex attention, so it never hits the FlashAttention-2 bug. ROCm keeps the floor, as on main. The CPU test has an XPU case.
Also, since 41476c6 the floor raises max_num_seqs instead of lowering max_num_batched_tokens, so the 16,384 -> 4,096 example no longer happens on any device.
… controller The controller assumed the generator's budget (2048 when unset) to apply two vLLM rules: max_num_seqs <= budget, and the FlashAttention-2 floor (budget / 64). fit_max_num_seqs applies both after the budget is resolved, so the controller only computes concurrency. The FA2 floor now applies only on FA2 GPUs, and the resolver returns vLLM's value unchanged (an A800 keeps 8192).
…ction; SGLang as on main resolve_scheduler_limits replaces resolve_max_num_batched_tokens and fit_max_num_seqs. Unset max_num_batched_tokens: ask vLLM's config builder what vllm serve picks, without max_num_seqs (vLLM raised when max_num_seqs was above its pick), then cap at max_num_seqs x max_model_len. On FA2 GPUs, max_num_seqs >= max_num_batched_tokens // 64; then max_num_seqs <= max_num_batched_tokens. The controller keeps its power of two and no longer reads max_num_batched_tokens. SGLang's engine is back to main: unset passes nothing, so SGLang uses its own default.
… devices XPU runs only flex attention (_validate_platform), so it never hits the FA2 bug. ROCm keeps the floor, as on main.
|
Reply from claude: @claude please review 0940851. Changes since your last review (9b205ba):
|
|
Claude finished @felipemello1's task in 3m 19s —— View job Approve. Please fill in the "Summary (human-written)" section before merging. 0940851 resolves the XPU comment. I left two should-consider inline comments: the FA2 floor when the capped budget isn't a power of two, and SGLang losing the controller's clamp. Review: #5952 (review) |
There was a problem hiding this comment.
Verdict: Approve -- please address the item below before merging. 0940851 puts both vLLM scheduler limits in one place: resolve_scheduler_limits in the engine. The controller now only sizes concurrency, and the XPU comment from the last review is resolved. A maintainer still needs to review, because this changes the generator's default perf and memory on H100, B200/GB300 and ROCm.
What changed since 9b205ba. resolve_scheduler_limits(engine_kwargs) builds a probe EngineArgs with max_num_seqs=None and asks it what vllm serve picks. It caps that at max_num_seqs * max_model_len. It then fits max_num_seqs to [budget // 64 (CUDA below SM90 only), budget]. The controller returns 2x the even share, rounded up to a power of two, with no clamp. The FA2 cap on the budget is gone, and so is the SGLang DP-split change.
Example.
budget unset, max_model_len 4096
GB300, controller 512 -> (16384, 512)
A10G, controller 16 -> (2048, 32) floor now in the engine (main: controller gave 32)
A10G, controller 4096 -> (2048, 2048) (main: same, clamped in the controller)
XPU, controller 16 -> (vllm serve's pick, 16) no FA2 floor
budget set to 4096, A10G, 8 -> (4096, 64)
Must fix
- PR description: the "Summary (human-written)" section is still empty. The author has to fill it in. Agents don't.
Should consider
torchtitan/rl/generator/vllm/config.py:64-- on FA2, the// 64floor isn't safe when the newmax_num_seqs * max_model_lencap gives a budget that isn't a power of two (inline).torchtitan/rl/controller/controller.py:576-- without the clamp, SGLang'smax_running_requests/full_prefill_max_reqchange too, and the controller's startup log shows the pre-fit value (inline).
Details
- Resolved (XPU thread).
device_type == "cuda" and not has_cuda_capability(9, 0)skips XPU and keeps ROCm, wheredevice_typeis"cuda"andhas_cuda_capabilityis False on HIP. That matches the docstring and the description. The new("xpu", False, 8, 4096, 8)test case guards it. - Probe.
max_num_seqs=Nonein the probe avoids vLLM'smax_num_seqs > max_num_batched_tokenscheck against its own pick. The CPU test asserts that the probe leaves it out. The probe runs beforecompilation_configis added and afteradd_extra_vllm_engine_args, so extras such asperformance_modereach vLLM's rules. That ordering is correct. - Invariant. Every return path satisfies
max_num_seqs <= max_num_batched_tokens, and on FA2,max_num_seqs >= budget // 64. vLLM's own check therefore can't fire, whatever value the controller passes. - Callsites.
VLLMEngine.build_engine_args(andgenerate.pythrough it) andtest_bitwise_parity.py:246-258all callresolve_scheduler_limitsand pass the fitted pair to bothEngineArgsandget_vllm_compilation_config. Nothing else readsmax_num_seqs_per_generator_dp_rankexcept the controller log and the SGLang engine. - Controller docstring. The new example
16 -> 16is correct, and the comment explains the power-of-two rounding.
Not verified: that vLLM's create_engine_config(OPENAI_API_SERVER) accepts max_num_seqs=None and leaves shared objects in engine_kwargs unchanged, and that vLLM's profile run puts the remainder on the last request (vLLM isn't installed here). Also not verified: the GPU results in the description.
| # TODO(https://github.com/Dao-AILab/flash-attention/issues/3117): drop once fixed. vLLM's memory profile splits | ||
| # max_num_batched_tokens over max_num_seqs requests, the remainder on the last; FA2 writes out of bounds past 64. | ||
| # XPU is skipped: it runs only flex attention (_validate_platform in vllm/engine.py). | ||
| max_num_seqs = max(max_num_seqs, max_num_batched_tokens // 64) |
There was a problem hiding this comment.
Should consider: this floor only keeps every profile request at 64 tokens or fewer when max_num_batched_tokens is a power of two. On main the budget was always 2,048 or a value the user set. This PR adds the max_num_seqs * max_model_len cap at line 53, and that cap can produce a budget that isn't a power of two. Then // 64 rounds down, and the comment above says vLLM puts the remainder on the last request.
Example on an A10G: generate.py --max-num-seqs 1 with max_model_len=1000 resolves to (1000, 15). The profile then runs 15 requests of 66 tokens, which is past the 65-token trigger in flash-attention#3117. With max_num_seqs=2 you get (2000, 31), where 30 requests get 64 tokens and the last gets 80. Using ceil instead of floor doesn't fix it (16 requests -> 62 each, last 70).
The smallest fix keeps main's invariant (a power-of-two budget split over a power-of-two max_num_seqs). On this path, round the capped value down to a power of two, e.g. max_num_batched_tokens = 1 << (max_num_batched_tokens.bit_length() - 1): 1000 -> 512 -> 8 x 64. If you'd rather not touch the cap, a user-set or capped budget that isn't a multiple of 64 x max_num_seqs could raise ValueError on FA2 GPUs. This is niche (FA2 only, tiny max_num_seqs * max_model_len), and I haven't run it.
|
|
||
| # 2x leaves room for uneven routing across DP ranks, validation and a growing buffer. A power | ||
| # of two splits vLLM's max_num_batched_tokens evenly over max_num_seqs (resolve_scheduler_limits). | ||
| return 2 ** math.ceil(math.log2(2 * even_share)) |
There was a problem hiding this comment.
Should consider: removing the clamp here also changes SGLang. SGLangEngine._build_server_args passes this value as max_running_requests (times DP) and full_prefill_max_req (sglang/engine.py:431,475). On main it was clamped to [32, 2048] when the budget was unset. Now it has neither bound. For example, 16 rollouts over 2 DP ranks gives 16 (main: 32), and more than 1,024 rollouts per DP rank gives 4,096 or more (main: 2,048). So "SGLang matches main again" isn't quite accurate.
The small end looks harmless. The large end lets SGLang capture full prefill graphs for more requests, and no in-repo SGLang recipe reaches it. Either say so in the description, or keep min(..., 2048) for SGLang in its engine if the upper bound mattered there. Also, the controller's logger.info("max_num_seqs=%d ...") at line 765 now logs the pre-fit value. Logging the fitted max_num_seqs in resolve_scheduler_limits would keep startup logs accurate on FA2 GPUs.
Summary (human-written)
Agent details
TLDR: With
max_num_batched_tokensunset, the vLLM generator now uses whatvllm servepicks for the GPU: 16,384 on a GB300, 8,192 on an H100, by GPU memory on every GPU platform vLLM supports. On main it got 2,048 on every GPU. SGLang already used its own default, and its code is unchanged. On Qwen3.5-35B-A3B (MoE, 4 GB300s, DP4 x EP4), 16,384 gives 1.72x the prefill and 1.60x the mixed-step throughput of 2,048.Problem
max_num_batched_tokenscaps the tokens one engine step schedules on a DP rank: one per running decode, plus prefill chunks.vllm serveand theLLMclass. The generator builds its engine withLLMEngine.from_engine_args, which falls back to 2,048 on every GPU.CompilationMode.NONE), so it lists the FULL CUDA graph sizes itself, before the engine exists, up tomax_num_batched_tokens. A bigger step runs eager.max_num_seqswith an assumed 2,048: at mostmax_num_batched_tokens(vLLM raises otherwise) and at leastmax_num_batched_tokens/ 64 (a FlashAttention-2 bug, flash-attention issue 3117).Solution
resolve_scheduler_limitsin the vLLM engine returns(max_num_batched_tokens, max_num_seqs). Whenmax_num_batched_tokensis unset, it asks vLLM's config builder whatvllm servepicks (create_engine_config(UsageContext.OPENAI_API_SERVER), 0.05 s), then caps it atmax_num_seqsxmax_model_len, asvllm servedoes.max_num_seqsout of that call (vLLM raises when it is above vLLM's pick), then fits it: at leastmax_num_batched_tokens// 64 on CUDA devices below SM90 (FlashAttention-2), at mostmax_num_batched_tokenseverywhere.generate.pybuilds its engine args withVLLMEngine.build_engine_argsinstead of its own copy.Results
Conditions: real weights, bf16; max_num_seqs 512, max_model_len 16,384, gpu_memory_limit 0.9; random prompts (no prefix hits); decode = 64-token prompts x 256 output tokens, prefill = 4,096-token prompts x 1 output token, mixed = 200 decoders, then 64 prompts of 4,096 tokens 0.5 s later; torchtitan c561eee, vLLM nightly 1.0.0.dev20261105; one run per row.
Not measured: an RL run end to end. These runs used earlier heads; on these GPUs they resolve the same values as this one.
You may ask:
usage_context=UsageContext.OPENAI_API_SERVERtofrom_engine_args? The engine would get the same number, but the FULL graph list is built before the engine, so it would stop at 2,048 (setup C: prefill 0.76x of main). A longer list works for the graphs (vLLM drops sizes above its value, with a warning that prints both lists), but the twomax_num_seqsrules still need the exact value.from_engine_argsstill falls back to 2,048, andmax_num_seqsabove the value still raises. 0.34 can build prefill graphs up to its own value, which removes only the graph reason.EngineArgs._set_default_max_num_seqs_and_batched_tokens_argsis private, and it needs the configs that onlycreate_engine_configbuilds.max_num_batched_tokens, so a big fixed value costs graph memory on every GPU.vllm serve's values and not theLLMclass's (16,384 on an H100, 8,192 on an A10G)? The A10G CI engine would move to 8,192. On an H100, 8,192 vs 2,048 moved wall time by under 1%, so there is no evidence for 16,384 there.NOTE: the
max_num_batched_tokens/ 64 floor onmax_num_seqsnow applies only on CUDA devices below SM90 (FlashAttention-2), ROCm included as on main. SM90+ and XPU (which runs only flex attention) skip it, so small runs there getmax_num_seqsbelow main's 32.generate.py --max-num-seqs 1on a FlashAttention-2 GPU now getsmax_num_batched_tokens// 64 (32 at 2,048).NOTE: Dist-MoE generators size their scratch from
max_num_batched_tokens. The Dist-MoE debug recipe andtest_generator_dist_moe_mxfp8.pyleave it unset, so they now run 16,384 on SM100. So does the Muse Spark 816B DAPO recipe on GB300: its Dist-MoE scratch grows from 2 to 16 GiB per GPU, taken from the KV cache. Not run.NOTE: open PRs touching the same code. The vision-encoder CUDA graphs PR calls
get_vllm_compilation_config, which now needsmax_num_batched_tokens. The PR that moves the Terminal-Bench 35B-A3B recipe to Dist-MoE + FULL graphs leaves it unset, so on GB300 it would run 16,384 with FULL graphs. The V2 runner port editsvllm/config.pynearget_vllm_compilation_config. Whichever lands second rebases.Follow up
resolve_scheduler_limits).Test plan
pytest tests/rl/unit_tests/cpuwith main merged (GRPO on XPU included): 714 passed, 7 skipped.test_unset_max_num_batched_tokens_uses_vllm_serve_defaultcovers 5 cases: plain, the FlashAttention-2 floor, no floor on XPU, the clamp (and that the probe leavesmax_num_seqsout), and themax_num_seqsxmax_model_lencap.VLLMEngine.build_engine_args, then vLLM's owncreate_engine_config()on its result (Qwen3-0.6B, max_model_len 2,048). (max_num_seqs, max_num_batched_tokens) in -> out: (64, unset) -> (64, 16,384), largest graph 16,384; (32,768, unset) -> (16,384, 16,384); (2, unset) -> (2, 4,096); (64, 4,096) -> (64, 4,096). vLLM accepted all 4. The previous head raised on the second case.torchtitan.rl.generateat TP1;test_bitwise_parity.py::TestBitwiseParityVarlen3 passed;test_generator_dp_cudagraph.py::test_vllm_dp_decode_graphs_with_prefilling_peerpassed with both ranks at 16,384;test_generator_dist_moe_mxfp8.pyandtest_vllm_mla_backends.py2 passed.ciflow/rl(A10G at 2,048, H100 at 8,192),ciflow/b200(16,384).