Skip to content

[graph_trainer] Remove cuda_graph passes in graph_trainer by default - #5023

Merged
IvanKobzarev merged 1 commit into
pytorch:mainfrom
IvanKobzarev:gt-cudaconfigs
Oct 13, 2026
Merged

IvanKobzarev merged 1 commit into
pytorch:mainfrom
IvanKobzarev:gt-cudaconfigs

Conversation

@IvanKobzarev

@IvanKobzarev IvanKobzarev commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

The main goal is to make GraphTrainer to work seamlessly with outer CUDA graph capture by default.
In torchtitan case - torchtitan trainer is doing cudagraph capture.

  1. Removing cuda_graph.py passes from default passes
  2. Preserve them in codebase and keep them tested on ci for users that would be constructing the set of passes on their own and can use them for some special cases like partial cudagraphs etc.

@pytorch-bot pytorch-bot Bot added the ciflow/fake-pg Run 1-GPU Fake PG integration tests label Oct 2, 2026
@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Oct 2, 2026
@IvanKobzarev IvanKobzarev added the ciflow/h100.8 Trigger H100.8 CI label Oct 2, 2026
@IvanKobzarev IvanKobzarev changed the title [graph_trainer] Restore full-step CUDA graph capture [graph_trainer] cudagraph configs fix Oct 2, 2026
@pytorch-bot pytorch-bot Bot added the ciflow/b200 Trigger B200 CI label Oct 7, 2026
@IvanKobzarev IvanKobzarev changed the title [graph_trainer] cudagraph configs fix [graph_trainer] Use client-owned CUDA graph capture Oct 7, 2026
@IvanKobzarev IvanKobzarev changed the title [graph_trainer] Use client-owned CUDA graph capture [graph_trainer] Remove graph_trainer inner cudagraph passes Oct 7, 2026
@IvanKobzarev
IvanKobzarev force-pushed the gt-cudaconfigs branch 2 times, most recently from 08930d5 to 978824f Compare October 8, 2026 12:26
@IvanKobzarev IvanKobzarev changed the title [graph_trainer] Remove graph_trainer inner cudagraph passes [graph_trainer] Use client-owned CUDA graph capture Oct 8, 2026
@IvanKobzarev IvanKobzarev changed the title [graph_trainer] Use client-owned CUDA graph capture [graph_trainer] Remove cuda_graph passes in graph_trainer by default Oct 8, 2026

@SherlockNoMad SherlockNoMad 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.

mostly looks good to me, should be good for land when you address the comment.

@IvanKobzarev
IvanKobzarev force-pushed the gt-cudaconfigs branch 2 times, most recently from f6bda32 to f7fbdfc Compare October 13, 2026 17:57
syed-ahmed added a commit that referenced this pull request Oct 13, 2026
#5023 moves CUDA graph capture out of `cuda_graph_pass`
and into the client `TrainingEngine`, which captures the whole
forward/backward as one graph. Paged stashing composed with the old
pass-level capture by sitting outside each captured subgraph; with a
whole-step graph it ends up inside one, where `PagedStashRunner`'s
host-side work is not capturable -- the overflow flag's `event.query()`,
the freelist reset, and the Triton warmup, which cannot compile during
capture.

Invert the nesting. Wrap the eager forward/backward in the CUDA graph
first, then run the runner around that: the runner stays on the host and
may rerun the step, and the graph holds only the step itself.

An overflow still has to drop the graph before the pages it baked
pointers into are released, so `PagedStashRunner` takes a
`reset_cuda_graphs` callback rather than calling the module-level
function, which after #5023 has no trainer graph to reset. The trainer
passes one that tears its graph down and rebuilds the wrapper, and the
rebuilt wrapper is looked up on every attempt so a blocking rerun picks
it up.

Whole-step capture also lifts the pipeline-parallel restriction in
`next_entries`, which returned no entries under capture: a stage-level
graph captured at one point in the schedule would replay that point's
skip and prefetch decisions for every microbatch. The trainer captures
every pipeline action at its own place, so the schedule-dependent
answers replay correctly and skipping and prefetching work under GraphPP
with graphs on.

Measured on 4xGB200, DeepSeek-V3 debugmodel + HybridEP, PP=2
Interleaved1F1B / 4 microbatches, FSDP 2, EP 2, round-robin routing;
peak reserved on the worst rank, saved-but-not-paged against paged:

  HybridEP capacity factor    1.0     2.0     4.0     8.0
  saved, not paged          10.89   14.72   23.05   39.19 GiB
  paged                      9.68   10.00   11.22   13.82 GiB

Capture is what makes the un-paged side cost `layers x padded`: it pins
every layer's padded buffer in the graph's private pool. The stash pool
that replaces them is 2217.56 MiB at capacity factor 1, 2 and 4 and
2219.01 MiB at 8, while the padded residency grows 2016 -> 16138 MiB, so
the pool follows live rows and not the padding. Over the sweep the
un-paged slope is 4.06 GiB per capacity-factor unit against 0.61 paged.

The runtime mechanics are now tested the way they run, with the step
captured. `test_blocking_mode` drives the whole-step graph and absorbs
the separate pass-level CUDA graph case it duplicated. `test_deferred_mode`
gains a captured step, so the default overflow policy is covered around a
graph and not only eagerly.
`test_reloads_are_prefetched_one_schedule_entry_ahead` captures and
replays a prefetched reload, since prefetching is how the stash runs
under the trainer's graph. `test_paged_activation_lives_until_its_copy_is_joined`
captures the release, which is where it bites: an activation held past
its join keeps its padding in the graph's private pool for the life of
the graph, and that per-layer residency is what paging removes.
`test_schedule_decides_which_stashes_stay_resident` pins `next_entries`
under capture with a pipeline schedule -- the one place the lifted
restriction needs covering, since skipping and prefetching both read it.
`test_sizing_keeps_one_pool_of_live_pages` gains the `worst_case +
actual` decomposition an earlier consolidation dropped.

What stays eager is what capture cannot reach: the graph-pass and
partition tests run at trace time, before there is a stream to capture;
the schedule and sizing tests are arithmetic over actions and page
counts; and the optimizer-skipping test turns on `optimizers.step()`
honoring the flag on device, which runs outside the forward-backward
graph.

Paged stashing had two integration tests, one per concurrency mode,
because the modes could not be combined. They can, so one covers it:
`aot_fx_trace_deepseek_v3_graph_pp_hybridep_paged_stash` drops
`disable_cuda_graphs` and runs GraphPP, the whole-step CUDA graph and
paged stashing together. It passes on 4 GPUs with "Recorded CUDA graph"
on every rank, GraphPP sizing engaged on every rank, and no token drops.
The FSDP+TP config it replaces is the only coverage lost; TP does not
fit alongside PP 2 and FSDP 2 at 4 GPUs.
Remove cuda_graph_pass from GraphTrainer default pass construction, configuration, precompile, and GraphPP wiring while keeping the pass implementation available for explicit callers. The client TrainingEngine owns outer capture around the complete forward/backward execution.
@IvanKobzarev
IvanKobzarev merged commit bed2b9e into pytorch:main Oct 13, 2026
syed-ahmed added a commit that referenced this pull request Oct 13, 2026
#5023 moves CUDA graph capture out of `cuda_graph_pass`
and into the client `TrainingEngine`, which captures the whole
forward/backward as one graph. Paged stashing composed with the old
pass-level capture by sitting outside each captured subgraph; with a
whole-step graph it ends up inside one, where `PagedStashRunner`'s
host-side work is not capturable -- the overflow flag's `event.query()`,
the freelist reset, and the Triton warmup, which cannot compile during
capture.

Invert the nesting. Wrap the eager forward/backward in the CUDA graph
first, then run the runner around that: the runner stays on the host and
may rerun the step, and the graph holds only the step itself.

An overflow still has to drop the graph before the pages it baked
pointers into are released, so `PagedStashRunner` takes a
`reset_cuda_graphs` callback rather than calling the module-level
function, which after #5023 has no trainer graph to reset. The trainer
passes one that tears its graph down and rebuilds the wrapper, and the
rebuilt wrapper is looked up on every attempt so a blocking rerun picks
it up.

Whole-step capture also lifts the pipeline-parallel restriction in
`next_entries`, which returned no entries under capture: a stage-level
graph captured at one point in the schedule would replay that point's
skip and prefetch decisions for every microbatch. The trainer captures
every pipeline action at its own place, so the schedule-dependent
answers replay correctly and skipping and prefetching work under GraphPP
with graphs on.

Measured on 4xGB200, DeepSeek-V3 debugmodel + HybridEP, PP=2
Interleaved1F1B / 4 microbatches, FSDP 2, EP 2, round-robin routing;
peak reserved on the worst rank, saved-but-not-paged against paged:

  HybridEP capacity factor    1.0     2.0     4.0     8.0
  saved, not paged          10.89   14.72   23.05   39.19 GiB
  paged                      9.68   10.00   11.22   13.82 GiB

Capture is what makes the un-paged side cost `layers x padded`: it pins
every layer's padded buffer in the graph's private pool. The stash pool
that replaces them is 2217.56 MiB at capacity factor 1, 2 and 4 and
2219.01 MiB at 8, while the padded residency grows 2016 -> 16138 MiB, so
the pool follows live rows and not the padding. Over the sweep the
un-paged slope is 4.06 GiB per capacity-factor unit against 0.61 paged.

The runtime mechanics are now tested the way they run, with the step
captured. `test_blocking_mode` drives the whole-step graph and absorbs
the separate pass-level CUDA graph case it duplicated. `test_deferred_mode`
gains a captured step, so the default overflow policy is covered around a
graph and not only eagerly.
`test_reloads_are_prefetched_one_schedule_entry_ahead` captures and
replays a prefetched reload, since prefetching is how the stash runs
under the trainer's graph. `test_paged_activation_lives_until_its_copy_is_joined`
captures the release, which is where it bites: an activation held past
its join keeps its padding in the graph's private pool for the life of
the graph, and that per-layer residency is what paging removes.
`test_schedule_decides_which_stashes_stay_resident` pins `next_entries`
under capture with a pipeline schedule -- the one place the lifted
restriction needs covering, since skipping and prefetching both read it.
`test_sizing_keeps_one_pool_of_live_pages` gains the `worst_case +
actual` decomposition an earlier consolidation dropped.

What stays eager is what capture cannot reach: the graph-pass and
partition tests run at trace time, before there is a stream to capture;
the schedule and sizing tests are arithmetic over actions and page
counts; and the optimizer-skipping test turns on `optimizers.step()`
honoring the flag on device, which runs outside the forward-backward
graph.

Paged stashing had two integration tests, one per concurrency mode,
because the modes could not be combined. They can, so one covers it:
`aot_fx_trace_deepseek_v3_graph_pp_hybridep_paged_stash` drops
`disable_cuda_graphs` and runs GraphPP, the whole-step CUDA graph and
paged stashing together. It passes on 4 GPUs with "Recorded CUDA graph"
on every rank, GraphPP sizing engaged on every rank, and no token drops.
The FSDP+TP config it replaces is the only coverage lost; TP does not
fit alongside PP 2 and FSDP 2 at 4 GPUs.
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/h100.8 Trigger H100.8 CI 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