Repository navigation
Warn when save_checkpoint writes into a tag that already has files - #9122
Open
ArchanaChetan07 wants to merge 2 commits into
Open
ArchanaChetan07 wants to merge 2 commits into
ArchanaChetan07 wants to merge 2 commits into
Conversation
save_checkpoint writes each rank's files directly to their final names in <save_dir>/<tag>/, also when that tag already holds a checkpoint (a re-save under a fixed tag, or default global_step<N> tags after load_checkpoint(tag=<older>)). A crash during such a save can leave a tag with files from two different saves that load_checkpoint restores without error. Have rank 0 log a warning before any rank writes when the tag directory is not empty. The check runs before the barrier that precedes the writes, so it cannot race with other ranks writing into a fresh tag when tag validation is disabled. Refs deepspeedai#9066 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: ArchanaChetan07 <apatil@sandiego.edu>
ArchanaChetan07
requested review from
loadams,
tjruwase and
tohtana
as code owners
November 19, 2026 03:37
Codex Review Summary: ✅ CompletedThis 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. |
Only warn the first time a given tag directory is found non-empty, so intentional re-saves under a fixed tag (e.g. 'best') do not log the warning on every save. In the test, delay rank 0's check so that placing it after the barrier (where other ranks may already have written into a fresh tag) fails reliably with tag_validation 'Ignore', and assert only after every rank has run every save, so a failure on one rank does not leave the other waiting in a collective. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: ArchanaChetan07 <apatil@sandiego.edu>
This branch has not been deployed
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.
Addresses #9066 (minimum option (c) from the issue; does not close it).
What
save_checkpointwrites each rank's files straight to their final names in<save_dir>/<tag>/, even when that tag already holds a checkpoint (a re-save under a fixed tag, or the defaultglobal_step<N>tags afterload_checkpoint(tag=<older>)in the same directory). A crash during such a save can leave the tag with files from two saves, andload_checkpointrestores it without error.This PR implements the minimum suggested in the issue: before any rank writes, rank 0 (local rank 0 with
use_node_local_storage) logs a warning if the tag directory already has entries, naming the directory and suggesting a newsave_diror an unused tag. Behaviour is otherwise unchanged; nothing is refused, since the issue leaves refusing (and the crash-safe options (a)/(b)) as a compatibility decision for maintainers. A missing or empty tag directory does not warn. The warning is logged once per tag directory per engine, so intentional re-saves under a fixed tag (e.g."best") do not repeat it on every save.The check runs inside the existing
rank == 0/makedirsblock, before thedist.barrier()that precedes any writes, so other ranks cannot have written into a fresh tag yet. (Placing it after the barrier would race withcheckpoint.tag_validation: "Ignore", where there is no collective between the check and the other ranks' writes.) The tag defaulting (global_step<N>/str(tag)) moved above that block; it is pure, so this is just a reorder.This does not touch the end of
save_checkpoint/latesthandling that #9071 changes.Tests
New
tests/unit/checkpoint/test_existing_tag_warning.py, 2 ranks, ZeRO stage 1, parametrized overtag_validationWarn/Ignore:Rank 0's check is delayed by 2 s in the test, so a check placed after the barrier would see rank 1's ZeRO shard in the fresh tag; with that placement the
Ignorecase fails reliably (verified). Assertions run after every rank has done every save, so a failure on one rank does not hang the other in a collective. The test also fails without the engine change.Validation
DS_ACCELERATOR=cpu, gloo.tests/):LOCAL_SIZE=2 DS_ACCELERATOR=cpu python -m pytest unit/checkpoint/test_existing_tag_warning.py→ 2 passedLOCAL_SIZE=2 DS_ACCELERATOR=cpu python -m pytest unit/checkpoint/test_tag_validation.py unit/checkpoint/test_latest_checkpoint.py unit/checkpoint/test_other_optimizer.py unit/checkpoint/test_zero_optimizer.py -k 'not nvme and not fp16 and not bf16'→ 63 passed, 14 skipped, 3 failed. The 3 failures (test_zero_optimizer.py:TestZeROCheckpoint::test_load_optimizer_state[1-False-Adam],TestZeROCheckpoint::test_hybrid_optimizer_state[1],TestZeROCheckpointFrozenWeights::test_load_optimizer_state[1]) fail identically on unmodified master in my environment: the source install reports version0.0.0, which the ZeRO-1 loader rejects as a pre-0.3.17 checkpoint. Unrelated to this change.LOCAL_SIZE=2 DS_ACCELERATOR=cpu python -m pytest unit/checkpoint/test_existing_tag_warning.py unit/checkpoint/test_tag_validation.py unit/checkpoint/test_latest_checkpoint.py unit/checkpoint/test_other_optimizer.py→ 11 passed, 2 skippedpre-commit run --files <changed files>: all hooks passsave_checkpointentry, so the check runs the same way), non-local checkpoint engines (os.listdirraising is treated as "nothing there").Dedup check
No comments or linked PRs on #9066 at time of writing; searched open/closed PRs for
9066,save_checkpoint overwrite,checkpoint tag exists. Related but different: #9071 (latestordering).AI disclosure
Code, test and this description were drafted with an AI assistant (Claude Code); I reviewed the diff and ran the commands above.
🤖 Generated with Claude Code