-
Notifications
You must be signed in to change notification settings - Fork 26.3k
Fix for test_ddp_apply_optim_in_backward for gloo #170239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Fix for test_ddp_apply_optim_in_backward for gloo #170239
Conversation
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/170239
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (1 Unrelated Failure)As of commit 5f54666 with merge base beb6c77 ( UNSTABLE - The following job is marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
0786b7e to
b24ae97
Compare
|
cc @d4l3k who would be a suitable reviewer for this change? (tentatively assigned you but feel free to re-assign) |
|
@albmalamd can you please provide more information in your PR description? I know the two of us discussed this on a call but the lack of context here makes it hard for others to review. Thanks. |
|
hey @jeffdaily, I've added a description. Please have a look. Thank you! |
b24ae97 to
5f54666
Compare
|
To add the ciflow label This helps ensure we don't trigger CI on this PR until it is actually authorized to do so. Please ping one of the reviewers if you do not have access to approve and run workflows. |
|
To add the ciflow label This helps ensure we don't trigger CI on this PR until it is actually authorized to do so. Please ping one of the reviewers if you do not have access to approve and run workflows. |
|
I can see why this would solve it but the copy is being done nonblocking so you should be able to do this without a CPU synchronization. By the time run() completes all of the CPU operations are completed and the copy (HtoD) should follow stream semantics |
Fixes #155714
Problem
AsyncAllreduceCUDAHostWorkin ProcessGroupGloo was producing incorrect results when performing allreduce operations on CUDA/HIP tensors, causingtest_ddp_apply_optim_in_backwardto fail. The problem is common for both CUDA and HIP however it was hidden by different CI setup (no torchvision installed so the test execution was incomplete).Root Cause
ProcessGroupGloo is a CPU-based collective communication backend. For CUDA tensors, it:
The bug was in the
synchronize()method, which used:events[i].block(c10::impl::VirtualGuardImpl(device.type()).getStream(device));event.block(stream)callscudaStreamWaitEvent()/hipStreamWaitEvent(), providing only GPU-GPU synchronizationFix
Changed to
event.synchronize():cudaEventSynchronize()/hipEventSynchronize(), which blocks the CPU thread until the event completes, providing proper CPU-GPU synchronization. This ensures GPU copy operations have actually completed before Gloo accesses the data.