Skip to content

Use the collection's groups in the optimizer; warn on TP and GTP fallbacks - #8889

Draft
Connor-XY wants to merge 83 commits into
NVIDIA:mainfrom
Connor-XY:yx/pstate-unit-U6
Draft

Connor-XY wants to merge 83 commits into
NVIDIA:mainfrom
Connor-XY:yx/pstate-unit-U6

Conversation

@Connor-XY

@Connor-XY Connor-XY commented Nov 3, 2026 •

Copy link
Copy Markdown
Contributor

This PR moves the optimizer's duplicate filters and expert naming off the global parallel state, and makes the tensor-parallel and GTP helpers warn when they still fall back to it. It's part of the parallel_state deprecation (#6307). Gradient-norm and zero-count filtering now treat a TP or GTP group that the model's collection sets to None as an axis that's off, instead of reading the global rank, so a model on its own grid gets the same norm as on the standard grid. The distributed optimizer, the param-group dump and the MFSDP v2 optimizer name experts by the model's expert-parallel layout. The duplicate filters, model_parallel_cuda_manual_seed, resolve_gtp_remat_group, gtp_replica_rank and the DDP and optimizer group setup helpers emit a ProcessGroupFallbackWarning when a caller leaves out a group. Callers that build optimizers, DDP or linears, or seed the RNG, without a ProcessGroupCollection are affected, as are maintainers of the optimizer, distributed optimizer and GTP code. It carries #8042, three parts of #8045, #8731, and the core and GTP parts of #8734. Each commit is one original change, so please review commit by commit. A final commit regenerates tools/process_group_usage_allowlist.json. It builds on #8890 (#8049's resolve_process_groups and warn_global_process_group_fallback, which the new warnings use) and #8892 (#8045's get_ep_rank_and_size and get_model_ep_rank_and_size, which the optimizers call). It lands after #8891, which passes stock training's collection to DDP and the optimizer, #8895, which seeds the RNG from it, and #8898, which passes it to the optimizer with Gloo groups on, so stock runs reach none of the new warnings.

Review

This PR's own commits: Connor-XY/Megatron-LM@25ecaf8...41edc4b

The full PR diff also shows the earlier PRs of the stack until they merge.

Commits

Behavior changes for callers

  • A collection passed to the optimizer builders must set tp (None when TP is off). Otherwise set_duplicate_filter_groups raises ValueError; before, an unset tp read as None and the filters used the global TP rank.
  • In that collection, tp, expt_tp, gtp_remat or expt_gtp_remat set to None now means the axis is off for the duplicate filters, not "use the global group". An unset expt_tp defaults to tp.
  • An unset gtp_remat or expt_gtp_remat resolves through resolve_gtp_remat_group, as the model's layers resolve it, instead of getattr(..., "gtp_remat", None). When the field is unset, these two can return different groups.
  • Expert names on the standard grid don't change, so checkpoints from the standard grid load unchanged. Optimizer state saved on a custom EP grid before this change uses global-layout names and won't match.
  • On the standard grid, groups, ranks, seeds, duplicate filtering and checkpoints don't change.
  • DistributedDataParallel without pg_collection, setup_process_groups_for_optimizer without one, and direct calls without groups to the duplicate filters, model_parallel_cuda_manual_seed or gtp_replica_rank warn once per owner and argument, and raise under an error filter. resolve_gtp_remat_group warns only when the global GTP group has more than one rank.
  • About 520 test calls of model_parallel_cuda_manual_seed without a collection now warn once per process. They are not converted here.
  • The fallbacks read group ranks. A rank forced with set_tensor_model_parallel_rank or the expert rank setters no longer replaces the group rank there.
  • Needs determinism-exempt: the registered kernel files change only by warnings, group plumbing and owner= keywords.

Teams

core-adlr, core-nemo, dist-optimizer, gtp, mcore-optimizer

Testing

I ran the 7 unit-test files that cover this change at this PR's commit on one 4-GPU GB300 node. I compared each failure with the same test at the end of the stack (#8989, same code) and at the commit the stack starts from.

  • All 50 tests pass. Tests that skip themselves on this setup aren't counted.
  • The process-group allowlist check passes at this commit.
Test files
  • tests/unit_tests/distributed/mfsdp_v2/test_mcore_moe.py
  • tests/unit_tests/optimizer/test_distrib_optimizer_param_name.py
  • tests/unit_tests/optimizer/test_fully_sharded_optimizer_param_name.py
  • tests/unit_tests/optimizer/test_grad_norm_gtp_invariance.py
  • tests/unit_tests/optimizer/test_param_group_map_expert_names.py
  • tests/unit_tests/test_process_groups_config.py
  • tests/unit_tests/transformer/test_fsdp_dtensor_expert_offsets.py

🤖 Generated with Claude Code

@copy-pr-bot

copy-pr-bot Bot commented Nov 3, 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.

Connor-XY and others added 18 commits November 3, 2026 22:18
Originally NVIDIA#7487.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#6259.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#6293.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#6257.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#6303.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
…mmunicator caches on teardown

Originally NVIDIA#7029.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#8026.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#8723.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#8017.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#8049.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#8039.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
…sformer part)

Originally NVIDIA#8045, split by code owner into 5 parts: this is the transformer part; the others are training, mcore-optimizer, dist-optimizer, tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#8022.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#8023.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
… converter

Originally NVIDIA#8033.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#8044.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#8722, split by code owner into 6 parts: this is the core part; the others are post-training, transformer, moe, hybrid-model, tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Connor-XY and others added 22 commits November 3, 2026 22:40
…ate (hybrid-model part)

Originally NVIDIA#8754, split by code owner into 6 parts: this is the hybrid-model part; the others are transformer, gpt, training, unowned files, tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
…and MTP fall back to the global pipeline state"

Originally part of NVIDIA#8754's tests. They land with the hybrid-model part, which they exercise, instead of with the rest of NVIDIA#8754's tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#8722, split by code owner into 6 parts: this is the moe part; the others are core, post-training, transformer, hybrid-model, tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#8722, split by code owner into 6 parts: this is the hybrid-model part; the others are core, post-training, transformer, moe, tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#8722, split by code owner into 6 parts: this is the tests part; the others are core, post-training, transformer, moe, hybrid-model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#8732.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#8073.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
… part)

Originally NVIDIA#8748, split by code owner into 7 parts: this is the moe part; the others are core, post-training, transformer, multi-modal, hybrid-model, tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
…rid-model part)

Originally NVIDIA#8748, split by code owner into 7 parts: this is the hybrid-model part; the others are core, post-training, transformer, multi-modal, moe, tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
…ts part)

Originally NVIDIA#8748, split by code owner into 7 parts: this is the tests part; the others are core, post-training, transformer, multi-modal, moe, hybrid-model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
…raphs part)

Originally NVIDIA#8755, split by code owner into 9 parts: this is the cuda-graphs part; the others are batch-invariant+moe, moe, core, gpt, hybrid-model, multi-modal, data-parallelism, tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
…groups

Originally NVIDIA#8042.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
…e-optimizer part)

Originally NVIDIA#8045, split by code owner into 5 parts: this is the mcore-optimizer part; the others are transformer, training, dist-optimizer, tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
…-optimizer part)

Originally NVIDIA#8045, split by code owner into 5 parts: this is the dist-optimizer part; the others are transformer, training, mcore-optimizer, tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
…s part)

Originally NVIDIA#8045, split by code owner into 5 parts: this is the tests part; the others are transformer, training, mcore-optimizer, dist-optimizer.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Originally NVIDIA#8731.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
…d (core part)

Originally NVIDIA#8734, split by code owner into 9 parts: this is the core part; the others are gtp, mcore-optimizer, dist-optimizer, mcore-emerging-optimizers, tests, data-parallelism, training, moe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
…d (gtp part)

Originally NVIDIA#8734, split by code owner into 9 parts: this is the gtp part; the others are core, mcore-optimizer, dist-optimizer, mcore-emerging-optimizers, tests, data-parallelism, training, moe.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
…allbacks to WORLD or the global grid"

Originally part of NVIDIA#8734's tests. They land with the core part, which they exercise, instead of with the rest of NVIDIA#8734's tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: Yan Xu <yxu1@nvidia.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant