Skip to content

[ROCm] Keep FSDP/HSDP/TP tests within the RCCL /dev/shm budget - #200632

Closed
albmalamd wants to merge 1 commit into
pytorch:mainfrom
ROCm:albmalamd/rocm-test-reuse-process-groups-shm
Closed

albmalamd wants to merge 1 commit into
pytorch:mainfrom
ROCm:albmalamd/rocm-test-reuse-process-groups-shm

Conversation

@albmalamd

@albmalamd albmalamd commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Linked issue or supporting maintainer

Supported by @jeffdaily

BC-breaking?

No

Summary (human written only)

Follow-up to #198299, #198301 and #198302. Some FSDP/HSDP/TP distributed tests started failing with ENOSPC error again on 10 GiB /dev/shm after RCCL 2.32.3 doubled the per-communicator /dev/shm segment to 82.6 MB per rank. This change reuses or frees the groups they create (MoE expert group, TP and HSDP meshes, hybrid-shard auto groups) and runs each tp_ep configuration in its own processes. Peak /dev/shm drops from ~10.6 GB to at most 5.3 GB.

Agent details (if applicable)

I used Cursor (Claude) to root-cause the failures, write the change and run the validation below. I reviewed the code and the results.

Agent-generated details

Root cause. RCCL's proxy-ops pool is sized as ops[MAX_OPS_PER_PEER * NCCL_MAX_LOCAL_RANKS] and ncclShmOpen fallocates all of it. The NCCL v2.32.3 sync raised NCCL_MAX_LOCAL_RANKS from 72 to 144, so each communicator reserves 82,576,040 B per rank, up from ~41 MB. Only about 16 communicators per rank fit in 10 GiB on 8 GPUs.

Changes.

Rejected alternative. Freeing tp_ep's groups when its configuration changes fails with Could not resolve the process group registered under the name 3. DeviceMesh.__eq__/__hash__ ignore process groups, so DTensor caches return an equal mesh whose groups were destroyed. A generic per-test group cleanup in MultiProcContinuousTest would hit the same hazard.

Validation. 8x MI300X, 10 GiB /dev/shm, torch 2.13.0+rocm10.2.0a20261008 (RCCL 2.32.3). test_fully_shard_training.py on main needs a newer torch than this wheel, so its identical change was validated on release/2.13.

python -m pytest distributed/fsdp/test_fsdp_core.py -k mixture_of_experts -v --timeout 900
python -m pytest distributed/fsdp/test_fsdp_hybrid_shard.py -v --timeout 900
python -m pytest distributed/fsdp/test_fsdp_tp_integration.py -v --timeout 900
python -m pytest distributed/fsdp/test_hsdp_dtensor_state_dict.py -v --timeout 900
python -m pytest "distributed/_composable/fsdp/test_fully_shard_training.py::TestFullyShardNDTraining" -v --timeout 900
Scope Before After Peak /dev/shm after
test_fsdp_core.py -k mixture_of_experts ENOSPC 12 passed 1.3 GB
test_fsdp_hybrid_shard.py ENOSPC 7 passed 5.3 GB
test_fsdp_tp_integration.py ENOSPC 3 passed 2.0 GB
test_hsdp_dtensor_state_dict.py ENOSPC 8 passed 2.0 GB
TestFullyShardNDTraining (incl. 4x tp_ep) ENOSPC 5 passed 5.3 GB

test_mixture_of_experts_offload_true_no_shard_cuda also has a pre-existing, unrelated flaky FSDP-vs-DDP parity mismatch on ROCm, seen with RCCL 2.30.7 too.

cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang

@pytorch-bot

pytorch-bot Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 2fd94f3 with merge base 0398ae1 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@pytorch-bot pytorch-bot Bot added module: rocm AMD GPU support for Pytorch release notes: distributed (fsdp) release notes category labels Oct 12, 2026
@jithunnair-amd jithunnair-amd added ciflow/trunk Trigger trunk jobs on your pull request ciflow/periodic-rocm-mi350 Trigger "distributed_4gpu" config (only runs distributed tests that need >2GPUs) CI on ROCm MI350 ciflow/periodic-rocm-mi300 Trigger "distributed" config CI on ROCm MI300/MI325 ciflow/periodic-rocm-mi200 Trigger "distributed" config CI on ROCm MI200 labels Oct 12, 2026
classes create, because on RCCL every communicator keeps a per-rank proxy-ops
segment in /dev/shm until the test processes exit. They were sized for a
~40 MB segment (RCCL 2.30.7). RCCL 2.32.3 picked up the NCCL v2.32.3 change
that raised NCCL_MAX_LOCAL_RANKS from 72 to 144, and the proxy-ops pool is
sized statically from it, so each communicator now fallocate()s 82,576,040 B
per rank. On 8 GPUs only about 16 communicators per rank fit in a 10 GiB
/dev/shm, and these tests fail again with:

    Error while creating shared memory segment /dev/shm/nccl-XXXXXX
    (size 82576040), error: No space left on device (28)

The over-reservation itself is being fixed in RCCL separately (size the pool
by the communicator's local ranks). This change keeps the tests well within
the budget regardless of the RCCL version.

MixtureOfExperts (test_fsdp_core.py TestParityWithDDP, 12 tests) created a new
size-1 expert group on every model build. It now shares one expert group per
parent group. TestTPFSDPIntegration and TestHSDPWithDeviceMeshAndDTensor are
continuous tests that built the same mesh in every test or subtest. They now
build it once per class, as pytorch#198299 does. In test_fsdp_hybrid_shard_basic_setup
the use_device_mesh=False subtests let FSDP create new intra/inter-node groups
for every model. Reusing them would skip the automatic setup the test checks,
so they are destroyed at the end of the subtest instead.
test_shard_placement_fn_tp_ep still needs ~27 communicators per rank with the
mesh reuse from pytorch#198301, so it is parametrized over (tp_degree, dp_replicate)
and each configuration runs in its own processes. This renames the test to
test_shard_placement_fn_tp_ep_tp_degree_{1,2}_dp_replicate_{1,2}.

For tp_ep, freeing the previous configuration's groups when the configuration
changes was also tried. It fails with "Could not resolve the process group
registered under the name 3": DeviceMesh.__eq__/__hash__ ignore process groups,
so DTensor caches hand back an equal mesh from the previous configuration whose
groups were destroyed. The same hazard applies to destroying non-default groups
generically after each MultiProcContinuousTest test. Raising --shm-size only
moves the ceiling.

Test Plan:

8x MI300X, 10 GiB /dev/shm, torch 2.13.0+rocm10.2.0a20261008 (RCCL 2.32.3),
running the test files from this branch (and the same change on release/2.13
for test_fully_shard_training.py, whose main version needs a newer torch than
the wheel):

```
python -m pytest distributed/fsdp/test_fsdp_core.py -k mixture_of_experts -v --timeout 900
python -m pytest distributed/fsdp/test_fsdp_hybrid_shard.py -v --timeout 900
python -m pytest distributed/fsdp/test_fsdp_tp_integration.py -v --timeout 900
python -m pytest distributed/fsdp/test_hsdp_dtensor_state_dict.py -v --timeout 900
python -m pytest "distributed/_composable/fsdp/test_fully_shard_training.py::TestFullyShardNDTraining" -v --timeout 900
```

| Scope | Before | After | Peak /dev/shm after |
|---|---|---|---|
| test_fsdp_core.py -k mixture_of_experts | ENOSPC | 12 passed | 1.3 GB |
| test_fsdp_hybrid_shard.py | ENOSPC | 7 passed | 5.3 GB |
| test_fsdp_tp_integration.py | ENOSPC | 3 passed | 2.0 GB |
| test_hsdp_dtensor_state_dict.py | ENOSPC | 8 passed | 2.0 GB |
| TestFullyShardNDTraining (incl. 4x tp_ep) | ENOSPC | 5 passed | 5.3 GB |

Before, every scope peaked at ~10.6 GB. Unrelated to /dev/shm,
test_mixture_of_experts_offload_true_no_shard_cuda has a pre-existing flaky
FSDP-vs-DDP parity mismatch on ROCm (also seen with RCCL 2.30.7).

This PR was authored with the help of an AI assistant (Cursor).
@albmalamd
albmalamd force-pushed the albmalamd/rocm-test-reuse-process-groups-shm branch from 14cfcb2 to 2fd94f3 Compare October 12, 2026 15:25
@pytorch-bot

pytorch-bot Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Workflows were awaiting approval. CI has now been triggered for the ciflow labels on this PR.

@jeffdaily jeffdaily left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My agent came up with this analysis, but I've read and approved it.

Validated on 8x MI300X (gfx942) with RCCL 2.30.7 (41,291,776 B of /dev/shm per communicator per rank) and a 10 GiB /dev/shm. On main, test_fsdp_core.py -k mixture_of_experts fails 7/12 with ENOSPC; with this PR all 35 tests across the five commands pass, and peak /dev/shm drops 2.6-16x (MoE 10.6 GB -> 0.66 GB, hybrid shard 7.85 -> 2.48, TP 6.44 -> 0.99, HSDP 6.61 -> 0.99, ND training 9.25 -> 3.63). One correction to the description: ND training still peaks at 11 communicators per rank, which is about 7.3 GB on RCCL 2.32.3, so "at most 5.3 GB" is understated for that file; it still fits in 10 GiB.

@jeffdaily
jeffdaily marked this pull request as ready for review October 12, 2026 23:47
@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@github-actions github-actions Bot added bot-triaged This is a label only to be used by the auto triage bot triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Oct 12, 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

pragupta pushed a commit to ROCm/pytorch that referenced this pull request Oct 14, 2026
pytorch#200632) (#3808)

## Linked issue or supporting maintainer

Supported by @jeffdaily 

## BC-breaking?

No

## Summary (human written only)

Follow-up to pytorch#198299, pytorch#198301 and pytorch#198302. Some FSDP/HSDP/TP distributed
tests started failing with ENOSPC error again on 10 GiB `/dev/shm` after
RCCL 2.32.3 doubled the per-communicator `/dev/shm` segment to 82.6 MB
per rank. This change reuses or frees the groups they create (MoE expert
group, TP and HSDP meshes, hybrid-shard auto groups) and runs each
`tp_ep` configuration in its own processes. Peak `/dev/shm` drops from
~10.6 GB to at most 5.3 GB.

## Agent details (if applicable)

I used Cursor (Claude) to root-cause the failures, write the change and
run the validation below. I reviewed the code and the results.

<details>
<summary>Agent-generated details</summary>

**Root cause.** RCCL's proxy-ops pool is sized as `ops[MAX_OPS_PER_PEER
* NCCL_MAX_LOCAL_RANKS]` and `ncclShmOpen` `fallocate`s all of it. The
NCCL v2.32.3 sync raised `NCCL_MAX_LOCAL_RANKS` from 72 to 144, so each
communicator reserves 82,576,040 B per rank, up from ~41 MB. Only about
16 communicators per rank fit in 10 GiB on 8 GPUs.

**Changes.**
- `MixtureOfExperts` shares one size-1 expert group per parent group
instead of creating one per model build.
- `TestTPFSDPIntegration` and `TestHSDPWithDeviceMeshAndDTensor` build
their mesh once per class, as in pytorch#198299.
- `test_fsdp_hybrid_shard_basic_setup` destroys the groups FSDP
auto-creates in its `use_device_mesh=False` subtests. Reusing them would
skip the setup path under test.
- `test_shard_placement_fn_tp_ep` is parametrized over `(tp_degree,
dp_replicate)`, because it still needs ~27 communicators per rank with
the pytorch#198301 reuse.

**Rejected alternative.** Freeing `tp_ep`'s groups when its
configuration changes fails with `Could not resolve the process group
registered under the name 3`. `DeviceMesh.__eq__`/`__hash__` ignore
process groups, so DTensor caches return an equal mesh whose groups were
destroyed. A generic per-test group cleanup in `MultiProcContinuousTest`
would hit the same hazard.

**Validation.** 8x MI300X, 10 GiB `/dev/shm`, torch
2.13.0+rocm10.2.0a20261008 (RCCL 2.32.3). `test_fully_shard_training.py`
on `main` needs a newer torch than this wheel, so its identical change
was validated on release/2.13.

```
python -m pytest distributed/fsdp/test_fsdp_core.py -k mixture_of_experts -v --timeout 900
python -m pytest distributed/fsdp/test_fsdp_hybrid_shard.py -v --timeout 900
python -m pytest distributed/fsdp/test_fsdp_tp_integration.py -v --timeout 900
python -m pytest distributed/fsdp/test_hsdp_dtensor_state_dict.py -v --timeout 900
python -m pytest "distributed/_composable/fsdp/test_fully_shard_training.py::TestFullyShardNDTraining" -v --timeout 900
```

| Scope | Before | After | Peak /dev/shm after |
|---|---|---|---|
| test_fsdp_core.py -k mixture_of_experts | ENOSPC | 12 passed | 1.3 GB
|
| test_fsdp_hybrid_shard.py | ENOSPC | 7 passed | 5.3 GB |
| test_fsdp_tp_integration.py | ENOSPC | 3 passed | 2.0 GB |
| test_hsdp_dtensor_state_dict.py | ENOSPC | 8 passed | 2.0 GB |
| TestFullyShardNDTraining (incl. 4x tp_ep) | ENOSPC | 5 passed | 5.3 GB
|

`test_mixture_of_experts_offload_true_no_shard_cuda` also has a
pre-existing, unrelated flaky FSDP-vs-DDP parity mismatch on ROCm, seen
with RCCL 2.30.7 too.

</details>


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

(cherry picked from commit 605ec3f)
rocm-repo-management-api-6 Bot added a commit to ROCm/pytorch that referenced this pull request Oct 15, 2026
rocm-repo-management-api-6 Bot added a commit to ROCm/pytorch that referenced this pull request Oct 15, 2026
rocm-repo-management-api-6 Bot added a commit to ROCm/pytorch that referenced this pull request Oct 19, 2026
pytorchmergebot pushed a commit that referenced this pull request Oct 31, 2026
… the RCCL /dev/shm budget (#202272)

## Linked issue or supporting maintainer

Supported by @jeffdaily

## BC-breaking?

No

## Summary (human written only)

Follow-up to #198299 and #200632. `test_composability.py::ComposabilityTest`, `TestFullyShardPrefetch::test_fully_shard_backward_prefetch` and `TestFullyShardFrozen::test_train_mixed_requires_grad_per_group` fail with ENOSPC on a 10 GiB `/dev/shm`, because RCCL 2.32.3 reserves 82.6 MB of `/dev/shm` per communicator per rank. `ComposabilityTest` now builds each mesh once per class, as #198299 did for `test_pp_composability.py`. The `reshard_after_forward=2` subtests of the two FSDP tests run in their own processes, as #200632 does for `tp_ep`. Peak `/dev/shm` drops from ~10.2 GB to at most 7.9 GB, and runtime does not increase.

## Agent details (if applicable)

I used Cursor (Claude) to root-cause the failures, write the change and run the validation below. I reviewed the code and the results.

<details>
<summary>Agent-generated details</summary>

**Root cause.** RCCL's proxy-ops pool is sized as `ops[MAX_OPS_PER_PEER * NCCL_MAX_LOCAL_RANKS]` with `NCCL_MAX_LOCAL_RANKS` = 144, and `ncclShmOpen` `fallocate`s all of it, so every communicator reserves 82,576,040 B of `/dev/shm` per rank until the processes exit. Only `localRanks` of the 144 slots are ever used.

**Changes.**
- `test/distributed/test_composability.py` has its own `ComposabilityTest`, separate from the one #198299 changed in `_composable/test_composability/test_pp_composability.py`. Its workers are reused for the whole class, and every `test_pp_*` built a new `("dp", "pp")` mesh: 2 communicators per rank (16 across the 8 ranks) per test, 14 tests. It now uses the same class-level `_get_mesh` cache as #198299, so the class builds 2 meshes.
- `TestFullyShardPrefetch` and `TestFullyShardFrozen` already run each test in fresh processes, but a single test exhausts `/dev/shm`. `fully_shard(reshard_after_forward=2)` builds a new post-forward `DeviceMesh` on every call, and its groups live until the processes exit: 48 two-rank communicators per rank in the prefetch test, 32 in the frozen test. FSDP creates these meshes internally, so a test cannot reuse them. The `reshard_after_forward=2` subtests therefore move to:
  - `test_fully_shard_backward_prefetch_reshard_to_2_{None,utils,composable}`;
  - `test_train_mixed_requires_grad_per_group_reshard_to_2_use_activation_checkpointing_{False,True}`.

  Each new test runs its variant in its own processes. Coverage is unchanged.

**Rejected alternative.** Destroying groups at the end of a test or subtest: `DeviceMesh.__eq__`/`__hash__` ignore process groups, so DTensor caches can return an equal mesh whose groups were destroyed (see #200632).

**Validation.** 8x MI300X, 10 GiB `/dev/shm`, torch 2.15.0+rocm10.2.0rc0, with RCCL 2.32.3 as shipped in the wheel. The same change was applied on release/2.15, because `main`'s `test_fully_shard_comm.py` imports `torch.distributed.fsdp.experimental`, which that wheel lacks. On release/2.15, `test_composability.py` and `test_fully_shard_frozen.py` match `main`. `main`'s `test_fully_shard_comm.py` also has tests this change does not touch, and they were not run: `test_numerics_with_leading_dims`, several `TestCase` and `FSDPTestMultiThread` classes that create no RCCL communicators, and `test_unused_backward_prefetch_with_post_forward_mesh` in `TestFullyShardPrefetch`, which makes three `reshard_after_forward=2` calls in its own processes. Each file was run whole, twice with this change and once without it.

```
cd test
export PYTORCH_TEST_WITH_ROCM=1 PYTORCH_TESTING_DEVICE_ONLY_FOR=cuda BACKEND=nccl WORLD_SIZE=8 TEMP_DIR=$(mktemp -d)
python -m pytest -v -s distributed/test_composability.py
python -m pytest -v -s distributed/_composable/fsdp/test_fully_shard_comm.py
python -m pytest -v -s distributed/_composable/fsdp/test_fully_shard_frozen.py
```

| File | Before | After (2 runs) | Peak /dev/shm before -> after | Runtime before -> after |
|---|---|---|---|---|
| test_composability.py | `test_pp_fsdp_*` ENOSPC | 20 passed, 2 skipped | 10197 MB -> 2547 MB | 76-86 s -> 42-50 s |
| test_fully_shard_comm.py | `test_fully_shard_backward_prefetch` ENOSPC (exit -6) | 39 passed, 1 skipped | 10108 MB -> 6642 MB | 589 s -> 567-590 s |
| test_fully_shard_frozen.py | `test_train_mixed_requires_grad_per_group` ENOSPC (exit -6) | 5 passed | 10189 MB -> 7902 MB | 146 s -> 140-149 s |

The frozen file's 7902 MB peak comes from the untouched `test_train_mixed_requires_grad_across_groups`.

</details>

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

Co-authored-by: Cursor <[email protected]>
jithunnair-amd pushed a commit to ROCm/pytorch that referenced this pull request Nov 4, 2026
albmalamd added a commit to ROCm/pytorch that referenced this pull request Nov 4, 2026
… the RCCL /dev/shm budget (pytorch#202272)

## Linked issue or supporting maintainer

Supported by @jeffdaily

## BC-breaking?

No

## Summary (human written only)

Follow-up to pytorch#198299 and pytorch#200632. `test_composability.py::ComposabilityTest`, `TestFullyShardPrefetch::test_fully_shard_backward_prefetch` and `TestFullyShardFrozen::test_train_mixed_requires_grad_per_group` fail with ENOSPC on a 10 GiB `/dev/shm`, because RCCL 2.32.3 reserves 82.6 MB of `/dev/shm` per communicator per rank. `ComposabilityTest` now builds each mesh once per class, as pytorch#198299 did for `test_pp_composability.py`. The `reshard_after_forward=2` subtests of the two FSDP tests run in their own processes, as pytorch#200632 does for `tp_ep`. Peak `/dev/shm` drops from ~10.2 GB to at most 7.9 GB, and runtime does not increase.

## Agent details (if applicable)

I used Cursor (Claude) to root-cause the failures, write the change and run the validation below. I reviewed the code and the results.

<details>
<summary>Agent-generated details</summary>

**Root cause.** RCCL's proxy-ops pool is sized as `ops[MAX_OPS_PER_PEER * NCCL_MAX_LOCAL_RANKS]` with `NCCL_MAX_LOCAL_RANKS` = 144, and `ncclShmOpen` `fallocate`s all of it, so every communicator reserves 82,576,040 B of `/dev/shm` per rank until the processes exit. Only `localRanks` of the 144 slots are ever used.

**Changes.**
- `test/distributed/test_composability.py` has its own `ComposabilityTest`, separate from the one pytorch#198299 changed in `_composable/test_composability/test_pp_composability.py`. Its workers are reused for the whole class, and every `test_pp_*` built a new `("dp", "pp")` mesh: 2 communicators per rank (16 across the 8 ranks) per test, 14 tests. It now uses the same class-level `_get_mesh` cache as pytorch#198299, so the class builds 2 meshes.
- `TestFullyShardPrefetch` and `TestFullyShardFrozen` already run each test in fresh processes, but a single test exhausts `/dev/shm`. `fully_shard(reshard_after_forward=2)` builds a new post-forward `DeviceMesh` on every call, and its groups live until the processes exit: 48 two-rank communicators per rank in the prefetch test, 32 in the frozen test. FSDP creates these meshes internally, so a test cannot reuse them. The `reshard_after_forward=2` subtests therefore move to:
  - `test_fully_shard_backward_prefetch_reshard_to_2_{None,utils,composable}`;
  - `test_train_mixed_requires_grad_per_group_reshard_to_2_use_activation_checkpointing_{False,True}`.

  Each new test runs its variant in its own processes. Coverage is unchanged.

**Rejected alternative.** Destroying groups at the end of a test or subtest: `DeviceMesh.__eq__`/`__hash__` ignore process groups, so DTensor caches can return an equal mesh whose groups were destroyed (see pytorch#200632).

**Validation.** 8x MI300X, 10 GiB `/dev/shm`, torch 2.15.0+rocm10.2.0rc0, with RCCL 2.32.3 as shipped in the wheel. The same change was applied on release/2.15, because `main`'s `test_fully_shard_comm.py` imports `torch.distributed.fsdp.experimental`, which that wheel lacks. On release/2.15, `test_composability.py` and `test_fully_shard_frozen.py` match `main`. `main`'s `test_fully_shard_comm.py` also has tests this change does not touch, and they were not run: `test_numerics_with_leading_dims`, several `TestCase` and `FSDPTestMultiThread` classes that create no RCCL communicators, and `test_unused_backward_prefetch_with_post_forward_mesh` in `TestFullyShardPrefetch`, which makes three `reshard_after_forward=2` calls in its own processes. Each file was run whole, twice with this change and once without it.

```
cd test
export PYTORCH_TEST_WITH_ROCM=1 PYTORCH_TESTING_DEVICE_ONLY_FOR=cuda BACKEND=nccl WORLD_SIZE=8 TEMP_DIR=$(mktemp -d)
python -m pytest -v -s distributed/test_composability.py
python -m pytest -v -s distributed/_composable/fsdp/test_fully_shard_comm.py
python -m pytest -v -s distributed/_composable/fsdp/test_fully_shard_frozen.py
```

| File | Before | After (2 runs) | Peak /dev/shm before -> after | Runtime before -> after |
|---|---|---|---|---|
| test_composability.py | `test_pp_fsdp_*` ENOSPC | 20 passed, 2 skipped | 10197 MB -> 2547 MB | 76-86 s -> 42-50 s |
| test_fully_shard_comm.py | `test_fully_shard_backward_prefetch` ENOSPC (exit -6) | 39 passed, 1 skipped | 10108 MB -> 6642 MB | 589 s -> 567-590 s |
| test_fully_shard_frozen.py | `test_train_mixed_requires_grad_per_group` ENOSPC (exit -6) | 5 passed | 10189 MB -> 7902 MB | 146 s -> 140-149 s |

The frozen file's 7902 MB peak comes from the untouched `test_train_mixed_requires_grad_across_groups`.

</details>

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

Co-authored-by: Cursor <[email protected]>
(cherry picked from commit 4a73df5)
pragupta pushed a commit to ROCm/pytorch that referenced this pull request Nov 4, 2026
…s within the RCCL /dev/shm budget (pytorch#202272) (#3940)

## Linked issue or supporting maintainer

Supported by @jeffdaily

## BC-breaking?

No

## Summary (human written only)

Follow-up to pytorch#198299 and pytorch#200632.
`test_composability.py::ComposabilityTest`,
`TestFullyShardPrefetch::test_fully_shard_backward_prefetch` and
`TestFullyShardFrozen::test_train_mixed_requires_grad_per_group` fail
with ENOSPC on a 10 GiB `/dev/shm`, because RCCL 2.32.3 reserves 82.6 MB
of `/dev/shm` per communicator per rank. `ComposabilityTest` now builds
each mesh once per class, as pytorch#198299 did for `test_pp_composability.py`.
The `reshard_after_forward=2` subtests of the two FSDP tests run in
their own processes, as pytorch#200632 does for `tp_ep`. Peak `/dev/shm` drops
from ~10.2 GB to at most 7.9 GB, and runtime does not increase.

## Agent details (if applicable)

I used Cursor (Claude) to root-cause the failures, write the change and
run the validation below. I reviewed the code and the results.

<details>
<summary>Agent-generated details</summary>

**Root cause.** RCCL's proxy-ops pool is sized as `ops[MAX_OPS_PER_PEER
* NCCL_MAX_LOCAL_RANKS]` with `NCCL_MAX_LOCAL_RANKS` = 144, and
`ncclShmOpen` `fallocate`s all of it, so every communicator reserves
82,576,040 B of `/dev/shm` per rank until the processes exit. Only
`localRanks` of the 144 slots are ever used.

**Changes.**
- `test/distributed/test_composability.py` has its own
`ComposabilityTest`, separate from the one pytorch#198299 changed in
`_composable/test_composability/test_pp_composability.py`. Its workers
are reused for the whole class, and every `test_pp_*` built a new
`("dp", "pp")` mesh: 2 communicators per rank (16 across the 8 ranks)
per test, 14 tests. It now uses the same class-level `_get_mesh` cache
as pytorch#198299, so the class builds 2 meshes.
- `TestFullyShardPrefetch` and `TestFullyShardFrozen` already run each
test in fresh processes, but a single test exhausts `/dev/shm`.
`fully_shard(reshard_after_forward=2)` builds a new post-forward
`DeviceMesh` on every call, and its groups live until the processes
exit: 48 two-rank communicators per rank in the prefetch test, 32 in the
frozen test. FSDP creates these meshes internally, so a test cannot
reuse them. The `reshard_after_forward=2` subtests therefore move to:
-
`test_fully_shard_backward_prefetch_reshard_to_2_{None,utils,composable}`;
-
`test_train_mixed_requires_grad_per_group_reshard_to_2_use_activation_checkpointing_{False,True}`.

Each new test runs its variant in its own processes. Coverage is
unchanged.

**Rejected alternative.** Destroying groups at the end of a test or
subtest: `DeviceMesh.__eq__`/`__hash__` ignore process groups, so
DTensor caches can return an equal mesh whose groups were destroyed (see
pytorch#200632).

**Validation.** 8x MI300X, 10 GiB `/dev/shm`, torch
2.15.0+rocm10.2.0rc0, with RCCL 2.32.3 as shipped in the wheel. The same
change was applied on release/2.15, because `main`'s
`test_fully_shard_comm.py` imports
`torch.distributed.fsdp.experimental`, which that wheel lacks. On
release/2.15, `test_composability.py` and `test_fully_shard_frozen.py`
match `main`. `main`'s `test_fully_shard_comm.py` also has tests this
change does not touch, and they were not run:
`test_numerics_with_leading_dims`, several `TestCase` and
`FSDPTestMultiThread` classes that create no RCCL communicators, and
`test_unused_backward_prefetch_with_post_forward_mesh` in
`TestFullyShardPrefetch`, which makes three `reshard_after_forward=2`
calls in its own processes. Each file was run whole, twice with this
change and once without it.

```
cd test
export PYTORCH_TEST_WITH_ROCM=1 PYTORCH_TESTING_DEVICE_ONLY_FOR=cuda BACKEND=nccl WORLD_SIZE=8 TEMP_DIR=$(mktemp -d)
python -m pytest -v -s distributed/test_composability.py
python -m pytest -v -s distributed/_composable/fsdp/test_fully_shard_comm.py
python -m pytest -v -s distributed/_composable/fsdp/test_fully_shard_frozen.py
```

| File | Before | After (2 runs) | Peak /dev/shm before -> after |
Runtime before -> after | |---|---|---|---|---|
| test_composability.py | `test_pp_fsdp_*` ENOSPC | 20 passed, 2 skipped
| 10197 MB -> 2547 MB | 76-86 s -> 42-50 s | | test_fully_shard_comm.py
| `test_fully_shard_backward_prefetch` ENOSPC (exit -6) | 39 passed, 1
skipped | 10108 MB -> 6642 MB | 589 s -> 567-590 s | |
test_fully_shard_frozen.py | `test_train_mixed_requires_grad_per_group`
ENOSPC (exit -6) | 5 passed | 10189 MB -> 7902 MB | 146 s -> 140-149 s |

The frozen file's 7902 MB peak comes from the untouched
`test_train_mixed_requires_grad_across_groups`.

</details>

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


(cherry picked from commit 4a73df5)

Co-authored-by: Cursor <[email protected]>
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 5, 2026
… the RCCL /dev/shm budget (pytorch#202272)

## Linked issue or supporting maintainer

Supported by @jeffdaily

## BC-breaking?

No

## Summary (human written only)

Follow-up to pytorch#198299 and pytorch#200632. `test_composability.py::ComposabilityTest`, `TestFullyShardPrefetch::test_fully_shard_backward_prefetch` and `TestFullyShardFrozen::test_train_mixed_requires_grad_per_group` fail with ENOSPC on a 10 GiB `/dev/shm`, because RCCL 2.32.3 reserves 82.6 MB of `/dev/shm` per communicator per rank. `ComposabilityTest` now builds each mesh once per class, as pytorch#198299 did for `test_pp_composability.py`. The `reshard_after_forward=2` subtests of the two FSDP tests run in their own processes, as pytorch#200632 does for `tp_ep`. Peak `/dev/shm` drops from ~10.2 GB to at most 7.9 GB, and runtime does not increase.

## Agent details (if applicable)

I used Cursor (Claude) to root-cause the failures, write the change and run the validation below. I reviewed the code and the results.

<details>
<summary>Agent-generated details</summary>

**Root cause.** RCCL's proxy-ops pool is sized as `ops[MAX_OPS_PER_PEER * NCCL_MAX_LOCAL_RANKS]` with `NCCL_MAX_LOCAL_RANKS` = 144, and `ncclShmOpen` `fallocate`s all of it, so every communicator reserves 82,576,040 B of `/dev/shm` per rank until the processes exit. Only `localRanks` of the 144 slots are ever used.

**Changes.**
- `test/distributed/test_composability.py` has its own `ComposabilityTest`, separate from the one pytorch#198299 changed in `_composable/test_composability/test_pp_composability.py`. Its workers are reused for the whole class, and every `test_pp_*` built a new `("dp", "pp")` mesh: 2 communicators per rank (16 across the 8 ranks) per test, 14 tests. It now uses the same class-level `_get_mesh` cache as pytorch#198299, so the class builds 2 meshes.
- `TestFullyShardPrefetch` and `TestFullyShardFrozen` already run each test in fresh processes, but a single test exhausts `/dev/shm`. `fully_shard(reshard_after_forward=2)` builds a new post-forward `DeviceMesh` on every call, and its groups live until the processes exit: 48 two-rank communicators per rank in the prefetch test, 32 in the frozen test. FSDP creates these meshes internally, so a test cannot reuse them. The `reshard_after_forward=2` subtests therefore move to:
  - `test_fully_shard_backward_prefetch_reshard_to_2_{None,utils,composable}`;
  - `test_train_mixed_requires_grad_per_group_reshard_to_2_use_activation_checkpointing_{False,True}`.

  Each new test runs its variant in its own processes. Coverage is unchanged.

**Rejected alternative.** Destroying groups at the end of a test or subtest: `DeviceMesh.__eq__`/`__hash__` ignore process groups, so DTensor caches can return an equal mesh whose groups were destroyed (see pytorch#200632).

**Validation.** 8x MI300X, 10 GiB `/dev/shm`, torch 2.15.0+rocm10.2.0rc0, with RCCL 2.32.3 as shipped in the wheel. The same change was applied on release/2.15, because `main`'s `test_fully_shard_comm.py` imports `torch.distributed.fsdp.experimental`, which that wheel lacks. On release/2.15, `test_composability.py` and `test_fully_shard_frozen.py` match `main`. `main`'s `test_fully_shard_comm.py` also has tests this change does not touch, and they were not run: `test_numerics_with_leading_dims`, several `TestCase` and `FSDPTestMultiThread` classes that create no RCCL communicators, and `test_unused_backward_prefetch_with_post_forward_mesh` in `TestFullyShardPrefetch`, which makes three `reshard_after_forward=2` calls in its own processes. Each file was run whole, twice with this change and once without it.

```
cd test
export PYTORCH_TEST_WITH_ROCM=1 PYTORCH_TESTING_DEVICE_ONLY_FOR=cuda BACKEND=nccl WORLD_SIZE=8 TEMP_DIR=$(mktemp -d)
python -m pytest -v -s distributed/test_composability.py
python -m pytest -v -s distributed/_composable/fsdp/test_fully_shard_comm.py
python -m pytest -v -s distributed/_composable/fsdp/test_fully_shard_frozen.py
```

| File | Before | After (2 runs) | Peak /dev/shm before -> after | Runtime before -> after |
|---|---|---|---|---|
| test_composability.py | `test_pp_fsdp_*` ENOSPC | 20 passed, 2 skipped | 10197 MB -> 2547 MB | 76-86 s -> 42-50 s |
| test_fully_shard_comm.py | `test_fully_shard_backward_prefetch` ENOSPC (exit -6) | 39 passed, 1 skipped | 10108 MB -> 6642 MB | 589 s -> 567-590 s |
| test_fully_shard_frozen.py | `test_train_mixed_requires_grad_per_group` ENOSPC (exit -6) | 5 passed | 10189 MB -> 7902 MB | 146 s -> 140-149 s |

The frozen file's 7902 MB peak comes from the untouched `test_train_mixed_requires_grad_across_groups`.

</details>

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

Co-authored-by: Cursor <[email protected]>
dominikjastrzebskix pushed a commit to dominikjastrzebskix/pytorch that referenced this pull request Nov 9, 2026
… the RCCL /dev/shm budget (pytorch#202272)

## Linked issue or supporting maintainer

Supported by @jeffdaily

## BC-breaking?

No

## Summary (human written only)

Follow-up to pytorch#198299 and pytorch#200632. `test_composability.py::ComposabilityTest`, `TestFullyShardPrefetch::test_fully_shard_backward_prefetch` and `TestFullyShardFrozen::test_train_mixed_requires_grad_per_group` fail with ENOSPC on a 10 GiB `/dev/shm`, because RCCL 2.32.3 reserves 82.6 MB of `/dev/shm` per communicator per rank. `ComposabilityTest` now builds each mesh once per class, as pytorch#198299 did for `test_pp_composability.py`. The `reshard_after_forward=2` subtests of the two FSDP tests run in their own processes, as pytorch#200632 does for `tp_ep`. Peak `/dev/shm` drops from ~10.2 GB to at most 7.9 GB, and runtime does not increase.

## Agent details (if applicable)

I used Cursor (Claude) to root-cause the failures, write the change and run the validation below. I reviewed the code and the results.

<details>
<summary>Agent-generated details</summary>

**Root cause.** RCCL's proxy-ops pool is sized as `ops[MAX_OPS_PER_PEER * NCCL_MAX_LOCAL_RANKS]` with `NCCL_MAX_LOCAL_RANKS` = 144, and `ncclShmOpen` `fallocate`s all of it, so every communicator reserves 82,576,040 B of `/dev/shm` per rank until the processes exit. Only `localRanks` of the 144 slots are ever used.

**Changes.**
- `test/distributed/test_composability.py` has its own `ComposabilityTest`, separate from the one pytorch#198299 changed in `_composable/test_composability/test_pp_composability.py`. Its workers are reused for the whole class, and every `test_pp_*` built a new `("dp", "pp")` mesh: 2 communicators per rank (16 across the 8 ranks) per test, 14 tests. It now uses the same class-level `_get_mesh` cache as pytorch#198299, so the class builds 2 meshes.
- `TestFullyShardPrefetch` and `TestFullyShardFrozen` already run each test in fresh processes, but a single test exhausts `/dev/shm`. `fully_shard(reshard_after_forward=2)` builds a new post-forward `DeviceMesh` on every call, and its groups live until the processes exit: 48 two-rank communicators per rank in the prefetch test, 32 in the frozen test. FSDP creates these meshes internally, so a test cannot reuse them. The `reshard_after_forward=2` subtests therefore move to:
  - `test_fully_shard_backward_prefetch_reshard_to_2_{None,utils,composable}`;
  - `test_train_mixed_requires_grad_per_group_reshard_to_2_use_activation_checkpointing_{False,True}`.

  Each new test runs its variant in its own processes. Coverage is unchanged.

**Rejected alternative.** Destroying groups at the end of a test or subtest: `DeviceMesh.__eq__`/`__hash__` ignore process groups, so DTensor caches can return an equal mesh whose groups were destroyed (see pytorch#200632).

**Validation.** 8x MI300X, 10 GiB `/dev/shm`, torch 2.15.0+rocm10.2.0rc0, with RCCL 2.32.3 as shipped in the wheel. The same change was applied on release/2.15, because `main`'s `test_fully_shard_comm.py` imports `torch.distributed.fsdp.experimental`, which that wheel lacks. On release/2.15, `test_composability.py` and `test_fully_shard_frozen.py` match `main`. `main`'s `test_fully_shard_comm.py` also has tests this change does not touch, and they were not run: `test_numerics_with_leading_dims`, several `TestCase` and `FSDPTestMultiThread` classes that create no RCCL communicators, and `test_unused_backward_prefetch_with_post_forward_mesh` in `TestFullyShardPrefetch`, which makes three `reshard_after_forward=2` calls in its own processes. Each file was run whole, twice with this change and once without it.

```
cd test
export PYTORCH_TEST_WITH_ROCM=1 PYTORCH_TESTING_DEVICE_ONLY_FOR=cuda BACKEND=nccl WORLD_SIZE=8 TEMP_DIR=$(mktemp -d)
python -m pytest -v -s distributed/test_composability.py
python -m pytest -v -s distributed/_composable/fsdp/test_fully_shard_comm.py
python -m pytest -v -s distributed/_composable/fsdp/test_fully_shard_frozen.py
```

| File | Before | After (2 runs) | Peak /dev/shm before -> after | Runtime before -> after |
|---|---|---|---|---|
| test_composability.py | `test_pp_fsdp_*` ENOSPC | 20 passed, 2 skipped | 10197 MB -> 2547 MB | 76-86 s -> 42-50 s |
| test_fully_shard_comm.py | `test_fully_shard_backward_prefetch` ENOSPC (exit -6) | 39 passed, 1 skipped | 10108 MB -> 6642 MB | 589 s -> 567-590 s |
| test_fully_shard_frozen.py | `test_train_mixed_requires_grad_per_group` ENOSPC (exit -6) | 5 passed | 10189 MB -> 7902 MB | 146 s -> 140-149 s |

The frozen file's 7902 MB peak comes from the untouched `test_train_mixed_requires_grad_across_groups`.

</details>

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

Co-authored-by: Cursor <[email protected]>
li-lizhe added a commit to li-lizhe/pytorch that referenced this pull request Nov 16, 2026
_get_dp_tp_mesh now takes the device type instead of reading it off the
class, so every test that builds the mesh exercises the device it is
handed. The mesh is still built once and cached, preserving the /dev/shm
budget fix from pytorch#200632.

The cached mesh keeps this honest only because all variants of this class
target one device type per run; the type assertion is implicit in the
call.
li-lizhe added a commit to li-lizhe/pytorch that referenced this pull request Dec 2, 2026
_get_dp_tp_mesh now takes the device type instead of reading it off the
class, so every test that builds the mesh exercises the device it is
handed. The mesh is still built once and cached, preserving the /dev/shm
budget fix from pytorch#200632.

The cached mesh keeps this honest only because all variants of this class
target one device type per run; the type assertion is implicit in the
call.

This branch was previously deployed

1 inactive deployment
bedrock — 2fd94f3f Deployed Oct 12, 2026 by jeffdaily
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-triaged This is a label only to be used by the auto triage bot ciflow/periodic-rocm-mi200 Trigger "distributed" config CI on ROCm MI200 ciflow/periodic-rocm-mi300 Trigger "distributed" config CI on ROCm MI300/MI325 ciflow/periodic-rocm-mi350 Trigger "distributed_4gpu" config (only runs distributed tests that need >2GPUs) CI on ROCm MI350 ciflow/trunk Trigger trunk jobs on your pull request Merged module: rocm AMD GPU support for Pytorch open source release notes: distributed (fsdp) release notes category triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants