Skip to content

[graph_trainer] Drop "schedule" FSDP modes for SPMD gradient accumulation - #5024

Merged
SherlockNoMad merged 1 commit into
mainfrom
bahuang/graph_trainer_drop_spmd_schedule_mode
Oct 2, 2026
Merged

SherlockNoMad merged 1 commit into
mainfrom
bahuang/graph_trainer_drop_spmd_schedule_mode

Conversation

@SherlockNoMad

Copy link
Copy Markdown
Contributor

Replaces #4998, whose stacked base branch was merged and can no longer be retargeted. Rebased onto main now that #5005 (the SPMD gradient accumulation config) has landed; same single commit.

Why

fsdp_param_unshard_mode="schedule" / fsdp_grad_reduce_mode="schedule" extracted FSDP all-gather / reduce-scatter out of the PP=1 joint graph into standalone UNSHARD / REDUCE_GRAD schedule actions. With PP=1 there is a single stage, so tracking these collectives as separate schedule actions gives no scheduling benefit over keeping them inside the first/last (or every) microbatch graph -- but it required a lot of extra machinery (mixed REPEAT computation types, extra extracted graphs, merge/compile paths, runtime branches).

PP>1 is unchanged and still always uses scheduled UNSHARD / REDUCE_GRAD.

What

Remaining PP=1 + GA combinations:

  • (every_microbatch, every_microbatch): FULL_FORWARD_BACKWARD per microbatch
  • (first_microbatch, last_microbatch) (default): FIRST_WITH_UNSHARD, FORWARD_BACKWARD, LAST_WITH_REDUCE_GRAD, then RESHARD
  • Mixed combinations are rejected with a ValueError.

Removed:

  • FORWARD_BACKWARD_REPEAT_WITH_UNSHARD / FORWARD_BACKWARD_REPEAT_WITH_REDUCE_GRAD, joint_forward_backward_computation_type and its lookup table
  • PP=1 extraction of standalone UNSHARD / REDUCE_GRAD graphs, their merge passes, annotation/compilation, _compile_optional_graph
  • GraphExecutionPlan.requires_graph_extraction (replaced by has_gradient_accumulation) and a duplicated precompile check
  • PP=1 UNSHARD / REDUCE_GRAD schedule actions (schedule is now per-microbatch actions + RESHARD)
  • Runtime branch deciding whether grad reduction ran inside the joint graph

Net: +99 / -419.

Tests

  • test_graph_pp_runner.py, test_graph_pp_passes.py, test_trace_module.py: 162 passed, 3 skipped.
  • Replaced the three "schedule" integration jobs with aot_fx_trace_llama3_ga_first_unshard_last_reduce_fsdp (default FSDP GA path had no coverage).
  • Ran both remaining FSDP=4 + GA configs for 10 steps on 4 GPUs with seed=42, deterministic=True; both modes produce identical loss/grad_norm (stdout precision):
mode step 1 loss step 10 loss step 10 grad_norm
first/last 8.14194 3.99857 1.9983
every/every 8.14194 3.99857 1.9983

After rebasing onto main: one import conflict in test_graph_pp_runner.py (kept WAIT_REDUCE_GRAD from #4662, dropped the now-unused UNSHARD). pre-commit and pyflakes are clean. The unit tests above were run before the rebase; they could not be re-run locally because current main imports WAIT_REDUCE_GRAD (#4662), which needs a newer PyTorch than the local build. Relying on CI for the post-rebase run.

…tion

fsdp_param_unshard_mode="schedule" and fsdp_grad_reduce_mode="schedule"
extracted FSDP all-gather / reduce-scatter out of the PP=1 joint graph into
standalone UNSHARD / REDUCE_GRAD schedule actions. For PP=1 there is only
one stage, so tracking these collectives as separate schedule actions adds
no scheduling freedom over keeping them inside the first/last (or every)
microbatch graph, while costing a lot of machinery.

Remove the option. PP>1 still always uses scheduled UNSHARD / REDUCE_GRAD.
The remaining PP=1 combinations are:
- (every_microbatch, every_microbatch): FULL_FORWARD_BACKWARD per microbatch
- (first_microbatch, last_microbatch): FIRST_WITH_UNSHARD, FORWARD_BACKWARD,
  LAST_WITH_REDUCE_GRAD, then RESHARD
Mixed combinations are rejected.

Simplifications this enables:
- Remove FORWARD_BACKWARD_REPEAT_WITH_UNSHARD / _REDUCE_GRAD computation
  types, joint_forward_backward_computation_type and its lookup table.
- Remove PP=1 extraction of standalone UNSHARD / REDUCE_GRAD graphs, their
  merge passes, annotation/compilation, and _compile_optional_graph.
- Drop GraphExecutionPlan.requires_graph_extraction (use
  has_gradient_accumulation) and the duplicated precompile check.
- PP=1 runtime schedule only emits per-microbatch actions plus RESHARD.
- Remove the runtime branch deciding whether grad reduction ran in the
  joint graph.

Tests: replace the three "schedule" integration jobs with one covering the
default (first_microbatch, last_microbatch) FSDP path, and update unit
tests.
@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
@SherlockNoMad
SherlockNoMad merged commit 224708a into main Oct 2, 2026
SherlockNoMad added a commit that referenced this pull request Oct 2, 2026
…n and PP (#4999)

Rebased onto `main` after #5024 (dropping the SPMD "schedule" FSDP
modes) landed.

## Why
GraphTrainer comments, docstrings, and error messages referred to the
execution paths inconsistently (`PP=1`, `PP>1`, "SPMD", "scheduled
SPMD", "direct SPMD"), and several "SPMD" descriptions only applied to
one of the two SPMD paths. This makes the code harder to follow now that
SPMD with and without gradient accumulation use different executors.

## What
Standardize on three named paths, defined once in `make_graph_runtime`:

1. **SPMD without gradient accumulation**: no PP, one microbatch per
step (`GraphTrainerJointStageGraphs`, single `FULL_FORWARD_BACKWARD`)
2. **SPMD with gradient accumulation**: no PP, more than one microbatch
(`GraphTrainerScheduledFwdBwdStageGraphs`)
3. **PP**: pipeline parallelism

Fixes to comments that were inaccurate:
- `stage.py` / `runner.py` claimed SPMD without gradient accumulation
uses runtime-owned gradient slots; its reduced gradients go directly to
`param.grad`. Only PP uses the slots.
- `FORWARD_BACKWARD_NOGRADACCUM` was described as the SPMD graph
"without gradient accumulation"; it is the first graph of SPMD with
gradient accumulation.

Error/warning text now uses the same names (e.g. "SPMD with gradient
accumulation does not support ..."). The PP=1 test helper is renamed to
`_make_test_spmd_plan`.

No behavior change beyond message text.

## Tests
- `test_graph_pp_runner.py`, `test_graph_pp_passes.py`,
`test_trace_module.py`: 162 passed, 3 skipped.
- pre-commit clean.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/fake-pg Run 1-GPU Fake PG integration tests 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