Repository navigation
[rl] Log the generator's CUDA graph padding fraction - #5945
felipemello1 wants to merge 3 commits into
Conversation
The vLLM model runner pads each forward to a CUDA graph capture size (plus TP rounding and DP equalization). Nothing reported how many forward tokens were padding. TorchTitanGPUModelRunner now counts real and padded tokens of real forwards (dummy runs excluded). VLLMEngine attaches the counts to one finished request per engine step, and rank 0 logs generator/cudagraph_padding_fraction, a mean weighted by forward tokens.
Review round 1: - Log generator/cudagraph_padding_frac whatever the carrying request's prefix: the counts cover every request in the engine, training and validation alike. - Counters are class attributes, so runners built with object.__new__ in tests keep working. - Count before the linear-attention TODO; name the fields num_engine_*. - Test that dummy runs stay out of the counts.
…names the fixed key
|
Reply from claude: @claude please review |
|
Claude finished @felipemello1's task in 3m 37s —— View job Approve -- please fill in the human-written summary before merging. Review |
There was a problem hiding this comment.
Verdict: Approve -- please address the items below before merging. The approach is the smallest one that gets an engine-wide vLLM stat to W&B: it adds no vLLM flag, no config field and no new channel. The counting matches vLLM's own CUDAGraphStat inputs. This touches the RL generator, so a maintainer still needs to review.
What this PR does. TorchTitanGPUModelRunner sums real and padded tokens for each real forward. It does this in its existing _determine_batch_execution_and_padding override, and a flag set in _dummy_run keeps dummy forwards out. When a VLLMEngine.step finishes at least one request, the step pops those sums and attaches them to the first finished request's RequestMetricsInputs. Rank 0 then emits them as generator/cudagraph_padding_frac = Mean(padded - real, count=padded). Because each DP rank pops its own counter, every forward is counted at most once across DP.
Example.
DP rank 1, engine steps since last pop: decode x3 -> graph 4, decode x5 -> graph 8
step finishes requests [r7, r9] -> r7.metrics_inputs gets (unpadded=8, padded=12); r9 gets (0, 0)
rank 0 builds r7's Completion -> Metric("generator/cudagraph_padding_frac", Mean(4, count=12))
trainer step that takes r7 + another DP rank's (3, 4) carrier -> (4+1)/(12+4) = 0.31
Must fix
- PR description -- "Summary (human-written)" is empty. The author needs to fill it in. Agents don't.
Should consider
torchtitan/rl/generator/dispatcher.py:439-- the key name says "cudagraph", but the value also covers SP rounding and DP equalization, and it is logged in eager runs too (inline).torchtitan/rl/generator/dispatcher.py:391-395-- drop the speculative "a second such stat should..." sentence from the TODO (inline).
Details
- Alternative considered: reading the counts in
Generator.sync_log_step->engine.log_stats(step). That path only runs on rank 0, on the RPC side rather than the engine-loop thread, so reading the runner's counters there would race withstep(). It also can't see the other DP ranks' runners without a new collective, and it has no path into the controller'sMetricsProcessor. Riding on a finished request avoids all three, so the piggyback is justified. - TP > 1: only TP rank 0 forwards finished requests (
dispatcher.py:process_finished_requests), so each replica's counts are added once. Counters on TP ranks > 0 are never read, which is harmless. - Lost counts: counts can be lost on failed rollouts and on completions the trainer never takes. That only shrinks the sample. The carrier is whichever request finishes first in a step, which is independent of the request's outcome, so the ratio stays unbiased. DAPO-filtered groups still contribute their metrics through the batcher's metric-only groups.
- Final step: validation runs only at the start and end, so the documented double point at the final step is the only collision.
- Tests: the new and extended tests guard real invariants: dummy runs are excluded, the runner resets after a pop, and the Mean is weighted by padded tokens.
Not verified: that driver_worker.model_runner resolves through vLLM's WorkerWrapperBase and that batch_descriptor.num_tokens includes DP equalization in the pinned vLLM. vLLM isn't readable on this runner; the author's GPU run suggests both hold.
| ) | ||
| metrics.append( | ||
| m.Metric( | ||
| "generator/cudagraph_padding_frac", |
There was a problem hiding this comment.
The value covers all forward padding: CUDA graph capture sizes, sequence-parallel rounding and DP equalization. Your own comment above notes that eager steps count too. So a run with cuda_graph.mode="NONE" still logs cudagraph_padding_frac, where the number is really SP/DP padding. A name for what is measured, e.g. generator/forward_padding_frac or generator/padded_token_frac, would avoid that confusion. Since the key is new, now is the cheapest time to rename it.
There was a problem hiding this comment.
Reply from claude: Kept the name on purpose. Felipe asked for a CUDA graph padding metric, and in the default FULL mode almost all of this value is capture-size padding. The comment above the key says eager steps count only sequence-parallel rounding, so an eager run reads as near 0 rather than wrong. Happy to rename to generator/forward_padding_frac if a maintainer prefers.
| # in SchedulerStats / IterationStats, which only reach a registered | ||
| # vllm.v1.metrics.loggers.StatLoggerBase (VllmOtelStatLogger, when | ||
| # VLLMEngine.Config.stat_logger is set). To log one to W&B, carry it on a | ||
| # finished request like the CUDA graph padding counts (VLLMEngine.step). A second | ||
| # such stat should switch to one list of engine metrics built in VLLMEngine.step. |
There was a problem hiding this comment.
The last sentence ("A second such stat should switch to one list of engine metrics built in VLLMEngine.step") is a design note about future code. The comment should stay a TODO that describes where these stats live now and how to reach them. Suggest dropping that sentence. Whoever adds the second stat can decide the shape then.
There was a problem hiding this comment.
Reply from claude: A round of reviewers asked for that sentence. Without it, the next engine stat would copy this pattern and add two more fields to RequestMetricsInputs. It names the switch point rather than a design. I'll drop it if a maintainer disagrees.
Summary (human-written)
Agent details
TLDR: A new metric,
generator/cudagraph_padding_frac, shows how much of the generator's forward work is padding. Example: decodes of 3 and 5 requests replay the 4- and 8-token CUDA graphs, so 4 of 12 forward tokens are padding (0.33).Problem
max_num_seqsand the capture sizes decide how much padding a run gets.Solution
TorchTitanGPUModelRunnercounts real and padded tokens in its existing_determine_batch_execution_and_paddingoverride. These are the numbers vLLM's ownCUDAGraphStatuses (num_tokensvsbatch_descriptor.num_tokens)._dummy_runoverride keeps them out.VLLMEngine.stepattaches the engine's counts since the last report to one finished request. Rank 0 already gets every DP rank's finished requests, so each rank's counts are added once.Mean(paddings, count=padded tokens). It covers every request in the engine, training and validation alike. Over a run, each forward is counted at most once: counts on a completion that is never logged (a failed group, or a training request that finishes after the trainer stops) are lost. One training step's value covers the completions that step took.You may ask: why not read vLLM's own stats?
CUDAGraphStatonly with itscudagraph_metricsflag. Even then,LLMEngine.step()never returns it: it only goes to stat loggers.VllmOtelStatLogger, is off by default and exports to OpenTelemetry, not W&B. Getting the stat to W&B would need a new stat logger on each DP rank, plus the same hand-off through a finished request that this PR uses.VLLM_LOG_STATS_INTERVALseconds. Our engine runs with stats on, so that logger is always there.Results
NOTE:
Test plan
test_generator.py::test_cudagraph_padding_frac_weights_each_engine_step_by_its_tokenstest_vllm_dist_moe_padding_mask.py::test_runner_leaves_dummy_runs_out_of_the_token_countstest_generator.py::test_step_returns_finished_requests_without_grad(counts attached to the finished request) andtest_vllm_dist_moe_padding_mask.py::test_runner_publishes_the_unpadded_count_before_vllm_pads(the runner counts and resets).test_vllm_wrapper.pyis skipped above because this host'sattn_gymhas nomlamodule. Main fails to import it the same way.tests/rl/unit_tests/gpu). The counters are class attributes, sotest_gdn_graph_metadata.py, which builds the runner without__init__, keeps working.