← Back to Pull requests

Place restored step for fused and capturable optimizers on universal checkpoint load #9056

Merged
dundysm merged 3 files (104 lines) on Nov 12, 2026 14:26 UTC
View on GitHub
dundysm dundysm commented on Nov 11, 2026 13:34 UTC
Author

fixes #8884

universal checkpoint loading writes step straight into optimizer.state, so it skips the placement that torch.optim.Optimizer.load_state_dict applies (_process_value_according_to_param_policy). for fused=True or capturable=True param groups torch needs step as 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's FusedAdam / CPUAdam), so the first fused step after resume fails.

change

  • place_restored_optimizer_step in base_optimizer.py: for fused or capturable groups, turn step into a float32 tensor on the param device; other groups keep it as loaded, same as torch.

  • call it in load_hp_checkpoint_state_from_checkpoint_dir after the saved group settings are copied back, since those settings (including fused) decide the placement. this covers zero-1/2 and the bf16 optimizer, which share this path.

  • zero-3 has its own loader (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

    TestUniversalCheckpointFusedTorchAdamW in tests/unit/checkpoint/test_universal_checkpoint.py: train with fused torch AdamW, save, convert with ds_to_universal, resume with fused AdamW, 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 (all int_step=True cases, 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 the fused_adam / cpu_adam op build fails).

  • pre-commit run --files on 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 no fused / capturable flags, 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.

    Diff: 104 lines (+103 / -1) across 3 files Reviewer: delock Review duration: 1491m
    All Vouch review confidence checks passed
    Residual risk 0.10 = Change Risk (0.34) × (1 − Review Confidence (0.71)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.34 · 104 lines diff across 3 files
    0.34
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.57 · 2 substantive comment(s)
    0.57
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    71%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.278
    Real PR Conversation Timeline
    4 items
    dundysm dundysm commented on Nov 11, 2026 13:34 UTC
    Author

    @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.

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Nov 11, 2026 13:35 UTC
    Bot

    <!-- 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

  • 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.

    </details>

    </details>

    delock delock approved these changes on Nov 12, 2026 08:19 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    dundysm dundysm
    Labels
    risk: low confidence: 71.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 33.8% (LOW) · Higher = larger blast radius
    33.8%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 71.5% · Lower = rushed or shallow review
    71.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 9.6% · Safe to merge
    9.6%