[dev] Add experimental decoupled compact LayerWise DDP layout for Muon - #5388
Merged
Wohox merged 8 commits intoJul 1, 2026
Merged
Conversation
Wohox
force-pushed
the
pingtian/claude/muon-layerwise-compact-buffers
branch
from
June 17, 2026 09:37
a2a4b68 to
6e726d3
Compare
Wohox
marked this pull request as ready for review
June 17, 2026 09:50
Contributor
Author
|
/ok to test f615b2d |
6 tasks
Wohox
force-pushed
the
pingtian/claude/muon-layerwise-compact-buffers
branch
from
June 23, 2026 01:51
f615b2d to
e965c83
Compare
Contributor
Author
|
/ok to test e965c83 |
Contributor
Author
|
/ok to test 8c128c8 |
…uffer distopt Two changes from PR NVIDIA#5388 review (FDecaYed): 1. Make the compact decoupled LayerWise layout the DEFAULT. Replace the `--no-use-layer-wise-param-layout` (store_false) flag with `--use-layer-wise-param-layout` (store_true, default False), and flip the DistributedDataParallelConfig.use_layer_wise_param_layout default to False. The padded LayerWise layout is now opt-in (its dp_size*max(shard_load) padding is a large memory overhead and the reduce-scatter perf gain is not always significant). validate_args message updated to the new flag name. 2. Drop the separate `use_distributed_optimizer` argument threaded into _ParamAndGradBucketGroup. Instead, each _ParamAndGradBuffer bakes its per-buffer DistOpt decision into its own ddp_config ONCE via dataclasses.replace (a LayerWise/Muon buffer on the compact decoupled layout disables DistributedOptimizer; siblings keep the model-level setting). buffer.ddp_config is then the single source of truth and bucket groups simply inherit it in partition_buckets -- no per-site threading or per-call replace. Behavior-preserving. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: pingtianl <pingtianl@nvidia.com>
Wohox
force-pushed
the
pingtian/claude/muon-layerwise-compact-buffers
branch
from
June 26, 2026 08:40
0689947 to
b21a44a
Compare
Wohox
added a commit
to Wohox/Megatron-LM
that referenced
this pull request
Jun 26, 2026
…uffer distopt Two changes from PR NVIDIA#5388 review (FDecaYed): 1. Make the compact decoupled LayerWise layout the DEFAULT. Replace the `--no-use-layer-wise-param-layout` (store_false) flag with `--use-layer-wise-param-layout` (store_true, default False), and flip the DistributedDataParallelConfig.use_layer_wise_param_layout default to False. The padded LayerWise layout is now opt-in (its dp_size*max(shard_load) padding is a large memory overhead and the reduce-scatter perf gain is not always significant). validate_args message updated to the new flag name. 2. Drop the separate `use_distributed_optimizer` argument threaded into _ParamAndGradBucketGroup. Instead, each _ParamAndGradBuffer bakes its per-buffer DistOpt decision into its own ddp_config ONCE via dataclasses.replace (a LayerWise/Muon buffer on the compact decoupled layout disables DistributedOptimizer; siblings keep the model-level setting). buffer.ddp_config is then the single source of truth and bucket groups simply inherit it in partition_buckets -- no per-site threading or per-call replace. Behavior-preserving. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: pingtianl <pingtianl@nvidia.com>
Contributor
Author
|
/ok to test 505f3ed |
Flip OptimizerConfig.use_layer_wise_param_layout from True to False so the compact decoupled LayerWise DDP layout is the default, and update the docstring so the (default) annotation tracks the False branch. Signed-off-by: Pingtian Li <pingtianl@nvidia.com>
FDecaYed
enabled auto-merge
June 29, 2026 05:22
Contributor
Author
|
/ok to test 667002c |
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/28358870884 |
Contributor
Author
|
/ok to test ccf1d1b |
…layout) Regenerate golden_values_dev_dgx_gb200.json for gpt3_moe_mcore_te_ep8_resume_torch_dist_dist_muon and its _1node variant. Removing --no-use-layer-wise-param-layout switches these tests from the compact decoupled LayerWise layout back to the default padded LayerWise layout, which changes the deterministic trajectory. Values regenerated in the GB200 CI container (mcore-pyt-dev-dgx_gb200, torch nv26.04) on GB200; an unchanged sibling test reproduced its committed golden bitwise, confirming CI fidelity. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Signed-off-by: Pingtian Li <pingtianl@nvidia.com>
The compact decoupled LayerWise DDP layout (now the default) routes non-Muon (Adam) params through a real DistributedOptimizer (reduce-scatter) instead of the legacy in-LayerWise all-reduce path, shifting lm-loss/num-zeros within tolerance and lowering peak memory. Regenerated on dgx_h100 with the common_pile CI dataset; verified deterministic + resume-consistency pass. Signed-off-by: Pingtian Li <pingtianl@nvidia.com>
Contributor
Author
|
/ok to test 99af691 |
Contributor
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/28483433802 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do ?
Add an experimental compact, decoupled LayerWise DDP buffer layout for the Muon (layer-wise) distributed optimizer that removes the persistent
dp_size * max(shard_load)padding from the long-lived param/grad buffers.There is no new flag: this reuses the existing
--no-use-layer-wise-param-layout. With a Muon layer-wise distributed optimizer under--use-distributed-optimizer, disabling the shard-aligned padded LayerWise layout (use_layer_wise_param_layout=False) selects the compact decoupled path.use_layer_wise_param_layoutis mirrored onto bothDistributedDataParallelConfigandOptimizerConfig(auto-populated by field name, defaultTrue= padded layout), so the configs read it directly — no derived switch.In this mode
use_distributed_optimizerbecomes a per-buffer property:DistributedOptimizersemantics: all-reduce gradients, legacy whole-param ping-pong ownership, andallgather_paramsparam sync.DistributedOptimizerlayout.The effective flag is computed per
_ParamAndGradBuffer/_ParamAndGradBucketGroup.partition_bucketssplits a force-single bucket group (disable_bucketing / non-first VPP chunks) by the effective per-bucketuse_distributed_optimizer, so Muon (all-reduce) and sibling (reduce-scatter) buckets never share a group; when all buckets agree this collapses to a single group, identical to the prior behavior.get_modelandwrap_model_chunks_with_ddpshare a singleif use_layer_wise_distributed_optimizer:branch — both the padded and compact cases forceddp_config.use_distributed_optimizer=True, tag params for buffer routing, and compute the LayerWisefull_param_layout. The padded-vs-compact decision lives entirely incompute_full_param_layout/_ParamAndGradBuffer, which readddp_config.use_layer_wise_param_layout.Compatibility
use_layer_wise_param_layout=True).fp8_param_gather=False(params persist in bf16) is supported.DistributedOptimizerparam buffers that the layer-wise path does not provide.num_distributed_optimizer_instances == 1(the non-DistOpt Muon buffers only all-reduce within a single optimizer instance).Issue tracking
For PRs from open-source community contributors:
Linked issue:
Contribution process
Pre-checks
Code review
Feel free to message or comment @NVIDIA/mcore-oncall to help accelerate your merge into main. The less complex your PR is, the faster it will be approved and merged!
All PRs start as draft. If you open a non-draft PR, it will be automatically converted to draft.
Step 1: Mark PR as "Ready for Review"
.github/CODEOWNERS.Final Review might get declined if these requirements are not fulfilled.
Step 2: Final Review
For PRs that change
megatron/core, once all expert reviewers have approved, theFinal Reviewlabel is applied automatically and final reviewers are assigned.For PRs outside
megatron/core, this step is skipped.Step 3: Approved
Once all required reviewers have approved, the
Approvedlabel is applied automatically.Merge
Any member of mcore-engineers will be able to merge your PR.