Repository navigation
feat(optim): optional bfloat16 momentum for Muon - #4117
Closed
faresobeid wants to merge 1 commit into
Closed
faresobeid wants to merge 1 commit into
faresobeid wants to merge 1 commit into
Conversation
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.
optim.bf16_momentum = true(Muon only, default off) keeps the Muon momentum in bfloat16 instead of the parameter dtype (fp32). The AdamW group inside Muon is unchanged.BF16MomentumMuoncreates the momentum in bfloat16. dion's update already casts the gradient to the momentum dtype and the momentum to bfloat16 before Newton-Schulz, so nothing else changes.torch.optim.Optimizer.load_state_dictcasts floating-point state to the param dtype. After a load the momentum is cast back to bfloat16, so it stays bfloat16 across resume. Checked on CPU: with plain dionMuonit comes back fp32; with this class it stays bfloat16.Measurements
GLM-4.5-Air, 2 nodes of 8xH200, CP 4, EP 8, optimizer step only (random grads), steady state, max over ranks:
offload = "none", fp32 momentumoffload = "none", bf16 momentumoffload = "optimizer", fp32 momentumoffload = "optimizer", bf16 momentumLoss A/B: Qwen3-0.6B SFT on
PrimeIntellect/Reverse-Text-SFT, 1 GPU, Muon lr 5e-5, batch 32, 150 steps. Mean train loss per window:The bf16 runs are within the spread between seeds. This is a small dense model on a short run. It is not evidence for long or large-MoE runs.
Checks
tests/unit/orchestrator+tests/unit/test_configs.py -m "not gpu": 350 passed.ruff check,ruff format --check.Note
Medium Risk
Changes optimizer state dtype and checkpoint resume behavior for Muon; training dynamics may differ on long or large runs despite short A/B checks.
Overview
Adds an opt-in
optim.bf16_momentumflag on Muon (default off) to store Muon momentum in bfloat16 instead of the parameter dtype, cutting optimizer state size and CPU offload traffic at the cost of lower momentum precision.When enabled, optimizer setup uses a new
BF16MomentumMuonsubclass that initializes Muon momentum in bf16 and re-casts momentum to bf16 afterload_state_dict, so checkpoint resume does not leave momentum in fp32. The embedded AdamW/Lion path for non-Muon params is unchanged.Reviewed by Cursor Bugbot for commit 6c81152. Bugbot is set up for automated code reviews on this repo. Configure here.