Skip to content

Test ZeRO-3 checkpoint tag selection across resume modes - #8501

Open
ai-yang wants to merge 1 commit into
deepspeedai:masterfrom
ai-yang:fix/zero3-checkpoint-tag-20260913
Open

ai-yang wants to merge 1 commit into
deepspeedai:masterfrom
ai-yang:fix/zero3-checkpoint-tag-20260913

Conversation

@ai-yang

@ai-yang ai-yang commented Sep 13, 2026 •

Copy link
Copy Markdown

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.

  • Explicit older string/integer tags, with/without latest, load_optimizer_states=False, and both load_module_only values.
  • Explicit older tags on full resume and implicit tag=None selecting the newer checkpoint.
  • Eleven parameter combinations, each executed at world sizes 1 and 2.

Validation

Fresh runs on official master f94aa5c52aadf02096c17df422b90b581e9b86c6 plus only the test addition:

DS_ACCELERATOR=cpu LOCAL_SIZE=2 OMP_NUM_THREADS=1 MAX_JOBS=2 PYTHONPATH=.:tests \
  python -m pytest --forked -q tests/unit/checkpoint/test_zero_optimizer.py::TestZeROCheckpointTag
# 11 passed, 1 pytest harness deprecation warning, 239.67s

DS_ACCELERATOR=cuda CUDA_VISIBLE_DEVICES=0,1 LOCAL_SIZE=2 OMP_NUM_THREADS=1 MAX_JOBS=2 PYTHONPATH=.:tests \
  python -m pytest --forked -q tests/unit/checkpoint/test_zero_optimizer.py::TestZeROCheckpointTag
# 11 passed, 1 pytest harness deprecation warning, 255.22s

python -m pre_commit run --files tests/unit/checkpoint/test_zero_optimizer.py
# All applicable hooks passed.

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 later while 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/v1 targets for this legacy checkpoint test; the CPU/GPU commands above were run directly.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Sep 13, 2026 •

Copy link
Copy Markdown

Codex Review Summary

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

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-09-13T05:56:33.585982Z 1fbcf66 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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment thread deepspeed/runtime/engine.py Outdated
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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@ai-yang

ai-yang commented Oct 12, 2026

Copy link
Copy Markdown
Author

The current head 9e52b5d4bb14b5f78d4e22373ea650eda0417603 includes numeric-tag normalization with str(tag), and both commits carry Signed-off-by trailers. DCO and test collection pass; the main DeepSpeedAI CI job is skipped, so the green aggregate does not represent an executed GPU suite. The targeted GPU results in the description are the previously recorded September 21 validation. Could a reviewer check the updated numeric-tag handling and confirm whether an additional upstream CI run is needed?

@YidaWeng

Copy link
Copy Markdown

Current master (273609900) already contains the production behavior this PR was targeting: #8891 removed the get_fp32_state_dict_from_zero_checkpoint(load_dir) call and now passes the resolved tag to _load_zero_checkpoint(). The PR is now dirty because the edited line no longer exists.

The TestZeROCheckpointTag coverage is still valuable. Would you consider rebasing this as a test-only PR (explicit older tag with/without latest, load_optimizer_states=False, and both load_module_only values)? Otherwise it can likely be closed.

@ai-yang

ai-yang commented Nov 2, 2026

Copy link
Copy Markdown
Author

Thanks for pointing out #8891. I agree that the production edit is superseded. A test-only revision has been prepared locally on official master ab7fd98faac9921e441567d86e2d4d691d278b13, retaining the missing two-checkpoint tag-selection coverage rather than duplicating the engine fix.

The retained cases check every restored parameter as well as client metadata, covering explicit earlier string/integer tags, present/absent latest, module-only modes, full resume and implicit latest. Fresh validation passed 11 parametrized cases on CPU/Gloo and 11 on CUDA/NCCL (world sizes 1 and 2, up to two RTX 3090s), plus real reconstruction smoke.

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 <1685901819@qq.com>
@ai-yang
ai-yang force-pushed the fix/zero3-checkpoint-tag-20260913 branch from 9e52b5d to 20d7fc2 Compare November 13, 2026 16:12
@ai-yang ai-yang changed the title Fix ZeRO-3 checkpoint tag selection during weight reconstruction Test ZeRO-3 checkpoint tag selection across resume modes Nov 13, 2026

ai-yang commented Nov 13, 2026 •

Copy link
Copy Markdown
Author

The test-only revision is now pushed as 20d7fc296e6c774b768e82aabc07666898970da3, rebased on master f94aa5c5. The superseded engine change is removed. The two-checkpoint matrix retains explicit older string/integer tags, with/without latest, both module-only modes, full resume, and implicit latest.

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 tests/unit/v1 targets for the legacy test, so the direct device runs are documented explicitly.

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

2 participants