Skip to content

[FSDP2] Use separate NCCL communicator for reduce-scatter to enable AG/RS overlap - #177015

Closed
weifengpy wants to merge 1 commit into
gh/weifengpy/91/basefrom
gh/weifengpy/91/head
Closed

weifengpy wants to merge 1 commit into
gh/weifengpy/91/basefrom
gh/weifengpy/91/head

Conversation

@weifengpy

@weifengpy weifengpy commented Mar 10, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

@ngimel pointed that the same NCCL communicator serialize all-gather and reduce-scatter. Using different cuda streams are not enough. We must also use different PGs

This is confirmed with unit test and profiler traces below. Want to let @awgu take a look to see if this change makes sense. The risk is mainly extra NCCL workspace memory from separate reduce-scatter PG

python -m torch.distributed.run --nproc_per_node=2 test/distributed/_composable/fsdp/test_fully_shard_overlap.py -k test_fully_shard_backward_comm_overlap

comparison_annotated

…/RS overlap

Give all-gather and reduce-scatter different ProcessGroups so they go through
separate NCCL communicators and can truly overlap in the backward pass. Previously
both used the same shard_process_group, which serialized them on a single
communicator.

Add test_fully_shard_backward_comm_overlap to verify that the real FSDP code path
with separate PGs (fsdp_bwd) is faster than a serialized single-communicator
reference (ref_bwd). The test uses real compute and collectives with large
parameter dimensions (16384x16384) instead of CUDA sleeps.

Authored with Claude.

[ghstack-poisoned]
@pytorch-bot

pytorch-bot Bot commented Mar 10, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/177015

Note: Links to docs will display an error until the docs builds have been completed.

❌ 3 New Failures, 1 Unrelated Failure

As of commit 0ba8af0 with merge base a790959 (image):

NEW FAILURES - The following jobs have failed:

UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:

This comment was automatically generated by Dr. CI and updates every 15 minutes.

weifengpy added a commit that referenced this pull request Mar 10, 2026
…/RS overlap

Give all-gather and reduce-scatter different ProcessGroups so they go through
separate NCCL communicators and can truly overlap in the backward pass. Previously
both used the same shard_process_group, which serialized them on a single
communicator.

Add test_fully_shard_backward_comm_overlap to verify that the real FSDP code path
with separate PGs (fsdp_bwd) is faster than a serialized single-communicator
reference (ref_bwd). The test uses real compute and collectives with large
parameter dimensions (16384x16384) instead of CUDA sleeps.

Authored with Claude.

ghstack-source-id: 5691aeb
Pull Request resolved: #177015
@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests release notes: distributed (fsdp) release notes category labels Mar 10, 2026
@weifengpy weifengpy changed the title [FSDP] Use separate NCCL communicator for reduce-scatter to enable AG/RS overlap [FSDP2] Use separate NCCL communicator for reduce-scatter to enable AG/RS overlap Mar 10, 2026
@weifengpy
weifengpy requested a review from awgu March 10, 2026 09:23
@awgu

awgu commented Mar 10, 2026 •

Copy link
Copy Markdown
Collaborator

In my experience, overlapping comms on the same NCCL communicator that use the same network resources does not lead to any meaningful improvements and can make the variance worse across groups. I would rather serialize all DP comms.

@weifengpy

Copy link
Copy Markdown
Contributor Author

I would rather serialize all DP comms

that means we only need one cuda stream for AG and RS? note we have AG steam and RS steam today. consolidating AG and RS is also a good thing

In my experience, overlapping comms on the same NCCL communicator does not lead to any meaningful improvements and can make the variance worse across groups.

This PR used separate PGs for AG and RS. do you mean overlapping comms on different NCCL communicators?

@awgu

awgu commented Mar 10, 2026

Copy link
Copy Markdown
Collaborator

Sorry I misspoke about the NCCL communicator.

I meant that overlapping comms that use the same network resources is generally hurtful, and I would actively try to avoid that when possible. You can try to benchmark for the workloads you care about, but for my use cases, this is not worth it.

that means we only need one cuda stream for AG and RS? note we have AG steam and RS steam today. consolidating AG and RS is also a good thing

I mean that the stream that the comm kernels run on can be the same stream so that the comm kernels are serialized.

weifengpy added a commit that referenced this pull request Mar 11, 2026
…tream"


All-gather and reduce-scatter use the same NCCL communicator. We have 2 options
* Option 1: Merge all-gather and reduce-scatter into one: this is the PR
* Option 2: Use seaprate PGs to truly overlap all-gather and reduce-scatter #177015

[ghstack-poisoned]
@weifengpy

weifengpy commented Mar 11, 2026 •

Copy link
Copy Markdown
Contributor Author

I mean that the stream that the comm kernels run on can be the same stream so that the comm kernels are serialized.

chatted with @awgu offline on the other direction about merging all_gather_stream and reduce_scatter_stream #177098 . awgu is very specific about PG NCCL stream and fsdp-side stream (reduce_scatter_stream covers more than dist.reduce-scatter)

it turns out reduce_scatter_stream covers following compute around reduce-scatters. we would lose the overlapping between AG and those compute if merging strams

  1. Pre-divide — tensor.div_(predivide_factor) (_fsdp_collectives.py:529 via _div_if_needed). In-place division of the RS input. (Only when force_sum_reduction_for_comms=True and factor != 1)
  2. NCCL ReduceScatter — reduce_scatter_comm(output_tensor=..., input_tensor=..., group=..., op=...) (_fsdp_collectives.py:531-536) → dispatches ncclReduceScatter kernel.
  3. Post-divide — reduce_output.div_(postdivide_factor) (_fsdp_collectives.py:589 via _div_if_needed). In-place division of the RS output. (Only when force_sum_reduction_for_comms=True and factor != 1)
  4. Dtype cast — reduce_output.to(orig_dtype) (_fsdp_collectives.py:590 via _to_dtype_if_needed). Casts from reduce_dtype back to orig_dtype (e.g. fp32→bf16). (Only when dtypes differ)
  5. D2H copy — new_sharded_grad.to(torch.device("cpu"), non_blocking=...) (_fsdp_collectives.py:613-614). Copies sharded fp32 grad from GPU to CPU pinned memory. (Only with CPU offloading)
  6. Grad accumulation — fsdp_param.sharded_param.grad._local_tensor += new_sharded_grad (_fsdp_collectives.py:625). In-place add for gradient accumulation. (Only when grad already exists, i.e. gradient accumulation)

one example cpu offloading, there is overlapping between grad D2H and AG
Screenshot 2026-03-11 at 13 59 06

@weifengpy

Copy link
Copy Markdown
Contributor Author

close this as the change is up to benchmarking

@weifengpy weifengpy closed this Mar 11, 2026
@github-actions
github-actions Bot deleted the gh/weifengpy/91/head branch April 11, 2026 02:23
weifengpy added a commit that referenced this pull request Jun 5, 2026
By default FSDP2 runs all-gather and reduce-scatter on separate CUDA streams but
through the same process group -- one NCCL communicator, which processes one
collective at a time and so serializes them on the wire. This adds an opt-in
FSDPModule API to give reduce-scatter its own communicator:

    FSDPModule.set_separate_reduce_scatter_group(enable=True, *, recurse=True)

When enabled, FSDP creates a dedicated process group over the shard ranks
(dist.new_group), one per distinct set of shard ranks (typically one
communicator), so reduce-scatter and all-gather can progress concurrently when
the network can sustain it; enable=False resets to the shared group. The default
is unchanged -- reduce-scatter shares the shard process group -- so this is
purely opt-in and creates no extra communicators unless requested.

This redesigns the approach explored in (closed) PR #177015, which made the
separate communicator the unconditional default (and created one even for
post-forward meshes); here it is an opt-in toggle.

Test Plan:
```
python test/distributed/_composable/fsdp/test_fully_shard_overlap.py \
  TestFullyShardOverlap.test_set_separate_reduce_scatter_group \
  TestFullyShardOverlap.test_fully_shard_backward_comm_overlap
```
Both pass on 4xH100:
- test_set_separate_reduce_scatter_group: default shares the shard PG; enabling
  creates one dedicated PG shared across same-rank-set meshes; disabling resets
  to the shared PG.
- test_fully_shard_backward_comm_overlap: real backward AG/RS overlap (large
  matmuls + collectives) is no slower than a serialized single-communicator
  reference.

Authored with Claude.

ghstack-source-id: 13013ba
Pull-Request: #186335
weifengpy added a commit that referenced this pull request Jun 5, 2026
By default FSDP2 runs all-gather and reduce-scatter on separate CUDA streams but
through the same process group -- one NCCL communicator, which processes one
collective at a time and so serializes them on the wire. This adds an opt-in
FSDPModule API to give reduce-scatter its own communicator:

    FSDPModule.set_separate_reduce_scatter_group(enable=True, *, recurse=True)

When enabled, FSDP creates a dedicated process group over the shard ranks
(dist.new_group), one per distinct set of shard ranks (typically one
communicator), so reduce-scatter and all-gather can progress concurrently when
the network can sustain it; enable=False resets to the shared group. The default
is unchanged -- reduce-scatter shares the shard process group -- so this is
purely opt-in and creates no extra communicators unless requested.

This redesigns the approach explored in (closed) PR #177015, which made the
separate communicator the unconditional default (and created one even for
post-forward meshes); here it is an opt-in toggle.

Test Plan:
```
python test/distributed/_composable/fsdp/test_fully_shard_overlap.py \
  TestFullyShardOverlap.test_set_separate_reduce_scatter_group \
  TestFullyShardOverlap.test_fully_shard_backward_comm_overlap
```
Both pass on 4xH100:
- test_set_separate_reduce_scatter_group: default shares the shard PG; enabling
  creates one dedicated PG shared across same-rank-set meshes; disabling resets
  to the shared PG.
- test_fully_shard_backward_comm_overlap: real backward AG/RS overlap (large
  matmuls + collectives) is no slower than a serialized single-communicator
  reference.

Authored with Claude.

ghstack-source-id: 13013ba
Pull-Request: #186335
weifengpy added a commit that referenced this pull request Jun 5, 2026
By default FSDP2 runs all-gather and reduce-scatter on separate CUDA streams but
through the same process group -- one NCCL communicator, which processes one
collective at a time and so serializes them on the wire. This adds an opt-in
FSDPModule API to give reduce-scatter its own communicator:

    FSDPModule.set_separate_reduce_scatter_group(enable=True, *, recurse=True)

When enabled, FSDP creates a dedicated process group over the shard ranks
(dist.new_group), one per distinct set of shard ranks (typically one
communicator), so reduce-scatter and all-gather can progress concurrently when
the network can sustain it; enable=False resets to the shared group. The default
is unchanged -- reduce-scatter shares the shard process group -- so this is
purely opt-in and creates no extra communicators unless requested.

This redesigns the approach explored in (closed) PR #177015, which made the
separate communicator the unconditional default (and created one even for
post-forward meshes); here it is an opt-in toggle.

Test Plan:
```
python test/distributed/_composable/fsdp/test_fully_shard_overlap.py \
  TestFullyShardOverlap.test_set_separate_reduce_scatter_group \
  TestFullyShardOverlap.test_fully_shard_backward_comm_overlap
```
Both pass on 4xH100:
- test_set_separate_reduce_scatter_group: default shares the shard PG; enabling
  creates one dedicated PG shared across same-rank-set meshes; disabling resets
  to the shared PG.
- test_fully_shard_backward_comm_overlap: real backward AG/RS overlap (large
  matmuls + collectives) is no slower than a serialized single-communicator
  reference.

Authored with Claude.

ghstack-source-id: 6364399
Pull-Request: #186335
weifengpy added a commit that referenced this pull request Jun 8, 2026
By default FSDP2 runs all-gather and reduce-scatter on separate CUDA streams but
through the same process group -- one NCCL communicator, which processes one
collective at a time and so serializes them on the wire. This adds an opt-in
FSDPModule API to give reduce-scatter its own communicator:

    FSDPModule.set_separate_reduce_scatter_group(enable=True, *, recurse=True)

When enabled, FSDP creates a dedicated process group over the shard ranks
(dist.new_group), one per distinct set of shard ranks (typically one
communicator), so reduce-scatter and all-gather can progress concurrently when
the network can sustain it; enable=False resets to the shared group. The default
is unchanged -- reduce-scatter shares the shard process group -- so this is
purely opt-in and creates no extra communicators unless requested.

This redesigns the approach explored in (closed) PR #177015, which made the
separate communicator the unconditional default (and created one even for
post-forward meshes); here it is an opt-in toggle.

Test Plan:
```
python test/distributed/_composable/fsdp/test_fully_shard_overlap.py \
  TestFullyShardOverlap.test_set_separate_reduce_scatter_group \
  TestFullyShardOverlap.test_fully_shard_backward_comm_overlap
```
Both pass on 4xH100:
- test_set_separate_reduce_scatter_group: default shares the shard PG; enabling
  creates one dedicated PG shared across same-rank-set meshes; disabling resets
  to the shared PG.
- test_fully_shard_backward_comm_overlap: real backward AG/RS overlap (large
  matmuls + collectives) is no slower than a serialized single-communicator
  reference.

Authored with Claude.

ghstack-source-id: c0ca593
Pull-Request: #186335
weifengpy added a commit that referenced this pull request Jun 8, 2026
By default FSDP2 runs all-gather and reduce-scatter on separate CUDA streams but
through the same process group -- one NCCL communicator, which processes one
collective at a time and so serializes them on the wire. This adds an opt-in
FSDPModule API to give reduce-scatter its own communicator:

    FSDPModule.set_separate_reduce_scatter_group(enable=True, *, recurse=True)

When enabled, FSDP creates a dedicated process group over the shard ranks
(dist.new_group), one per distinct set of shard ranks (typically one
communicator), so reduce-scatter and all-gather can progress concurrently when
the network can sustain it; enable=False resets to the shared group. The default
is unchanged -- reduce-scatter shares the shard process group -- so this is
purely opt-in and creates no extra communicators unless requested.

This redesigns the approach explored in (closed) PR #177015, which made the
separate communicator the unconditional default (and created one even for
post-forward meshes); here it is an opt-in toggle.

Test Plan:
```
python test/distributed/_composable/fsdp/test_fully_shard_overlap.py \
  TestFullyShardOverlap.test_set_separate_reduce_scatter_group \
  TestFullyShardOverlap.test_fully_shard_backward_comm_overlap
```
Both pass on 4xH100:
- test_set_separate_reduce_scatter_group: default shares the shard PG; enabling
  creates one dedicated PG shared across same-rank-set meshes; disabling resets
  to the shared PG.
- test_fully_shard_backward_comm_overlap: real backward AG/RS overlap (large
  matmuls + collectives) is no slower than a serialized single-communicator
  reference.

Authored with Claude.

ghstack-source-id: c0ca593
Pull-Request: #186335
Co-authored-by: Lei Tian <[email protected]>
weifengpy added a commit that referenced this pull request Jun 9, 2026
By default FSDP2 runs all-gather and reduce-scatter on separate CUDA streams but
through the same process group -- one NCCL communicator, which processes one
collective at a time and so serializes them on the wire. This adds an opt-in
FSDPModule API to give reduce-scatter its own communicator:

    FSDPModule.set_separate_reduce_scatter_group(enable=True, *, recurse=True)

When enabled, FSDP creates a dedicated process group over the shard ranks
(dist.new_group), one per distinct set of shard ranks (typically one
communicator), so reduce-scatter and all-gather can progress concurrently when
the network can sustain it; enable=False resets to the shared group. The default
is unchanged -- reduce-scatter shares the shard process group -- so this is
purely opt-in and creates no extra communicators unless requested.

This redesigns the approach explored in (closed) PR #177015, which made the
separate communicator the unconditional default (and created one even for
post-forward meshes); here it is an opt-in toggle.

Test Plan:
```
python test/distributed/_composable/fsdp/test_fully_shard_overlap.py \
  TestFullyShardOverlap.test_set_separate_reduce_scatter_group \
  TestFullyShardOverlap.test_fully_shard_backward_comm_overlap
```
Both pass on 4xH100:
- test_set_separate_reduce_scatter_group: default shares the shard PG; enabling
  creates one dedicated PG shared across same-rank-set meshes; disabling resets
  to the shared PG.
- test_fully_shard_backward_comm_overlap: real backward AG/RS overlap (large
  matmuls + collectives) is no slower than a serialized single-communicator
  reference.

Authored with Claude.

ghstack-source-id: 0b0a02b
Pull-Request: #186335
Co-authored-by: Lei Tian <[email protected]>
weifengpy added a commit that referenced this pull request Jun 9, 2026
By default FSDP2 runs all-gather and reduce-scatter on separate CUDA streams but
through the same process group -- one NCCL communicator, which processes one
collective at a time and so serializes them on the wire. This adds an opt-in
FSDPModule API to give reduce-scatter its own communicator:

    FSDPModule.set_separate_reduce_scatter_group(enable=True, *, recurse=True)

When enabled, FSDP creates a dedicated process group over the shard ranks
(dist.new_group), one per distinct set of shard ranks (typically one
communicator), so reduce-scatter and all-gather can progress concurrently when
the network can sustain it; enable=False resets to the shared group. The default
is unchanged -- reduce-scatter shares the shard process group -- so this is
purely opt-in and creates no extra communicators unless requested.

This redesigns the approach explored in (closed) PR #177015, which made the
separate communicator the unconditional default (and created one even for
post-forward meshes); here it is an opt-in toggle.

Test Plan:
```
python test/distributed/_composable/fsdp/test_fully_shard_overlap.py \
  TestFullyShardOverlap.test_set_separate_reduce_scatter_group \
  TestFullyShardOverlap.test_fully_shard_backward_comm_overlap
```
Both pass on 4xH100:
- test_set_separate_reduce_scatter_group: default shares the shard PG; enabling
  creates one dedicated PG shared across same-rank-set meshes; disabling resets
  to the shared PG.
- test_fully_shard_backward_comm_overlap: real backward AG/RS overlap (large
  matmuls + collectives) is no slower than a serialized single-communicator
  reference.

Authored with Claude.

ghstack-source-id: ae2c755
Pull-Request: #186335
Co-authored-by: Lei Tian <[email protected]>
pytorchmergebot pushed a commit that referenced this pull request Jun 10, 2026
…186335)

By default FSDP2 runs all-gather and reduce-scatter on separate CUDA streams but
through the same process group -- one NCCL communicator, which processes one
collective at a time and so serializes them on the wire. This adds an opt-in
FSDPModule API to give reduce-scatter its own communicator:

    FSDPModule.set_separate_reduce_scatter_group(enable=True, *, recurse=True)

When enabled, FSDP creates a dedicated process group over the shard ranks
(dist.new_group), one per distinct set of shard ranks (typically one
communicator), so reduce-scatter and all-gather can progress concurrently when
the network can sustain it; enable=False resets to the shared group. The default
is unchanged -- reduce-scatter shares the shard process group -- so this is
purely opt-in and creates no extra communicators unless requested.

This redesigns the approach explored in (closed) PR #177015, which made the
separate communicator the unconditional default (and created one even for
post-forward meshes); here it is an opt-in toggle.

Test Plan:
```
python test/distributed/_composable/fsdp/test_fully_shard_overlap.py \
  TestFullyShardOverlap.test_set_separate_reduce_scatter_group \
  TestFullyShardOverlap.test_fully_shard_backward_comm_overlap
```
Both pass on 4xH100:
- test_set_separate_reduce_scatter_group: default shares the shard PG; enabling
  creates one dedicated PG shared across same-rank-set meshes; disabling resets
  to the shared PG.
- test_fully_shard_backward_comm_overlap: real backward AG/RS overlap (large
  matmuls + collectives) is no slower than a serialized single-communicator
  reference.

Authored with Claude.

Co-authored-by: Lei Tian <[email protected]>
Pull Request resolved: #186335
Approved by: https://github.com/anshul-si
ghstack dependencies: #186000

Co-authored-by: Lei Tian <[email protected]>
jemitche1 pushed a commit to jemitche1/pytorch that referenced this pull request Jun 13, 2026
…ytorch#186335)

By default FSDP2 runs all-gather and reduce-scatter on separate CUDA streams but
through the same process group -- one NCCL communicator, which processes one
collective at a time and so serializes them on the wire. This adds an opt-in
FSDPModule API to give reduce-scatter its own communicator:

    FSDPModule.set_separate_reduce_scatter_group(enable=True, *, recurse=True)

When enabled, FSDP creates a dedicated process group over the shard ranks
(dist.new_group), one per distinct set of shard ranks (typically one
communicator), so reduce-scatter and all-gather can progress concurrently when
the network can sustain it; enable=False resets to the shared group. The default
is unchanged -- reduce-scatter shares the shard process group -- so this is
purely opt-in and creates no extra communicators unless requested.

This redesigns the approach explored in (closed) PR pytorch#177015, which made the
separate communicator the unconditional default (and created one even for
post-forward meshes); here it is an opt-in toggle.

Test Plan:
```
python test/distributed/_composable/fsdp/test_fully_shard_overlap.py \
  TestFullyShardOverlap.test_set_separate_reduce_scatter_group \
  TestFullyShardOverlap.test_fully_shard_backward_comm_overlap
```
Both pass on 4xH100:
- test_set_separate_reduce_scatter_group: default shares the shard PG; enabling
  creates one dedicated PG shared across same-rank-set meshes; disabling resets
  to the shared PG.
- test_fully_shard_backward_comm_overlap: real backward AG/RS overlap (large
  matmuls + collectives) is no slower than a serialized single-communicator
  reference.

Authored with Claude.

Co-authored-by: Lei Tian <[email protected]>
Pull Request resolved: pytorch#186335
Approved by: https://github.com/anshul-si
ghstack dependencies: pytorch#186000

Co-authored-by: Lei Tian <[email protected]>
gplutop7 pushed a commit to gplutop7/pytorch that referenced this pull request Jul 15, 2026
…ytorch#186335)

By default FSDP2 runs all-gather and reduce-scatter on separate CUDA streams but
through the same process group -- one NCCL communicator, which processes one
collective at a time and so serializes them on the wire. This adds an opt-in
FSDPModule API to give reduce-scatter its own communicator:

    FSDPModule.set_separate_reduce_scatter_group(enable=True, *, recurse=True)

When enabled, FSDP creates a dedicated process group over the shard ranks
(dist.new_group), one per distinct set of shard ranks (typically one
communicator), so reduce-scatter and all-gather can progress concurrently when
the network can sustain it; enable=False resets to the shared group. The default
is unchanged -- reduce-scatter shares the shard process group -- so this is
purely opt-in and creates no extra communicators unless requested.

This redesigns the approach explored in (closed) PR pytorch#177015, which made the
separate communicator the unconditional default (and created one even for
post-forward meshes); here it is an opt-in toggle.

Test Plan:
```
python test/distributed/_composable/fsdp/test_fully_shard_overlap.py \
  TestFullyShardOverlap.test_set_separate_reduce_scatter_group \
  TestFullyShardOverlap.test_fully_shard_backward_comm_overlap
```
Both pass on 4xH100:
- test_set_separate_reduce_scatter_group: default shares the shard PG; enabling
  creates one dedicated PG shared across same-rank-set meshes; disabling resets
  to the shared PG.
- test_fully_shard_backward_comm_overlap: real backward AG/RS overlap (large
  matmuls + collectives) is no slower than a serialized single-communicator
  reference.

Authored with Claude.

Co-authored-by: Lei Tian <[email protected]>
Pull Request resolved: pytorch#186335
Approved by: https://github.com/anshul-si
ghstack dependencies: pytorch#186000

Co-authored-by: Lei Tian <[email protected]>
@Luosuu

Luosuu commented Jul 26, 2026

Copy link
Copy Markdown

Hi @weifengpy
curious about whether you find any use case that benefits from separate NCCL communicators to overlap AG/RS? Thanks!

aws-kingrj pushed a commit to amazon-contributing/upstream-to-pytorch that referenced this pull request Jul 29, 2026
…ytorch#186335)

By default FSDP2 runs all-gather and reduce-scatter on separate CUDA streams but
through the same process group -- one NCCL communicator, which processes one
collective at a time and so serializes them on the wire. This adds an opt-in
FSDPModule API to give reduce-scatter its own communicator:

    FSDPModule.set_separate_reduce_scatter_group(enable=True, *, recurse=True)

When enabled, FSDP creates a dedicated process group over the shard ranks
(dist.new_group), one per distinct set of shard ranks (typically one
communicator), so reduce-scatter and all-gather can progress concurrently when
the network can sustain it; enable=False resets to the shared group. The default
is unchanged -- reduce-scatter shares the shard process group -- so this is
purely opt-in and creates no extra communicators unless requested.

This redesigns the approach explored in (closed) PR pytorch#177015, which made the
separate communicator the unconditional default (and created one even for
post-forward meshes); here it is an opt-in toggle.

Test Plan:
```
python test/distributed/_composable/fsdp/test_fully_shard_overlap.py \
  TestFullyShardOverlap.test_set_separate_reduce_scatter_group \
  TestFullyShardOverlap.test_fully_shard_backward_comm_overlap
```
Both pass on 4xH100:
- test_set_separate_reduce_scatter_group: default shares the shard PG; enabling
  creates one dedicated PG shared across same-rank-set meshes; disabling resets
  to the shared PG.
- test_fully_shard_backward_comm_overlap: real backward AG/RS overlap (large
  matmuls + collectives) is no slower than a serialized single-communicator
  reference.

Authored with Claude.

Co-authored-by: Lei Tian <[email protected]>
Pull Request resolved: pytorch#186335
Approved by: https://github.com/anshul-si
ghstack dependencies: pytorch#186000

Co-authored-by: Lei Tian <[email protected]>
jerrymannil pushed a commit to ROCm/pytorch that referenced this pull request Jul 29, 2026
…ytorch#186335)

By default FSDP2 runs all-gather and reduce-scatter on separate CUDA streams but
through the same process group -- one NCCL communicator, which processes one
collective at a time and so serializes them on the wire. This adds an opt-in
FSDPModule API to give reduce-scatter its own communicator:

    FSDPModule.set_separate_reduce_scatter_group(enable=True, *, recurse=True)

When enabled, FSDP creates a dedicated process group over the shard ranks
(dist.new_group), one per distinct set of shard ranks (typically one
communicator), so reduce-scatter and all-gather can progress concurrently when
the network can sustain it; enable=False resets to the shared group. The default
is unchanged -- reduce-scatter shares the shard process group -- so this is
purely opt-in and creates no extra communicators unless requested.

This redesigns the approach explored in (closed) PR pytorch#177015, which made the
separate communicator the unconditional default (and created one even for
post-forward meshes); here it is an opt-in toggle.

Test Plan:
```
python test/distributed/_composable/fsdp/test_fully_shard_overlap.py \
  TestFullyShardOverlap.test_set_separate_reduce_scatter_group \
  TestFullyShardOverlap.test_fully_shard_backward_comm_overlap
```
Both pass on 4xH100:
- test_set_separate_reduce_scatter_group: default shares the shard PG; enabling
  creates one dedicated PG shared across same-rank-set meshes; disabling resets
  to the shared PG.
- test_fully_shard_backward_comm_overlap: real backward AG/RS overlap (large
  matmuls + collectives) is no slower than a serialized single-communicator
  reference.

Authored with Claude.

Co-authored-by: Lei Tian <[email protected]>
Pull Request resolved: pytorch#186335
Approved by: https://github.com/anshul-si
ghstack dependencies: pytorch#186000

Co-authored-by: Lei Tian <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests release notes: distributed (fsdp) release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants