-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
[Kernel] DeepGemm MoE : Integrate triton permute / unpermute kernels #20903
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[Kernel] DeepGemm MoE : Integrate triton permute / unpermute kernels #20903
Conversation
👋 Hi! Thank you for contributing to the vLLM project. 💬 Join our developer Slack at https://slack.vllm.ai to discuss your PR in #pr-reviews, coordinate on features in #feat- channels, or join special interest groups in #sig- channels. Just a reminder: PRs would not trigger full CI run by default. Instead, it would only run Once the PR is approved and ready to go, your PR reviewer(s) can run CI to test the changes comprehensively before merging. To run CI, PR reviewers can either: Add 🚀 |
This pull request has merge conflicts that must be resolved before it can be |
There was a problem hiding this 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 @varun-sundar-rabindranath, 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 kernel-level optimizations for the Mixture of Experts (MoE) layers, specifically targeting the DeepEPHTPrepareAndFinalize and DeepGEMM combination. The changes aim to improve computational efficiency and memory utilization by refining how workspaces are allocated and by integrating specialized, high-performance permute and unpermute kernels. These enhancements are crucial for scaling MoE models effectively.
Highlights
- DeepGEMM Optimization - Workspace Allocation: Implemented more precise workspace allocation for DeepGEMM by leveraging
local_num_experts
and CPU-sideexpert_num_tokens
. This avoids overallocation and improves memory efficiency for MoE layers, particularly within thedeep_gemm_moe.py
anddeep_gemm_utils.py
modules. - DeepGEMM Optimization - Permute/Unpermute Kernels: Integrated new
ep_scatter
andep_gather
Triton kernels (adapted from LightLLM) to handle the permute and unpermute operations within the DeepGEMM MoE flow. These new kernels, found indeep_gemm_utils.py
, replace the previous_moe_permute
implementation for enhanced performance. - Unified Weight Application and Reduction: Modified the DeepGEMM kernels to internally handle the application of router weights and the final reduction step. This change simplifies the overall MoE pipeline by making the
TopKWeightAndReduceNoOP
class a pass-through, as these operations are now performed directly within the optimized DeepGEMM kernel. - Modular Kernel Interface Enhancements: Updated the core modular kernel interfaces across various MoE implementations (
modular_kernel.py
,fused_moe.py
,batched_deep_gemm_moe.py
,cutlass_moe.py
,fused_batched_moe.py
,triton_deep_gemm_moe.py
) to support the newtopk_weights
andapply_router_weight_on_input
parameters, ensuring compatibility and flexibility for future optimizations.
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 is currently in preview and 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 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.
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 the DeepEP and DeepGEMM MoE kernels, focusing on workspace allocation and leveraging efficient scatter/gather kernels. The changes span multiple files within the fused MoE framework, aiming to improve performance and memory utilization.
Signed-off-by: Varun Sundar Rabindranath <[email protected]>
533d77f
to
25dae3d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add unit tests for this, or do you think this is sufficiently covered by your moe testing framework, @varun-sundar-rabindranath?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The deepgemm_unpermute_and_reduce and deepgemm_moe_permute pass on the functionality to the lightllm ep_scatter / ep_gather kernels. I am fairly confident that those aren't buggy.
But, I'll add some unit test anyways.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we land this without any unit tests for the lightllm kernels ? I can add unit tests in a followup PR. Thanks.
Signed-off-by: Varun Sundar Rabindranath <[email protected]>
Purpose
Optimizations for DeepEPHTPrepareAndFinalize + DeepGEMM combination.
Optimizations
Torch trace for a single modular_kernel execution:
python3 -m tests.kernels.moe.modular_kernel_tools.profile_modular_kernel --pf-type DeepEPHTPrepareAndFinalize --experts-type DeepGemmExperts --quant-dtype torch.float8_e4m3fn --block-shape 128 128 --torch-trace-dir-path ./torch_trace_files/ --topk 4
main
+ #20725: - m64_0_trace.jsonthis PR
(changes on top of main + 20725) - m64_0_trace.jsonFrom the torch traces, you could see that using dedicated scatter / gather kernels results in much lesser torch ops.
Test Plan
pytest -s tests/kernels/moe/test_modular_kernel_combinations.py
- all tests passe2e :
VLLM_FUSED_MOE_CHUNK_SIZE=64 VLLM_ALL2ALL_BACKEND="deepep_high_throughput" VLLM_USE_DEEP_GEMM=1 vllm serve Qwen/Qwen3-30B-A3B-FP8 --trust-remote-code --enable-expert-parallel --data-parallel-size 2 --port 9010
lm_eval --model local-completions --tasks gsm8k --model_args model=Qwen/Qwen3-30B-A3B-FP8,base_url=http://127.0.0.1:9010/v1/completions,num_concurrent=30,max_retries=3 --limit 100
Test Result
Performance
commands:
VLLM_ALL2ALL_BACKEND="deepep_high_throughput" VLLM_USE_DEEP_GEMM=1 vllm serve Qwen/Qwen3-30B-A3B-FP8 --trust-remote-code --enable-expert-parallel --data-parallel-size 2 --port 9010 --no-enable-prefix-caching
python3 ./benchmarks/benchmark_serving.py --model Qwen/Qwen3-30B-A3B-FP8 --dataset-name sharegpt --sharegpt-output-len 1 --port 9010 --dataset-path ./ShareGPT_V3_unfiltered_cleaned_split.json`
This PR
main
(Optional) Documentation Update