fix(megatron): refresh masters after weights-only load - #2149
Draft
bvolpato wants to merge 1 commit into
Draft
Conversation
Signed-off-by: bvolpato <brunocvcunha@gmail.com>
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.
A Megatron weights-only checkpoint load updates the model or LoRA tensors but leaves optimizer master weights at their previous values. The next optimizer step copies those stale masters back over the restored checkpoint. This affects Tinker
load_state()/load_weights(optimizer=False)and complements the selective-resume controls in #2010.Keep the live optimizer available to the strategy while the existing restore flags control optimizer history. After a weights-only load, refresh masters from the restored model. Use Megatron's native reload and fill the gaps in the pinned HybridDeviceOptimizer and Transformer Engine precision-aware paths, preserving Adam moments, counters, scheduler state, and parameter aliases. Full optimizer restores retain the checkpoint's master precision.
Reproduction and validation
5.0, while its master remains0.9. Both full-state controls pass.The GPU test has not run on this host. Keep this draft pending distributed validation. Ruff, Black, and gitleaks hooks passed.
Downsides
Weights-only loading now performs the necessary local model-to-master copies. CPU-offloaded optimizers also refresh their host copies, and quantized parameters may require temporary dequantization. This cost occurs during checkpoint loading rather than each training step. Compatibility handling follows the currently pinned Megatron/Transformer Engine layouts and should be rechecked on dependency upgrades.
Risk and rollback
The main risk is incorrect master/shard mapping in a GPU optimizer variant; the CPU invariants and pending GPU roundtrip target that boundary. FSDP still honors its explicit optimizer restore flag. To avoid the affected path during rollback, restore optimizer state as well as weights, then revert the change.