Repository navigation
[ROCm][test] Reuse device meshes across FSDP2 ND-mesh subtests - #198301
Closed
chinmaydk99 wants to merge 1 commit into
Closed
chinmaydk99 wants to merge 1 commit into
chinmaydk99 wants to merge 1 commit into
Conversation
test_2d_mlp_with_nd_mesh and test_3d_mlp_with_nd_mesh build a global mesh and pass it to their subtest helpers, but each helper overwrote it with a freshly built mesh, so every subtest created new NCCL communicators. test_shard_placement_fn_tp_ep rebuilt its meshes in every subtest even though they depend only on tp_degree and dp_replicate. On RCCL every communicator keeps a ~40 MB proxy-ops segment per rank in /dev/shm until the test's processes exit, so each of these tests exceeded a 10 GiB /dev/shm on 8 GPUs and failed with ENOSPC. Use the mesh that is passed in, and build the tp_ep meshes once per configuration. Peak /dev/shm on 8x MI300X at this commit: 2D 16.1 -> 1.3 GB, 3D 21.4 -> 1.6 GB, tp_ep 20.5 -> 8.8 GB.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/198301
Note: Links to docs will display an error until the docs builds have been completed. ❌ You can merge normally! (7 Unrelated Failures), 1 Unclassified FailureAs of commit a13af27 with merge base f704053 ( UNCLASSIFIED FAILURE - DrCI could not classify the following job because the workflow did not run on the merge base. The failure may be pre-existing on trunk or introduced by this PR:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
BROKEN TRUNK - The following jobs 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. |
|
Warning: Unknown label
Please add the new label to .github/pytorch-probot.yml |
This was referenced Sep 23, 2026
Merged
Merged
pragupta
approved these changes
Sep 24, 2026
pragupta
pushed a commit
to ROCm/pytorch
that referenced
this pull request
Sep 24, 2026
…ts (pytorch#198301) (#3694) Cherry-pick of pytorch#198301 into `release/2.12`. test_2d_mlp_with_nd_mesh and test_3d_mlp_with_nd_mesh build a global mesh and pass it to their subtest helpers, but each helper overwrote it with a freshly built mesh, so every subtest created new NCCL communicators. test_shard_placement_fn_tp_ep rebuilt its meshes in every subtest even though they depend only on tp_degree and dp_replicate. On RCCL every communicator keeps a ~40 MB proxy-ops segment per rank in /dev/shm until the test's processes exit, so each of these tests exceeded a 10 GiB /dev/shm on 8 GPUs and failed with ENOSPC. Use the mesh that is passed in, and build the tp_ep meshes once per configuration. Peak /dev/shm on 8x MI300X at this commit: 2D 16.1 -> 1.3 GB, 3D 21.4 -> 1.6 GB, tp_ep 20.5 -> 8.8 GB. Cherry-picked with `-x` from `a13af274c73c022c92f42f7925947f960d52e12d`; applied cleanly with no conflicts. Touches one file: `test/distributed/_composable/fsdp/test_fully_shard_training.py` (+8/-3). **Note:** the upstream PR is still open at the time of this cherry-pick. If it is squashed or rebased on merge, the SHA in the `(cherry picked from ...)` trailer will not exist in `main` — the PR link above is the stable reference for provenance.
pragupta
pushed a commit
to ROCm/pytorch
that referenced
this pull request
Sep 24, 2026
…ts (pytorch#198301) (#3695) Cherry-pick of pytorch#198301 into `release/2.13`. test_2d_mlp_with_nd_mesh and test_3d_mlp_with_nd_mesh build a global mesh and pass it to their subtest helpers, but each helper overwrote it with a freshly built mesh, so every subtest created new NCCL communicators. test_shard_placement_fn_tp_ep rebuilt its meshes in every subtest even though they depend only on tp_degree and dp_replicate. On RCCL every communicator keeps a ~40 MB proxy-ops segment per rank in /dev/shm until the test's processes exit, so each of these tests exceeded a 10 GiB /dev/shm on 8 GPUs and failed with ENOSPC. Use the mesh that is passed in, and build the tp_ep meshes once per configuration. Peak /dev/shm on 8x MI300X at this commit: 2D 16.1 -> 1.3 GB, 3D 21.4 -> 1.6 GB, tp_ep 20.5 -> 8.8 GB. Cherry-picked with `-x` from `a13af274c73c022c92f42f7925947f960d52e12d`; applied cleanly with no conflicts. Touches one file: `test/distributed/_composable/fsdp/test_fully_shard_training.py` (+8/-3). **Note:** the upstream PR is still open at the time of this cherry-pick. If it is squashed or rebased on merge, the SHA in the `(cherry picked from ...)` trailer will not exist in `main` — the PR link above is the stable reference for provenance.
pragupta
pushed a commit
to ROCm/pytorch
that referenced
this pull request
Sep 24, 2026
…ts (pytorch#198301) (#3696) Cherry-pick of pytorch#198301 into `release/2.14`. test_2d_mlp_with_nd_mesh and test_3d_mlp_with_nd_mesh build a global mesh and pass it to their subtest helpers, but each helper overwrote it with a freshly built mesh, so every subtest created new NCCL communicators. test_shard_placement_fn_tp_ep rebuilt its meshes in every subtest even though they depend only on tp_degree and dp_replicate. On RCCL every communicator keeps a ~40 MB proxy-ops segment per rank in /dev/shm until the test's processes exit, so each of these tests exceeded a 10 GiB /dev/shm on 8 GPUs and failed with ENOSPC. Use the mesh that is passed in, and build the tp_ep meshes once per configuration. Peak /dev/shm on 8x MI300X at this commit: 2D 16.1 -> 1.3 GB, 3D 21.4 -> 1.6 GB, tp_ep 20.5 -> 8.8 GB. Cherry-picked with `-x` from `a13af274c73c022c92f42f7925947f960d52e12d`; applied cleanly with no conflicts. Touches one file: `test/distributed/_composable/fsdp/test_fully_shard_training.py` (+8/-3). **Note:** the upstream PR is still open at the time of this cherry-pick. If it is squashed or rebased on merge, the SHA in the `(cherry picked from ...)` trailer will not exist in `main` — the PR link above is the stable reference for provenance.
chinmaydk99
marked this pull request as ready for review
September 25, 2026 12:42
jeffdaily
approved these changes
Sep 28, 2026
Collaborator
|
@pytorchbot merge -i |
Collaborator
albmalamd
added a commit
to ROCm/pytorch
that referenced
this pull request
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).
pytorchmergebot
pushed a commit
that referenced
this pull request
Oct 12, 2026
## 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. <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 #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 #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: #200632 Approved by: https://github.com/jeffdaily
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
test_2d_mlp_with_nd_mesh and test_3d_mlp_with_nd_mesh build a global mesh and pass it to their subtest helpers, but each helper overwrote it with a freshly built mesh, so every subtest created new NCCL communicators. test_shard_placement_fn_tp_ep rebuilt its meshes in every subtest even though they depend only on tp_degree and dp_replicate.
On RCCL every communicator keeps a ~40 MB proxy-ops segment per rank in /dev/shm until the test's processes exit, so each of these tests exceeded a 10 GiB /dev/shm on 8 GPUs and failed with ENOSPC.
Use the mesh that is passed in, and build the tp_ep meshes once per configuration. Peak /dev/shm on 8x MI300X at this commit: 2D 16.1 -> 1.3 GB, 3D 21.4 -> 1.6 GB, tp_ep 20.5 -> 8.8 GB.
cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang