Skip to content

Warn when save_checkpoint writes into a tag that already has files - #9122

Open
ArchanaChetan07 wants to merge 2 commits into
deepspeedai:masterfrom
ArchanaChetan07:fix/9066-warn-existing-tag
Open

ArchanaChetan07 wants to merge 2 commits into
deepspeedai:masterfrom
ArchanaChetan07:fix/9066-warn-existing-tag

Conversation

@ArchanaChetan07

@ArchanaChetan07 ArchanaChetan07 commented Nov 19, 2026 •

Copy link
Copy Markdown

Addresses #9066 (minimum option (c) from the issue; does not close it).

What

save_checkpoint writes 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 default global_step<N> tags after load_checkpoint(tag=<older>) in the same directory). A crash during such a save can leave the tag with files from two saves, and load_checkpoint restores 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 new save_dir or 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 / makedirs block, before the dist.barrier() that precedes any writes, so other ranks cannot have written into a fresh tag yet. (Placing it after the barrier would race with checkpoint.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 / latest handling that #9071 changes.

Tests

New tests/unit/checkpoint/test_existing_tag_warning.py, 2 ranks, ZeRO stage 1, parametrized over tag_validation Warn / Ignore:

  • fresh tag → no warning on any rank
  • existing but empty tag dir → no warning
  • re-save into a tag with a checkpoint → exactly one warning on rank 0, none on rank 1
  • a second re-save under the same tag → no further warning

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 Ignore case 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

  • Hardware: CPU only (WSL2 Ubuntu, 24 cores), torch CPU build, DS_ACCELERATOR=cpu, gloo.
  • Commands (from tests/):
    • LOCAL_SIZE=2 DS_ACCELERATOR=cpu python -m pytest unit/checkpoint/test_existing_tag_warning.py → 2 passed
    • LOCAL_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 version 0.0.0, which the ZeRO-1 loader rejects as a pre-0.3.17 checkpoint. Unrelated to this change.
    • after the second commit: 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 skipped
    • pre-commit run --files <changed files>: all hooks pass
  • Not validated: GPU, NVMe offload, MoE and pipeline save paths (they go through the same save_checkpoint entry, so the check runs the same way), non-local checkpoint engines (os.listdir raising 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 (latest ordering).

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

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>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-19T03:39:41.304725Z c3e5f94 PR opened
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. and removed skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. labels Nov 19, 2026
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>
@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. and removed skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. labels Nov 19, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant