Repository navigation
[rl] SGLang generator: decode CUDA graphs up to max_num_seqs - #6417
felipemello1 wants to merge 3 commits into
Conversation
SGLang's decode graphs stop at min(512, max_running_requests), and it runs a larger decode batch eagerly. Capture up to max_num_seqs, the largest decode batch.
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 2m 29s —— View job Needs discussion: all the measurements ran at DP 1, and I couldn't confirm from SGLang's source whether |
There was a problem hiding this comment.
Verdict: Needs discussion -- the change is the right size and matches the vLLM rule, but every measurement ran at DP 1, and I couldn't confirm from SGLang's source whether cuda_graph_config["decode"]["max_bs"] counts requests per attention-DP rank or across the whole instance.
What this PR does. For every cuda_graph mode except "none", _build_server_args now sets SGLang's largest decode graph size to max_num_seqs. Before, it used SGLang's default, min(512, max_running_requests) on a GB300. Prefill settings don't change. They are now built into the same cuda_graph_config dict, which is passed only when graphs are on.
Example.
max_num_seqs = 1024, DP 1, GB300
main: decode graphs 1..512; a 900-row decode batch runs eagerly (57 ms/step)
this PR: decode graphs 1..512, 544, ..., 1024; a 900-row batch pads to 928 and replays (18.6 ms/step)
max_num_seqs <= 512 on a GB300: graphs are the same as before
Must fix
torchtitan/rl/generator/sglang/engine.py:159-161-- this comment justifies banning CUDA-graph keys inextra_server_args. It says "SGLang's default capture sizes also stay within the step budget that Dist-MoE's buffers and the DeepEP / HybridEP capacity check assume." After this PR the decode cap is TorchTitan's, not SGLang's default. The claim still holds:max_num_seqsdecode tokens per DP rank fit inSGLangModelWrapper'smax_num_tokens_per_step, which ischunked_prefill_size + max_running_requests // attn_dp_size(model_wrapper.py:358). The comment should say so, for example: "The engine's decode graphs stop at max_num_seqs, a DP rank's decode tokens per step, which is within the step budget that ...".
Questions
- Unverified (SGLang source not available here): under attention DP, does SGLang read
decode.max_bsas a per-DP-rank batch size? The engine passesmax_running_requests = max_num_seqs * dpbecause SGLang splits that value over DP ranks (engine.py:437). Ifmax_bsis also divided byattn_dp_size, or compared against the global count, DP > 1 captures onlymax_num_seqs / dprows per rank. That is a regression from the defaultmin(512, max_num_seqs * dp). Please cite the SGLang line that appliesmax_bs, or run one DP 2 build and check the largest captured decode size. - The graph-memory note says nothing reserves memory for the extra graphs, since
mem_fraction_staticis set by TorchTitan. #6332 adds a user override formax_num_seqs. Has a largemax_num_seqs(e.g. 4096, 112 more graphs) been built once on a large model, to show that capture doesn't OOM? If it hasn't, a maintainer should decide whether the vLLM-parity rule is enough, or whether the cap should be bounded.
Details
- Gate: the problem is real (decode batches above 512 rows run eagerly on main when
max_num_seqs> 512). The fix sits at the right layer (the engine already ownscuda_graph_config), adds no knob, and matchesVLLMCudaGraphConfig's decode cap (vllm/config.py:126,:197). The +32% gain is about 5x the reported run-to-run spread. - The
!= "none"guard is required. Per the__post_init__comment, SGLang applies per-phase graph keys overdisable_cuda_graph, so passingcuda_graph_configwith"none"could capture graphs. - MoE step budget: with no MTP, one decode token per request gives at most
max_num_seqstokens per DP rank, which is withinmax_num_tokens_per_step. #6414 (SGLang MTP) bans MoE for now, so the k + 1 tokens per verify row don't reach the EP capacity check yet. - Overlap search: "sglang cuda graph" found #6414 (MTP), #6415 (GDN prefill graphs), #6200 (full prefill graphs for linear attention) and #6332 (
max_num_seqsoverride). None of them edits the decodecuda_graph_configblock, so there's nothing to rebase onto. Through #6332, a user-setmax_num_seqsnow also sets the graph count.
Not verified: SGLang's handling of cuda_graph_config.decode.max_bs (source not available in this environment), and runs at DP > 1.
Before merge: fill in the human-written summary.
…s, within the step budget
|
Reply from claude: Fixed the comment in bbd4126. The # before
# checks of cuda_graph assume are off. SGLang's default capture sizes
# also stay within the step budget that Dist-MoE's buffers and the
# DeepEP / HybridEP capacity check assume.
# after
# checks of cuda_graph assume are off. SGLang's prefill capture sizes and
# the decode graphs, which stop at max_num_seqs (a DP rank's decode
# tokens per step), stay within the step budget that Dist-MoE's buffers
# and the DeepEP / HybridEP capacity check assume.
So at DP 2 and Large @claude please review |
|
Claude finished @felipemello1's task in 1m 34s —— View job Needs discussion: nothing is left for the author to fix. Whether to bound the decode-graph cap at a large |
There was a problem hiding this comment.
Verdict: Needs discussion -- nothing is left for the author to fix. A maintainer still has to decide whether capping decode graphs at max_num_seqs is enough, given that no large-model or large-max_num_seqs build has run.
What this PR does. For every cuda_graph mode except "none", the engine now caps SGLang's decode graphs at max_num_seqs instead of SGLang's default, min(512, max_running_requests). The prefill settings don't change.
Example.
max_num_seqs = 1024, DP 2, GB300 (per the author's SGLang citations)
main: each rank captures decode graphs 1..512; a 900-row decode batch on a rank runs eagerly
this PR: each rank captures 1..512, 544, ..., 1024; that batch pads to 928 and replays
max_num_seqs <= 512 on a GB300: same graphs as before
Earlier review, at bbd4126
- Must fix 1 (stale
extra_server_argscomment,engine.py:159-162): resolved. The comment now ties the decode cap to the step budget. That matchesmodel_wrapper.py:358-360, where the budget ischunked_prefill_size + max_running_requests // attn_dp_size, andmax_running_requests // attn_dp_sizeequalsmax_num_seqs(engine.py:439). - Question (does
decode.max_bscount per DP rank?): answered. The author cites SGLang 851642ade: graphs are chosen by the largest per-rank count (decode_cuda_graph_runner.py:858-864,:921-925), and sizes are clamped to the per-rankreq_to_token_pool(base_cuda_graph_runner.py:79-115,kv_cache_configurator.py:183). The two halves are consistent. A count across all ranks would conflict with the per-rank pool clamp. Unverified here: SGLang's source isn't in this environment. - Question (graph memory at a large
max_num_seqs): still open, and it's a maintainer's call. Nothing reserves memory for the extra graphs, because TorchTitan setsmem_fraction_staticitself. At 4,096 that is 112 more graphs than main, and #6332 lets users setmax_num_seqs. The author has a 27B build at 4,096 planned. Until it runs, a maintainer decides whether to accept parity with vLLM's rule (VLLMCudaGraphConfigcaps atmax_num_seqswith the same exposure) or to bound the cap.
Details
- Re-reviewed every commit since the last full review. That is bbd4126 (a comment-only change) plus a merge of main, which touches no file in this PR.
cuda_graph="decode"now passescuda_graph_config={"decode": {...}}together withdisable_prefill_cuda_graph=True. There is no prefill key, so per-phase prefill settings can't re-enable prefill graphs. The author's decode-mode run built and decoded at up to 1,024 rows. The description doesn't say prefill stayed eager in that run. Worth one line if it was checked.- The PR adds no knob and changes no shared code.
Not verified: the SGLang lines the author cited, and builds at DP > 1 or at a large max_num_seqs on a large model.
Before merge: fill in the human-written summary.
|
Reply from claude: I ran the large build. On Qwen3.5-27B, Qwen3.5-27B, one GB300, Why they match:
So the cap's worst case is bounded by how many requests fit in memory. The extra graphs appear only when memory holds that many requests: Qwen3.5-0.8B at 1,024 added 16 graphs and kept its KV capacity (body). A dense model with a large |
|
Reply from claude: A follow-up with a dense model, where SGLang doesn't cap the requests. On Qwen3-14B, Qwen3-14B, one GB300, What it means:
So at 4096 requests per DP rank, a dense 14B pays about 34 s more decode capture at startup and 3.3 GB more decode graph memory, in exchange for no eager decode steps above 512 requests. Whether to cap that is the maintainers' call. |
Summary (human-written)
Agent details
TLDR:
SGLangEnginecaptures decode CUDA graphs up tomax_num_seqsrequests, the rule the vLLM engine already follows. SGLang's default stops at 512 and runs a larger decode batch eagerly. Qwen3.5-0.8B on one GB300 atmax_num_seqs1024: +32% output tok/s (5,669 -> 7,477), decode steps 57.1 -> 18.6 ms.Problem
max_num_seqsrequests per DP rank. The controller sets it to 2x each DP rank's share of the rollouts in flight, rounded up to a power of two (max_num_seqs_per_generator_dp_rank): 4,096 rollouts in flight over 8 DP ranks give 1,024.min(512, max_running_requests)on GPUs with at least 160 GB (memory_hook.py,_handle_gpu_memory_settings).max_num_seqs1024, every decode step of the agent load below had more than 512 rows (up to 1,019). Each ran eagerly, at 57 ms on average.Solution
_build_server_argssetscuda_graph_config["decode"]["max_bs"] = max_num_seqsfor everycuda_graphmode except "none".This is the vLLM engine's rule: its decode graph cap is
max_num_seqs(VLLMCudaGraphConfig.get_vllm_compilation_config).max_num_seqs, plusmax_num_seqsitself.max_num_seqs<= 512 the graphs are the same as before on a GB300. On GPUs below 160 GB, SGLang's default is smaller (256 or less at TP < 4), so this PR captures more graphs there.Results
+32% is about 5x the run-to-run spread of this harness: 3-6% over two runs per engine of a 128-session load. Prefill steps take longer with this PR because they hold more tokens: faster decode lets more turns arrive per second.
You may ask:
max_num_batched_tokensstill overrides it.NOTE: more decode graphs take more GPU memory, and TorchTitan sets
mem_fraction_staticitself, so SGLang's own reserve for graph memory doesn't apply: the graphs take what the static pool leaves. The ladder adds one graph per 32 rows above 512: 16 more atmax_num_seqs1,024, 112 more at 4,096. The controller capsmax_num_seqsonly atmax_num_batched_tokens. The 0.8B run above kept the same KV capacity. Qwen3.5-27B on one GB300 captures the same 19 graphs at 4,096 as at 256: SGLang's linear-attention state cache caps it at 119 requests. A dense model pays the full ladder: on Qwen3-14B (one GB300), 4,096 captures 164 decode graphs instead of 36 at 256, with 48.9 s instead of 14.8 s of decode capture and 3.36 GB instead of 0.09 GB of decode graph memory. The vLLM engine has the same exposure.NOTE: with MTP, SGLang's decode ladder is denser (one graph per 16 rows above 272), and each row holds k + 1 tokens. Build time and graph memory with MTP at a large
max_num_seqswere not measured.Test plan
SGLangEnginethroughadd_requestsandstep. It records each step's kind and rows by wrappingscheduler.run_batch.pytest tests/rl/unit_tests/cpu: 771 passed, 8 skipped, 2 failed. The 2 fail on main too:test_kv_offload_coordination.py::test_terminal_cleanup_preserves_block_identity, 2 cases.TestSGLangBitwiseParityKDA(1 GPU, breakable graphs): 6 passed on one GB300.cuda_graph="decode"(decode graphs, prefill eager), which no GPU test class runs: the same harness built the engine in that mode atmax_num_seqs1024 (67 s) and ran the 1,024-session load for 60 s. Decode steps had 1,016 rows on average (up to 1,024), p50 13.6 ms.max_num_seqs5, below 512, where nothing changes. They do build the engine with the new decode config.