Skip to content

Support independent expert optimizer instances in MFSDP v2 - #7341

Open
Autumn1998 wants to merge 1 commit into
NVIDIA:mainfrom
Autumn1998:feat/mfsdp-v2-independent-expert-dp
Open

Autumn1998 wants to merge 1 commit into
NVIDIA:mainfrom
Autumn1998:feat/mfsdp-v2-independent-expert-dp

Conversation

@Autumn1998

Copy link
Copy Markdown
Contributor

Summary

Building on #7277, this change adds expert_num_distributed_optimizer_instances so dense and expert parameters can use independent instance counts.

  • Defaults to num_distributed_optimizer_instances, preserving existing behavior.
  • Reuses outer process groups when instance counts match.

@Autumn1998
Autumn1998 requested a review from a team as a code owner September 15, 2026 08:23
@Autumn1998
Autumn1998 requested a review from a team September 15, 2026 08:23
@Autumn1998
Autumn1998 requested review from a team as code owners September 15, 2026 08:23
@copy-pr-bot

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

@svcnvidia-nemo-ci
svcnvidia-nemo-ci marked this pull request as draft September 15, 2026 08:23
@github-actions

Copy link
Copy Markdown
Contributor

This PR has been automatically converted to draft because all PRs must start as drafts.

When you are ready for review, click Ready for Review to begin the review process. This will:

  1. Add the oncall reviewer (optional reviewer)
  2. Add required review teams based on your changes

See the contribution guide for more details.

@wujingyue wujingyue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure it's needed? This changes the mesh and the mesh is typically aligned with network topology -- most likely [inter-nvl, intra-nvl] for production settings.

@wujingyue

Copy link
Copy Markdown
Contributor

Are you sure it's needed? This changes the mesh and the mesh is typically aligned with network topology -- most likely [inter-nvl, intra-nvl] for production settings.

Oh, maybe this is for supporting something like HFSDP for dense and Zero3+EP for MoE? That would make sense to me.

@Autumn1998

Autumn1998 commented Sep 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Are you sure it's needed? This changes the mesh and the mesh is typically aligned with network topology -- most likely [inter-nvl, intra-nvl] for production settings.

Oh, maybe this is for supporting something like HFSDP for dense and Zero3+EP for MoE? That would make sense to me.

Yes, I recently found that some customers require using HSDP, with the outer dimension set to ZeRO-1 and the inner dimension set to ZeRO-3 for dense part, while using a fully ZeRO-1 configuration plus EP for MoE part.

Alternatively, we could add a single switch to control whether HSDP is enabled for the expert, for example: --enable-expert-hsdp 🤔

shjwudp added a commit to shjwudp/Megatron-LM that referenced this pull request Sep 16, 2026
…zer-instances

Cherry-pick NVIDIA#7341: support independent expert optimizer instances in MFSDP v2
@Autumn1998

Copy link
Copy Markdown
Contributor Author

cc @wujingyue for the earlier discussion about the HSDP integration .

@wujingyue

wujingyue commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

the outer dimension set to ZeRO-1 and the inner dimension set to ZeRO-3 for dense part, while using a fully ZeRO-1 configuration plus EP for MoE part.

This use case makes sense to me.

Alternatively, we could add a single switch to control whether HSDP is enabled for the expert, for example: --enable-expert-hsdp

I'm not sure about the best API.

Could you rebase the PR so I can review it again?

In general, we've been using DataParallelConfig as a domain-specific language to dictate how to fully_shard. However, the friction has always been that DataParallelConfig is less powerful.

Have you considered letting users (instead of the mcore adapter) fully_shard directly and still running that model in Megatron's training loop? That could be the right solution going forward.

@Autumn1998
Autumn1998 force-pushed the feat/mfsdp-v2-independent-expert-dp branch from 8cb509e to 9507679 Compare October 22, 2026 03:46
@Autumn1998

Copy link
Copy Markdown
Contributor Author

the outer dimension set to ZeRO-1 and the inner dimension set to ZeRO-3 for dense part, while using a fully ZeRO-1 configuration plus EP for MoE part.

This use case makes sense to me.

Alternatively, we could add a single switch to control whether HSDP is enabled for the expert, for example: --enable-expert-hsdp

I'm not sure about the best API.

Could you rebase the PR so I can review it again?

In general, we've been using DataParallelConfig as a domain-specific language to dictate how to fully_shard. However, the friction has always been that DataParallelConfig is less powerful.

Have you considered letting users (instead of the mcore adapter) fully_shard directly and still running that model in Megatron's training loop? That could be the right solution going forward.

That sounds useful for advanced users, but I think most users still want MCore to handle the sharding setup. I’d keep the config-based path and offer direct fully_shard for cases that need more control.

@Autumn1998
Autumn1998 requested a review from wujingyue October 22, 2026 08:01
@Autumn1998 Autumn1998 self-assigned this Oct 22, 2026
@Autumn1998
Autumn1998 marked this pull request as ready for review October 22, 2026 08:02
@Autumn1998
Autumn1998 requested a review from a team as a code owner October 22, 2026 08:02
@wujingyue
wujingyue removed the request for review from a team October 22, 2026 22:04

@wujingyue wujingyue left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise

@Autumn1998
Autumn1998 force-pushed the feat/mfsdp-v2-independent-expert-dp branch 3 times, most recently from 330a790 to 26e0d41 Compare October 30, 2026 04:41
@wujingyue
wujingyue self-requested a review October 30, 2026 05:21
@Autumn1998

Copy link
Copy Markdown
Contributor Author

/ok to test 26e0d41

Dense and expert parameters can now use different numbers of distributed
optimizer instances, so each domain gets its own outer (HSDP) group.

Add expert_num_distributed_optimizer_instances to
DistributedDataParallelConfig, initialize_model_parallel and the
--expert-num-distributed-optimizer-instances argument. It defaults to
num_distributed_optimizer_instances, which keeps the existing behavior, and
a value of 1 gives experts no outer axis. Only MFSDP v2 accepts differing
counts; v1 DDP and DistOpt reject them. This replaces the expert_hsdp flag.
expert_outer_dp_sharding_strategy still defaults to
outer_dp_sharding_strategy, or to no_shard when experts have no outer axis.

parallel_state keeps the expert inter-instance group and adds a dense one.
get_inter_distributed_optimizer_instance_group returns the dense group by
default and the expert group with expert=True, exposed as
ProcessGroupCollection.inter_dist_opt and inter_expt_dist_opt. The dense group
reuses the expert group when the two counts match and is built only when they
differ.

Extend the hybrid placements test to cover independent dense and expert
outer sizes.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Signed-off-by: tongliu <tongliu@nvidia.com>
@Autumn1998
Autumn1998 force-pushed the feat/mfsdp-v2-independent-expert-dp branch from 26e0d41 to 8ebc58e Compare November 2, 2026 05:10
@Autumn1998

Copy link
Copy Markdown
Contributor Author

/ok to test 8ebc58e

This branch was successfully deployed

2 active 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.

2 participants