Skip to content

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

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

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

Conversation

@ETOgaosion
Copy link
Copy Markdown
Collaborator

What does this PR do?

Add concise overview of what this PR aims to achieve or accomplish. Reference related GitHub issues and PRs that help with the review.

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 on lines +598 to +604
for k in bypass_keys:
if hasattr(self.transformer_config, k):
backup[k] = getattr(self.transformer_config, k, None)
delattr(self.transformer_config, k)
transformer_config_dict = asdict(self.transformer_config)
for k in backup:
setattr(self.transformer_config, k, backup[k])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The current implementation of _save_transformer_config temporarily removes attributes from self.transformer_config to facilitate JSON serialization via asdict. However, if an exception occurs during the asdict call, these attributes will not be restored, potentially leaving the transformer_config object in a corrupted state for the remainder of the training process. It is safer to use a try...finally block to ensure attributes are always restored.

Suggested change
for k in bypass_keys:
if hasattr(self.transformer_config, k):
backup[k] = getattr(self.transformer_config, k, None)
delattr(self.transformer_config, k)
transformer_config_dict = asdict(self.transformer_config)
for k in backup:
setattr(self.transformer_config, k, backup[k])
try:
for k in bypass_keys:
if hasattr(self.transformer_config, k):
backup[k] = getattr(self.transformer_config, k, None)
delattr(self.transformer_config, k)
transformer_config_dict = asdict(self.transformer_config)
finally:
for k in backup:
setattr(self.transformer_config, k, backup[k])

Comment on lines +611 to +614
if type(value) in ignore_types:
pop_keys.append(key)
if callable(value):
pop_keys.append(key)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

The type check type(value) in ignore_types (where ignore_types contains Callable) is ineffective for identifying callable objects. In Python, the type of a function is types.FunctionType, not collections.abc.Callable. While the subsequent callable(value) check correctly identifies functions, this specific block is redundant and relies on an incorrect type comparison logic. It is better to rely solely on the callable() check.

Suggested change
if type(value) in ignore_types:
pop_keys.append(key)
if callable(value):
pop_keys.append(key)
if callable(value):
pop_keys.append(key)

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