Fix gradient accumulation under FSDP2: defer cross-replica all-reduce - #162
Open
Sullivan07043 wants to merge 1 commit into
Open
Fix gradient accumulation under FSDP2: defer cross-replica all-reduce#162Sullivan07043 wants to merge 1 commit into
Sullivan07043 wants to merge 1 commit into
Conversation
ddp_sync_grad only handled DistributedDataParallel. Under FSDP2 (fully_shard) it was a silent no-op, so every micro-step of an accumulation window ran the full cross-node gradient reduction and grad_accum_iter saved no communication (measured: accum=4 step = 4x the accum=1 step on 2x8 A100 over Ethernet). Defer only the cross-replica all-reduce via FSDPModule.set_requires_all_reduce on non-boundary micro-steps. The intra-node reduce-scatter still runs every micro-step, so gradients stay sharded and per-rank memory does not grow. Validated on 2x 8xA100-80GB (HSDP shard=8 replicate=2): accum=4 step 54.5 s vs 88.8 s unamortized on a fleet whose accum=1 step is 22.2 s.
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.
Fixes #161 (
ddp_sync_gradis a silent no-op under FSDP2, sotrainer.grad_accum_itersaves no communication).Change. Add an FSDP2 branch to
ddp_sync_grad: on non-boundary micro-steps, defer only the cross-replica all-reduce viaFSDPModule.set_requires_all_reduce(enabled, recurse=False)on everyFSDPModule. Restore it in thefinallyblock. The intra-node reduce-scatter still runs each micro-step, so gradients stay sharded and per-rank memory does not grow. DDP behavior is unchanged.Validation (2x 8xA100-80GB, Ethernet, HSDP shard=8 replicate=2, batch 64/rank, fleet whose accum=1 step is 22.2 s):
Decomposition from the two measured points: compute 10.8 s + sync 11.4 s per micro-batch. Throughput 1.63x at accum=4. Loss stayed in the expected band.
One commit, 18 added lines, no API change.