Repository navigation
Conversation
_preconnect_shared_p2p_edges exchanges one tensor per physical pipeline pair, from the lower rank to the higher rank, on the assumption that the pair channel is bidirectional. The communicator is, but NCCL connects each send direction of a pair separately on first use. The higher-to-lower path is therefore still connected lazily inside the schedule, at the first send from the higher rank. That breaks the setup contract that every P2P path is connected before pipeline execution or CUDA-graph capture, which the per-edge path (_preconnect_p2p_edge_groups) and the neighbor exchange replaced in pytorch#197488 both honor. On ROCm this lazy connect deadlocks ScheduleTest.test_unshard_lookahead_fsdp_parity (PP=2 x DP=2 FSDP) in about half of the runs. The higher rank's RCCL proxy allocates the connection buffer and calls hipStreamSynchronize, which waits behind that rank's in-flight receive kernel on a shared hardware queue. The lower rank's matching send cannot launch because its IPC buffer registration waits on the same busy proxy, so neither side progresses, and the ProcessGroupNCCL watchdogs are blocked behind the stuck ncclGroupEnd. The fix exchanges the setup tensor in both directions of each pair, in the same order on both peers, so the schedule never creates a P2P connection. Switching the test to per-edge groups or tuning ROCm hardware queues would only hide the problem for one test or platform. The RCCL proxy behavior is being reported to ROCm separately. Test Plan: Run on 8x MI300X (ROCm) against a release/2.15 build whose torch/distributed/pipelining/_p2p.py is identical to main: ```bash cd test PYTORCH_TEST_WITH_ROCM=1 python3 distributed/pipelining/test_schedule.py -v -k P2PInitializationTest PYTORCH_TEST_WITH_ROCM=1 python3 distributed/pipelining/test_schedule.py --use-pytest -q PYTORCH_TEST_WITH_ROCM=1 python3 distributed/pipelining/test_schedule_multiproc.py --use-pytest -v PYTORCH_TEST_WITH_ROCM=1 python3 distributed/pipelining/test_schedule_multiproc.py --use-pytest -v -k test_unshard_lookahead_fsdp_parity ``` The updated unit test fails without the fix (2 P2P calls instead of 4) and passes with it. test_schedule.py passes (155 tests) and test_schedule_multiproc.py passes (66 tests). The FSDP parity test hung in 8/17 runs before the fix, and in 8/8 runs when the lower rank's first send is delayed by 200 ms; with the fix it passed 22/22 and 8/8. With NCCL_DEBUG=INFO, no rank creates a P2P connection after the first schedule step. This change was authored with assistance from an AI coding assistant. Co-authored-by: Cursor <[email protected]>
PR Status: Approved 🚀Please fix all CI failures and trigger merge by commenting "@pytorchbot merge". 🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/204061
Note: Links to docs will display an error until the docs builds have been completed. ✅ No FailuresAs of commit aed4df0 with merge base e2c2673 ( This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
|
|
@claude Review the changes in this PR |
jeffdaily
left a comment
There was a problem hiding this comment.
LGTM. @sanketpurandare, can you take a look since this touches the setup from #197488?
|
@pytorchbot merge |
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 |
Merge failedReason: 1 jobs have failed, first few of them are: Auto Request Review Details for Dev Infra teamRaised by workflow job |
|
@pytorchbot merge -f "unrelated failures" |
Merge startedYour change will be merged immediately since you used the force (-f) flag, bypassing any CI checks (ETA: 1-5 minutes). Please use Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
… P2P pairs (pytorch#204061) (#3986) ## Linked issue or supporting maintainer Supported by @jeffdaily ## BC-breaking? No ## Summary (human written only) On ROCm, ScheduleTest.test_unshard_lookahead_fsdp_parity hangs because the shared-group P2P setup added in pytorch#197488 only connects one direction of each pipeline pair (lower to higher rank). NCCL connects each send direction separately, so the reverse direction is still connected lazily mid-schedule, which deadlocks in RCCL. This PR makes the setup exchange in both directions, matching the per-edge path and the behavior before pytorch#197488. ## Agent details (if applicable) The following analysis was produced by an AI coding assistant (Cursor) and reviewed by me: > **Root cause.** `_preconnect_shared_p2p_edges` sends one tensor per physical pipeline > pair, lower rank to higher rank, assuming the pair channel is bidirectional. The > communicator is, but NCCL connects each send direction separately on first use, so the > higher-to-lower path is connected lazily at the higher rank's first `SEND_F` inside the > schedule. With `NCCL_DEBUG=INFO`, PP rank 0 connects `Channel 08/1 0->1` during setup, > while PP rank 1 connects `Channel 08/1 1->0` only after `time_step 4, action 1SEND_F0`. > > **Why it hangs on ROCm** (rocgdb, all ranks blocked host-side in `dist.isend`): > > - PP rank 1: `ProcessGroupNCCL::sendImpl -> ncclGroupEnd -> ncclP2PPreconnectFunc -> p2pSendSetup -> ncclProxyCallBlocking`. > - PP rank 1 proxy thread: `p2pSendProxySetup -> ncclP2pAllocateShareableBuffer -> ncclCudaCallocDebug -> hipStreamSynchronize`, waiting behind the rank's in-flight `RECV_F0` kernel on a shared hardware queue. > - PP rank 0: `ncclLaunchPrepare -> ncclRegisterP2pIpcBuffer -> ipcRegisterBuffer -> ncclProxyConnect` to rank 1's busy proxy, so its send never launches and rank 1's receive never completes. > > It is a race: a pair deadlocks when the higher rank reaches its first send about 5 ms > before the lower rank. With the original code and the lower rank's first send delayed by > 200 ms, the test hangs 8/8 at the default `GPU_MAX_HW_QUEUES` and passes 8/8 with > `GPU_MAX_HW_QUEUES=16`. > > **Fix.** Exchange the setup tensor in both directions of each pair, in the same order on > both peers. With the fix, no rank creates a P2P connection after the first schedule step. > The per-edge path (`_preconnect_p2p_edge_groups`) already preconnects both directions, > and the neighbor exchange replaced in pytorch#197488 did as well. > > **Alternatives not taken.** Switching the test to per-edge groups or `nccl-lazy`, or > tuning ROCm hardware queues, would only avoid the hang for one test or platform. The > RCCL proxy behavior (a blocking stream sync in the proxy while RCCL kernels are in > flight) is being reported to ROCm separately, with a two-GPU reproducer. > > **Validation** on 8x MI300X (ROCm) against a release/2.15 build whose `_p2p.py` is > identical to main: > > | Case | Without fix | With fix | > |---|---|---| > | `test_unshard_lookahead_fsdp_parity` | 8/17 hang | 22/22 pass | > | Same test, lower rank's first send delayed 200 ms (test-only harness) | 8/8 hang | 8/8 pass | > | `test_schedule_multiproc.py` | hangs at this test | 66 passed | > | `test_schedule.py` | not run | 155 passed | > | `P2PInitializationTest` (updated unit test) | fails (2 != 4 P2P calls) | passes | > > **Not verified:** behavior on CUDA. The lazy reverse-direction connect is generic NCCL > behavior, but a hang has only been observed on ROCm. Pull Request resolved: pytorch#204061 Approved by: https://github.com/pragupta, https://github.com/jeffdaily (cherry picked from commit 1f18fa1) Co-authored-by: Cursor <[email protected]>
Linked issue or supporting maintainer
Supported by @jeffdaily
BC-breaking?
No
Summary (human written only)
On ROCm, ScheduleTest.test_unshard_lookahead_fsdp_parity hangs because the shared-group
P2P setup added in #197488 only connects one direction of each pipeline pair (lower to
higher rank). NCCL connects each send direction separately, so the reverse direction is
still connected lazily mid-schedule, which deadlocks in RCCL. This PR makes the setup
exchange in both directions, matching the per-edge path and the behavior before #197488.
Agent details (if applicable)
The following analysis was produced by an AI coding assistant (Cursor) and reviewed by me: