[bugfix] fix MTP checkpoint saving with TP > 1 - #210
Merged
Merged
Conversation
MultiTokenPredictionLayer.tp_group stays None on mcore 0.16, so sharded_state_dict computes tp rank 0 on every TP rank and marks the replicated enorm/hnorm weights as main replicas on all of them. Saving then fails with "Invalid access pattern". Fall back to the global TP group, which is what forward already resolves None to.
4 tasks
tastelikefeet
approved these changes
Sep 25, 2026
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.
Saving an mcore checkpoint fails for Qwen3.5/3.6 MoE with MTP when TP > 1:
On mcore 0.16 the base
MultiTokenPredictionLayerdoesn't settp_group, soself.tp_group = getattr(self, 'tp_group', None)leaves it as None.MegatronModule.sharded_state_dictonly falls back to the global TP group when the attribute is missing, andmake_sharded_tensor_for_checkpointonly falls back whentp_groupanddp_cp_groupare both None (dp_cp_groupalways comes in via metadata). Soget_pg_rank(None)returns 0 on every TP rank and the replicated enorm/hnorm weights get the same replica_id on both TP ranks, i.e. two main replicas.Fall back to the global TP group when it's None. Forward doesn't change: the gather/scatter calls that take
self.tp_groupalready resolve None to the same group.Tested on Qwen3.6-35B-A3B, 2 nodes x 8 H200, TP=2 EP=8, mtp_num_layers=1, megatron-core 0.16.1, ms-swift 4.5.3. With this change the run saves checkpoints at step 6 and step 12 with
validate_access_integrityon. Resuming from the step-6 one (--finetune false) gives loss 0.50693 / 0.48621 at steps 7 / 8, vs 0.50688 / 0.48642 in the original run.The same save path also hits a separate pickling error in ms-swift, fixed in modelscope/ms-swift#10242.