Fix EPLB + FP4 Quantization Compatibility Issue#13715
Fix EPLB + FP4 Quantization Compatibility Issue#13715Fridge003 merged 5 commits intosgl-project:mainfrom
Conversation
Summary of ChangesHello @shifangx, 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 resolves a compatibility issue arising from the simultaneous use of expert-parallel load balancing and FP4 quantization within Mixture-of-Experts models. The fix involves refining the parameter selection logic in the Highlights
Using Gemini Code AssistThe 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 by creating a comment using either
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 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. 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
|
There was a problem hiding this comment.
Code Review
This pull request addresses an issue related to --enable-eplb and fp4 by correctly filtering parameters in the get_moe_weights method. The change is applied consistently across multiple model files, which is good. However, this has led to significant code duplication, as the get_moe_weights method is now identical in seven different files. I recommend refactoring this duplicated logic into a common base class. This would greatly improve the maintainability of the codebase, making future changes to this logic much simpler. I've added a specific comment with a suggestion on how to implement this refactoring.
Can you remind me why the swizzled shape has no expert dim? |
|
I got an error of: Here is my script: https://gist.github.com/kaixih/32bdc4fec4feabe9305d1acb2e1f96db (adapted from your slack messge) |
|
Setting SGLANG_MOE_NVFP4_DISPATCH=1 for prefill node should solve this. |
|
Perhaps it would be better for a colleague who is familiar with the fp4 weight format to handle this issue. |
The description was generated by AI and may not be accurate. |
|
Just tried this fix in 0.5.5.post.2 container with script here except I have to manually start router and client. I didn't obverse any issue running e2e. |
78772fa to
02ee723
Compare
dd53378 to
ee86ef4
Compare
|
/tag-and-rerun-ci |
Co-authored-by: Shu Wang <shuw@nvidia.com>
Co-authored-by: Shu Wang <shuw@nvidia.com>
Note: The following description was generated by AI and may not be accurate.
EPLB + FP4 Quantization Compatibility Issue Analysis and Fix
Problem Description
When using EPLB (Expert-based Load Balancing) for expert rebalancing, the system crashes with an
AssertionError:Error Location:
sglang/python/sglang/srt/eplb/expert_location_updater.py:176Environment Configuration
--enable-eplband--expert-distribution-recorder-mode statRoot Cause
When using FP4 quantization,
ModelOptNvFp4FusedMoEMethodcreates some special parameters whose shapes do not meet the requirements for EPLB expert migration:1. Global Expert Scale Parameters
In
sglang/python/sglang/srt/layers/quantization/modelopt_quant.py:1240-1252:Problem:
num_experts(288), notnum_local_physical_experts(6)_sglang_require_global_experts = True, indicating they are global parameters2. Swizzled Blockscale Parameters
In
sglang/python/sglang/srt/layers/quantization/modelopt_quant.py:1197and1214:The
swizzle_blockscalefunction reshapes the tensor, losing the expert dimension:Problem:
w13_weight_scaleshape:[num_local_experts, M, K][M_padded, K_padded]- missing expert dimension3. Why Are These Parameters Included?
In
deepseek_v2.py, theget_moe_weights()method returns all expert parameters:This includes all parameters registered via
register_parameter, including the problematic parameters above.Code Call Chain
Where
routed_experts_weights_of_layercomes from:Solution
Modify the
get_moe_weights()method in all MoE models to filter out parameters that should not participate in EPLB migration:Motivation
Modifications
Accuracy Tests
Benchmarking and Profiling
Checklist