Skip to content

[megatron, ckpt] refactor: optimize mcore ckpt manager impl#6014

Open
ETOgaosion wants to merge 4 commits intoverl-project:mainfrom
ETOgaosion:refactor_mcore_ckpt_manager
Open

[megatron, ckpt] refactor: optimize mcore ckpt manager impl#6014
ETOgaosion wants to merge 4 commits intoverl-project:mainfrom
ETOgaosion:refactor_mcore_ckpt_manager

Conversation

@ETOgaosion
Copy link
Copy Markdown
Collaborator

@ETOgaosion ETOgaosion commented Apr 15, 2026

What does this PR do?

Refactoring Megatron checkpoint menager to avoid complex logics, following the way mentioned in #5630

Problem

Now the mcore checkpoint manager has multiple backends: mbridge, dist_checkpointing, verl original implemenation, and there are 2 model related save_contents APIs: model, hf_model, which is complex in implemenation.

Also, the API implementation in codes is complex, save_contents are transformed with should_save_xxx judgement and the backends converted to use_xxx judgement. These naming is confusing and makes users difficult to understand saving logics.

Refactor

So, let's make things clearer for mcore checkpoint mechanism.

First, refer to FSDP checkpoint APIs, model now means save sharded models, and hf_model will save the whole model.

To align with FSDP, mcore uses the same API.

For mcore, there is no sharded models, and have dist_checkpoint and mbridge backends, so in theory:

  • When mbridge enabled, model and hf_model should work the same, they all save huggingface model (only save once)
  • When mbridge disabled and use dist_checkpoint, model should use mcore dist_checkpoint implementation and hf_model should save hf_model use verl's implementation (old methods, should deprecate to reduce maintenance burden)

For future and checkpoint manager refactor:

  • mbridge shall be enabled by default
  • dist_checkpoint as a fall back method in background when model in save_contents
    • We can leave it to be an API default as false
    • We will not support both mbridge and dist_checkpoint as false
  • hf_model should only supported by mbridge

Shown in Figure:

Image

cc @ISEEKYAN @vermouth1992 @PeterSH6 @wuxibin89 @khazic @tongyx361

Checklist Before Starting

  • Search for similar PRs. Paste at least one query link here: ...
  • Format the PR title as [{modules}] {type}: {description} (This will be checked by the CI)
    • {modules} include fsdp, megatron, veomni, sglang, vllm, rollout, trainer, ci, training_utils, recipe, hardware, deployment, ray, worker, single_controller, misc, perf, model, algo, env, tool, ckpt, doc, data, cfg, reward, fully_async, one_step_off
    • If this PR involves multiple modules, separate them with , like [megatron, fsdp, doc]
    • {type} is in feat, fix, refactor, chore, test
    • If this PR breaks any API (CLI arguments, config, function signature, etc.), add [BREAKING] to the beginning of the title.
    • Example: [BREAKING][fsdp, megatron] feat: dynamic batching

Test

For changes that can not be tested by CI (e.g., algorithm implementation, new model support), validate by experiment(s) and show results like training curve plots, evaluation results, etc.

API and Usage Example

Demonstrate how the API changes if any, and provide usage example(s) if possible.

# Add code snippet or script demonstrating how to use this

Design & Code Changes

Demonstrate the high-level design if this PR is complex, and list the specific changes.

Checklist Before Submitting

Important

Please check all the following items before requesting a review, otherwise the reviewer might deprioritize this PR for review.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors MegatronCheckpointManager to support modular checkpointing backends, primarily introducing use_mbridge for HuggingFace format weights. The update replaces monolithic state dict generation with composable builders to avoid unnecessary overhead and includes a new suite of unit tests. Technical feedback recommends using a try...finally block to ensure transformer configuration attributes are restored after serialization and removing redundant type checks for callable objects.

Comment thread verl/utils/checkpoint/megatron_checkpoint_manager.py Outdated
Comment thread verl/utils/checkpoint/megatron_checkpoint_manager.py
ETOgaosion and others added 2 commits April 17, 2026 13:52
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@ETOgaosion ETOgaosion requested a review from wucong25 as a code owner April 20, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant