Place restored step for fused and capturable optimizers on universal checkpoint load #9056
@sfc-gh-truwase could you take a look when you have a moment? this places the restored step the way torch.optim.Optimizer.load_state_dict does, for both the zero-1/2 and zero-3 universal load paths.
<!-- codex-pull-request-review-summary -->
<!-- codex-review-state:v1 {"code_review":{"commit_sha":"b11b080e0b7fa936f70dd7dfa8c59b922d50f3f4","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} -->
<details>
<summary><strong>Codex Review Summary</strong>: ✅ Completed</summary>
This comment shows the latest Codex review activity on this pull request.
| Review | Status | Commit | Review trigger |
| --- | --- | --- | --- |
| 📝 Code Review | ✅ Completed <relative-time datetime="2026-11-11T13:40:29.127349Z">2026-11-11T13:40:29.127349Z</relative-time> | b11b080 | PR opened |
<details> <summary>ℹ️ About Codex in GitHub</summary>
<br/>
Your 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.
</details>
</details>
Approved these changes.
delock
dundysm
fixes #8884
universal checkpoint loading writes
stepstraight intooptimizer.state, so it skips the placement thattorch.optim.Optimizer.load_state_dictapplies (_process_value_according_to_param_policy). forfused=Trueorcapturable=Trueparam groups torch needsstepas a float32 tensor on the param's device; the restored value is whatever the checkpoint file held (a cpu tensor, or a python int for checkpoints written from deepspeed'sFusedAdam/CPUAdam), so the first fused step after resume fails.change
place_restored_optimizer_stepinbase_optimizer.py: for fused or capturable groups, turnstepinto a float32 tensor on the param device; other groups keep it as loaded, same as torch.load_hp_checkpoint_state_from_checkpoint_dirafter the saved group settings are copied back, since those settings (includingfused) decide the placement. this covers zero-1/2 and the bf16 optimizer, which share this path.load_hp_checkpoint_state_from_checkpoint_dir_stage3) with the same gap; it now places each sub-group's step the same way after its group settings are restored. this is a separate loop at the end so it should not conflict with #8870, which moves the zero-3 step line.test
TestUniversalCheckpointFusedTorchAdamWintests/unit/checkpoint/test_universal_checkpoint.py: train with fused torchAdamW, save, convert withds_to_universal, resume with fusedAdamW, train 3 more steps and check the step count continues. parametrized over zero stage 1/2/3 and over an int step in the universal checkpoint. on an accelerator the plain case is the reported failure (cpu step vs cuda params); on cpu the int step case is the one that reproduces it.tests run
hardware: cpu only (8 vcpu x86_64, no gpu), torch 2.14.1+cpu, python 3.13,
DS_ACCELERATOR=cpu, gloo.pytest unit/checkpoint/test_universal_checkpoint.py -k FusedTorchAdamW: 6 passed. without the fix: 3 failed (allint_step=Truecases,RuntimeError: API has changed, state_steps argument must contain a list of singleton tensors), 3 passed.pytest unit/checkpoint/test_universal_checkpoint.py: the new 6 pass, the existing dp tests skip on cpu.pytest unit/checkpoint/test_autotp_uc_checkpoint.py: 32 passed, 12 skipped, 1 failed; the same failure on master (the box has no c++ compiler, so thefused_adam/cpu_adamop build fails).pre-commit run --fileson the changed files: all passed.not validated: the cuda fused path on a gpu (the exact error in the issue), and zero offload (offload uses
CPUAdam, which has nofused/capturableflags, so it is unaffected). no numerics, throughput or memory change outside the resume.duplicate check: no open pr references #8884 or changes this step placement; #8870 touches the zero-3 step line for non-adam state keys but not the device or dtype.