-
-
Notifications
You must be signed in to change notification settings - Fork 11.2k
[Feature] Add MetaShufflingMoE as Optional MoE backend to Llama4 models #27891
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?
[Feature] Add MetaShufflingMoE as Optional MoE backend to Llama4 models #27891
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 You ask your reviewers to trigger select CI tests on top of 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 If you have any questions, please reach out to us on Slack at https://slack.vllm.ai. 🚀 |
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 MetaShufflingMoE as a new, optional Mixture-of-Experts backend for Llama4 models, aimed at improving performance, particularly Time to First Token (TTFT). The changes include adding the necessary environment variables, the MetaShufflingMoE layer implementation, and its integration into the Llama4 model.
My review has identified a few critical issues in the new MetaShufflingMoE implementation that could lead to runtime crashes, especially in scenarios not covered by the current tests (e.g., when used without a shared expert). I've provided code suggestions to fix these issues. Overall, the feature is a valuable addition, and with these fixes, it should be more robust.
| if envs.VLLM_META_SHUFFLING_GEMM_BACKEND == "cutlass": | ||
| scatter_add_dense_tokens( | ||
| out_tokens=shared_out, | ||
| in_tokens=routed_out, | ||
| token_indices=route_info.token_indices, | ||
| valid_token_count=route_info.num_routed_tokens, | ||
| ) | ||
| return shared_out |
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.
When shared_out is None and the cutlass backend is used, scatter_add_dense_tokens is called with out_tokens=None, which will likely cause a crash. Subsequently, return shared_out would return None, leading to a None.view() call in the caller, which will also crash. This can happen when MetaShufflingMoE is used without a shared expert.
To fix this, we should create a zero tensor for shared_out if it's None. The shape can be derived from scores and routed_out.
| if envs.VLLM_META_SHUFFLING_GEMM_BACKEND == "cutlass": | |
| scatter_add_dense_tokens( | |
| out_tokens=shared_out, | |
| in_tokens=routed_out, | |
| token_indices=route_info.token_indices, | |
| valid_token_count=route_info.num_routed_tokens, | |
| ) | |
| return shared_out | |
| if envs.VLLM_META_SHUFFLING_GEMM_BACKEND == "cutlass": | |
| if shared_out is None: | |
| shared_out = torch.zeros( | |
| scores.shape[0], | |
| routed_out.shape[-1], | |
| dtype=routed_out.dtype, | |
| device=routed_out.device, | |
| ) | |
| scatter_add_dense_tokens( | |
| out_tokens=shared_out, | |
| in_tokens=routed_out, | |
| token_indices=route_info.token_indices, | |
| valid_token_count=route_info.num_routed_tokens, | |
| ) | |
| return shared_out |
Signed-off-by: Zoey Sun <[email protected]>
|
This pull request has merge conflicts that must be resolved before it can be |
6acfc0e to
4609478
Compare
Purpose
Add MetaShufflingMoE as an Optional MoE backend for Llama4 models.
This PR adds only the TP support for bf16 models. It has basic skeleton code to prepare for future support of EP and fp8 models.
MetaShufflingMoE shows better TTFT performance at 1k and 2k input len
--request-rate 4 --random-input-len 1024 --random-output-len 128 --num-prompts 1000
--request-rate 4 --random-input-len 2048 --random-output-len 128 --num-prompts 1000
Test Plan
Running lm_eval
HF_HUB_DISABLE_XET=1 with-proxy VLLM_USE_MODELSCOPE=False lm_eval --model vllm --model_args "pretrained=meta-llama/Llama-4-Scout-17B-16E-Instruct,trust_remote_code=True,tensor_parallel_size=8,max_model_len=32768" --tasks gsm8k --num_fewshot 8 --batch_size 128Baseline results
Test Result
Cutlass Backend
HF_HUB_DISABLE_XET=1 with-proxy VLLM_USE_MODELSCOPE=False VLLM_USE_META_SHUFFLING_MOE=1 lm_eval --model vllm --model_args "pretrained=meta-llama/Llama-4-Scout-17B-16E-Instruct,trust_remote_code=True,tensor_parallel_size=8,max_model_len=32768" --tasks gsm8k --num_fewshot 8 --batch_size 128Triton Backend
HF_HUB_DISABLE_XET=1 with-proxy VLLM_USE_MODELSCOPE=False VLLM_USE_META_SHUFFLING_MOE=1 VLLM_META_SHUFFLING_GEMM_BACKEND=triton lm_eval --model vllm --model_args "pretrained=meta-llama/Llama-4-Scout-17B-16E-Instruct,trust_remote_code=True,tensor_parallel_size=8,max_model_len=32768" --tasks gsm8k --num_fewshot 8 --batch_size 128Essential Elements of an Effective PR Description Checklist
supported_models.mdandexamplesfor a new model.