[training] fix: Synchronize MIMO loss scalers - #5591
Open
yaoyu-33 wants to merge 1 commit into
Open
Conversation
Signed-off-by: Yu Yao <yaoyu.094@gmail.com>
Contributor
Author
|
/ok to test 1088cf5 |
Contributor
|
LGTM overall. The world-synced loss-scaler consensus is correct: it snapshots each unique scaler (deduped by id, deep-copied) before super().prepare_grads(), all-reduces found_inf with MAX over the world, then restores and replays a single update(global_found_inf). Returning the global flag keeps every rank skipping/keeping the step in lockstep. device=cuda matches the existing convention in this file. Two minor, non-blocking observations on how the test covers upstream-API assumptions:
Neither is merge-blocking; both would surface loudly at runtime if the assumption breaks. Suggested test cases
|
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.
Problem
Non-colocated MegatronMIMO training supports FP16 dynamic loss scaling, but each disjoint module grid owns a separate inner optimizer and scaler. If only one module grid overflows, its inner
prepare_grads()updates that scaler before the outerMimoOptimizerperforms world-wide found-inf consensus. The global step is skipped, but the scaler states remain different.On the next finite step, the terminal module scales the loss with its local value while upstream modules unscale the propagated gradients with different values. This silently changes effective gradient magnitudes across the connected model. With an initial scale of 8 and
hysteresis=1, the two-rank reproducer observed[4.0, 8.0]after an encoder-only overflow.Megatron-LM PR #5331 synchronizes update success after preparation; it does not reconcile the scaler mutation that already occurred.
Fix
Bridge now wraps its MIMO optimizer so the dynamic scaler update uses the world-wide found-inf result:
BF16 and constant-loss-scale paths delegate directly to MCore and add no extra collective. The wrapper reuses the same module infos and inner optimizers, preserving scheduler and checkpoint ownership.
Validation
Fail before / pass after with the unchanged regression:
8.0, expected globally backed-off4.0.1 passed.Real two-rank FP16 reproducer:
[4.0, 8.0].[4.0, 4.0].Adjacent tests:
87 passed.Scope
This changes only Bridge-created MIMO optimizers using dynamic FP16 scaling. It does not alter BF16/constant scaling, repair already-divergent scaler values in existing checkpoints, or change direct Megatron-LM users.