Skip to content

Order all-gather streams after post-forward reshard in FSDP comm test - #197827

Closed
pablo-garay wants to merge 1 commit into
pytorch:mainfrom
ROCm:jeffdaily/fsdp-comm-test-post-forward-stream-sync
Closed

pablo-garay wants to merge 1 commit into
pytorch:mainfrom
ROCm:jeffdaily/fsdp-comm-test-post-forward-stream-sync

Conversation

@pablo-garay

Copy link
Copy Markdown
Contributor

TestFullyShardCollectiveOps._test_all_gather exercises foreach_all_gather directly with its own copy-in and all-gather streams. Its reshard_after_forward=8 leg calls fsdp_param_group._to_sharded_post_forward(), which clones each parameter's post-forward chunk on the current stream, and then immediately runs foreach_all_gather, whose copy-in kernel reads those clones on all_gather_copy_in_stream. Nothing orders the two: real FSDP records _reshard_after_forward_event in reshard() and makes both all-gather streams wait on it in unshard(), but the test drives the helpers by hand and skips that step, and the pool streams are non-blocking with respect to the current stream. When the clones have not landed yet, whole 8-rank post-forward groups all-gather stale chunks (fresh zeros or recycled memory), which is the k/8-chunk mismatch pattern in the DISABLED issue's CI logs (12.5 and 25 percent of elements, always at the post-forward assertEqual, never at the first leg, whose preceding full_tensor() comparison drains the current stream). On this host the test failed 3 of 25 and 8 of 25 fresh runs under CPU and GPU contention; a deliberate stall on the current stream after the reshard makes it fail every time on an idle GPU, and the event ordering makes that pass.

Make both all-gather streams wait for the current stream right after _to_sharded_post_forward(), the same ordering unshard() provides. The reduce-scatter tests in the class already go through unshard()/reshard() and foreach_reduce's own wait_stream, which is why they never failed. The threaded process group is not involved: the earlier #195281 event fix did not change this signature.

Fixes #195655

Test Plan:

On a ROCm 10.0 gfx950 host, with stress-ng (64 CPU workers, 4 VM workers) and a GEMM co-tenant process on the same GPU, the unfixed test failed 3 of 25 fresh-process runs (8 of 25 on a two-GPU set); with the fix:

for i in $(seq 25); do PYTHONPATH=test:test/distributed python -m pytest test/distributed/_composable/fsdp/test_fully_shard_comm.py -k test_all_gather_fp32; done
# 1 passed, in each of the 25 fresh processes under the same contention
for i in $(seq 10); do PYTHONPATH=test:test/distributed python -m pytest test/distributed/_composable/fsdp/test_fully_shard_comm.py -k "test_all_gather_fp32 or test_reduce_scatter"; done
# 3 passed, 1 skipped, in each of the 10 fresh processes on an idle GPU

This PR was authored with the assistance of an AI agent (Claude). The analysis and test results were verified by hand.

TestFullyShardCollectiveOps._test_all_gather exercises foreach_all_gather directly with its own copy-in and all-gather streams. Its reshard_after_forward=8 leg calls fsdp_param_group._to_sharded_post_forward(), which clones each parameter's post-forward chunk on the current stream, and then immediately runs foreach_all_gather, whose copy-in kernel reads those clones on all_gather_copy_in_stream. Nothing orders the two: real FSDP records _reshard_after_forward_event in reshard() and makes both all-gather streams wait on it in unshard(), but the test drives the helpers by hand and skips that step, and the pool streams are non-blocking with respect to the current stream. When the clones have not landed yet, whole 8-rank post-forward groups all-gather stale chunks (fresh zeros or recycled memory), which is the k/8-chunk mismatch pattern in the DISABLED issue's CI logs (12.5 and 25 percent of elements, always at the post-forward assertEqual, never at the first leg, whose preceding full_tensor() comparison drains the current stream). On this host the test failed 3 of 25 and 8 of 25 fresh runs under CPU and GPU contention; a deliberate stall on the current stream after the reshard makes it fail every time on an idle GPU, and the event ordering makes that pass.

Make both all-gather streams wait for the current stream right after _to_sharded_post_forward(), the same ordering unshard() provides. The reduce-scatter tests in the class already go through unshard()/reshard() and foreach_reduce's own wait_stream, which is why they never failed. The threaded process group is not involved: the earlier pytorch#195281 event fix did not change this signature.

Fixes pytorch#195655

Test Plan:

On a ROCm 10.0 gfx950 host, with stress-ng (64 CPU workers, 4 VM workers) and a GEMM co-tenant process on the same GPU, the unfixed test failed 3 of 25 fresh-process runs (8 of 25 on a two-GPU set); with the fix:

```
for i in $(seq 25); do PYTHONPATH=test:test/distributed python -m pytest test/distributed/_composable/fsdp/test_fully_shard_comm.py -k test_all_gather_fp32; done
# 1 passed, in each of the 25 fresh processes under the same contention
for i in $(seq 10); do PYTHONPATH=test:test/distributed python -m pytest test/distributed/_composable/fsdp/test_fully_shard_comm.py -k "test_all_gather_fp32 or test_reduce_scatter"; done
# 3 passed, 1 skipped, in each of the 10 fresh processes on an idle GPU
```

Authored with an AI assistant (Claude Code); the diff was reviewed by the human author.
@pytorch-bot

pytorch-bot Bot commented Sep 20, 2026 •

Copy link
Copy Markdown

🔗 Helpful Links

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

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

✅ No Failures

As of commit 7a58592 with merge base c00221a (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 the topic: not user facing topic category label Sep 20, 2026
@jithunnair-amd jithunnair-amd added ciflow/trunk Trigger trunk jobs on your pull request ciflow/periodic-rocm-mi300 Trigger "distributed" config CI on ROCm MI300/MI325 ciflow/periodic-rocm-mi200 Trigger "distributed" config CI on ROCm MI200 labels Sep 20, 2026
@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ciflow/periodic-rocm-mi200 Trigger "distributed" config CI on ROCm MI200 ciflow/periodic-rocm-mi300 Trigger "distributed" config CI on ROCm MI300/MI325 ciflow/trunk Trigger trunk jobs on your pull request Merged open source topic: not user facing topic category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DISABLED test_all_gather_fp32 (__main__.TestFullyShardCollectiveOps)

5 participants