[FSDP] Add reduce-sum gradient reduction helper#1961
Draft
HAOCHENYE wants to merge 1 commit into
Draft
Conversation
Add BaseModel.set_gradient_reduce_sum(), which switches every sharded FSDPModule under the model to pure SUM gradient reduction by pairing set_gradient_divide_factor(1.0) with set_force_sum_reduction_for_comms(True). The pairing is required: setting only the divide factor routes FSDP through NCCL PreMulSum, which silently zeros bf16 gradients on torch 2.10, whereas forcing plain ReduceOp.SUM is exact in bf16 without upcasting. The helper is not yet wired into any fully_shard path, so training behavior is unchanged. Includes a 2-rank bf16 regression test asserting the reduced gradient equals the exact SUM of per-rank local gradients (non-zero, non-mean).
HAOCHENYE
force-pushed
the
reduce-sum-01-fsdp-helper
branch
from
July 17, 2026 08:11
c216448 to
184b6ca
Compare
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.
This PR (1/5) — behavior-neutral. Adds
BaseModel.set_gradient_reduce_sum(), which pairsset_gradient_divide_factor(1.0)withset_force_sum_reduction_for_comms(True)over everyFSDPModule(torch>=2.10 guarded, avoids the bf16 NCCL PreMulSum zeroing trap). Not wired into anyfully_shardyet.Full stack (merge bottom-up, under #1959):
reduce-sum-01-fsdp-helper— [FSDP] Add reduce-sum gradient reduction helperreduce-sum-02-split-logging— [Loss] Split logging loss from backward lossreduce-sum-03-switch-sum— [FSDP][Loss] Switch gradient reduction to SUMreduce-sum-04-remove-world-size— [Refactor] Remove unused world_size plumbingreduce-sum-05-drop-nonglobal— [Refactor] Drop non-global aux-loss averaging mode