Skip to content

Scope layerwise optimizer collectives to be per module for mulitmodal mimo training - #6192

Merged
yashaswikarnati merged 3 commits into
NVIDIA:mainfrom
yashaswikarnati:agent/mimo-layerwise-optimizer-support
Aug 24, 2026
Merged

yashaswikarnati merged 3 commits into
NVIDIA:mainfrom
yashaswikarnati:agent/mimo-layerwise-optimizer-support

Conversation

@yashaswikarnati

@yashaswikarnati yashaswikarnati commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • allow the MIMO entry point to use the LayerWise distributed optimizer
  • scope LayerWise gradient-statistics, parameter-existence, and zero-count collectives to each module's intra_dist_opt group;
  • propagate explicit gradient-statistics, tensor-parallel, and expert-tensor-parallel groups to child optimizers;
  • gather LayerWise checkpoint parameter-group metadata on the owning dp_cp or expt_dp group;
  • align optimizer parameter-group keys on an optional caller-supplied process group, preserving WORLD as the default, and pass each MIMO module's intra_dist_opt group;

@copy-pr-bot

copy-pr-bot Bot commented Aug 1, 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.

@yashaswikarnati
yashaswikarnati marked this pull request as ready for review August 4, 2026 00:23
@yashaswikarnati
yashaswikarnati requested a review from a team as a code owner August 4, 2026 00:23
@yashaswikarnati
yashaswikarnati requested a review from a team August 4, 2026 00:23
@yashaswikarnati
yashaswikarnati requested review from a team as code owners August 4, 2026 00:23
@yashaswikarnati
yashaswikarnati force-pushed the agent/mimo-layerwise-optimizer-support branch 2 times, most recently from 8ad7ddd to 588b3ac Compare August 23, 2026 00:23
@yashaswikarnati
yashaswikarnati requested review from a team as code owners August 23, 2026 00:23
@yashaswikarnati
yashaswikarnati marked this pull request as draft August 23, 2026 00:24
Signed-off-by: ykarnati <ykarnati@nvidia.com>
@yashaswikarnati
yashaswikarnati force-pushed the agent/mimo-layerwise-optimizer-support branch from a82946c to 680fc4e Compare August 23, 2026 23:52
@yashaswikarnati
yashaswikarnati marked this pull request as ready for review August 23, 2026 23:53
@yashaswikarnati

Copy link
Copy Markdown
Contributor Author

/ok to test 680fc4e

Signed-off-by: ykarnati <ykarnati@nvidia.com>
@yashaswikarnati
yashaswikarnati force-pushed the agent/mimo-layerwise-optimizer-support branch from 680fc4e to 145297c Compare August 24, 2026 00:02
@yashaswikarnati

Copy link
Copy Markdown
Contributor Author

/ok to test 145297c

@yashaswikarnati yashaswikarnati changed the title Support layer-wise distributed optimizers in MIMO Scope layerwise optimizer collectives to be per module for mulitmodal mimo training Aug 24, 2026
Signed-off-by: ykarnati <ykarnati@nvidia.com>
@svcnvidia-nemo-ci svcnvidia-nemo-ci added the Final Review PR is in the "final review" stage label Aug 24, 2026
@yashaswikarnati
yashaswikarnati removed request for a team August 24, 2026 05:08
@yashaswikarnati

Copy link
Copy Markdown
Contributor Author

/ok to test e047dfb

@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 Aug 24, 2026
@yashaswikarnati
yashaswikarnati added this pull request to the merge queue Aug 24, 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/32750099346

Merged via the queue into NVIDIA:main with commit 0560fbb Aug 24, 2026
95 of 97 checks passed
@yashaswikarnati
yashaswikarnati deleted the agent/mimo-layerwise-optimizer-support branch August 24, 2026 17:33
ksivaman pushed a commit to ksivaman/Megatron-LM that referenced this pull request Sep 1, 2026
… mimo training (NVIDIA#6192)

Signed-off-by: ykarnati <ykarnati@nvidia.com>
xuwchen pushed a commit to xuwchen/Megatron-LM that referenced this pull request Oct 14, 2026
… mimo training (NVIDIA#6192)

Signed-off-by: ykarnati <ykarnati@nvidia.com>
(cherry picked from commit 0560fbb)
Signed-off-by: xuwenc <xuwenc@nvidia.com>
xuwchen pushed a commit to xuwchen/Megatron-LM that referenced this pull request Oct 14, 2026
… mimo training (NVIDIA#6192)

Signed-off-by: ykarnati <ykarnati@nvidia.com>
(cherry picked from commit 0560fbb)
Signed-off-by: xuwenc <xuwenc@nvidia.com>
nemo-autobot-origin Bot pushed a commit to svcnemo-autobot/Megatron-LM that referenced this pull request Oct 19, 2026
Single repair commit for the 2026-10-16 main->dev sync of the 100-commit
main slice ending at 302ed23 onto dev
dee456a.

Dependencies
- pyproject.toml: add gigatoken to the training and mlm extras, which
  code imported from main requires.
- uv.lock: regenerated with uv 0.7.2 (Dockerfile pin); adds gigatoken
  0.10.0, awkward 2.14.0 and awkward-cpp 57; no removals.

Tests adapted from main's API to dev's API
- transformer/test_multi_token_prediction.py: dev's MTPLossLoggingHelper
  exposes reduced values via reduce_loss_in_tracker()/tracker["values"].
- data/test_get_batch.py: dev's pretrain_hybrid.get_batch reads
  args.linear_cp_layout and args.context_parallel_size.
- inference/contexts/test_dynamic_prefix_caching.py: on dev the engine
  records the Mamba match count before admission; set it like the engine.
- models/mimo/test_mimo_1f1b_schedule.py: pass use_layer_wise_param_layout
  so DistributedDataParallelConfig agrees with the layer-wise optimizer.
- transformer/experimental_attention_variant/test_attention_variant_dsa.py:
  dynamic context parallel on dev requires max_seqlen_per_dp_cp_rank.
- transformer/test_multi_token_prediction.py (main NVIDIA#6119 speculative-decoding
  capture test): dev stores the MTP input on model._decoder_hidden_states_cache,
  not on inference_context.mtp_decoder_hidden_states.

Golden values
- moe/gpt3_moe_mcore_te_ep8_resume_torch_dist_dist_muon dev H100 golden
  refreshed from the exact merge-candidate run: main 0560fbb (NVIDIA#6192)
  makes the LayerWise Muon child grad statistics span the intra
  distributed-optimizer group; reverting only that line reproduces dev's
  previous golden values exactly.

- tests: set max_seqlen_per_dp_cp_rank in dev dynamic-CP/scheduler test configs
  (transformer_layer, transformer_config_dynamic_cp, dsv4_hybrid_attention_cp) to
  satisfy main NVIDIA#5902 validation; dev arguments.py already derives it when a
  sequence-packing scheduler is set.
- tests: transformer/test_thd_cuda_graph.py balanced DSA dynamic-pack case with
  max_seqlen_per_dp_cp_rank=None now expects main NVIDIA#5902's earlier
  ModelParallelConfig validation message.
- tests: extend main NVIDIA#6284 mimo overlap-lifecycle optimizer mock with the dev
  _optimizer_state_offloader/_layer_wise_non_distopt_child attributes (NVIDIA#6244).
- tests: extend main NVIDIA#6119 HybridModel MTP forward stub with dev
  moe_n_hash_layers and pg_collection.dp_cp used by the dev forward.

Megatron-FSDP v2 symmetric memory (requester-approved alignment with main)
- experimental/dbuffer.py, experimental/parameter_group.py: take main's
  version. Symmetric-memory MFSDP raises "requires PyTorch 2.12 or later"
  on PyTorch builds without torch.distributed._symmetric_memory
  .is_symm_mem_tensor, as on main. This drops dev's allocation-flag
  fallback (ef8d090, 4a534df); with it, the symmetric path's losses
  diverged across ranks on dev's PyTorch 2.12 pre-release image and
  test_fully_shard_symmetric_memory_matches_default_and_profiles_nccl[3]
  failed on the merge candidate.
- mfsdp_v2 tests: skip the symmetric-memory cases on such builds
  (test_symmetric_memory.py, the symmetric_memory params of test_overlap.py
  and test_cuda_graph.py, and test_mcore_adapter.py nccl_ub). They run again
  once the image provides is_symm_mem_tensor.

Hybrid context parallelism (review 5570704991)
- models/hybrid/hybrid_block.py: HybridStack rejects
  linear_cp_layout='contiguous' with context parallelism when the segment
  contains GDN ('G') or KDA ('K') layers. main NVIDIA#6776 feeds contiguous
  shards to linear layers, but dev's GDN/KDA chunkwise and headwise paths
  still read their input layout from cp_partition_mode (zigzag by default)
  and would scramble token order. Contiguous Mamba/GDP and the zigzag
  GDN/KDA paths are unchanged.
- ssm/test_hybrid_block.py: cover the GDN/KDA rejection and the zigzag GDN
  and contiguous Mamba builds under CP=2.

Signed-off-by: svcnemo-autobot <svcnemo-autobot@nvidia.com>
nemo-autobot-origin Bot pushed a commit to svcnemo-autobot/Megatron-LM that referenced this pull request Oct 19, 2026
Single repair commit for the 2026-10-16 main->dev sync of the 100-commit
main slice ending at 302ed23 onto dev
dee456a.

Dependencies
- pyproject.toml: add gigatoken to the training and mlm extras, which
  code imported from main requires.
- uv.lock: regenerated with uv 0.7.2 (Dockerfile pin); adds gigatoken
  0.10.0, awkward 2.14.0 and awkward-cpp 57; no removals.

Tests adapted from main's API to dev's API
- transformer/test_multi_token_prediction.py: dev's MTPLossLoggingHelper
  exposes reduced values via reduce_loss_in_tracker()/tracker["values"].
- data/test_get_batch.py: dev's pretrain_hybrid.get_batch reads
  args.linear_cp_layout and args.context_parallel_size.
- inference/contexts/test_dynamic_prefix_caching.py: on dev the engine
  records the Mamba match count before admission; set it like the engine.
- models/mimo/test_mimo_1f1b_schedule.py: pass use_layer_wise_param_layout
  so DistributedDataParallelConfig agrees with the layer-wise optimizer.
- transformer/experimental_attention_variant/test_attention_variant_dsa.py:
  dynamic context parallel on dev requires max_seqlen_per_dp_cp_rank.
- transformer/test_multi_token_prediction.py (main NVIDIA#6119 speculative-decoding
  capture test): dev stores the MTP input on model._decoder_hidden_states_cache,
  not on inference_context.mtp_decoder_hidden_states.

Golden values
- moe/gpt3_moe_mcore_te_ep8_resume_torch_dist_dist_muon dev H100 golden
  refreshed from the exact merge-candidate run: main 0560fbb (NVIDIA#6192)
  makes the LayerWise Muon child grad statistics span the intra
  distributed-optimizer group; reverting only that line reproduces dev's
  previous golden values exactly.

- tests: set max_seqlen_per_dp_cp_rank in dev dynamic-CP/scheduler test configs
  (transformer_layer, transformer_config_dynamic_cp, dsv4_hybrid_attention_cp) to
  satisfy main NVIDIA#5902 validation; dev arguments.py already derives it when a
  sequence-packing scheduler is set.
- tests: transformer/test_thd_cuda_graph.py balanced DSA dynamic-pack case with
  max_seqlen_per_dp_cp_rank=None now expects main NVIDIA#5902's earlier
  ModelParallelConfig validation message.
- tests: extend main NVIDIA#6284 mimo overlap-lifecycle optimizer mock with the dev
  _optimizer_state_offloader/_layer_wise_non_distopt_child attributes (NVIDIA#6244).
- tests: extend main NVIDIA#6119 HybridModel MTP forward stub with dev
  moe_n_hash_layers and pg_collection.dp_cp used by the dev forward.

Megatron-FSDP v2 symmetric memory (requester-approved alignment with main)
- experimental/dbuffer.py, experimental/parameter_group.py: take main's
  version. Symmetric-memory MFSDP raises "requires PyTorch 2.12 or later"
  on PyTorch builds without torch.distributed._symmetric_memory
  .is_symm_mem_tensor, as on main. This drops dev's allocation-flag
  fallback (ef8d090, 4a534df); with it, the symmetric path's losses
  diverged across ranks on dev's PyTorch 2.12 pre-release image and
  test_fully_shard_symmetric_memory_matches_default_and_profiles_nccl[3]
  failed on the merge candidate.
- mfsdp_v2 tests: skip the symmetric-memory cases on such builds
  (test_symmetric_memory.py, the symmetric_memory params of test_overlap.py
  and test_cuda_graph.py, and test_mcore_adapter.py nccl_ub). They run again
  once the image provides is_symm_mem_tensor.

Hybrid context parallelism (review 5570704991)
- models/hybrid/hybrid_block.py: HybridStack rejects
  linear_cp_layout='contiguous' with context parallelism when the segment
  contains GDN ('G') or KDA ('K') layers. main NVIDIA#6776 feeds contiguous
  shards to linear layers, but dev's GDN/KDA chunkwise and headwise paths
  still read their input layout from cp_partition_mode (zigzag by default)
  and would scramble token order. Contiguous Mamba/GDP and the zigzag
  GDN/KDA paths are unchanged.
- ssm/test_hybrid_block.py: cover the GDN/KDA rejection and the zigzag GDN
  and contiguous Mamba builds under CP=2.
- tests: transformer/test_multi_token_prediction.py TestMultiTokenPredictionHybrid
  (main NVIDIA#6119) stub config sets cross_entropy_loss_fusion=False and
  cross_entropy_fusion_impl="native" (the TransformerConfig defaults);
  dev NVIDIA#8105 HybridModel.forward reads them when labels are given
  (review 5573599695).

Signed-off-by: svcnemo-autobot <svcnemo-autobot@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: medium nemotron

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants