Support DeepSeek-R1 w4a8 low latency deepep#8311
Support DeepSeek-R1 w4a8 low latency deepep#8311ayrnb wants to merge 95 commits intosgl-project:mainfrom
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @ayrnb, 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 specialized support for DeepSeek-R1 w4a8 quantized models to operate in a low-latency Deep Expert Parallelism (DeepEP) mode. It achieves this by adding a new execution path within the existing Mixture of Experts (MoE) layer, which includes custom data preprocessing and output handling tailored for this specific optimization.
Highlights
- New Low-Latency DeepEP Mode: I've introduced a new
deepep_ll(DeepEP Low Latency) mode within thecutlass_w4a8_moefunction. This mode is specifically designed to optimize performance for DeepSeek-R1 w4a8 quantized models. - Conditional Logic for DeepEP Modes: The
cutlass_w4a8_moefunction now includes conditional logic to handle input preparation and output processing differently based on theep_modeparameter. Fordeepep_llmode, it uses a new data preparation pipeline. - Specialized Data Preparation for Low Latency: A new function,
deepep_ll_get_cutlass_w4a8_moe_mm_data, has been added tokernels.py. This function is responsible for preparing the inputhidden_states, expert offsets, and problem sizes in a format suitable for the low-latency DeepEP mode, including a newcompute_problem_sizes_w4a8kernel. - Integration into MoE Layer Forward Pass: The main MoE layer's
forwardmethod inlayer.pyhas been updated to conditionally invoke a newforward_cutlass_w4a8_maskedmethod whenuse_w4afp8is true and theresolved_deepep_modeis set tolow_latency. This new method acts as the entry point for the optimized W4A8 path.
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
-
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. ↩
There was a problem hiding this comment.
Code Review
This pull request adds support for DeepSeek-R1 w4a8 in low latency deepep mode. The changes are well-contained and introduce a new execution path for this specific mode. I've provided a few suggestions to improve performance by vectorizing a loop, and to enhance code quality by removing dead code and a debug log statement. Overall, the implementation looks correct.
| for expert_idx in non_zero_indices: | ||
| num_non_zero_rows = local_topk_ids[expert_idx].item() | ||
| output[expert_idx, :num_non_zero_rows] = c2[ | ||
| c2_index : c2_index + num_non_zero_rows | ||
| ] | ||
| c2_index += num_non_zero_rows |
There was a problem hiding this comment.
This Python loop iterates over active experts to scatter the results. For performance-critical code running on a GPU, this can be a bottleneck due to the overhead of launching multiple operations from a Python loop. Consider vectorizing this operation or using a custom kernel for a more efficient implementation.
| else: | ||
| output = c2 |
There was a problem hiding this comment.
|
it can not enable cudagraph. 😭😭😭😭 |
Co-authored-by: Yineng Zhang <me@zhyncs.com>
Co-authored-by: pansicheng <sicheng.pan.chn@gmail.com>
…ivided by 4. (sgl-project#8449) Co-authored-by: Zhang Kaihong <zhangkaihong.zkh@alibaba-inc.com>
…as/sglang into feat/w4a8_support_ll_deepep
|
The code became too messy after the rebase, so I create a new PR #8464 |

Motivation
Follow #8247 #7762. Support deepep low latency mode for DeepSeek-R1 w4a8 model
Modifications
add forward_cutlass_w4a8_masked for deepep low latency mode
Checklist