-
Notifications
You must be signed in to change notification settings - Fork 3.1k
[WIP] Introduce flashinfer allreduce in MoE TP #7946
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?
Conversation
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 @yuan-luo, 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 a performance optimization for Mixture-of-Experts (MoE) layers in SGLang by integrating FlashInfer's custom allreduce operation. This change aims to replace the default PyTorch distributed all-reduce for specific scenarios, particularly for smaller token counts, to potentially achieve better communication efficiency and throughput in distributed MoE models.
Highlights
- FlashInfer Allreduce Integration: A new module (
python/sglang/srt/layers/flashinfer_comm.py
) has been introduced to encapsulate FlashInfer's custom allreduce operation, including necessary workspace management for inter-process communication (IPC). - Conditional MoE Optimization: The Fused Mixture-of-Experts (MoE) layer (
python/sglang/srt/layers/moe/fused_moe_triton/layer.py
) is updated to conditionally utilize this new FlashInfer allreduce forfinal_hidden_states
. This optimization is applied when FlashInfer is available, the new feature flag is enabled, and the input token count is 128 or less, potentially improving performance over standardtorch.distributed.all_reduce
. - New Configuration Option: A new server argument
--enable-flashinfer-allreduce
has been added topython/sglang/srt/server_args.py
, allowing users to enable or disable this specific FlashInfer allreduce optimization for MoE layers.
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 FlashInfer's custom all-reduce kernel to replace torch.distributed.all_reduce
for MoE layers, aiming for performance improvements. The changes include a new file flashinfer_comm.py
with the wrapper implementation, and modifications to fused_moe_triton/layer.py
to conditionally use this new kernel. The server arguments are also updated to control this feature.
My review has identified several critical issues in the new flashinfer_comm.py
file that need to be addressed. These include function signature mismatches, incorrect function calls that would lead to runtime errors, and the use of random dummy data in the core computation which would produce incorrect results. There is also a potential resource leak in the workspace manager. I have provided specific suggestions to fix these issues.
Please note this PR needs to use B200, otherwise will encounter this error.
|
c2ec629
to
8fd70ad
Compare
54b40de
to
15388b1
Compare
Encounter some problem in B200:
|
15388b1
to
0bc6068
Compare
0bc6068
to
8d1bb24
Compare
8d1bb24
to
7cabb5d
Compare
7cabb5d
to
b1d634f
Compare
Encounter some issues on H20. Flashinfer can't find cuda_fp4.h file.
|
I'll verify it on B200. |
b1d634f
to
50b914e
Compare
After install flashinfer_python-0.2.14.post1 in H20, it move forward:
Hopper passed cuda graph, but the result is incorrect. Inside the custom_all_reduce API, there's a flag_value, it needs to incremented by 1 for each AR. Otherwise the result is incorrect.
|
Check the flashinfer code, in trt-llm wrapper, it use the flag in this way,
So I changed the next_flag() in this way, but still incorrect.
|
Adding related PR:flashinfer-ai/flashinfer#1096 |
I tested that #6619 has better performance on custom_allreduce than trtllm-custom-allreduce used in flashinfer. |
Motivation
Introduce flashinfer custom allreduce into SGLang Fused MoE, replacing torch distributed all_reduce.
Modifications
Checklist