-
Notifications
You must be signed in to change notification settings - Fork 193
Fix BMM style MoE export in fp8_pc_pt recipe #515
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
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #515 +/- ##
==========================================
+ Coverage 73.44% 73.46% +0.02%
==========================================
Files 180 180
Lines 18147 18161 +14
==========================================
+ Hits 13328 13342 +14
Misses 4819 4819 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Zhiyu Cheng <[email protected]>
4bb85d1 to
fbd5417
Compare
Signed-off-by: Zhiyu Cheng <[email protected]>
| if weights_scaling_factor.shape[-1] == weight.shape[-1]: | ||
| # (num_experts, input_dim) -> (num_experts, 1, input_dim), BMM-style | ||
| return (weight / weights_scaling_factor.unsqueeze(-2)).to(torch.float8_e4m3fn) | ||
| elif weights_scaling_factor.shape[-1] == weight.shape[-2]: |
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.
do we also need to check weights_scaling_factor.shape[0] == weight.shape[0]
|
Could you share what models have you tested? |
| # Per-expert scaling only: (num_experts,) -> (num_experts, 1, 1) | ||
| return (weight / weights_scaling_factor[:, None, None]).to(torch.float8_e4m3fn) | ||
| elif weights_scaling_factor.dim() == 2: | ||
| # Per-channel scaling: check which dimension matches |
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.
Can we add a check here to make sure weight.shape[-1] != weight.shape[-2]?
What does this PR do?
Type of change: Bug fix
Overview: The Llama-4-Scout-17B-16E-Instruct model uses Llama4TextExperts, which stores expert weights in a BMM (batch matrix multiply) layout: (num_experts, input_dim, output_dim). This is different from standard MoE models. The FP8_PC_PT (FP8 per-channel per-token) quantization code didn't handle this layout properly, causing shape mismatches.
Usage
Testing
Before your PR is "Ready for review"
Additional Information