Repository navigation
Order all-gather streams after post-forward reshard in FSDP comm test - #197827
Closed
pablo-garay wants to merge 1 commit into
Closed
pablo-garay wants to merge 1 commit into
pablo-garay wants to merge 1 commit into
Conversation
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.
🔗 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 FailuresAs of commit 7a58592 with merge base c00221a ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
jeffdaily
approved these changes
Sep 21, 2026
Collaborator
|
@pytorchbot merge |
Collaborator
Merge startedYour 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 |
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.
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:
This PR was authored with the assistance of an AI agent (Claude). The analysis and test results were verified by hand.