Skip to content

[bugfix] drop dp_cp_group from content_metadata when saving mcore checkpoint - #10242

Open
WhichPaths wants to merge 1 commit into
modelscope:mainfrom
WhichPaths:fix/content-metadata-dp-cp-group
Open

WhichPaths wants to merge 1 commit into
modelscope:mainfrom
WhichPaths:fix/content-metadata-dp-cp-group

Conversation

@WhichPaths

Copy link
Copy Markdown

PR type

  • Bug Fix
  • New Feature
  • Document Updates
  • More Models or Datasets Support

PR information

Saving an mcore checkpoint fails in save_common with megatron-core 0.16.1:

TypeError: cannot pickle 'torch._C._distributed_c10d.ProcessGroup' object

save_mcore_checkpoint passes sharded_sd_metadata into _generate_state_dict(). While the sharded state dict is built, megatron-core's ensure_metadata_has_dp_cp_group() adds dp_cp_group (a ProcessGroup) to that dict in-place. Then the same dict is used as content_metadata and ends up in common.pt.

megatron-core's save_preprocess does call _clean_metadata_for_serialization, but only on the copy it uses for the consistency check, not on what gets written. Megatron-LM's training loop cleans it before calling dist_checkpointing.save (content_metadata=_clean_metadata_for_serialization(sharded_sd_metadata) in checkpointing.py), so this does the same. It also covers the if not models branch, which torch.saves kwargs directly.

Experiment results

Qwen3.6-35B-A3B, 2 nodes x 8 H200, TP=2 EP=8, mtp_num_layers=1, megatron-core 0.16.1, torch 2.10. Without this change the save crashes with the error above. With this change checkpoints at step 6 and step 12 save fine (dist checkpoint + HF safetensors), and resuming from the step-6 one gives loss 0.50693 / 0.48621 at steps 7 / 8, vs 0.50688 / 0.48642 in the original run, so the cleaned content_metadata loads back fine.

For MTP with TP > 1 the save also needs modelscope/mcore-bridge#210 (a replica_id issue in mcore-bridge).

…ckpoint

_generate_state_dict() passes sharded_sd_metadata to sharded_state_dict(),
which adds dp_cp_group (a ProcessGroup) to it in-place. The same dict is
then saved as content_metadata, so torch.save fails with
"cannot pickle 'ProcessGroup' object". Save a copy without it, like
Megatron-LM does with _clean_metadata_for_serialization.

This branch has not been deployed

No deployments
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.

2 participants