Repository navigation
Conversation
…/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]
🔗 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 FailureAs of commit 0ba8af0 with merge base a790959 ( 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. |
…/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
|
In my experience, overlapping 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
This PR used separate PGs for AG and RS. do you mean overlapping comms on different NCCL communicators? |
|
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.
I mean that the stream that the comm kernels run on can be the same stream so that the comm kernels are serialized. |
…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]
chatted with @awgu offline on the other direction about merging it turns out
one example cpu offloading, there is overlapping between grad D2H and AG |
|
close this as the change is up to benchmarking |
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
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
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
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
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]>
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]>
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]>
…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]>
…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]>
…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]>
|
Hi @weifengpy |
…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]>
…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]>

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