Skip to content

[cudagraph] Capture single-stage pipeline forward-backward steps - #4493

Merged
tianyu-l merged 1 commit into
pytorch:mainfrom
xmfan:cudagraph-review-followups
Sep 6, 2026
Merged

tianyu-l merged 1 commit into
pytorch:mainfrom
xmfan:cudagraph-review-followups

Conversation

@xmfan

@xmfan xmfan commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Enable CUDA graph capture and replay for pipeline schedules with one stage per rank, including GPipe and 1F1B. Capture the forward-backward schedule while keeping input preprocessing and token accounting outside the captured region.

This is a manually squashed consolidation of the previous stack and its review follow-ups:

The original PRs were submitted using stack-pr. After losing upstream write access, updating and landing that stack became difficult; this PR replaces those three unmerged PRs with one commit targeting main from xmfan:cudagraph-review-followups. It builds on the already merged #4430: Release consumed pipeline loss graphs.

The wrapper handles structured positional and keyword inputs, checks stable input structure and tensor metadata, and copies new tensor values into capture-owned buffers. Warmup invocation counting lives in wrap_with_cuda_graph and accounts for gradient accumulation and finite or continuous SDC replay schedules. As requested in review, gradient_accumulation_steps, sdc_num_steps, and sdc_num_replays are required keyword arguments. Two optimizer steps remain a conservative warmup default, allowing an eager step after lazy optimizer state initialization.

Pipeline capture reuses a device-resident loss sentinel on non-last stages. Configuration rejects looped schedules and pipeline validation, which reinitializes the shared schedule. The existing real-process-group 1F1B and PP+FSDP integration recipes now enable CUDA graphs and run 10 training steps.

Validation: CI

TorchFT changes and the separate CPU override-registry fix remain outside this PR's scope.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Meta Open Source bot. label Sep 5, 2026
@xmfan
xmfan marked this pull request as ready for review September 5, 2026 10:29
@xmfan

xmfan commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

@tianyu-l I don't have permissions to merge the stack 😂

@tianyu-l tianyu-l 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.

I couldn't merge previous stack either because they used ghstack. Maybe could you submit a consolidated one to ease the merge.

Comment thread torchtitan/distributed/cudagraph.py Outdated
Comment on lines +361 to +363
gradient_accumulation_steps: int = 1,
sdc_num_steps: int = 0,
sdc_num_replays: int = 0,

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.

these shouldn't have default

Manually consolidate pytorch#4432, pytorch#4433, and pytorch#4435 with their review follow-ups
on main, which already includes the pipeline loss-lifetime fix from pytorch#4430.

Support structured CUDA graph inputs, account for gradient accumulation
and SDC during warmup, and capture single-stage pipeline schedules while
keeping preprocessing outside capture. Require explicit accumulation and
SDC schedule arguments as requested in review.
@xmfan xmfan changed the title [cudagraph] Address warmup and pipeline capture review feedback [cudagraph] Capture single-stage pipeline forward-backward steps Sep 5, 2026
@xmfan
xmfan changed the base branch from xmfan/stack/52 to main September 5, 2026 23:03
@xmfan
xmfan force-pushed the cudagraph-review-followups branch from 66e8996 to b0f549c Compare September 5, 2026 23:03
@xmfan

xmfan commented Sep 5, 2026

Copy link
Copy Markdown
Contributor Author

Put everything in this PR

@tianyu-l
tianyu-l merged commit 966befc into pytorch:main Sep 6, 2026
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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