Skip to content

[Dev] Preserve HDO step across DP-reshardable resume - #7629

Merged
hxbai merged 2 commits into
NVIDIA:devfrom
HJSang:dev-hdo-step-dp-reshard
Sep 30, 2026
Merged

hxbai merged 2 commits into
NVIDIA:devfrom
HJSang:dev-hdo-step-dp-reshard

Conversation

@HJSang

@HJSang HJSang commented Sep 23, 2026

Copy link
Copy Markdown

What

When DistributedOptimizer wraps a HybridDeviceOptimizer (CPU optimizer offload) and loads a DP-reshardable checkpoint, the restored scalar step is written into self.optimizer.state, and the per-parameter state copy then overwrites it with the local template value. After resuming, Adam's bias correction restarts from the template step instead of the checkpointed one.

This PR writes the restored step into the state dict that is actually loaded (state_dict_state), and skips the per-parameter step in the HDO state-copy paths, so the value restored from param_groups is the one that sticks.

Tests

New TestDistributedOptimizer::test_hdo_dp_reshardable_preserves_step in tests/unit_tests/dist_checkpointing/test_optimizer.py: it steps an HDO optimizer 3 times, saves with distrib_optim_sharding_type=dp_reshardable, loads into a fresh optimizer that has stepped once, and asserts the step is 3 in both param_groups and the per-param state. setup_model_and_optimizer in tests/unit_tests/dist_checkpointing/utils.py gains an optimizer_config_kwargs pass-through.

Ran on 4× B200 with torchrun --nproc_per_node=4, -k "hdo or dp_reshardable or HybridDevice or offload":

  • this branch: 6 passed, 2 failed
  • dev @ 0e704edb1: 5 passed, 2 failed

The 2 failures (test_nonreshardable_optimizer_save_load[...-dp_reshardable-None]) are identical on dev and unrelated to this change.

Credit

Original fix by Nan Jiang (@nanjiangwill), developed in our internal fork (radixark#105). Upstreamed by me with the author preserved.

🤖 Generated with Claude Code

https://claude.ai/code/session_011KkXwkg28vJbR2T64TETxM

When DistributedOptimizer wraps a HybridDeviceOptimizer and loads a
DP-reshardable checkpoint, the restored scalar `step` was written into
`self.optimizer.state` and then overwritten by the local template value
while the per-parameter state was copied in. Write it into the state dict
that is loaded instead, and skip the per-parameter `step` in the HDO
state-copy paths.

Add a dist-ckpt unit test that resumes an HDO optimizer across a DP
resharding and checks the step is preserved.

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011KkXwkg28vJbR2T64TETxM
Signed-off-by: Hejian Sang <sanghj0923@gmail.com>
@copy-pr-bot

copy-pr-bot Bot commented Sep 23, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@HJSang
HJSang marked this pull request as ready for review September 24, 2026 00:21
@HJSang
HJSang requested review from a team as code owners September 24, 2026 00:21
@cspades

cspades commented Sep 24, 2026

Copy link
Copy Markdown
Member

/ok to test f685f98

Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011KkXwkg28vJbR2T64TETxM
Signed-off-by: Hejian Sang <sanghj0923@gmail.com>
@HJSang

HJSang commented Sep 24, 2026

Copy link
Copy Markdown
Author

Thanks for the review, @cspades! The linting failure was a black reformat of one set comprehension in the new test. That's fixed in a25b5b0 (formatting only, no logic change). Could you re-trigger CI?

/ok to test a25b5b0

@cspades

cspades commented Sep 25, 2026

Copy link
Copy Markdown
Member

/ok to test a25b5b0

@hxbai
hxbai added this pull request to the merge queue Sep 30, 2026
Merged via the queue into NVIDIA:dev with commit ac100f7 Sep 30, 2026
87 checks passed

This branch was previously deployed

2 inactive deployments
public — a25b5b0c Deployed Sep 25, 2026 by copy-pr-bot[bot] via finalize / publish-docs #10142
test — a25b5b0c Deployed Sep 25, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #22604
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants