Skip to content

[AUTOGENERATED] [release/2.11] Fix post-local SGD checkpoint reload race (#194614) - #3604

Merged
rocm-repo-management-api-6[bot] merged 1 commit into
release/2.11from
autogenerated/release/2.11_cherry-pick_pr-3600
Aug 29, 2026
Merged

rocm-repo-management-api-6[bot] merged 1 commit into
release/2.11from
autogenerated/release/2.11_cherry-pick_pr-3600

Conversation

@rocm-repo-management-api-6

Copy link
Copy Markdown

Cherry-pick of #3600

) (#3600)

## 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)

## Motivation

<!-- Explain the purpose of this PR and the goals it aims to achieve.
-->

## Technical Details

<!-- Explain the changes along with any relevant GitHub links. -->

## Test Plan

<!-- Explain any relevant testing done to verify this PR. -->

## Test Result

<!-- Briefly summarize test outcomes. -->

## Submission Checklist

- [ ] Look over the contributing guidelines at
https://github.com/ROCm/ROCm/blob/develop/CONTRIBUTING.md#pull-requests.
@rocm-repo-management-api-6
rocm-repo-management-api-6 Bot merged commit f1c3504 into release/2.11 Aug 29, 2026
@rocm-repo-management-api-6
rocm-repo-management-api-6 Bot deleted the autogenerated/release/2.11_cherry-pick_pr-3600 branch August 29, 2026 08:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant