Skip to content
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

Add Muon Optimizer to contrib #1126

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

leloykun
Copy link

@leloykun leloykun commented Nov 2, 2024

Adds support for @KellerJordan Muon optimizer detailed here: https://github.com/KellerJordan/modded-nanogpt

image

The Muon optimizer does steepest descent under approximately Spectral norm--or more accurately, under Schatten-p norm for some large p (with Schatten-infty norm = Spectral norm).

@leloykun leloykun changed the title Add support for the muon optimizer Add Muon Optimizer to contrib Nov 2, 2024
@leloykun
Copy link
Author

leloykun commented Nov 3, 2024

Hi all!

How do I restrict the tests to exclude vectors as weights?

@vroulet
Copy link
Collaborator

vroulet commented Nov 4, 2024

Hello @leloykun,

Looks like an interesting contribution thank you!

How do I restrict the tests to exclude vectors as weights?

I don't fully understand your question. Could you give more context?

Other questions/remarks:

How does this optimizer treat vector-shaped values? The"muon_iterator" could run on vectors but not return what you want, so how do you make the distinction? Should it take a mask to only apply on matrices? Should it raise value error?

Also could you add the mathematical description in the doc string? That would greatly help.

Finally, put references at the end of the docstring (we'll adopt this format with #1129)

Thank you!

@leloykun
Copy link
Author

leloykun commented Nov 4, 2024

Hi @vroulet,

Muon is only defined for matrix-shaped values.

I'm thinking of raising an error when the input is vector-shaped, but where's the best place to put it? If there are other optimizers here that does this, can you point me to them?

@vroulet
Copy link
Collaborator

vroulet commented Nov 11, 2024

Hello @leloykun

  • I would put a test in the init function.
  • What is the algorithm for? Most architectures have non-matrix shaped parameters (for example just the scalar parameters of a layer norm). If the algorithm is specific to some problem, could you make a quick notebook explaining the setup? (Is it for example for finetuning with LoRa?)
  • In any case, some doctest would be good.
  • For the tests, you may add a synthetic linear classification problem with centered data to test the algorithm for example (again if you have a specific setup let me know).

Thanks again and sorry for the delay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants