Skip to content

refactor(dtensor): delete the DTensor v1 native checkpoint implementation - #4273

Merged
terrykong merged 8 commits into
r0.8.0from
yukih/drop-dtensor-v1-checkpoint
Oct 6, 2026
Merged

terrykong merged 8 commits into
r0.8.0from
yukih/drop-dtensor-v1-checkpoint

Conversation

@yuki-97

@yuki-97 yuki-97 commented Sep 25, 2026 •

Copy link
Copy Markdown
Contributor

Part of the DTensor v1 removal series -- overall status is tracked in the description of #4198.

What does this PR do ?

Deletes nemo_rl/utils/native_checkpoint.py. It was the DTensor v1 worker's own DCP save/load layer; v1 was removed in #4198, so ModelState, OptimizerState, save_checkpoint and load_checkpoint have had zero production callers since. Automodel goes through AutomodelCheckpointManager -> nemo_automodel's Checkpointer, Megatron through megatron.bridge.training.checkpointing.

What changed

The two functions in that file that were still alive move to where they belong:

  • convert_dcp_to_hf -> new nemo_rl/models/automodel/convert.py. Deliberately not models/automodel/checkpoint.py: that module imports nemo_automodel at the top level, and the offline converter must keep running in any venv -- tests/functional/test_converters.sh invokes it under uv run --extra mcore, and the documented uv run examples/converters/convert_dcp_to_hf.py would otherwise require the automodel extra, which [tool.uv] conflicts makes mutually exclusive with mcore/vllm/trtllm/sglang.
  • save_tokenizer_on_rank0 -> AutomodelCheckpointManager._save_tokenizer_on_rank0 (staticmethod). Its only caller was that class's save_checkpoint, and the guard exists precisely because we pass tokenizer=None to save_model() and so bypass nemo_automodel's own rank-0 guard.

Also drops the v1 checkpoint layout from convert_dcp_to_hf and the weights_path.endswith("/model") tolerance in AutomodelCheckpointManager.load_checkpoint. Automodel's layout is fixed at <ckpt_dir>/model; no caller in the repo passes a path ending in /model, and the endswith branch could never have matched a real v1 path anyway (v1 wrote the shards flat in <ckpt_dir>).

Tests

TestSaveTokenizerOnRank0 moves to tests/unit/models/automodel/test_automodel_checkpoint.py, next to TestAutomodelCheckpointManager.

test_convert_dcp_to_hf is deleted rather than moved: convert_dcp_to_hf is already covered by tests/functional/test_converter_roundtrip.py, which runs in both L1 and Lfast (L1_Functional_Tests_Other_1.sh invokes test_converters.sh with the fast tag, so it is not skipped when FAST=1). That test converts a DTensor DCP checkpoint and compares the result against the original HF model with assert_state_dicts_equal at rtol=atol=1e-5 -- strictly stronger than the deleted unit test, which only asserted the converted weights differed from the original. The unit test was itself deselected in FAST mode for being slow (~62-114s), so its --deselect entry in excluded_unit_tests.sh goes too.

pyrefly.toml: nemo_rl/utils/native_checkpoint.py drops out of project-includes, nemo_rl/models/automodel/convert.py goes in.

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Sep 25, 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.

@yuki-97 yuki-97 added the CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version) label Sep 25, 2026
@yuki-97

yuki-97 commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 468fd41

@yuki-97

yuki-97 commented Sep 25, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test 6984ed8

@yuki-97 yuki-97 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Self-review via /review-pr-team: 3 agents (rl-expert/automodel, bug-finder + test-agent, devil's advocate).

Verdict — no findings above the confidence bar. LGTM, no action needed.

Verified clean

  • No dangling references to nemo_rl.utils.native_checkpoint or save_tokenizer_on_rank0 anywhere (docs are autodoc2-generated, so no hand-kept API list).
  • nemo_rl/models/automodel/convert.py has no direct or transitive nemo_automodel import (both parent __init__.py files are license-only), so it still runs under --extra mcore.
  • Dropping the endswith("/model") branch is safe: every caller's weights_path comes from get_resume_paths or os.path.join(..., "policy"|"value", "weights"). It also removes a save/load asymmetry, since Automodel's Checkpointer.save_model always writes <weights_path>/model.
  • test_converter_roundtrip.py converts an Automodel DTensor checkpoint and compares against the original HF model at rtol=atol=1e-5, and runs in both L1 and Lfast (run_test fast in L1_Functional_Tests_Other_1.sh), which is stronger than the deleted unit test.
  • TestSaveTokenizerOnRank0 keeps its assertions. The new automodel marker still runs it in L0_Unit_Tests_Automodel.sh, and the dropped routing test is covered by test_save_with_tokenizer_skipped_on_non_zero_rank.

Generated by Claude Code

@yuki-97
yuki-97 marked this pull request as ready for review September 25, 2026 14:50
@yuki-97
yuki-97 changed the base branch from main to r0.8.0 October 1, 2026 04:21
@yuki-97 yuki-97 added the cherry-pick-to-main Opt in: cherry-pick this PR's commit from the release branch back into main label Oct 1, 2026
@yuki-97
yuki-97 force-pushed the yukih/drop-dtensor-v1-checkpoint branch from 6984ed8 to a5c367b Compare October 1, 2026 04:29
@yuki-97

yuki-97 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test a5c367b

@terrykong terrykong left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Reviewed with /review-pr-team (rl-expert, expert-automodel, test-agent, comment-reviewer, bug-finder, design-reviewer, devil-advocate).

Clean deletion. The moves are in the right places: convert.py under models/automodel/ keeps the converter free of nemo_automodel, so it still runs under --extra mcore, and the rank-0 tokenizer guard now sits next to its only caller. We found no remaining reference to native_checkpoint, and no code, config or doc in the repo passes a path ending in /model, so dropping the endswith("/model") branch is safe. fast_L1_Functional_Tests_Other_1, which runs the converter roundtrip, passed at this head; the L0 jobs were still pending when we looked.

Two inline comments, both on convert.py: the unclear error a v0.7 v1-checkpoint user now hits (with a test), and the docstring for the new model/ path rule.

A small suggestion that does not need to block this PR: add a line to convert.py's module docstring saying it must not import nemo_automodel, so the next editor knows why the file is separate. Today only the --extra mcore functional test catches that.

Not run: pre-commit (this reviewer's host cannot build the linux-only lock); CI lint passed at this head.

Generated by Claude Code

Comment thread nemo_rl/models/automodel/convert.py Resolved
Comment thread nemo_rl/models/automodel/convert.py Resolved
@yuki-97
yuki-97 force-pushed the yukih/drop-dtensor-v1-checkpoint branch from a5c367b to 498d828 Compare October 1, 2026 14:53
@yuki-97

yuki-97 commented Oct 1, 2026

Copy link
Copy Markdown
Contributor Author

/ok to test bb0b8cf

@terrykong
terrykong merged commit 50301e1 into r0.8.0 Oct 6, 2026
95 checks passed
@terrykong
terrykong deleted the yukih/drop-dtensor-v1-checkpoint branch October 6, 2026 01:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cherry-pick-to-main Opt in: cherry-pick this PR's commit from the release branch back into main CI:Lfast Runs a fast test suite and re-use nightly `main` container (but sync dependencies to PRs version)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants