Repository navigation
Conversation
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1fbcf669b5
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| import pytest | ||
|
|
||
|
|
||
| class TestZeROCheckpointTag(DistributedTest): |
There was a problem hiding this comment.
Add the required Signed-off-by trailer
This non-merge commit has no Signed-off-by trailer, so it does not satisfy the repository's commit requirements. Please add the trailer using the configured Git name and email before merging.
AGENTS.md reference: AGENTS.md:L8-L8
Useful? React with 👍 / 👎.
| allowed_missing_keys = None | ||
| if self.zero_optimization_partition_weights() and not load_optimizer_states and not self.has_moe_layers: | ||
| checkpoint['module'] = get_fp32_state_dict_from_zero_checkpoint(load_dir) | ||
| checkpoint['module'] = get_fp32_state_dict_from_zero_checkpoint(load_dir, tag=tag) |
There was a problem hiding this comment.
Normalize the checkpoint tag before reconstruction
When a checkpoint was saved with a numeric tag and the caller later uses the same numeric value in load_checkpoint, this ZeRO-3 path now passes the integer directly to get_fp32_state_dict_from_zero_checkpoint, whose os.path.join(checkpoint_dir, tag) raises TypeError. This previously worked with the default save_latest=True because reconstruction re-read the stringified tag from latest, and save_checkpoint explicitly supports such values by applying str(tag); normalize the resolved load tag similarly before forwarding it.
Useful? React with 👍 / 👎.
|
The current head |
|
Current master ( The |
|
Thanks for pointing out #8891. I agree that the production edit is superseded. A test-only revision has been prepared locally on official master The retained cases check every restored parameter as well as client metadata, covering explicit earlier string/integer tags, present/absent The remote branch has not been replaced yet: the current contribution policy requires the human submitter to review the final diff and run the relevant tests before DCO attestation. I will not carry the old sign-off forward as evidence of that review. The next branch update will remove the superseded production edit and update the title and validation scope together. |
Signed-off-by: Rui <[email protected]>
9e52b5d to
20d7fc2
Compare
|
The test-only revision is now pushed as Fresh validation passed 11 parameter combinations on CPU/Gloo and 11 on CUDA/NCCL, each at world sizes 1 and 2 (up to two RTX 3090s), plus all applicable pre-commit checks. A wrong-partition-tag mutation fails the restored-parameter assertions. I reviewed the final diff and ran the relevant tests before signing off. The title and description now reflect only this test coverage; current CI selection returns no |
…speedai#9071) fixes deepspeedai#9067 ## what `save_checkpoint` had rank 0 write `<save_dir>/latest` as soon as its own files were on disk, then call `dist.barrier()`. if the job died while another rank was still writing its zero shard, `latest` named a tag missing that shard and every restart through `load_checkpoint(save_dir)` failed until someone edited `latest` by hand. `latest` was also truncated and rewritten in place, so a kill between the `open` and the `write` left it empty. this change: - adds a `dist.barrier()` after `checkpoint_engine.commit()` and before rank 0 writes `latest`, so `latest` only points at a tag once every rank's files for it are written (this is the ordering from before deepspeedai#2202, which moved the barrier after the write). the existing barrier after the write stays, so `save_checkpoint` still returns on every rank only after `latest` exists. - writes `latest` through a temporary file (`latest.tmp.<pid>`), `fsync`, and `os.replace`, so a reader sees either the previous tag or the new one, never an empty or partial file. - applies the same change to `_commit_decoupled_checkpoint`, which had the same write-then-barrier order (the decoupled engine's `commit` only waits for its own writer process, and only barriers on the first call to measure the folder size). ## sibling paths checked - regular commit path (`TorchCheckpointEngine`, `FastCheckpointEngine`): fixed. - decoupled commit path: fixed, same helper. - pipeline engine: inherits `save_checkpoint`, covered. - `deepspeed/checkpoint/ds_to_universal.py` also writes `latest_universal` in place, but it is an offline single-process converter with no cross-rank ordering issue; left unchanged to keep this pr focused. ## why this is not a duplicate searched open and closed prs for `9067`, `latest checkpoint barrier`, `os.replace latest`, `save_checkpoint` and `latest in:title`; nothing touches this write. the closest are deepspeedai#1486 (single latest writer, merged 2021) and deepspeedai#8501 (zero-3 tag selection on load, a different path). ## tests new test `tests/unit/checkpoint/test_latest_checkpoint.py::TestLatestWrittenAfterAllRanks::test_latest_waits_for_slow_rank`: two ranks, zero stage 1, rank 1 delays its zero shard save by 2 s, and a watcher thread on rank 0 records whether rank 1's shard exists at the moment `latest` first names the tag. it also checks that no `latest.*` temporary file is left behind. ``` DS_ACCELERATOR=cpu LOCAL_SIZE=2 pytest -q tests/unit/checkpoint/test_latest_checkpoint.py -k slow_rank ``` - with this change: passes (3/3 runs). - on master without the engine change: fails, `latest` names `tag1` while `zero_pp_rank_1_mp_rank_00_optim_states.pt` does not exist yet. hardware and software: cpu only, 8 vcpu intel xeon, 2 ranks over gloo via the cpu accelerator, torch 2.14.1+cpu, python 3.12, deepspeed master at 988b2e3. no gpu was used. the box has no c++ compiler, so the shm comm and fused adam ops could not be built; the test uses `torch_adam` and i ran with the shm comm op marked incompatible locally. `yapf` 0.43.0 and `flake8` 5.0.4 are clean on both changed files. ## compatibility matrix - validated: zero stage 1, fp32, cpu, 2 ranks, default torch checkpoint engine. - not validated on device: zero 2/3, offload, fp16/bf16, gpu/nccl, and the fast/decoupled checkpoint engines (they need the aio op). the change is only an extra collective barrier on all ranks plus how rank 0 writes one small text file, so it does not depend on zero stage or precision; the extra barrier adds one synchronization per save. --------- Signed-off-by: Dundy Pasupuleti <[email protected]>
Summary
Add regression coverage for ZeRO-3 checkpoint tag selection after #8891 fixed the runtime path. This revision changes only
tests/unit/checkpoint/test_zero_optimizer.py; it drops the superseded production edit.Related: #8499. The existing single-checkpoint tests cannot detect older metadata paired with newer weights. An open-PR search on 2026-11-13 found no other PR covering this two-checkpoint selection matrix; #9071 addresses publication of the latest marker after saves, not loading a requested older tag.
Coverage
The test trains a small real model, saves two observably different checkpoints, restores into a fresh engine, and checks client metadata and every gathered parameter against the pre-save snapshot.
latest,load_optimizer_states=False, and bothload_module_onlyvalues.tag=Noneselecting the newer checkpoint.Validation
Fresh runs on official master
f94aa5c52aadf02096c17df422b90b581e9b86c6plus only the test addition:CPU: 2 × Intel Xeon Gold 6133; GPU: up to 2 × NVIDIA RTX 3090 (24 GiB), driver 580.178.04. Python 3.11.15, PyTorch 2.12.1+cu126, CUDA runtime 12.6; CPU/Gloo and CUDA/NCCL. Each 11-case result includes both world sizes, totaling 22 distributed scenarios per backend.
Negative control: temporarily forcing only the ZeRO partition loader to select
laterwhile retaining the requested earlier model metadata makes the first older-tag case fail on restored parameter values (8/8 weight elements differ). The production file was restored byte-for-byte afterward. This is a mutation check of the new test, not an unmodified historical release run.An earlier sandboxed invocation failed before checkpoint execution because process creation was prohibited; the unrestricted runs above passed without code changes.
Validated: ZeRO-3, fp32, no offload, same-size legacy checkpoints, DP 1/2. Not validated: fp16/bf16, CPU/NVMe offload, universal checkpoints, DP resizing, TP/PP/MoE, multi-node or other accelerators. No production numerics, performance, or memory changes are claimed.
OpenAI Codex assisted with preparing and validating this revision.
I reviewed the final diff and ran the relevant tests before signing off. The current CI test selector reports no
tests/unit/v1targets for this legacy checkpoint test; the CPU/GPU commands above were run directly.