Fix megatron optimizer resume: retain lr_mult param-group key#9517
Closed
gusario wants to merge 1 commit into
Closed
Fix megatron optimizer resume: retain lr_mult param-group key#9517gusario wants to merge 1 commit into
gusario wants to merge 1 commit into
Conversation
fix(megatron): keep lr_mult in param groups for optimizer resume on mcore 0.17 _get_param_groups folded lr_mult into max_lr/min_lr and then popped it. mcore 0.17 promoted lr_mult to a required param-group identity key (consumed by DistributedOptimizer.sharded_state_dict(is_loading=True) -> make_needed_groups), so resuming optimizer state raised "Key lr_mult (or pre_lr_mult) not found in param_group". Keep the key instead of popping it; the LR schedule is unaffected (OptimizerParamScheduler reads max_lr/min_lr, never lr_mult).
Contributor
There was a problem hiding this comment.
Code Review
This pull request modifies swift/megatron/trainers/base.py to retain the lr_mult key in param_group instead of popping it, as mcore 0.17 requires it as a param-group identity key when resuming optimizer state. There are no review comments, so I have no feedback to provide.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
Jintao-Huang
approved these changes
Jun 9, 2026
Collaborator
Collaborator
|
This issue has been fixed. |
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.
Summary
Resuming a run with optimizer state —
finetune=falsetogether withmcore_modelormcore_adapter— crashes on megatron-core 0.17.x with:ValueError: Key lr_mult (or pre_lr_mult) not found in param_group {...}Training and checkpoint saving are unaffected; only resume fails.
Root cause
_get_param_groupsbuilds each param group with anlr_multfield, folds itinto
max_lr/min_lr, and then drops it viaparam_group.pop('lr_mult').On megatron-core ≤0.16 that pop was harmless cleanup —
lr_multhad alreadyserved its purpose and nothing read it afterwards. megatron-core 0.17 changed
that: it added
lr_multtoparam_group_identifier_keys, whichDistributedOptimizer.sharded_state_dict(is_loading=True)→make_needed_groupsuses to match param groups when loading optimizer state.With the key removed, that match fails and raises.
This only surfaces on resume because the load path calls
sharded_state_dictwith
is_loading=True(which triggers the matching roundtrip), whereas savinguses
is_loading=Falseand never looks at the identifier keys.Fix
Keep
lr_multon the param group instead of popping it.The learning-rate schedule is unaffected:
OptimizerParamSchedulerderives theLR from
max_lr/min_lrand never readslr_mult. Retaining the real value(rather than dropping or normalizing it) also keeps groups that differ only by
LR scaling — e.g.
vit_lr/aligner_lrvs the LLM — distinct, so optimizerstate is matched to the correct group on resume.
Verification
megatron-core 0.17.x, multi-GPU:
--save_steps Nto producecheckpoint-N.--finetune false --mcore_model <output_dir>/checkpoint-N.Before this change the resume crashes in
make_needed_groups; after it, theoptimizer (and RNG) state loads and training continues.
PR type
PR information
Fixes optimizer-state resume on megatron-core 0.17.x. See summary above.
Experiment results
N/A — behavioral fix; verification steps above.