Avoid redundant gradient synchronization during accumulation - #54
Open
ReichtumQian wants to merge 1 commit into
Open
Avoid redundant gradient synchronization during accumulation#54ReichtumQian wants to merge 1 commit into
ReichtumQian wants to merge 1 commit into
Conversation
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.
Summary
Flame currently synchronizes replicated gradients after every microbatch during gradient accumulation, resulting in redundant communication.
Replica synchronization is now deferred until the final microbatch. Composable DDP disables gradient synchronization on non-final microbatches, while HSDP disables only the replica all-reduce and keeps reduce-scatter enabled. Pure FSDP behavior is unchanged.
Problem
The training loop calls
backward()once per microbatch. With composable DDP, each backward currently triggers gradient synchronization, even though the optimizer is updated only after all accumulated microbatches have completed.As a result,
Kgradient accumulation steps performKreplica synchronizations instead of synchronizing once after the accumulated gradient is ready. This introduces redundant communication and can substantially reduce training throughput.For HSDP, the same redundant replica all-reduce can be avoided while still performing reduce-scatter after each microbatch, preserving sharded gradient storage.
Benchmark
Benchmarked with Flame's official
transformer_340M.jsonconfiguration:torch.compiledisabledGradient accumulation 1 is effectively unchanged, while accumulation 4 improves throughput by 3.24脳. The checked loss matched between the two versions, and peak memory remained approximately
9.76 GiBper GPU.