Skip to content

[ROCm][test] Keep composability and FSDP prefetch/frozen tests within the RCCL /dev/shm budget - #202272

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

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

Conversation

@albmalamd

@albmalamd albmalamd commented Oct 27, 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 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.

Agent-generated details

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 fallocates 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 [ROCm][test]Reuse device meshes across ComposabilityTest cases #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 [ROCm][test]Reuse device meshes across ComposabilityTest cases #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.

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

… the RCCL /dev/shm budget

Follow-up to pytorch#198299 and pytorch#200632. On ROCm with RCCL 2.32.3, these tests fail
on a 10 GiB /dev/shm with:

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

or, when the error hits a child process, with "Expected exit code 0 but got
-6". RCCL's proxy-ops pool is sized for NCCL_MAX_LOCAL_RANKS (144) and fully
fallocate()d, so every communicator costs 82.6 MB of /dev/shm per rank until
the test processes exit. The over-reservation is being fixed in RCCL
separately; this change keeps the tests well within the budget regardless.

test/distributed/test_composability.py has its own ComposabilityTest, which
pytorch#198299 did not cover (it changed _composable/test_composability/
test_pp_composability.py). Its workers are reused for the whole class and
every test_pp_* built a new mesh, so it now builds each distinct mesh once
per class, using the same _get_mesh helper as pytorch#198299.

TestFullyShardPrefetch and TestFullyShardFrozen already run each test in
fresh processes, but a single test exhausts /dev/shm on its own:
fully_shard(reshard_after_forward=2) builds a new post-forward mesh on every
call, and its groups live until the processes exit. The tests cannot reuse
these meshes because FSDP creates them internally, so the
reshard_after_forward=2 subtests move to new parametrized tests,
test_fully_shard_backward_prefetch_reshard_to_2_* and
test_train_mixed_requires_grad_per_group_reshard_to_2_*, which run each
variant in its own processes, as pytorch#200632 does for tp_ep. Coverage is
unchanged.

Destroying the groups at the end of each test or subtest was not used:
DeviceMesh equality ignores process groups, so DTensor caches can hand back
an equal mesh whose groups were destroyed (see pytorch#200632).

Test Plan:

8x MI300X, 10 GiB /dev/shm, torch 2.15.0+rocm10.2.0rc0 (RCCL 2.32.3, as
shipped in the wheel), with this change applied on release/2.15, where the
three files match main apart from tests that this change does not touch
(main's test_fully_shard_comm.py imports torch.distributed.fsdp.experimental,
which the wheel lacks, and adds test_unused_backward_prefetch_with_post_forward_mesh
to TestFullyShardPrefetch). 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 |
|---|---|---|---|
| test_composability.py | test_pp_fsdp_* ENOSPC | 20 passed, 2 skipped | 10197 MB -> 2547 MB |
| test_fully_shard_comm.py | test_fully_shard_backward_prefetch ENOSPC | 39 passed, 1 skipped | 10108 MB -> 6642 MB |
| test_fully_shard_frozen.py | test_train_mixed_requires_grad_per_group ENOSPC | 5 passed | 10189 MB -> 7902 MB |

Runtime is unchanged or lower (test_composability.py: 76-86 s -> 42-50 s;
the other two files within run-to-run noise). The frozen file's peak comes
from the untouched test_train_mixed_requires_grad_across_groups.

lintrunner was not available in the environment and was not run.

This commit was authored with the help of an AI assistant (Cursor).

Co-authored-by: Cursor <[email protected]>
@pytorch-bot pytorch-bot Bot added module: rocm AMD GPU support for Pytorch topic: not user facing topic category labels Oct 27, 2026
@pytorch-bot

pytorch-bot Bot commented Oct 27, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 4e1bfca with merge base 7c6df23 (image):
💚 Looks good so far! There are no failures yet. 💚

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

@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 27, 2026
@jeffdaily
jeffdaily marked this pull request as ready for review October 27, 2026 21:14

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

LGTM.

@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 27, 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

@pytorchmergebot

Copy link
Copy Markdown
Collaborator

Merge failed

Reason: 1 jobs have failed, first few of them are: Auto Request Review

Details for Dev Infra team

Raised by workflow job

@jeffdaily

Copy link
Copy Markdown
Collaborator

@pytorchbot merge

@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

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

This branch was previously deployed

1 inactive deployment
bedrock — 4e1bfcaa Deployed Oct 27, 2026 by jeffdaily via analyze #15938
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 topic: not user facing topic 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