-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Add Muon optimizer implementation and integration #39541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
f306cdc
afc45da
f896fce
c3786fc
b8b072b
6209688
e03e4f5
7009cdb
e70ca9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -158,6 +158,7 @@ | |
is_in_notebook, | ||
is_liger_kernel_available, | ||
is_lomo_available, | ||
is_muon_available, | ||
is_peft_available, | ||
is_safetensors_available, | ||
is_sagemaker_dp_enabled, | ||
|
@@ -1416,6 +1417,46 @@ def optimizer_hook(param): | |
if args.optim == OptimizerNames.ADAFACTOR: | ||
optimizer_cls = Adafactor | ||
optimizer_kwargs.update({"scale_parameter": False, "relative_step": False}) | ||
elif args.optim == OptimizerNames.MUON: | ||
if not is_muon_available(): | ||
raise ImportError( | ||
"You need to install `muon` in order to use muon optimizers. " | ||
"Install it with `pip install git+https://github.com/KellerJordan/Muon.git`." | ||
) | ||
from muon import Muon | ||
|
||
optimizer_cls = Muon | ||
optimizer_kwargs.update({"momentum": 0.95}) | ||
Comment on lines
+1420
to
+1429
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the import logic should live here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is a function called |
||
elif args.optim == OptimizerNames.MUON_ADAM: | ||
if not is_muon_available(): | ||
raise ImportError( | ||
"You need to install `muon` in order to use muon optimizers. " | ||
"Install it with `pip install git+https://github.com/KellerJordan/Muon.git`." | ||
) | ||
from muon import MuonWithAuxAdam | ||
|
||
optimizer_cls = MuonWithAuxAdam | ||
optimizer_kwargs.update({"lr": 3e-4, "betas": (0.9, 0.95)}) | ||
elif args.optim == OptimizerNames.MUON_SINGLE: | ||
if not is_muon_available(): | ||
raise ImportError( | ||
"You need to install `muon` in order to use muon optimizers. " | ||
"Install it with `pip install git+https://github.com/KellerJordan/Muon.git`." | ||
) | ||
from muon import SingleDeviceMuon | ||
|
||
optimizer_cls = SingleDeviceMuon | ||
optimizer_kwargs.update({"momentum": 0.95}) | ||
elif args.optim == OptimizerNames.MUON_SINGLE_ADAM: | ||
if not is_muon_available(): | ||
raise ImportError( | ||
"You need to install `muon` in order to use muon optimizers. " | ||
"Install it with `pip install git+https://github.com/KellerJordan/Muon.git`." | ||
) | ||
from muon import SingleDeviceMuonWithAuxAdam | ||
|
||
optimizer_cls = SingleDeviceMuonWithAuxAdam | ||
optimizer_kwargs.update({"lr": 3e-4, "betas": (0.9, 0.95)}) | ||
elif args.optim in [OptimizerNames.ADAMW_TORCH, OptimizerNames.ADAMW_TORCH_FUSED]: | ||
from torch.optim import AdamW | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't need these changes here, just import the optimizer in trainer.py as you did for muon. We can add more choices like
muon_adam
when specifyingoptim
valueThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deleted the _check_muon_available function and I added the other variations as well.