Skip to content

Conversation

@Yangyang0906C
Copy link

@Yangyang0906C Yangyang0906C commented Oct 23, 2025

PR Category

Train

PR Types

New Features

PR Description

Provide the implementation of muon referring to NVIDIA/Megatron-LM#1428

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Yangyang0906C, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request integrates the Muon optimizer, a new optimization algorithm that employs orthogonalization via Newton-Schulz iteration, into the Megatron-LM codebase. This integration includes comprehensive distributed training support, enabling the optimizer to scale effectively across multiple devices. Additionally, new configuration parameters and command-line arguments have been introduced to provide flexible control over Muon's behavior, making this advanced optimization technique accessible for large-scale model training.

Highlights

  • Muon Optimizer Integration: The pull request introduces and integrates the Muon optimizer, a novel optimization algorithm, into the Megatron-LM framework.
  • Distributed Training Support: The DistributedOptimizer has been extended to properly manage Muon's distributed parameter states and metadata, ensuring efficient operation in parallel environments.
  • Configurable Parameters: New configuration options and command-line arguments have been added, allowing users to fine-tune Muon's hyperparameters such as momentum, Nesterov acceleration, Newton-Schulz iteration steps, and matched AdamW RMS.
  • Core Algorithm Implementation: The core Muon algorithm, including the zeropower_via_newtonschulz5 function for orthogonalization and adjust_lr_wd_for_muon for learning rate adjustment, is now part of the codebase.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces the Muon optimizer, a novel optimizer that uses Newton-Schulz iteration for orthogonalization. The changes include the core Muon optimizer implementation, its integration into Megatron's distributed optimizer framework, and the necessary configuration and command-line arguments.

The implementation is comprehensive, including support for distributed and tensor-parallel training. My review focuses on ensuring correctness, especially in the complex distributed logic, and improving code clarity and maintainability. I've identified a couple of critical issues in the distributed optimizer integration that could lead to incorrect behavior or break existing features. I've also pointed out several medium-severity issues like typos and opportunities for code clarification.

@CLAassistant
Copy link

CLAassistant commented Nov 18, 2025

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ Caozhou1995
❌ Yangyouy
You have signed the CLA already but the status is still pending? Let us recheck it.

@Caozhou1995 Caozhou1995 changed the title provide muon optimizer [Train] Provide muon optimizer Nov 21, 2025

# For precision_aware_optimizer, the empty tensors should also be
# initialized with the correct dtype.
- tensors = {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keep the init dtype

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.

4 participants