Skip to content

[Dev] Add DeepEP v2 flex dispatcher backend#4793

Open
Autumn1998 wants to merge 7 commits into
NVIDIA:devfrom
Autumn1998:tongliu/deepepv2-flex-dispatcher
Open

[Dev] Add DeepEP v2 flex dispatcher backend#4793
Autumn1998 wants to merge 7 commits into
NVIDIA:devfrom
Autumn1998:tongliu/deepepv2-flex-dispatcher

Conversation

@Autumn1998

@Autumn1998 Autumn1998 commented May 14, 2026

Copy link
Copy Markdown
Contributor

What does this PR do ?

The DeepEP V2 support as a backend of flex dispatcher.

PR on main: #5153

⚠️ For major changes (either in lines of code or in its impact), please make sure to first share a design doc with the team. If you're unsure what's the best way to do so, contact the @mcore-oncall.

Issue tracking

For PRs from open-source community contributors:

  • New features: a linked issue is required. Please open a feature request and reference it here before submitting the PR.
  • Small updates (bug fixes, minor improvements): a linked issue is recommended and will accelerate the PR review process.

Linked issue:

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

Code review

Feel free to message or comment the @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"

  1. When your PR is ready, click Ready for Review.
  2. An oncall reviewer is auto-assigned and expert reviewers are notified based on your changes.
    • Some PRs may jump straight to step 2. This is determined by .github/CODEOWNERS.

⚠️ Only mark as ready once merge-conflicts are resolved and the CI is passing.
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, the Final Review label 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 Approved label is applied automatically.

Merge

Any member of mcore-engineers will be able to merge your PR.

For MRs into `dev` branch The proposed review process for `dev` branch is under active discussion.

MRs are mergable after one approval by either eharper@nvidia.com or zijiey@nvidia.com.

@Autumn1998 Autumn1998 requested review from a team as code owners May 14, 2026 03:24
@copy-pr-bot

copy-pr-bot Bot commented May 14, 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.

@Autumn1998 Autumn1998 force-pushed the tongliu/deepepv2-flex-dispatcher branch 2 times, most recently from c80462a to 1cd0541 Compare May 18, 2026 09:33
@Autumn1998 Autumn1998 changed the title [draft] Add DeepEP v2 flex dispatcher backend Add DeepEP v2 flex dispatcher backend Jun 4, 2026
@Autumn1998 Autumn1998 self-assigned this Jun 4, 2026
@Autumn1998

Copy link
Copy Markdown
Contributor Author

/ok to test 804a926

)
if ctx.async_finish:
event.current_stream_wait()
return None, grad_x, None, None, None, None, None

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.

DeepepV2Combine.forward has six inputs after ctx (buffer, x, handle, num_sms, async_finish, allocate_on_comm_stream), but this backward returns seven gradients. PyTorch autograd will raise an incorrect-gradient-count error when this combine participates in training backward. Can we drop one trailing None here?

return None, grad_x, None, None, None, None

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed

self.router_dtype = config.moe_router_dtype
self.capacity_factor = config.moe_expert_capacity_factor
self.permute_fusion = config.moe_permute_fusion
self.num_sms = config.moe_deepep_num_sms

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.

Question: should the v2 path leave num_sms as 0, or use buffer.get_theoretical_num_sms(...), instead of reusing moe_deepep_num_sms? DeepEP v2's ElasticBuffer can analytically choose SM/QP counts, so carrying over the v1 default may override the intended v2 behavior/perf tuning.

@Autumn1998 Autumn1998 Jun 11, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

However, this also means we lose the args for adjusting the number of DeepEP v2 SMs. I prefer to keep this, but set the default value to None, and then let v1 and v2 use different default values when it is None.

@Victarry Victarry changed the title Add DeepEP v2 flex dispatcher backend [Dev] Add DeepEP v2 flex dispatcher backend Jun 11, 2026
@Autumn1998 Autumn1998 enabled auto-merge June 11, 2026 14:04
@Autumn1998

Copy link
Copy Markdown
Contributor Author

/ok to test 98c7373

Signed-off-by: tongliu <tongliu@nvidia.com>
Signed-off-by: tongliu <tongliu@nvidia.com>
Signed-off-by: tongliu <tongliu@nvidia.com>
Signed-off-by: tongliu <tongliu@nvidia.com>
Signed-off-by: tongliu <tongliu@nvidia.com>
Signed-off-by: tongliu <tongliu@nvidia.com>
Signed-off-by: tongliu <tongliu@nvidia.com>
@Autumn1998 Autumn1998 force-pushed the tongliu/deepepv2-flex-dispatcher branch from 98c7373 to a71d0d1 Compare June 12, 2026 04:32
@Autumn1998

Copy link
Copy Markdown
Contributor Author

/ok to test 30e602f

@copy-pr-bot

copy-pr-bot Bot commented Jun 12, 2026

Copy link
Copy Markdown

/ok to test 30e602f

@Autumn1998, there was an error processing your request: E2

See the following link for more information: https://docs.gha-runners.nvidia.com/cpr/e/2/

@Autumn1998

Copy link
Copy Markdown
Contributor Author

/ok to test a71d0d1

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants