Skip to content

[FSDP2] Add set_separate_reduce_scatter_group (opt-in AG/RS overlap) - #186335

Closed
weifengpy wants to merge 3 commits into
gh/weifengpy/149/basefrom
gh/weifengpy/149/head
Closed

weifengpy wants to merge 3 commits into
gh/weifengpy/149/basefrom
gh/weifengpy/149/head

Conversation

@weifengpy

@weifengpy weifengpy commented Jun 5, 2026 •

Copy link
Copy Markdown
Contributor

Stack from ghstack (oldest at bottom):

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]

@pytorch-bot

pytorch-bot Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

❌ 8 New Failures, 1 Unrelated Failure

As of commit 7001fe3 with merge base f5d8a56 (image):

NEW FAILURES - The following jobs have failed:

BROKEN TRUNK - The following job failed but were present on the merge base:

👉 Rebase onto the `viable/strict` branch to avoid these failures

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

@pytorch-bot pytorch-bot Bot added ciflow/inductor ciflow/torchtitan Run TorchTitan integration tests release notes: distributed (fsdp) release notes category labels Jun 5, 2026
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

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge -i

@pytorch-bot

pytorch-bot Bot commented Jun 5, 2026

Copy link
Copy Markdown

This PR needs to be approved by an authorized maintainer before merge.

@weifengpy
weifengpy requested a review from anshul-si June 5, 2026 16:23
@anshul-si

Copy link
Copy Markdown
Contributor

@claude review this pr

@claude

claude Bot commented Jun 5, 2026 •

Copy link
Copy Markdown

Claude finished @anshul-si's task in 3m 29s —— View job


Review of PR #186335: [FSDP2] Add set_separate_reduce_scatter_group

  • Gather context and read changed files
  • Analyze implementation for correctness, safety, and style
  • Post review feedback

Overall: Clean, well-scoped opt-in API. The design — one dist.new_group per distinct set of shard ranks, cached to avoid creating redundant communicators — is sound. The property-based fallback (reduce_scatter_process_group or shard_process_group) keeps the default path zero-cost. A few observations below:


Issues

1. Process groups are never destroyed on disable (_fsdp_param_group.py:989-990)

When enable=False, the code sets mesh_info.reduce_scatter_process_group = None but doesn't call dist.destroy_process_group() on the old group. If a user toggles enable/disable multiple times, orphaned NCCL communicators accumulate. In practice this is likely fine for the "set once" use case, but worth documenting or handling if the API is intended to be toggled.

2. Ordering concern: set_symm_mem / set_allocate_memory_from_process_group vs set_separate_reduce_scatter_group (_fsdp_param_group.py:316-368)

set_symm_mem() and set_allocate_memory_from_process_group() both call ProcessGroupAllocReduceScatter(self._reduce_scatter_process_group) or SymmMemReduceScatter(self._reduce_scatter_process_group, backend) at init time to capture the group for memory allocation. If a user calls set_separate_reduce_scatter_group() after set_symm_mem(), the alloc mixin's self._group will point to the old shard PG while the __call__ dispatch uses the new dedicated PG — a mismatch between the group used for allocation and the group used for the collective. This could cause subtle correctness issues with symmetric memory.

Consider either:

  • Documenting that set_separate_reduce_scatter_group must be called before set_symm_mem / set_allocate_memory_from_process_group, or
  • Having _set_separate_reduce_scatter_group re-initialize _reduce_scatter_comm if it's a PG-capturing type.

3. post_forward_mesh_info not handled (_fsdp_param_group.py:975-1000)

_set_separate_reduce_scatter_group only modifies self.mesh_info, but _all_gather_process_group uses post_forward_mesh_info when is_sharded_post_forward is true. If reduce-scatter also uses the post-forward mesh in some codepath, that mesh's reduce_scatter_process_group would remain None. From the code, _reduce_scatter_process_group always reads from self.mesh_info (not post_forward_mesh_info), so this appears safe — but it's worth confirming this invariant holds for HSDP / non-standard mesh configurations.


Minor / Nits

4. Untyped new_groups dict (_fully_shard.py:786)

new_groups: dict = {}

Should be dict[tuple[int, ...], dist.ProcessGroup] to match the type annotation on _set_separate_reduce_scatter_group's parameter.

5. Performance test flakiness risk (test_fully_shard_overlap.py:272-273)

self.assertLessEqual(fsdp_time, ref_time)

Timing-based assertions are inherently flaky in CI (as noted in the class docstring). The existing overlap test already acknowledges this. Consider adding a small tolerance multiplier (e.g., self.assertLessEqual(fsdp_time, ref_time * 1.05)) or skipping in CI environments. The @skip_if_rocm_arch_multiprocess(MI200_ARCH) skip is good but CI A10G GPUs may also show variance under load.


What looks good

  • The new_groups caching pattern correctly deduplicates communicators across param groups that share the same shard ranks — this avoids the N-communicator-per-module problem from the closed PR [FSDP2] Use separate NCCL communicator for reduce-scatter to enable AG/RS overlap #177015.
  • The property-based fallback (or) is elegant and maintains backward compat with zero overhead when disabled.
  • The idempotency check (existing if existing is not None) prevents double-creation on repeated enable=True calls.
  • Good test coverage: both a functional unit test (test_set_separate_reduce_scatter_group) and a performance integration test.
  • The docstring is thorough and clearly explains the "why" (single NCCL communicator serializes collectives).

@weifengpy

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge -i

@pytorch-bot pytorch-bot Bot added the ciflow/trunk Trigger trunk jobs on your pull request label Jun 8, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged while ignoring the following 2 checks: torchtitan-test / torchtitan-x-pytorch-test / test-osdc (torchtitan_features_integration, 1, 1, mt-l-x86aavx2-189-704-a10g-8), inductor / inductor-test / test-osdc (inductor_huggingface, 1, 1, mt-l-x86aavx2-29-113-a10g)

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

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
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: New commits were pushed while merging. Please rerun the merge command.

Details for Dev Infra team Raised by workflow job

@weifengpy

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge

@weifengpy weifengpy added release notes: distributed (fsdp2) release notes category and removed release notes: distributed (fsdp) release notes category labels Jun 8, 2026
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge started

Your change will be merged once all checks pass (ETA 0-4 Hours).

Learn more about merging in the wiki.

Questions? Feedback? Please reach out to the PyTorch DevX Team

Advanced Debugging
Check the merge workflow status
here

[ghstack-poisoned]

Co-authored-by: Lei Tian <[email protected]>
@weifengpy
weifengpy force-pushed the gh/weifengpy/149/head branch from 9478aff to 3c68888 Compare June 8, 2026 19:39
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]>
@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: New commits were pushed while merging. Please rerun the merge command.

Details for Dev Infra team Raised by workflow job

[ghstack-poisoned]

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]>
[ghstack-poisoned]

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]>
@weifengpy

Copy link
Copy Markdown
Contributor Author

@pytorchmergebot merge -i

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]>
@github-actions
github-actions Bot deleted the gh/weifengpy/149/head branch July 11, 2026 02:22
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]>
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]>
pytorchmergebot pushed a commit that referenced this pull request Sep 14, 2026
Clears six MI200 (gfx90a) test gates and widens one tolerance. Each was root-caused on a 4x gfx90a host first; the two MI200 skips that turned out to be real library bugs stay, now with issue links.

- **elastic `test_tcp`** (DISABLED #144689) was never a gfx90a problem. `_WorkerServer("", 1234)` binds IPv6-only on the ROCm runners, where `getaddrinfo("localhost")` returns only `127.0.0.1`, so the request is refused; the hardcoded port was a second latent failure mode on shared runners. Binding `("127.0.0.1", 0)` and reading `_WorkerServer.port` fixes both on every platform, so the arch gate goes away with the bug.
- **`TestExternKernelCaller`** (#170205, #162803): both gates were added with no recorded root cause, and neither test has a gfx90a-specific failure mode on record. The timing test's separate gfx942 flakiness is a Triton codegen bug handled in #196673.
- **`TestFullyShardOverlap`**: one gate is from a ROCm 6.1-era DISABLED issue (#134139), the other was preemptive when the test landed (#186335); both are clean under stress on a current stack. The two `TestFullyShardPerParamMeshOverlap` gates stay - those hang 100% of the time on gfx90a with HSA queues frozen behind partially written packets, an RCCL launch-tracking deadlock filed as ROCm/rccl#2191.
- **`test_deleted_mempool_not_used_on_oom`**: the MI200 gate is dead code under the unconditional Linux skip for #176145 above it, so dropping it changes no test selection.

The DDP fp16 grad-layout tolerance is the one real numerics change. On gfx90a the fp16 case fails deterministically at 3.0e-3, always the same 1-of-512 element at 3.067e-3 absolute, reproducing byte for byte across machines and builds. It is not fp16 arithmetic: a CPU fp16 run tracks fp64 to 7e-6 while the MIOpen GPU run is off by 2.5e-3 on a gradient whose maximum magnitude is 5.4e-3. Per-op bisection localizes it to conv1's data and weight gradients amplified through conv0's 1568-term reduction, and `MIOPEN_DEBUG_CONV_IMPLICIT_GEMM=0` drops the error ~70x; the solvers are `ConvHipImplicitGemmGroup{Bwd,Wrw}Xdlops`, which MIOpen picks for these shapes only on gfx90a. Filed as ROCm/rocm-libraries#11938. The 8.0e-3 bound is measured, not fitted: over a 31-seed sweep the worst DDP versus full-batch difference is 3.8e-3 with each side up to 4.7e-3 from an fp64 reference, bounding the comparison at ~7.4e-3. It applies only to fp16 on gfx90a; CUDA and every other ROCm architecture keep 3.0e-3.

Test plan: on a 4x gfx90a (MI250X) host with ROCm 7.14, each affected test x25 in isolation, then its class, then the full file, plus lintrunner on every touched file. Every unskipped test is 25/25; the DDP fp16 case is 25/25 with the new tolerance and 0/10 without. Residual full-file failures reproduce identically on the unmodified files on that box. Cross-architecture coverage comes from the ciflow labels.

This description and the changes were authored with the assistance of Claude, an AI assistant, and reviewed by me.

Pull Request resolved: #196674
Approved by: https://github.com/jeffdaily

Co-authored-by: Jeff Daily <[email protected]>
anshul-si added a commit to anshul-si/flex_shard that referenced this pull request Oct 28, 2026
…#118)

Summary:
Pull Request resolved: meta-pytorch#118

Ported from meta-pytorch#84 (weifengpy). Applied unchanged.

A bucket's all-gathers and reduce-scatters run on separate streams but through its mesh's process group: one NCCL communicator, which runs one collective at a time, so a backward all-gather waits behind the reduce-scatter issued before it. meta-pytorch#84 measured, on 256 H100s with Llama 3.1 405B (blockwise FP8, 4,096 tokens per GPU): the all-gathers and reduce-scatters never overlapped, and a gather that started within 5 ms of a reduce-scatter's end took 46-47 ms against 27-28 ms after another gather. 85% of the backward gathers started that close, so the network time was the sum of both collectives (152.6 s of a 168 s step). FSDP2 has the same pattern, and `FSDPModule.set_separate_reduce_scatter_group` (pytorch/pytorch#186335) as the opt-in fix.

`FlexShardModule.set_separate_reduce_scatter_group(enable=True, *, recurse=True)` is its counterpart: each bucket reduce-scatters over a `DeviceMesh` built from a dedicated process group over its mesh's ranks (`dist.new_group` with local synchronization, one per distinct set of ranks, shared by the buckets, as FSDP2 shares its group), so the two collectives can progress together. Enabling again keeps the group; `False` goes back to the mesh's. 1-D meshes only; a 1-rank mesh has nothing to separate. The reduce path reads the bucket's `reduce_mesh` where it read its mesh, eager and compiled.

The FlexShard MXFP8 Dist-MoE benchmarks ran with this enabled in the FlexShard arm, and FSDP2's counterpart in the FSDP2 arm. fbcode torchtitan has no config option for it yet.

Reviewed By: weifengpy

Differential Revision: D127640092
anshul-si added a commit to anshul-si/flex_shard that referenced this pull request Nov 2, 2026
…#118)

Summary:

Ported from meta-pytorch#84 (weifengpy). Applied unchanged.

A bucket's all-gathers and reduce-scatters run on separate streams but through its mesh's process group: one NCCL communicator, which runs one collective at a time, so a backward all-gather waits behind the reduce-scatter issued before it. meta-pytorch#84 measured, on 256 H100s with Llama 3.1 405B (blockwise FP8, 4,096 tokens per GPU): the all-gathers and reduce-scatters never overlapped, and a gather that started within 5 ms of a reduce-scatter's end took 46-47 ms against 27-28 ms after another gather. 85% of the backward gathers started that close, so the network time was the sum of both collectives (152.6 s of a 168 s step). FSDP2 has the same pattern, and `FSDPModule.set_separate_reduce_scatter_group` (pytorch/pytorch#186335) as the opt-in fix.

`FlexShardModule.set_separate_reduce_scatter_group(enable=True, *, recurse=True)` is its counterpart: each bucket reduce-scatters over a `DeviceMesh` built from a dedicated process group over its mesh's ranks (`dist.new_group` with local synchronization, one per distinct set of ranks, shared by the buckets, as FSDP2 shares its group), so the two collectives can progress together. Enabling again keeps the group; `False` goes back to the mesh's. 1-D meshes only; a 1-rank mesh has nothing to separate. The reduce path reads the bucket's `reduce_mesh` where it read its mesh, eager and compiled.

The FlexShard MXFP8 Dist-MoE benchmarks ran with this enabled in the FlexShard arm, and FSDP2's counterpart in the FSDP2 arm. fbcode torchtitan has no config option for it yet.

Reviewed By: weifengpy

Differential Revision: D127640092
meta-codesync Bot pushed a commit to meta-pytorch/flex_shard that referenced this pull request Nov 2, 2026
Summary:

Ported from #84 (weifengpy). Applied unchanged.

A bucket's all-gathers and reduce-scatters run on separate streams but through its mesh's process group: one NCCL communicator, which runs one collective at a time, so a backward all-gather waits behind the reduce-scatter issued before it. #84 measured, on 256 H100s with Llama 3.1 405B (blockwise FP8, 4,096 tokens per GPU): the all-gathers and reduce-scatters never overlapped, and a gather that started within 5 ms of a reduce-scatter's end took 46-47 ms against 27-28 ms after another gather. 85% of the backward gathers started that close, so the network time was the sum of both collectives (152.6 s of a 168 s step). FSDP2 has the same pattern, and `FSDPModule.set_separate_reduce_scatter_group` (pytorch/pytorch#186335) as the opt-in fix.

`FlexShardModule.set_separate_reduce_scatter_group(enable=True, *, recurse=True)` is its counterpart: each bucket reduce-scatters over a `DeviceMesh` built from a dedicated process group over its mesh's ranks (`dist.new_group` with local synchronization, one per distinct set of ranks, shared by the buckets, as FSDP2 shares its group), so the two collectives can progress together. Enabling again keeps the group; `False` goes back to the mesh's. 1-D meshes only; a 1-rank mesh has nothing to separate. The reduce path reads the bucket's `reduce_mesh` where it read its mesh, eager and compiled.

The FlexShard MXFP8 Dist-MoE benchmarks ran with this enabled in the FlexShard arm, and FSDP2's counterpart in the FSDP2 arm. fbcode torchtitan has no config option for it yet.

Reviewed By: weifengpy

Differential Revision: D127640092

Pull Request resolved: #118
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 ciflow/trunk Trigger trunk jobs on your pull request Merged release notes: distributed (fsdp2) release notes category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants