Repository navigation
Conversation
## Summary Fixes pytorch#84886. There was a race in the post-local SGD checkpoint reload test. Rank 0 created the temporary checkpoint and all ranks synchronized after it was written. However, there was no synchronization after loading. Rank 0 could complete the test first, leave the temporary-file context, and delete the checkpoint before another rank opened it, causing FileNotFoundError. Serialize the checkpoint into an in-memory buffer on rank 0 and broadcast the bytes through the process group. Each rank then loads from its own BytesIO buffer. This removes the rank-0-owned file and its lifetime race instead of adding another barrier around temporary-file cleanup. It also removes the unnecessary shared-filesystem dependency while preserving coverage of serialization, device remapping, optimizer state restoration, and the missing-step fallback. The same changes applied to test_ddp_hook_pickling_powerSGD and unskipped the test. ## Reproduction On `main`, add a 3s delay on non-zero ranks between the post-save `dist.barrier()` and `torch.load` in `_test_post_localSGD_optimizer_step_reload`: ```python dist.barrier() if self.rank != 0: time.sleep(3) map_location = {"cuda:0": f"cuda:{self.rank:d}"} checkpoint = torch.load(chkpt_file, map_location=map_location) ``` And then execute the test: ``` BACKEND=nccl WORLD_SIZE=2 TEMP_DIR=/tmp/dist python test/distributed/test_distributed_spawn.py -v \ TestDistBackendWithSpawn.test_post_localSGD_optimizer_step_reload ``` Without the changes, the test returns: ``` FileNotFoundError: [Errno 2] No such file or directory: '/tmp/tmptsfocehr' ``` Pull Request resolved: pytorch#194614 Approved by: https://github.com/jeffdaily (cherry picked from commit 7658834)
jeffdaily
approved these changes
Aug 28, 2026
jeffdaily
deleted the
cherry-pick-194614-fix_post_localSGD_optimizer_step_reload
branch
August 28, 2026 16:39
Author
|
!cherry-pick --onto release/2.12 |
Author
|
!cherry-pick --onto release/2.11 |
|
Created branch autogenerated/release/2.12_cherry-pick_pr-3600 and #3603 Comment processed by Build |
rocm-repo-management-api-6 Bot
added a commit
that referenced
this pull request
Aug 29, 2026
Cherry-pick of #3600 Co-authored-by: albmalamd <[email protected]>
rocm-repo-management-api-6 Bot
added a commit
that referenced
this pull request
Aug 29, 2026
Cherry-pick of #3600 Co-authored-by: albmalamd <[email protected]>
|
Created branch autogenerated/release/2.11_cherry-pick_pr-3600 and #3604 Comment processed by Build |
Author
|
!cherry-pick --onto release/2.14 |
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.
Summary
Fixes pytorch#84886.
There was a race in the post-local SGD checkpoint reload test. Rank 0 created the temporary checkpoint and all ranks synchronized after it was written. However, there was no synchronization after loading. Rank 0 could complete the test first, leave the temporary-file context, and delete the checkpoint before another rank opened it, causing FileNotFoundError.
Serialize the checkpoint into an in-memory buffer on rank 0 and broadcast the bytes through the process group. Each rank then loads from its own BytesIO buffer.
This removes the rank-0-owned file and its lifetime race instead of adding another barrier around temporary-file cleanup. It also removes the unnecessary shared-filesystem dependency while preserving coverage of serialization, device remapping, optimizer state restoration, and the missing-step fallback.
The same changes applied to test_ddp_hook_pickling_powerSGD and unskipped the test.
Reproduction
On
main, add a 3s delay on non-zero ranks between the post-savedist.barrier()andtorch.loadin_test_post_localSGD_optimizer_step_reload:And then execute the test:
Without the changes, the test returns:
Pull Request resolved: pytorch#194614 Approved by: https://github.com/jeffdaily
(cherry picked from commit 7658834)
Motivation
Technical Details
Test Plan
Test Result
Submission Checklist
Cherry-picked to release/2.12 branch via #3603
Cherry-picked to release/2.11 branch via #3604