Add MLA support for Muon optimizer
Is your feature request related to a problem? Please describe.
Currently, the Muon optimizer implementation in megatron/core/optimizer/muon.py lacks support for MLA (Multi-Latent Attention) parameters, as indicated by the TODO comment (TODO(deyuf): support MLA).
MLA-related parameters are not tagged with is_qkv and thus undergo direct orthogonalization. Maybe it lead to some unpredictable result.
Describe the solution you'd like Add MLA support to the Muon optimizer.
@FDecaYed are you working on this? Otherwise feel free to assign to me.
Hiii @oblivioncat , Shall I work on this
hi,@janEbert @ericharper,When will this feature be completed and merged into the dev branch?
Hey @gaojingwei, I've started work on a preliminary implementation, but it'll probably take at least another week until I can properly finish and test it. Thanks for you patience!
Hey @gaojingwei, I've started work on a preliminary implementation, but it'll probably take at least another week until I can properly finish and test it. Thanks for you patience!
@janEbert hi,Sorry to bother you, but how is it going?
Hey, I've created PR #5015, which splits the up-projs (and sole Q-proj for q_lora_rank=None) parameters. I'll submit a separate PR with an additional feature flag for also splitting the MLA down-projs, since that's a lot more complex when dealing with model parallelism.
Hey, I've created PR #5015, which splits the up-projs (and sole Q-proj for
q_lora_rank=None) parameters. I'll submit a separate PR with an additional feature flag for also splitting the MLA down-projs, since that's a lot more complex when dealing with model parallelism.
thinks,I will try the pr for my models
Hey, I've created PR #5015, which splits the up-projs (and sole Q-proj for
q_lora_rank=None) parameters. I'll submit a separate PR with an additional feature flag for also splitting the MLA down-projs, since that's a lot more complex when dealing with model parallelism.
@janEbert I have synchronized the code and am performing full-parameter SFT on a 236B model with the DeepSeek-V3 architecture. I encountered an anomaly where the grad_norm remains extremely high (consistently above 5000) even after 400 steps. Interestingly, when I switch the optimizer to Adam, the grad_norm returns to a normal range.
Logs with the muon optimizer (Abnormal):
191: [2026-06-02 16:33:56] iteration 19/ 25394 | consumed samples: 912 | elapsed time per iteration (ms): 17911.8 | learning rate: 9.120000E-06 | global batch size: 48 | lm loss: 4.396684E-01 | seq_load_balancing_loss: 1.545433E+00 | load_balancing_loss: 0.000000E+00 | loss scale: 1.0 | grad norm: 5167.033 | number of skipped iterations: 0 | number of nan iterations: 0 |
0: Step Time : 19.76s GPU utilization: 152.6MODEL_TFLOP/s/GPU
191: [2026-06-02 16:34:16] iteration 20/ 25394 | consumed samples: 960 | elapsed time per iteration (ms): 19755.0 | learning rate: 9.600000E-06 | global batch size: 48 | lm loss: 4.206724E-01 | seq_load_balancing_loss: 1.578727E+00 | load_balancing_loss: 0.000000E+00 | loss scale: 1.0 | grad norm: 5167.031 | number of skipped iterations: 0 | number of nan iterations: 0 |
0: Step Time : 19.06s GPU utilization: 158.2MODEL_TFLOP/s/GPU
191: [2026-06-02 16:34:35] iteration 21/ 25394 | consumed samples: 1008 | elapsed time per iteration (ms): 19059.1 | learning rate: 1.008000E-05 | global batch size: 48 | lm loss: 4.342053E-01 | seq_load_balancing_loss: 1.568348E+00 | load_balancing_loss: 0.000000E+00 | loss scale: 1.0 | grad norm: 5167.028 | number of skipped iterations: 0 | number of nan iterations: 0 |
Logs with Adam optimizer (Normal):
191: [2026-06-02 15:00:28] iteration 19/ 25394 | consumed samples: 912 | elapsed time per iteration (ms): 17563.4 | learning rate: 9.120000E-06 | global batch size: 48 | lm loss: 4.379181E-01 | seq_load_balancing_loss: 1.387631E+00 | load_balancing_loss: 0.000000E+00 | loss scale: 1.0 | grad norm: 0.274 | number of skipped iterations: 0 | number of nan iterations: 0 |
0: Step Time : 18.32s GPU utilization: 164.5MODEL_TFLOP/s/GPU
191: [2026-06-02 15:00:46] iteration 20/ 25394 | consumed samples: 960 | elapsed time per iteration (ms): 18324.8 | learning rate: 9.600000E-06 | global batch size: 48 | lm loss: 4.180407E-01 | seq_load_balancing_loss: 1.389208E+00 | load_balancing_loss: 0.000000E+00 | loss scale: 1.0 | grad norm: 0.243 | number of skipped iterations: 0 | number of nan iterations: 0 |
0: Step Time : 18.75s GPU utilization: 160.8MODEL_TFLOP/s/GPU
Hey, thanks a lot for the report. I'll look into it. Sorry for the troubles.
Quick question: did you previously use --muon-no-split-qkv and the convergence looked better? I'm wondering if it could simply be a Muon misconfiguration. Could you also try a smaller LR or smaller --muon-extra-scale-factor?
Hey @gaojingwei, I've run some longer convergence tests (300 steps, 9B model), keeping the exact same setup between them, with only the optimizer or Attention variant changing:
| opt | attn | loss (first 10 mean) | loss (last 10 mean) | grad norm (first 10 mean) | grad norm (last 10 mean) |
|------+------+----------------------+---------------------+---------------------------+--------------------------|
| Adam | MHA | 9.466605 | 5.568543 | 30.363700 | 1.405400 |
| Adam | MLA | 10.097239 | 5.966680 | 54.376400 | 1.770100 |
| Muon | MHA | 11.168186 | 6.679527 | 42.279200 | 20.757900 |
| Muon | MLA | 11.300466 | 6.863670 | 61.932000 | 34.803800 |
These runs didn't have any form of hyperparameter optimization, and again, I kept all hyperparameters the same across runs, that's why Muon is so much worse than Adam. To me, these numbers don't indicate that Muon+MLA doesn't work.
Hey @gaojingwei, I've run some longer convergence tests (300 steps, 9B model), keeping the exact same setup between them, with only the optimizer or Attention variant changing:
| opt | attn | loss (first 10 mean) | loss (last 10 mean) | grad norm (first 10 mean) | grad norm (last 10 mean) | |------+------+----------------------+---------------------+---------------------------+--------------------------| | Adam | MHA | 9.466605 | 5.568543 | 30.363700 | 1.405400 | | Adam | MLA | 10.097239 | 5.966680 | 54.376400 | 1.770100 | | Muon | MHA | 11.168186 | 6.679527 | 42.279200 | 20.757900 | | Muon | MLA | 11.300466 | 6.863670 | 61.932000 | 34.803800 |These runs didn't have any form of hyperparameter optimization, and again, I kept all hyperparameters the same across runs, that's why Muon is so much worse than Adam. To me, these numbers don't indicate that Muon+MLA doesn't work.
Thanks for sharing your experiment. I've checked my training configuration, and muon-split-qkv is indeed set to True.
I am currently using the NeMo 2604 image, which contains a relatively old version of Megatron. For my testing, I used the main branch code from April 17th and then manually applied your PR (the image lacks some dependencies required by the very latest code).
I suspect the issue might be due to the outdated codebase. I will try to update everything to the latest main branch and run the test again.
I use megatron-lm code in NeMo 2604 images, set optim = dist_muon, the grad norm is ok. the megatron version is: 0.17.0rc0
One more question: Is there a webpage where I can view the Dockerfile for the NeMo image? Pulling the entire image is quite time-consuming, and I noticed that the image for version 26.04 (https://catalog.ngc.nvidia.com/orgs/nvidia/containers/nemo/tags?version=26.04) on NGC has been updated several times. I'm concerned that my local version might be out of sync with the latest one.
Hey,
I suspect the issue might be due to the outdated codebase. I will try to update everything to the latest main branch and run the test again.
This could be the cause of an issue, I agree. But also, are you sure that the Muon settings you're using are correct? Maybe it's just a matter of tuning hyperparameters.
One more question: Is there a webpage where I can view the Dockerfile for the NeMo image? Pulling the entire image is quite time-consuming, and I noticed that the image for version 26.04 (https://catalog.ngc.nvidia.com/orgs/nvidia/containers/nemo/tags?version=26.04) on NGC has been updated several times. I'm concerned that my local version might be out of sync with the latest one.
Please check out the README.md in Megatron-Bridge/docker to see how the NeMo image is built. As for the version, you can specify a concrete one by using, e.g., tag 26.04.01 (or 26.04.00 for an outdated one).
@janEbert , thank you, I update code to the latest, and update transformer_engine to 2.14.0 in Nemo 2604 image, then the grad norm return to normal.
So your suspicion was correct! Great to hear. :)