[bugfix] drop dp_cp_group from content_metadata when saving mcore checkpoint - #10242
Open
WhichPaths wants to merge 1 commit into
Open
WhichPaths wants to merge 1 commit into
WhichPaths wants to merge 1 commit into
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR type
PR information
Saving an mcore checkpoint fails in
save_commonwith megatron-core 0.16.1:save_mcore_checkpointpassessharded_sd_metadatainto_generate_state_dict(). While the sharded state dict is built, megatron-core'sensure_metadata_has_dp_cp_group()addsdp_cp_group(a ProcessGroup) to that dict in-place. Then the same dict is used ascontent_metadataand ends up in common.pt.megatron-core's
save_preprocessdoes 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 callingdist_checkpointing.save(content_metadata=_clean_metadata_for_serialization(sharded_sd_metadata)in checkpointing.py), so this does the same. It also covers theif not modelsbranch, which torch.saveskwargsdirectly.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_metadataloads back fine.For MTP with TP > 1 the save also needs modelscope/mcore-bridge#210 (a replica_id issue in mcore-bridge).