[NVIDIA] Fix num_experts in modelopt_quant#8811
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @wenscarl, 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 PR provides a hotfix to correctly set the num_experts attribute in the modelopt_quant module. Previously, layer.num_experts was being incorrectly set to the local number of experts, causing dimension inconsistencies with the trtllm_fp4_block_scale_moe API which expects the global number of experts. My change ensures layer.num_experts reflects the total global experts by multiplying the local expert count by the expert parallel world size.
Highlights
- Corrected num_experts calculation: I've updated the create_weights function in modelopt_quant.py to correctly calculate layer.num_experts. Instead of assigning the local num_experts directly, it now multiplies it by the result of get_moe_expert_parallel_world_size() to reflect the global number of experts.
- Dependency for parallel world size: To facilitate the correct calculation, I've added an import for get_moe_expert_parallel_world_size from sglang.srt.distributed.
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 provides a hotfix for an issue in modelopt_quant related to Mixture-of-Experts (MoE) models. The change correctly calculates the global number of experts by multiplying the number of local experts with the expert parallel world size. This resolves a dimension mismatch issue with the trtllm_fp4_block_scale_moe API, which expects the global number of experts. The fix is correct and well-targeted. I approve these changes.
|
It is a simple change to enable EP fp4 moe, which might affect the original TP case. So can we have both EP and TP accuracy numbers after this change? @wenscarl |
|
We can also perhaps test shared experts fusion with |
pavanimajety
left a comment
There was a problem hiding this comment.
LGTM, thanks for making the changes!
kaixih
left a comment
There was a problem hiding this comment.
Noticed the accuracy results are already provided in the description. Approved. Thx.
|
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
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
5ac4fcb to
85e68e2
Compare
A hotfix for #8779.
The trtllm_fp4_block_scale_moe API checks for the routing_logits dim to be consistent with num_experts(global). But previously at create_weight, the num_experts is overwritten by num_local_experts.
cc. @kushanam @zhyncs
Motivation
Modifications
Accuracy Test
With EP enabled:
Accuracy: 0.963
Invalid: 0.000
Latency: 697.093 s
Output throughput: 139.871 token/s
With TP enabled
Accuracy: 0.956
Invalid: 0.000
Latency: 636.827 s
Output throughput: 152.779 token/s
Benchmark & Profiling
With shared expert fusion
Accuracy: 0.963
Invalid: 0.000
Latency: 633.068 s
Output throughput: 154.200 token/s
Checklist