Skip to content

Add initial Muon+M-FSDPv2 implementation - #6425

Draft
janEbert wants to merge 22 commits into
NVIDIA:mainfrom
janEbert:muon-m-fsdp-v2
Draft

janEbert wants to merge 22 commits into
NVIDIA:mainfrom
janEbert:muon-m-fsdp-v2

Conversation

@janEbert

@janEbert janEbert commented Aug 11, 2026 •

Copy link
Copy Markdown
Contributor
  • I, the PR author, have personally reviewed every line of this PR.

What does this PR do?

Add Muon support for M-FSDPv2 based on an experimental optimized M-FSDPv1 prototype.
No integration into MCore yet.

This version uses all-Flat placements and uses an owner-based design:

  • Non-matrix parameters are simply computed like usual.
  • Unsharded, fully locally available matrix parameters are computed fully locally.
  • For each sharded matrix parameter, one owner (that owns at least one shard of that parameter) is picked, on which
    1. the full orthogonalization input is reconstructed,
    2. orthogonalization performed, and
    3. the updates are scattered back to the original destinations.

Pseudocode:

**** Fwd
for each FSDP unit:
    1. COMM: all-gather weight shards, each rank has full weights
    2. execute fwd, each rank has activations over local data

**** Bwd
for each FSDP unit:
    1. COMM: all-gather weight shards, each rank has full weights
    2. execute bwd, each rank has full gradients over local data
    3. COMM: reduce-scatter full gradients, each rank has gradient
       shards over global data for local weight shards

**** Opt step
for each FSDP unit:
    1. update local optimizer state shards using local gradient shards
       and local optimizer state shards
    2. produce local orthogonalization input shards using local
       optimizer state shards and (optionally, with Nesterov) local
       gradient shards
    3. COMM: on owner, gather orthogonalization input shards, each
       owner has full local orthogonalization inputs

       owner is heuristically picked depending on orthogonalization
       compute cost
    4. on owner, compute orthogonalization outputs (the full updates)
    5. COMM: owner scatters full updates, each rank has local update
       shards
    6. update local weight shards using local update shards

Internal design doc with more details: https://docs.google.com/document/d/11FGBYk-hdvGBGh_s-1tGBv2JYLicRPXIHApILtD6Mzw/edit?tab=t.vd156zcgkxyj

Minor information

  • The change to the get_containing_parameter_group signature is due to it being too strict; I needed to pass raw torch.Tensors to this function.

Issue tracking

Linked issue: Ref #5533.

@janEbert
janEbert requested a review from wujingyue August 11, 2026 00:09
@janEbert
janEbert requested review from a team as code owners August 11, 2026 00:09
@svcnvidia-nemo-ci
svcnvidia-nemo-ci marked this pull request as draft August 11, 2026 00:09
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically converted to draft because all PRs must start as drafts.

When you are ready for review, click Ready for Review to begin the review process. This will:

  1. Add the oncall reviewer (optional reviewer)
  2. Add required review teams based on your changes

See the contribution guide for more details.

@copy-pr-bot

copy-pr-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually.

Contributors can view more details about this message here.

@wujingyue wujingyue left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR!

https://google.github.io/eng-practices/review/developer/small-cls.html

This PR is too large for me to review right now. Could we reduce the first iteration to under 500 LOC (including tests), even if that means cutting features or simplifying the algorithm?



@dataclasses.dataclass(frozen=True)
class ShardPlan:

@wujingyue wujingyue Aug 11, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Apparently, most of the PR is spent on deciding the parameter-to-rank mapping. Can we separate this into another PR and make this PR focused on the most basic allgather-each-parameter-group solution? We may even keep this as a baseline for numerics testing.

Signed-off-by: janEbert <janpabloe@nvidia.com>
Signed-off-by: janEbert <janpabloe@nvidia.com>
Instead of grabbing it implicitly.

Signed-off-by: janEbert <janpabloe@nvidia.com>
Signed-off-by: janEbert <janpabloe@nvidia.com>
Now we initialize once at the start, but only if any rank contains
boundary parameters.

Signed-off-by: janEbert <janpabloe@nvidia.com>
Accordingly, we update the function signature and add a type cast to
ignore a type error.

Signed-off-by: janEbert <janpabloe@nvidia.com>
Signed-off-by: janEbert <janpabloe@nvidia.com>
Signed-off-by: janEbert <janpabloe@nvidia.com>
Signed-off-by: janEbert <janpabloe@nvidia.com>
We need to execute the closure in a gradient-enabled context.

Signed-off-by: janEbert <janpabloe@nvidia.com>
Signed-off-by: janEbert <janpabloe@nvidia.com>
Also move `Muon` import to the top.

Signed-off-by: janEbert <janpabloe@nvidia.com>
Signed-off-by: janEbert <janpabloe@nvidia.com>
Cached so not expensive, but prevents cache errors.

Signed-off-by: janEbert <janpabloe@nvidia.com>
Signed-off-by: janEbert <janpabloe@nvidia.com>
Signed-off-by: janEbert <janpabloe@nvidia.com>
Signed-off-by: janEbert <janpabloe@nvidia.com>
Signed-off-by: janEbert <janpabloe@nvidia.com>
Signed-off-by: janEbert <janpabloe@nvidia.com>
Signed-off-by: janEbert <janpabloe@nvidia.com>
- Fix style
- Adjust line length

Signed-off-by: janEbert <janpabloe@nvidia.com>
Signed-off-by: janEbert <janpabloe@nvidia.com>
@LucccaH

LucccaH commented Aug 25, 2026

Copy link
Copy Markdown

Hi @wujingyue , this PR has been pending for a while. Do you have an estimate of when it might move forward and get merged into the main branch?

BTW, I’d also like to see MFSDP v2 support functionality similar to the emerging optimizer support in the distributed optimizer path — specifically, allowing some parameters to use the Muon optimizer while others use Adam. Is this feature currently on the roadmap?

@wujingyue

Copy link
Copy Markdown
Contributor

We are splitting this into multiple PRs, following https://github.com/NVIDIA/Megatron-LM/blob/main/megatron/core/distributed/fsdp/src/docs/mfsdp_design.md#development-process.

#6597 is the first one.

shjwudp pushed a commit to shjwudp/Megatron-LM that referenced this pull request Sep 15, 2026
Squashed from NVIDIA#6425.

Signed-off-by: tongliu <tongliu@nvidia.com>
Signed-off-by: Jack Chang <jianbinc@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Oct 8, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@janEbert

janEbert commented Oct 8, 2026

Copy link
Copy Markdown
Contributor Author

(Accidentally pushed other PR branch here. Reverted now.)

This branch was previously deployed

2 inactive (outdated) deployments
test — 0ae4566d Deployed Aug 11, 2026 by copy-pr-bot[bot] via cicd-wait-in-queue #18656
public — 0ae4566d Deployed Aug 11, 2026 by copy-pr-bot[bot] via bump / bump-next-version #5718
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.

3 participants