Repository navigation
[rl] Generator: vLLM's dense CUDA graph sizes, plus a prefill tail - #5383
Conversation
9b59185 to
2d3bfba
Compare
2d3bfba to
3e832f6
Compare
f134db5 to
32633b3
Compare
32633b3 to
68ea196
Compare
|
@claude please review |
|
Claude finished @felipemello1's task in 2m 51s —— View job Request changes -- see the review. The KV/init cost of 6x more FULL graphs isn't measured yet, the decode-graph count in the |
There was a problem hiding this comment.
Verdict: Request changes -- the PR raises the number of FULL graphs about 6x (16 -> 96 at max_num_seqs 230), but the engine-init and KV-block cost of that is still <FILL IN>, and a stale docstring in worker.py gives the old graph count.
What this PR does. It replaces the generator's power-of-2 CUDA graph sizes with vLLM's spacing: 1, 2, 4, then every 8 up to 256, then every 16 up to max(1024, max_num_seqs). For FULL prefill it adds a coarse tail: every 512 up to 4096, then every 2048 up to the cap. max_num_seqs and the cap stay as exact sizes.
Example. max_num_seqs=230, max_num_batched_tokens=16384, FULL:
34 decodes main: pad to 64 PR: pad to 40
230 decodes main: 230 (exact) PR: 230 (exact)
1100-tok chunk main: pad to 2048 PR: pad to 1536
9000-tok chunk main: pad to 16384 PR: pad to 10240
FULL graphs main: 16 PR: 96 (decode graphs 9 -> 32)
Must fix
- PR description -- "engine init and KV blocks:
<FILL IN BEFORE POSTING>" is still a placeholder. This is the main cost of the PR.worker.py:116-118says vLLM's graph-memory estimate, which is taken out of the KV cache, charges every FULL mixed graph like the second-largest one. If that estimate scales with the graph count, 16 -> 96 mixed graphs (sizes up to 14336 tokens) could shrink the KV cache noticeably, and capture time grows too. I couldn't verify how vLLM computes the estimate. Please fill in the before/after for init time and KV blocks on one recipe. If KV loss is large, thin the 256-1024 +16 band for FULL (prefill doesn't need +16 there). torchtitan/rl/generator/vllm/worker.py:47-48(not in the diff) -- "one additional graph capture per decode-specialized batch size (11 at max_num_seqs 1024)". With this PR it is 83 at max_num_seqs 1024 (3 + 31 + 49). The 0.03 GiB figure for 11 decode graphs atworker.py:117-118also no longer describes the default. Update both, or drop the specific numbers.config.py:201-202-- the comment (and the "runs eager" answer in the description) is wrong for FULL mode: that batch replays the mixed graph. See the inline comment.
Should consider
test_generator.py:908-916-- exact-list asserts copy the implementation. Assert the invariants instead (inline).
Questions
- The description calls +16 up to 1024 "vLLM's own spacing" and "vLLM's default". As far as I know, vLLM's default
max_cudagraph_capture_sizeismin(2 * max_num_seqs, 512). Is the 1024 bound picked on purpose (evidence for 512-1024 at +16 rather than coarser)?
Details
- Gate: the problem is real: padding 34 rows to 64 costs +16% per decode step, as measured in the description. This is the right layer: torchtitan already owns
_default_capture_sizes, and vLLM's own +16 default would mean ~1000 graphs up to 16384. No overlapping PR found. - I checked the graph counts in the description against the code: 3 + 31 + 49 + 1 (230) + 6 + 6 = 96, and decode sizes up to 230 = 32. Both match.
max_num_seqs > 1024: the dense +16 band extends tomax_num_seqs, e.g. 4096 gives ~240 graphs below the tail. This is intentional per the docstring, but it multiplies the cost in item 1 for large-batch recipes.- The expert-SP filter still works: every size from 8 up is a multiple of 8, and only 1/2/4 and a non-aligned
max_num_seqsget dropped (same as before). - The 1024 -> 1536 gap pads a 1040-token chunk by about 48%, which is still better than main's pad to 2048.
Not verified: vLLM's graph-memory estimate formula and the resulting KV-block change (no GPU, vLLM source not readable here). A maintainer still needs to review.
| # Linear-attention (GDN, KDA) decode graphs stop at max_num_seqs. Without this size, | ||
| # at max_num_seqs=230 a batch of 225-230 pads to 232 and runs without a CUDA graph. |
There was a problem hiding this comment.
This says the wrong thing about what happens without this size. In FULL mode, TorchTitanCudagraphDispatcher.dispatch (worker.py:87-94) sends a uniform-decode batch above max_decode_capture_size to the mixed FULL graph. It runs eager only in batch-invariant mode. test_full_mode_decode_dispatch covers this: "3 decodes pad to 8, past the largest decode graph (2): mixed graph". So a batch of 225-230 replays the 232 mixed graph, with the slower mixed-path GDN/KDA and FA4 kernels. It doesn't run without a graph. In FULL_DECODE_ONLY, cap == max_num_seqs, so cap already adds this size and the separate entry only matters for FULL. The PR description's "runs eager" answer needs the same correction.
| # Linear-attention (GDN, KDA) decode graphs stop at max_num_seqs. Without this size, | |
| # at max_num_seqs=230 a batch of 225-230 pads to 232 and runs without a CUDA graph. | |
| # FULL decode graphs (decode kernels for GDN/KDA and FA4) stop at max_num_seqs. Without this | |
| # size, at max_num_seqs=230 a batch of 225-230 pads to 232 and replays the mixed graph instead. |
| assert cfg.cudagraph_capture_sizes == [ | ||
| *[1, 2, 4], | ||
| *range(8, 256, 8), # +8 | ||
| *range(256, 500, 16), # +16 | ||
| 500, # max_num_seqs: a full decode batch has its own graph | ||
| *range(512, 1025, 16), # +16 | ||
| *range(1536, 4097, 512), # +512 | ||
| *range(6144, 16385, 2048), # +2048 | ||
| ] |
There was a problem hiding this comment.
Optional: this rebuilds _default_capture_sizes with the same range calls, so it snapshots the ladder and every spacing tweak has to be copied here. It doesn't check the invariants the PR depends on. Assert those instead: 40 in sizes (34 sequences pad to 40), 500 in sizes (a full decode batch gets an exact graph), and sizes[-1] == 16384 (the largest chunk is graphed). The FULL_DECODE_ONLY test above has the same issue.
68ea196 to
b547051
Compare
|
Reply from claude: @claude please review again. Rebased on #5488's new head; head b547051.
|
|
Claude finished @felipemello1's task in 51s —— View job Approve -- all earlier must-fix items are resolved, see the review. |
There was a problem hiding this comment.
Verdict: Approve -- all three must-fix items from the last review are resolved at b547051, and the new commit adds no new problems.
Earlier findings
- Engine-init / KV cost: resolved. The description now has the before/after table (Qwen3.5-9B TP2, max_num_seqs 230). KV cache goes up 2.7%, real graph memory goes up 0.59 GiB, and engine init is 4% slower. It also explains why: vLLM's estimate charges each graph like the second largest one, which went from 8192 to 14336 tokens.
worker.py:47-48graph count: resolved. 83 matches the code at max_num_seqs 1024 (3 + 31 + 49).worker.py:118now labels the Qwen3-8B 0.03 GiB number as a measurement of 11 decode graphs.config.py:193-194comment: resolved. Both the comment and the description now say a 225-230 batch replays the mixed graph, and runs eager only in batch-invariant mode.
- Tests: resolved. They now check the invariants (40, 500, 16384) instead of copying the size ladder. The
[992, 1000]tail intest_cuda_graph_full_mode_drops_sizes_above_max_model_lenis correct for max_model_len 1000. - Question about the 1024 bound: answered (vLLM's Blackwell default, min(2 x max_num_seqs, 1024)).
Details
- Example, max_num_seqs=230, FULL, 16384 budget: 34 decodes pad to 40 (main: 64). 230 decodes get an exact graph. A 9000-token chunk pads to 10240 (main: 16384).
- With expert SP of degree 16, the +8 sizes are filtered out, so 34 sequences pad to 48. That is still better than 64, and the filter behaves as before.
- One tradeoff stays: the dense +16 band goes up to max_num_seqs when max_num_seqs is above 1024, so large-batch recipes capture many more graphs. The docstring says this is intentional, and the measured KV effect at 230 is positive.
Not verified: vLLM's estimate formula and the vllm/config/vllm.py reference (vLLM source not available here). A maintainer still needs to review.
b547051 to
326f534
Compare
| """CUDA graph sizes up to ``cap``. vLLM pads each step up to the next size. | ||
|
|
||
| 1 2 4 | ||
| 8 16 24 ... 248 +8 vLLM's spacing: 34 sequences pad to 40, not 64 |
There was a problem hiding this comment.
regarding "vLLM's spacing", could you share a code pointer?
if there is one, can we call their function, private or not?
There was a problem hiding this comment.
Reply from claude: vLLM builds its default list inline in VllmConfig._set_cudagraph_sizes: [1, 2, 4], then every 8 up to 256, then every 16 up to its cap (vllm/config/vllm.py lines 2336-2346 at the pinned 9f03b51; 2697-2707 on main). Its cap is min(2 x max_num_seqs, 1024 on Blackwell, 512 elsewhere) (lines 2226-2227).
We can't call it. It is a method on the VllmConfig that vLLM builds inside the engine, and it uses either our explicit list or its own list, not both (lines 2322-2327 vs 2328-2346). Its own list would continue every 16 up to max_num_batched_tokens: about 1,040 graphs at 16384. So we copy its spacing up to 1024 and add the prefill tail. 3d4dd0d puts this pointer in _default_capture_sizes's docstring.
326f534 to
3d4dd0d
Compare
|
Claude finished @felipemello1's task in 44s —— View job Approve: the rebase onto #5488 works with the new size ladder, and tianyu-l's question is answered in the docstring. See the review. |
There was a problem hiding this comment.
Verdict: Approve -- the rebase onto #5488's new head works with the new ladder, and tianyu-l's question has an answer in the code. The new head adds no new problems.
What changed since the last review (b547051 -> 3d4dd0d)
- Rebase:
capis nowmin(max(max_num_seqs, budget), max_num_seqs * max_model_len)(config.py:126-129)._default_capture_sizesdrops every size abovecap(config.py:202), so the new ladder works with the lower cap. The docstring examples (config.py:90-91) and the test tails match the code:In FULL,FULL, max_num_seqs=8, max_model_len=1000, budget 2048 -> cap 2048: ... 1024, 1536, 2048 FULL, max_num_seqs=1, max_model_len=1000, budget 2048 -> cap 1000: ... 976, 992, 1000cap >= max_num_seqsalways holds (max_model_len >= 1), so the exactmax_num_seqssize is never filtered out. - tianyu-l's question at
config.py:184(code pointer, and whether we can call vLLM's function): the author answered it in the thread. The docstring now points toVllmConfig._set_cudagraph_sizesand explains why we can't call it: vLLM uses either our list or its own, and its own list would keep the +16 spacing up to the budget. No pushback yet. tianyu-l should confirm the answer is enough. - Since the rebase leaves the cap unchanged at max_num_seqs 230 with budget and context both 16384, the engine-init/KV table in the description should still hold.
Not verified: the vllm/config/vllm.py line references (vLLM source not available here). The PR touches only torchtitan/rl/, and a maintainer still needs to review it.
The auto ladder was powers of 2 up to the cap. Agent rollouts keep a generator at a few dozen sequences, so decode padded up to the next power of 2 (34 running sequences -> the 64 graph). Use vLLM's default ladder (1, 2, 4, every 8 to 256, every 16 to 1024), then, for FULL prefill steps, every 512 up to 4096 and every 2048 up to max_num_batched_tokens.
3d4dd0d to
2ac320f
Compare
TLDR: The generator's default CUDA graph sizes go from powers of 2 to vLLM's spacing, plus a coarse tail for FULL prefill. 34 running sequences now pad to the 40 graph instead of the 64 graph. On a 4-layer Qwen3.5-35B-A3B, a 64-row decode step takes 2408 us and a 34-row step 2072 us.
Problem
VLLMCudaGraphConfigcaptures powers of 2 up to the cap, plusmax_num_seqsand the cap.Solution
_default_capture_sizes: 1, 2, 4, every 8 to 256, every 16 to 1024 (or tomax_num_seqs, if larger). This is vLLM's own spacing, and 1024 is vLLM's default limit on Blackwell.max_num_batched_tokens.max_num_seqsstays an exact size: FULL decode graphs stop atmax_num_seqs, so a full batch must not pad past it.capture_sizes, the cap, and the expert-parallel size filter.Results
You may ask:
max_num_seqs, 1024) on Blackwell? Prefill steps above it would run without a graph: 1.8x slower.max_num_seqsas its own size? FULL decode graphs exist only up tomax_num_seqs. A full batch of e.g. 230 padded to 232 finds no decode graph and replays the mixed graph, with the slower mixed-batch GDN/KDA and FA4 kernels (eager in batch-invariant mode).NOTE: Not measured: the new prefill sizes vs main's powers of 2 (which also graph 2048 to 16384, with more padding).
Test plan