Fix ref weights being broadcast on the first async update after resume#2224
Open
ishzgu wants to merge 1 commit into
Open
Fix ref weights being broadcast on the first async update after resume#2224ishzgu wants to merge 1 commit into
ishzgu wants to merge 1 commit into
Conversation
In async non-colocate mode, loading the reference checkpoint can leave the ref model active because actor restoration is guarded by offload_train. This causes the first update_weights() call after resume to broadcast reference weights instead of the resumed actor weights. Restore the actor model after initialization regardless of offload_train, while keeping sleep() conditional on offload_train.
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.
What does this PR do?
This PR fixes an incorrect first rollout weight update after resuming async non-colocate training with a reference model enabled.
The first
update_weights()call can broadcast reference model weights to the SGLang rollout engines instead of the resumed actor weights. In the affected runs, this caused a sharp reward drop and spikes in KL divergence andgrad_normimmediately after resume. The metrics recovered after approximately 2–3 training steps.This is a small bug fix in the Megatron actor initialization path. It does not introduce a new feature or refactor existing abstractions.
Reproduction
The issue can be reproduced under the following conditions:
--use-kl-lossor a nonzero--kl-coefReproduction sequence:
grad_normto spike.This is generally not visible during a fresh run because the actor load path can fall back to the reference checkpoint, making the initial actor and reference weights identical.
Observed behavior
The following W&B metrics show the abnormal spike immediately after checkpoint resume.
train/kl_lossandtrain/grad_normspike at the same training step and recover shortly afterward.These figures demonstrate the observed first-step regression. They support the reproduction but do not independently establish the root cause.
KL loss
Gradient norm
Root cause
Actor initialization first backs up the actor weights:
When a reference model is enabled,
load_other_checkpoint("ref", ...)loads the reference weights intoself.model. At the end ofload_other_checkpoint(), it also updates the active model tag:Previously, initialization restored the actor only inside the
offload_trainbranch:In async non-colocate mode,
offload_trainis disabled, so initialization can return with the reference weights still loaded.train_async.pythen immediately calls:The async distributed updater broadcasts weights from the currently loaded
self.model, which is still the reference model at this point.Fix
Restore the actor whenever initialization leaves a non-actor model active, and keep only
sleep()conditional onoffload_train:This makes the post-initialization model state consistent and ensures that the first rollout weight update uses the resumed actor weights.
Verification and limitations
The issue and root cause were reproduced in the reference-model resume scenario described above. The diagnosis was verified using an alternative defensive workaround that called
_switch_model("actor")at the beginning ofupdate_weights(). With this workaround, reference weights were no longer broadcast during the first update, and the first-step regression disappeared.The exact initialization-side patch in this PR has not yet been exercised in a complete end-to-end training run. The change is placed at initialization because that is where the inconsistent active-model state originates.
Only the reference-model path has been reproduced and checked. Initialization can also load
teacherorold_actormodel tags, and the generic active-tag check will restore the actor after those paths as well. Those configurations have not been tested as part of this PR.The reported issue does not affect colocate/offloaded training because the existing
offload_trainpath already restores the actor.