Overlap experimental Megatron-FSDP communication with two process groups - #5772
Draft
wujingyue wants to merge 1 commit into
Draft
Overlap experimental Megatron-FSDP communication with two process groups#5772wujingyue wants to merge 1 commit into
wujingyue wants to merge 1 commit into
Conversation
…ess group Launch gradient reduce-scatter eagerly in post_backward on a dedicated NCCL communicator (reduce_scatter_group) instead of the deferred "delayed reduction" scheduling, so reduce-scatter overlaps backward compute and all-gather. Remove the PreparedReduction/PendingReduction queues and the pre_backward deferral; the end-of-backward callback becomes a single wait_stream barrier. Delayed releases are unchanged. Thread an optional reduce_group through DBuffer and FsdpParameterGroup. Known limitation: the dedicated group is created via new_group in FsdpContext and not torn down (one leaked communicator per context); it should be created once at process-group setup and passed in, as mfsdp v1 does with fsdp_group_ag. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Jingyue Wu <jingyuew@nvidia.com>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
This was referenced Aug 17, 2026
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
Overlap communication in the experimental Megatron-FSDP path (
mfsdp_v2) bylaunching gradient reduce-scatter eagerly in
post_backwardon a dedicatedNCCL communicator, instead of the deferred "delayed reduction" scheduling.
All-gather stays on the mesh's default group; reduce-scatter runs on a separate
group, so the two collectives use different communicators and can run
concurrently. Delayed releases (forward prefetch) are unchanged.
What changed
FsdpContextgains a dedicatedreduce_scatter_group; each group'sreduce-scatter is launched immediately once its gradients are packed, on
reduce_scatter_stream.PreparedReduction/PendingReduction,the
prepared_reductions/pending_reductionsqueues, and the deferral to thenext
pre_backward. The end-of-backward callback is now a singlewait_streambarrier so the optimizer stream orders after the reductions (net -17 SLOC in
module.py).DBuffer.reduce_scatter/redistributeandFsdpParameterGroup.reduce_partial_gradientsaccept an optionalreduce_group.Why
The delayed reduction existed to overlap reduce-scatter with compute while keeping
all-gather and reduce-scatter ordered on one communicator. With a separate
reduce-scatter communicator, reduce-scatter launches eagerly without head-of-line
blocking against the next all-gather, removing the deferral/retention bookkeeping.
Validation
test_fully_shard_losses_match_baseline,test_backward_averages_across_dp_and_accumulates_across_calls, and theaccumulation / microbatch / memory tests pass (2 ranks).
overlaps backward GEMM (~0.45-0.66 of RS hidden under compute) and all-gather
(~0.44);
test_overlaps_communication_and_computepasses 5/5 at dim=8192. Atdim=4096 the collectives are too small to overlap (the delayed-reduction
baseline behaves identically) — see Increase Megatron-FSDP overlap test dim to 8192 for reliable overlap #5770 for the test-dim fix.
Known limitations
dist.new_groupinside
FsdpContextand not torn down — one leaked communicator per FSDPcontext. It should instead be created once at process-group setup and passed in
via a
ProcessGroupCollection, as mfsdp v1 does withfsdp_group_ag(
parallel_state.create_all_gather_groups). Not addressed here.reduce-scatter on the default; this dedicates the reduce-scatter group.
Equivalent for overlap.
construction.
measured.
🤖 Generated with Claude Code