Repository navigation
[graph_trainer] Drop "schedule" FSDP modes for SPMD gradient accumulation - #5024
Merged
Merged
Conversation
…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.
SherlockNoMad
requested review from
IvanKobzarev,
aditvenk,
sanketpurandare and
tianyu-l
as code owners
October 2, 2026 17:16
aditvenk
approved these changes
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces #4998, whose stacked base branch was merged and can no longer be retargeted. Rebased onto
mainnow 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 standaloneUNSHARD/REDUCE_GRADschedule 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_BACKWARDper microbatch(first_microbatch, last_microbatch)(default):FIRST_WITH_UNSHARD,FORWARD_BACKWARD,LAST_WITH_REDUCE_GRAD, thenRESHARDValueError.Removed:
FORWARD_BACKWARD_REPEAT_WITH_UNSHARD/FORWARD_BACKWARD_REPEAT_WITH_REDUCE_GRAD,joint_forward_backward_computation_typeand its lookup table_compile_optional_graphGraphExecutionPlan.requires_graph_extraction(replaced byhas_gradient_accumulation) and a duplicated precompile checkUNSHARD/REDUCE_GRADschedule actions (schedule is now per-microbatch actions +RESHARD)Net: +99 / -419.
Tests
test_graph_pp_runner.py,test_graph_pp_passes.py,test_trace_module.py: 162 passed, 3 skipped."schedule"integration jobs withaot_fx_trace_llama3_ga_first_unshard_last_reduce_fsdp(default FSDP GA path had no coverage).seed=42,deterministic=True; both modes produce identical loss/grad_norm (stdout precision):After rebasing onto
main: one import conflict intest_graph_pp_runner.py(keptWAIT_REDUCE_GRADfrom #4662, dropped the now-unusedUNSHARD). pre-commit and pyflakes are clean. The unit tests above were run before the rebase; they could not be re-run locally because currentmainimportsWAIT_REDUCE_GRAD(#4662), which needs a newer PyTorch than the local build. Relying on CI for the post-rebase run.