Skip to content

Fix Muon retaining unused CPU weight initializers - #7527

Merged
yashaswikarnati merged 2 commits into
NVIDIA:mainfrom
yashaswikarnati:codex/muon-initializer-cleanup-main
Sep 23, 2026
Merged

yashaswikarnati merged 2 commits into
NVIDIA:mainfrom
yashaswikarnati:codex/muon-initializer-cleanup-main

Conversation

@yashaswikarnati

@yashaswikarnati yashaswikarnati commented Sep 20, 2026 •

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

What does this PR do?

Layer-wise Muon only consumes saved high-precision initialization tensors for parameters owned by the local optimizer rank. Its early return from get_megatron_optimizer bypasses the existing model-wide cleanup, leaving CPU initialization copies for non-owned parameters referenced after optimizer construction.

Extract the existing cleanup into a shared helper and call it after construction on the emerging-optimizer and FSDP return paths, as well as the standard Adam/SGD path. The sweep runs after local master weights have been initialized and visits non-owned and frozen parameters too.

The change contains only the optimizer factory fix and focused regression tests.

CI uses the documented determinism-exempt label because this change releases saved initializer references after master-weight construction; optimizer arithmetic and kernel dispatch are unchanged.

Pre-checks

  • Added focused unit and distributed optimizer regression tests.
  • Added typing and a lifecycle docstring for the production helper.
  • Ran the repository formatting/lint checks.
  • Author's personal review (draft).

Signed-off-by: ykarnati <ykarnati@nvidia.com>
@copy-pr-bot

copy-pr-bot Bot commented Sep 20, 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.

Signed-off-by: ykarnati <ykarnati@nvidia.com>
@yashaswikarnati
yashaswikarnati marked this pull request as ready for review September 20, 2026 05:54
@yashaswikarnati
yashaswikarnati requested review from a team as code owners September 20, 2026 05:54
@yashaswikarnati

Copy link
Copy Markdown
Contributor Author

/ok to test 5e3a140

@yashaswikarnati yashaswikarnati changed the title Fix saved initializer cleanup across optimizer factory paths Fix Muon retaining unused CPU weight initializers Sep 20, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Approved All necessary approvals have been made label Sep 23, 2026
@yashaswikarnati
yashaswikarnati added this pull request to the merge queue Sep 23, 2026
@nemo-automation-bot

Copy link
Copy Markdown

🔄 Merge queue validation started!

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

Merged via the queue into NVIDIA:main with commit 8d1ea07 Sep 23, 2026
140 of 146 checks passed
@yashaswikarnati
yashaswikarnati deleted the codex/muon-initializer-cleanup-main branch September 23, 2026 07:58
shjwudp added a commit to shjwudp/Megatron-LM that referenced this pull request Sep 23, 2026
…onfig fields

Port dev's optimizer wiring hunks (dev:optimizer/__init__.py:767-822, 838-843,
968-993, 1013-1022) onto main:

- replace main's blanket MFSDPv2+emerging-optimizers rejection with the prototype's
  covered-only gate: --optimizer muon + muon_scalar_optimizer='adam' +
  use_distributed_optimizer=False + sharded expert main weights; every other
  combination keeps a hard rejection.
- single mixed dense/expert Muon bucket (dev keeps per-parameter expert metadata and
  MFSDP communication group), FsdpMuon wrap over the emerging-optimizers inner
  optimizer + FullyShardedOptimizer and grad_stats/tp_group attrs, and the Adam
  fallback's empty-shard filtering for MFSDP v2.
- OptimizerConfig.muon_dp_subgroup_size / muon_max_params_per_owner_chunk (dev
  :optimizer_config.py:282-288); CLI flows from LANES-PLUMB's arguments.py by name.
- expert_main_weight_is_sharded imported defensively from mcore_fsdp_adapter
  (LANES-PLUMB provides it; pointed error on the Muon+EP path if absent).

Keeps main's newer fixes untouched: _clear_high_precision_initializers (NVIDIA#7527),
hybrid-FSDP grad-stats group, 2-tuple bucket keys. No inter_dist_opt/inter_expt_dp
references in the ported hunks (audited per LANES-PLUMB contract addendum).

Signed-off-by: Jack Chang <jianbinc@nvidia.com>
xuwchen pushed a commit to xuwchen/Megatron-LM that referenced this pull request Oct 14, 2026
Signed-off-by: ykarnati <ykarnati@nvidia.com>
(cherry picked from commit 8d1ea07)
Signed-off-by: xuwenc <xuwenc@nvidia.com>
xuwchen pushed a commit to xuwchen/Megatron-LM that referenced this pull request Oct 14, 2026
Signed-off-by: ykarnati <ykarnati@nvidia.com>
(cherry picked from commit 8d1ea07)
Signed-off-by: xuwenc <xuwenc@nvidia.com>

This branch was previously deployed

2 inactive deployments
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 determinism-exempt

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants