Skip to content

[Feature] Select a dedicated V4.1 DeepInfer MegaMoE module - #20395

Closed
linfeng-yuan wants to merge 20 commits into
vllm-project:mainfrom
linfeng-yuan:refactor/deepinfer-megamoe-v41-module
Closed

linfeng-yuan wants to merge 20 commits into
vllm-project:mainfrom
linfeng-yuan:refactor/deepinfer-megamoe-v41-module

Conversation

@linfeng-yuan

@linfeng-yuan linfeng-yuan commented Oct 31, 2026 •

Copy link
Copy Markdown
Collaborator

What this PR does / why we need it?

Add opt-in DeepInfer MegaMoE for DeepSeek V4.1 on Ascend 950: routed MXFP4 and shared FP8 experts execute in one dispatch/GEMM/SwiGLU/combine launch.

A dedicated DeepGemmV41MoE uses the existing FusedMoEFactory extension points and owns local routing and fused communication.

Pack weights once and reuse process-group-owned symmetric storage across layers and serialized target/draft calls. Validate configuration before native loading; reject unsupported configurations explicitly. The MLA stream-lifetime adjustment stays outside graph capture and imports the private NPU API lazily.

Pinned native sources, JIT resources, licenses and provenance follow RFC #20620. A5 images and CI share one build-prerequisite installer; parser pins remain build-only.

Target: main. Matching release backport: #20520.

Does this PR introduce any user-facing change?

Enable with --additional-config '{"deepgemm_mega_moe":true,"enable_fused_mc2":0}'. Supports V4.1, Ascend 950, TP1/linear EP8 and serialized target/draft execution. EPLB replicas, nonlinear placement and overlapping microbatches are rejected. Ordinary MoE remains the default. Release note: release_notes/fragments/20395.yaml.

How was this patch tested?

  • Forward-context regression: 51 passed on both the CI-pinned vLLM source and v0.32.0.
  • Editable-install regression uses the real setuptools command on an initially absent package directory; ordinary extensions and the MegaMoE binary/JIT resources/licenses are preserved.
  • Clean pinned native dependency build passed. Four required NPU APIs import successfully in the serving container.
  • Eight-rank analytic checks with that fresh build: 112/112 passed, max absolute difference 0, including 16 graph capture/replay cases, variable/zero-token ranks, 4092-token input and target/draft storage reuse. Every rank verifies the loaded package path and binary SHA256; JIT starts from an empty cache.
  • Main/release shared backend, packaging, builder and focused-test sources are byte-identical.
  • Current-source DeepSeek V4.1 + DSpark5 functional smoke passed 4/4 requests (DP8/TP1/EP8, eager, temperature 0; short and ~8K inputs). Python native bindings were rebuilt from matching sources; the established ACLNN vendor package and warmed runtime JIT caches were reused. Coverage is limited to these functional requests; full-dataset accuracy was not run and runtime caches were warm.
  • bash format.sh ci passed locally. Latest-head official pre-commit/mypy, both full CPU UT lanes and selected hardware E2E all passed: CI gate.

Checklist

  • Boundary and failure-path regression coverage.

  • Focused tests exercise production code and assert behavior.

  • Latest-head pre-commit, full CPU UT and selected E2E gates all passed.

  • vLLM main: vllm-project/vllm@24420b7

Signed-off-by: linfeng-yuan <1102311262@qq.com>
Signed-off-by: linfeng-yuan <1102311262@qq.com>
Replace the experimental MegaMoE Prefill host fence with the tested MLA lifetime adjustment. Document allocator assumptions, diagnostic evidence, broader wrapper scope, and outstanding hardware validation.

Signed-off-by: linfeng-yuan <1102311262@qq.com>
Reuse upstream factory, checkpoint and graph-op interfaces while removing ALLTOALL aliasing and the W4A8 execution interception. Preserve local routing, FP32 gate weights and fused shared-expert ownership.

Signed-off-by: linfeng-yuan <1102311262@qq.com>
Signed-off-by: linfeng-yuan <1102311262@qq.com>
@github-actions

Copy link
Copy Markdown
Contributor

👋 Hi! Thank you for contributing to the vLLM Ascend project. The following points will speed up your PR merge:‌‌

  • A PR should do only one thing, smaller PRs enable faster reviews.
  • Every PR should include unit tests and end-to-end tests ‌to ensure it works and is not broken by other future PRs.
  • Write the commit message by fulfilling the PR description to help reviewer and future developers understand.

If CI fails, you can run linting and testing checks locally according Contributing and Testing.


Tip

💡 Consider Linking a Related Issue or RFC

Your PR title contains the [Feature] tag, indicating a bug fix or new feature.

Linking a related issue or RFC in the PR description is strongly encouraged — it gives reviewers helpful context and speeds up the review. You can use any of these keywords:

  • Fixes #<issue_number>
  • Closes #<issue_number>
  • Resolves #<issue_number>
  • Refs #<rfc_or_issue_number> (for RFCs)

🙏 Thanks for helping us keep the project well-organized!

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces an experimental DeepInfer MegaMoE backend designed for DeepSeek V4.1 models running on Ascend 950 NPUs. By implementing a dedicated execution module, the changes bypass generic MoE communication paths, allowing for more efficient fused EP kernel utilization and symmetric scratchpad management. Additionally, the PR includes a memory management optimization for MLA tensors to improve performance and stability during inference.

Highlights

  • Dedicated MegaMoE Module: Introduced the DeepGemmV41MoE module specifically for DeepSeek V4.1, enabling optimized execution on Ascend 950 hardware.
  • Memory Management: Implemented an MLA lifetime adjustment to reduce deferred tensor reuse, replacing previous host-side synchronization.
  • Configuration: Added an opt-in configuration flag 'deepgemm_mega_moe' to enable the experimental backend.
  • Weight Packing: Integrated custom weight packing and symmetric buffer management to align with the DeepInfer kernel requirements.
New Features

🧠 You can now enable Memory (public preview) to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize the Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counterproductive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

Suggested PR Title:

[Ops][Feature] Add DeepInfer MegaMoE backend for DeepSeek V4.1 on Ascend 950

Suggested PR Summary:

### What this PR does / why we need it?
This pull request introduces an experimental, opt-in DeepInfer MegaMoE backend with fused shared experts for DeepSeek V4.1 on Ascend 950 (TP1 and linear EP8). It also includes a same-stream lifetime adjustment for native MLA to reduce deferred tensor reuse, replacing the previous prefill host synchronization.

Feedback:
Two issues were identified in `vllm_ascend/ops/fused_moe/deepgemm_v41.py` where calling `.view()` on potentially non-contiguous weight and scale tensors could raise a `RuntimeError`. It is recommended to ensure these tensors are contiguous by calling `.contiguous()` before performing `.view()` operations.

### Does this PR introduce _any_ user-facing change?
Yes, it adds an experimental opt-in configuration option `deepgemm_mega_moe` in `AscendConfig`.

### How was this patch tested?
The changes are covered by new unit tests in `tests/ut/ops/fused_moe/test_deepgemm_v41.py`, `tests/ut/ops/fused_moe/test_deepgemm_v41_module.py`, and `tests/ut/ops/test_packaged_attention.py`.

Comment on lines +68 to +77
(w13, s13), (w2, s2) = deep_gemm.transform_weights_for_mega_moe(
(
layer.w13_weight.data.view(torch.int8),
layer.w13_weight_scale.data.view(torch.uint8).contiguous().view(torch.int16),
),
(
layer.w2_weight.data.view(torch.int8),
layer.w2_weight_scale.data.view(torch.uint8).contiguous().view(torch.int16),
),
)

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.

high

To prevent potential RuntimeErrors when weights or scales are not contiguous (which can happen depending on how the checkpoint is loaded or sharded), it is safer to call .contiguous() before performing any .view() operations. Additionally, we can simplify the double .view() on the weight scales by calling .contiguous() directly on the original tensor before viewing it as torch.int16.

        (w13, s13), (w2, s2) = deep_gemm.transform_weights_for_mega_moe(\n            (\n                layer.w13_weight.data.contiguous().view(torch.int8),\n                layer.w13_weight_scale.data.contiguous().view(torch.int16),\n            ),\n            (\n                layer.w2_weight.data.contiguous().view(torch.int8),\n                layer.w2_weight_scale.data.contiguous().view(torch.int16),\n            ),\n        )

Comment on lines +130 to +134
if scale.dtype == torch.float32:
# Match the DS checkpoint conversion: FP32 powers of two to UE8M0.
scale = ((scale.view(torch.int32) >> 23) & 0xFF).to(torch.uint8)
elif scale.dtype in (torch.uint8, getattr(torch, "float8_e8m0fnu", None)):
scale = scale.view(torch.uint8)

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.

high

If scale is not contiguous, calling .view() directly on it will raise a RuntimeError. Ensuring the tensor is contiguous before calling .view() prevents potential runtime crashes during weight processing.

        if scale.dtype == torch.float32:\n            # Match the DS checkpoint conversion: FP32 powers of two to UE8M0.\n            scale = ((scale.contiguous().view(torch.int32) >> 23) & 0xFF).to(torch.uint8)\n        elif scale.dtype in (torch.uint8, getattr(torch, 

Build the DeepInfer-pinned operator with its native setup.py and ship its extension and JIT resources in the Ascend namespace. Replace serving-time header overrides with two version-scoped device include corrections. Resolve external NPU packages safely and use the vLLM cache root by default.

Signed-off-by: linfeng-yuan <1102311262@qq.com>
(cherry picked from commit bb5cb3c)
Signed-off-by: linfeng-yuan <1102311262@qq.com>
Signed-off-by: linfeng-yuan <1102311262@qq.com>
(cherry picked from commit 11c1799)
Signed-off-by: linfeng-yuan <1102311262@qq.com>
(cherry picked from commit d4ab6ab)
Signed-off-by: linfeng-yuan <1102311262@qq.com>
Signed-off-by: linfeng-yuan <1102311262@qq.com>
(cherry picked from commit 041e706)
Signed-off-by: linfeng-yuan <1102311262@qq.com>
(cherry picked from commit 144b752)
Signed-off-by: linfeng-yuan <1102311262@qq.com>
Signed-off-by: linfeng-yuan <1102311262@qq.com>
@linfeng-yuan linfeng-yuan added the ready-precise run selected e2e test for pr label Nov 3, 2026
Signed-off-by: linfeng-yuan <1102311262@qq.com>
Signed-off-by: linfeng-yuan <1102311262@qq.com>
Signed-off-by: linfeng-yuan <1102311262@qq.com>
Signed-off-by: linfeng-yuan <1102311262@qq.com>
Signed-off-by: linfeng-yuan <1102311262@qq.com>
Signed-off-by: linfeng-yuan <1102311262@qq.com>
@github-actions github-actions Bot removed the documentation Improvements or additions to documentation label Nov 4, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

7 similar comments
@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions github-actions Bot removed the ready-precise run selected e2e test for pr label Nov 26, 2026
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