Repository navigation
[graph_trainer] Group SPMD gradient accumulation settings into one config - #4997
Merged
SherlockNoMad merged 1 commit intoOct 1, 2026
Conversation
…nfig fsdp_param_unshard_mode, fsdp_gradient_sync_mode, and gradient_accum_in_wgrad_fusion only make sense for SPMD (PP=1) runs with gradient accumulation. They lived at the top level of GraphTrainerCompileConfig with "auto" values and per-mode PP=1/PP>1 caveats, so every user had to reason about them. Move them into compile.spmd_gradient_accumulation (SPMDGradientAccumulationConfig): - fsdp_param_unshard_mode: every_microbatch | first_microbatch | schedule - fsdp_grad_reduce_mode: every_microbatch | last_microbatch | schedule - fuse_wgrad_accumulation: auto | disabled | enabled Outside SPMD with gradient accumulation the settings are ignored with a warning instead of raising: a single PP=1 microbatch keeps FSDP collectives in the joint graph, and PP>1 always extracts them as schedule actions without WGrad fusion. The FSDP fields are also ignored without FSDP. first_microbatch and schedule unsharding now imply fsdp_reshard_after_forward=never for the compiled graphs, which makes the default (first_microbatch, last_microbatch) work with FSDP out of the box.
SherlockNoMad
marked this pull request as ready for review
October 1, 2026 18:21
SherlockNoMad
requested review from
IvanKobzarev,
aditvenk,
sanketpurandare and
tianyu-l
as code owners
October 1, 2026 18:21
SherlockNoMad
merged commit Oct 1, 2026
059b8e3
into
bahuang/graph_trainer_single_config
8 checks passed
SherlockNoMad
added a commit
that referenced
this pull request
Oct 2, 2026
…nfig (#5005) Replaces #4997, which was merged into its stacked base branch (`bahuang/graph_trainer_single_config`) instead of `main`. Rebased onto `main` now that #4983 has landed; same single commit. ## Why - `fsdp_param_unshard_mode`, `fsdp_gradient_sync_mode` and `gradient_accum_in_wgrad_fusion` only make sense for users running SPMD (PP=1) with gradient accumulation. - This simplifies the mental model for SPMD with GA and for PP>1: - **SPMD without GA:** FSDP collectives always stay in the graph, so there is nothing to configure. - **PP>1:** FSDP collectives are always extracted as `UNSHARD` / `REDUCE_GRAD` schedule actions, so there is nothing to configure. Before this PR, every user saw these settings at the top level of `GraphTrainerCompileConfig`, with `auto` values and per-mode caveats like "PP>1: error". ## What - New `compile.spmd_gradient_accumulation: SPMDGradientAccumulationConfig` with three fields: | Old (`compile.*`) | New (`compile.spmd_gradient_accumulation.*`) | Values | |---|---|---| | `fsdp_param_unshard_mode` | `fsdp_param_unshard_mode` | `every_microbatch`, `first_microbatch` (default), `schedule` | | `fsdp_gradient_sync_mode` | `fsdp_grad_reduce_mode` | `every_microbatch`, `last_microbatch` (default), `schedule` | | `gradient_accum_in_wgrad_fusion` | `fuse_wgrad_accumulation` | `auto` (default), `disabled`, `enabled` | `auto` is gone from the FSDP modes. `only_in_first_microbatch` / `only_in_last_microbatch` become `first_microbatch` / `last_microbatch`, and `extracted_in_schedule_stage` / `deferred_as_schedule_stage` become `schedule`. - **Ignored instead of raising:** outside SPMD with GA (PP>1, or a single microbatch), non-default settings are ignored with a warning. The FSDP fields are also ignored when FSDP is disabled. Wgrad fusion still applies without FSDP. - **Parameter reuse implies no resharding:** `first_microbatch` and `schedule` unsharding reuse unsharded parameters across microbatches, so they now imply `fsdp_reshard_after_forward=never` for the compiled graphs. Before, the defaults raised an error with FSDP unless the user set that flag manually. - `GraphExecutionPlan.reuse_unsharded_parameters` becomes a derived property. - The runtime schedule adds one `RESHARD` at the end of the step. - Explicitly setting `fsdp_reshard_after_forward="always"` together with these modes logs a warning. - The FSDP wgrad-fusion error now says `fsdp_grad_reduce_mode` must be `'last_microbatch' or 'schedule'`. Before, it named only `'schedule'`, though the check accepts both. ## Behavior changes - **Old field names:** recipes that set the old `compile.*` fields need to move to `compile.spmd_gradient_accumulation.*`. No in-repo recipes used them other than the integration tests, which are updated here. - **Errors become warnings:** with PP>1 or a single microbatch, `fuse_wgrad_accumulation="enabled"` or non-default FSDP modes now log a warning instead of raising. - **Integration jobs take a new code path:** the CI integration jobs that use extracted (`schedule`) unsharding now reuse unsharded parameters across microbatches, instead of running `UNSHARD`/`RESHARD` per microbatch. ## Test plan - **`test_graph_pp_runner.py` passes (58 tests).** New and updated tests cover: - parameter reuse forcing `reshard_after_forward=never` - the ignored-config warnings for PP>1, GA=1 and no FSDP - wgrad fusion without FSDP - the FSDP split-reduction error - **Full graph_trainer unit suite:** 444 passed, 24 failed. The same 24 fail on the base commit locally because of environment issues: cudnn `disable_global_flags`, missing `autoparallel`, and an Inductor config key. `test_autoparallel_integration_matrix` was excluded because `torchvision` isn't installed. - **Not yet run:** GPU integration tests and a loss comparison. - **Gap:** the default (`first_microbatch`, `last_microbatch`) FSDP path has no GPU integration coverage yet. - `pre-commit` clean (pyrefly skipped locally). - After rebasing onto `main`: `test_graph_pp_runner.py` and `test_graph_pp_passes.py` pass (105), pre-commit clean, and a 10-step 1-GPU SPMD GA run matches the pre-rebase loss (step 1 8.11272, step 10 4.03365).
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.
Stacked on #4983.
Why
fsdp_param_unshard_mode,fsdp_gradient_sync_modeandgradient_accum_in_wgrad_fusiononly make sense for users running SPMD (PP=1) with gradient accumulation.This simplifies the mental model for SPMD with GA and for PP>1:
UNSHARD/REDUCE_GRADschedule actions, so there is nothing to configure.Before this PR, every user saw these settings at the top level of
GraphTrainerCompileConfig, withautovalues and per-mode caveats like "PP>1: error".What
New
compile.spmd_gradient_accumulation: SPMDGradientAccumulationConfigwith three fields:compile.*)compile.spmd_gradient_accumulation.*)fsdp_param_unshard_modefsdp_param_unshard_modeevery_microbatch,first_microbatch(default),schedulefsdp_gradient_sync_modefsdp_grad_reduce_modeevery_microbatch,last_microbatch(default),schedulegradient_accum_in_wgrad_fusionfuse_wgrad_accumulationauto(default),disabled,enabledautois gone from the FSDP modes.only_in_first_microbatch/only_in_last_microbatchbecomefirst_microbatch/last_microbatch, andextracted_in_schedule_stage/deferred_as_schedule_stagebecomeschedule.Ignored instead of raising: outside SPMD with GA (PP>1, or a single microbatch), non-default settings are ignored with a warning. The FSDP fields are also ignored when FSDP is disabled. Wgrad fusion still applies without FSDP.
Parameter reuse implies no resharding:
first_microbatchandscheduleunsharding reuse unsharded parameters across microbatches, so they now implyfsdp_reshard_after_forward=neverfor the compiled graphs. Before, the defaults raised an error with FSDP unless the user set that flag manually.GraphExecutionPlan.reuse_unsharded_parametersbecomes a derived property.RESHARDat the end of the step.fsdp_reshard_after_forward="always"together with these modes logs a warning.The FSDP wgrad-fusion error now says
fsdp_grad_reduce_modemust be'last_microbatch' or 'schedule'. Before, it named only'schedule', though the check accepts both.Behavior changes
compile.*fields need to move tocompile.spmd_gradient_accumulation.*. No in-repo recipes used them other than the integration tests, which are updated here.fuse_wgrad_accumulation="enabled"or non-default FSDP modes now log a warning instead of raising.schedule) unsharding now reuse unsharded parameters across microbatches, instead of runningUNSHARD/RESHARDper microbatch.Test plan
test_graph_pp_runner.pypasses (58 tests). New and updated tests cover:reshard_after_forward=neverdisable_global_flags, missingautoparallel, and an Inductor config key.test_autoparallel_integration_matrixwas excluded becausetorchvisionisn't installed.first_microbatch,last_microbatch) FSDP path has no GPU integration coverage yet.pre-commitclean (pyrefly skipped locally).