Repository navigation
[release/2.14] Fix post-local SGD checkpoint reload race (#194614) - #4061
Merged
jeffdaily merged 1 commit intoNov 23, 2026
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) Co-authored-by: Cursor <[email protected]>
jeffdaily
marked this pull request as ready for review
November 23, 2026 22:27
jeffdaily
approved these changes
Nov 23, 2026
jeffdaily
deleted the
albmalamd/cherry-pick/2.14/194614-fix-post-localsgd-reload-race
branch
November 23, 2026 22:28
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