Skip to content

[Feature] Optimize DeepSeek's DeepEP on Ascend NPU#8355

Merged
zhyncs merged 35 commits intosgl-project:mainfrom
iforgetmyname:feature/ascend_deepep_optimize
Aug 9, 2025
Merged

[Feature] Optimize DeepSeek's DeepEP on Ascend NPU#8355
zhyncs merged 35 commits intosgl-project:mainfrom
iforgetmyname:feature/ascend_deepep_optimize

Conversation

@iforgetmyname
Copy link
Collaborator

@iforgetmyname iforgetmyname commented Jul 25, 2025

Motivation

Following our roadmap #8004, this is the first pr to support deepep expert parallelism and speed up with some fusion kernels. Now it is possible to activate --enable-deepep-moe with --deepep-mode low_latency only under pd disaggregation scenario on decode nodes. However, we only support W8A8 int8 quant method currently.

More info about our DeepEP-compatible kernels, check out our roadmap in sgl-kernel-npu

Modifications

  • a new DeepEPMoE impl w/ gemm and swiglu fusion kernels
  • gating_topk kernel using fp32 precision to improve accuracy
  • introducing fused rms_norm kernel and add_rms_norm kernel
  • introducing fused rope kernel under certain condition, waiting to be generalized

Checklist

Accuracy & Performance

Accuracy with python3 -m sglang.test.few_shot_gsm8k --num-questions 1318

image

Performance on 2xA3 PD disaggregation w/o DP-ATTN

image

Code Format

image

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Summary of Changes

Hello @iforgetmyname, 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 significant optimizations for DeepSeek's DeepEP (Deep Expert Parallel) Mixture of Experts (MoE) implementation, specifically targeting Huawei Ascend NPUs. It integrates NPU-specific kernels and quantization methods for key operations like MoE gating, rotary embeddings, and W8A8 quantization, aiming to enhance performance and efficiency on Ascend hardware.

Highlights

  • NPU-Specific DeepEP MoE Implementation: Introduced AscendDeepEPMoE to leverage Ascend NPU capabilities for DeepEP MoE layers. This includes specialized weight loading for W8A8 scales and an NPU-optimized forward pass utilizing torch_npu operations like npu_grouped_matmul and npu_swiglu. The get_moe_impl_class function now conditionally returns this NPU-optimized class.
  • W8A8 Quantization for NPU: Added W8A8EPMoEMethod to support W8A8 integer quantization specifically for EPMoE on Ascend NPUs, enabling more efficient memory usage and computation. The EPMoE initialization logic was updated to integrate this new quantization method.
  • Optimized NPU Kernels for Core Operations: Integrated torch_npu kernels for critical operations: MoE Top-K gating (npu_moe_gating_top_k) and Rotary Embedding (npu_mrope). This provides significant performance improvements for these components when running on Ascend NPUs, with fallbacks to native implementations for unsupported configurations.
  • Refined W8A8 INT8 Quantization Methods: Enhanced existing W8A8 INT8 quantization methods for NPU by optimizing RMSNorm with npu_add_rms_norm and npu_rms_norm. Additionally, the bias fusion logic in linear layers was refined to ensure correct bias application and prevent double-addition in tensor parallelism scenarios.
  • NPU-Aware Conditional Logic and Global Arguments: Adjusted conditional imports for certain quantization kernels to be NPU-aware, ensuring that only relevant kernels are loaded based on the hardware. The 'quantization' argument was also added to the global server arguments, allowing for dynamic configuration of quantization schemes.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

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 issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize 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 counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments or fill out our survey to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces optimizations for DeepSeek's DeepEP on Ascend NPU. The changes are extensive, adding NPU-specific kernels and logic for MoE layers, quantization, and rotary embeddings.

My review has identified a few critical issues that need to be addressed:

  • There's a method signature mismatch in AscendDeepEPMoE.forward that will cause runtime errors.
  • The NPU-specific path in select_experts returns an incorrect type, which will lead to unpacking errors.
  • There are also some bugs in the weight loading logic for NPU that need to be fixed.

Additionally, I've pointed out some areas for code improvement, such as moving local imports to the top level and removing dead code, to enhance maintainability.

Overall, this is a significant feature addition. Please address the critical issues to ensure correctness.

@iforgetmyname iforgetmyname force-pushed the feature/ascend_deepep_optimize branch from 3545556 to 74e3d91 Compare July 26, 2025 07:59
@iforgetmyname iforgetmyname changed the title [WIP] [Feature] Optimize DeepSeek's DeepEP on Ascend NPU [Feature] Optimize DeepSeek's DeepEP on Ascend NPU Jul 26, 2025
@iforgetmyname iforgetmyname changed the title [Feature] Optimize DeepSeek's DeepEP on Ascend NPU [Feature][1/N] Optimize DeepSeek's DeepEP on Ascend NPU Jul 26, 2025
@iforgetmyname iforgetmyname marked this pull request as ready for review July 26, 2025 08:18
@Alcanderian Alcanderian changed the title [Feature][1/N] Optimize DeepSeek's DeepEP on Ascend NPU [Feature] Optimize DeepSeek's DeepEP on Ascend NPU Jul 28, 2025
@gemini-code-assist
Copy link
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

1 similar comment
@gemini-code-assist
Copy link
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@Alcanderian
Copy link
Collaborator

I cannot see any npu deepep calls in this PR. Are they hidden behind deepep-compatible interfaces?

And VLLM test failed

@iforgetmyname
Copy link
Collaborator Author

I cannot see any npu deepep calls in this PR. Are they hidden behind deepep-compatible interfaces?

yes, refer to the interface

And VLLM test failed

looks like fixed in #8859 and #8881

@ping1jing2
Copy link
Collaborator

I cannot see any npu deepep calls in this PR. Are they hidden behind deepep-compatible interfaces?

And VLLM test failed

seems like #8837 is the cause. 8837/checks

@ping1jing2
Copy link
Collaborator

I cannot see any npu deepep calls in this PR. Are they hidden behind deepep-compatible interfaces?

And VLLM test failed

see #8886

@ping1jing2 ping1jing2 enabled auto-merge (squash) August 7, 2025 03:42
@Alcanderian Alcanderian requested a review from Edwardf0t1 as a code owner August 8, 2025 11:00
@Alcanderian Alcanderian added the ready-to-merge The PR is ready to merge after the CI is green. label Aug 9, 2025
@zhyncs zhyncs disabled auto-merge August 9, 2025 08:34
@zhyncs zhyncs merged commit 137e75d into sgl-project:main Aug 9, 2025
104 of 116 checks passed
@iforgetmyname iforgetmyname deleted the feature/ascend_deepep_optimize branch August 9, 2025 09:11
narutolhy pushed a commit to narutolhy/sglang that referenced this pull request Aug 17, 2025
Co-authored-by: ronnie_zheng <zl19940307@163.com>
Co-authored-by: Hexq0210 <hexq0809521@gmail.com>
MahmoudAshraf97 pushed a commit to MahmoudAshraf97/sglang that referenced this pull request Sep 8, 2025
Co-authored-by: ronnie_zheng <zl19940307@163.com>
Co-authored-by: Hexq0210 <hexq0809521@gmail.com>
@ping1jing2 ping1jing2 self-assigned this Dec 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

high priority ready-to-merge The PR is ready to merge after the CI is green.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants