fix unit_moe: use loaded weight scales, force activation scale=1.0 - #1456
Draft
yangulei wants to merge 2 commits into
Draft
fix unit_moe: use loaded weight scales, force activation scale=1.0#1456yangulei wants to merge 2 commits into
yangulei wants to merge 2 commits into
Conversation
The previous implementation forced both weight and activation scales to 1.0, which caused accuracy issues. Now only activation scales are forced to 1.0 while weight scales use the loaded values from the model. Signed-off-by: Youlei Yang <youlei.yang@intel.com>
yangulei
requested review from
Wei-Lin-Intel,
czhu15,
mgawarkiewicz-intel,
piotrbocian,
taotod and
wpyszka
as code owners
May 19, 2026 06:45
yangulei
marked this pull request as draft
May 19, 2026 06:46
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes enable_unit_moe behavior for FP8 per-channel MoE on Gaudi by preserving loaded weight scales (to avoid accuracy regressions) while still forcing activation scales to 1.0 in unit-moe mode.
Changes:
- Removed the unit-moe weight “scale absorption” logic from
fp8_channel_moe_prepare_weightsso weights are no longer rescaled to implicitly bake in scales. - Updated
VllmMixtureOfExpertsOpFP8PerChannel.forwardso weight scales always use loaded values, while unit-moe forces activation quantization scale (x_scale) to1.0in the dynamic path.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1227
to
+1231
| if self.enable_unit_moe: | ||
| x_fp8 = torch.ops.hpu.cast_to_fp8_v2(x, 1.0, False, False, torch.float8_e4m3fn)[0] | ||
| x_scale = 1.0 | ||
| else: | ||
| x_fp8, x_scale = dynamic_quant(x) |
Collaborator
|
will this change impacts the runtime performance? |
Collaborator
Author
Not sure. |
Move .item() conversion of weight scales to fp8_channel_moe_prepare_weights (called once at weight load time) to avoid H2D transfers during inference. The pre-computed scalar lists are stored on moe_op and used directly in forward. Signed-off-by: Youlei Yang <youlei.yang@intel.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The previous unit_moe implementation forced both weight and activation scales to 1.0, which caused accuracy issues in some cases.
This fix changes the behavior to:
Changes:
fp8_channel_moe_prepare_weightsthat was absorbing scales into weightsVllmMixtureOfExpertsOpFP8PerChannel.forward: weight scales always use loaded values; only activation scales (x_scale,w2_input_scale) are forced to 1.0 whenenable_unit_moeis set