Skip to content

Fix gradient counting for muon+expert biases - #6099

Merged
philipcmonk merged 1 commit into
NVIDIA:mainfrom
philipcmonk:muon-norms
Jul 30, 2026
Merged

Fix gradient counting for muon+expert biases#6099
philipcmonk merged 1 commit into
NVIDIA:mainfrom
philipcmonk:muon-norms

Conversation

@philipcmonk

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

What does this PR do?

This is another gradient-counting bug, like #5916 and #6080. In this case, the most likely condition is: Muon/Layerwise optimizer, EP>1, TP>1, ETP=1, and experts with linear biases. These are all common except that it's rare for experts to have biases. However, it's the default if you don't pass --disable-bias-linear. The only under or overcounted parameters are those biases, so the impact on the gradient norm is also pretty small.

There are several other configurations (all requiring the layerwise optimizer and expert biases) that trigger this. The issue is LayerWiseDistributedOptimizer wrapped its child optimizers without propagating the regular and expert tensor-parallel process groups. As a result, gradient-norm duplicate filtering fell back to the global TP group, incorrectly excluding some expert parameters when ETP differed from TP. The fix attaches both process groups to each child optimizer and passes them explicitly to zero-counting, ensuring expert parameters are deduplicated using the expert topology.

Probably we should move all global-process-group fallbacks to the edge, around get_megatron_optimizer, and make all internal code require explicit process groups. For now, this is the minimal fix, plus a regression test.

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

Signed-off-by: Philip Monk <pmonk@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Jul 28, 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.

@philipcmonk

Copy link
Copy Markdown
Contributor Author

/ok to test

@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label Jul 29, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added Approved All necessary approvals have been made and removed Final Review PR is in the "final review" stage labels Jul 29, 2026
@philipcmonk
philipcmonk added this pull request to the merge queue Jul 29, 2026
@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/30483925180

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/30483976702

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/30484696390

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/30502502574

@svcnvidia-nemo-ci

Copy link
Copy Markdown
Contributor

🔄 Merge queue validation started!

You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/30502651163

Merged via the queue into NVIDIA:main with commit 6183f9d Jul 30, 2026
90 of 92 checks passed
@philipcmonk
philipcmonk deleted the muon-norms branch July 30, 2026 03:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Approved All necessary approvals have been made complexity: low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants