Keep qwix out of tpu-inference's fused MoE kernel and pre-quantize weights - #5136
Open
sierraisland wants to merge 1 commit into
Open
Keep qwix out of tpu-inference's fused MoE kernel and pre-quantize weights#5136sierraisland wants to merge 1 commit into
sierraisland wants to merge 1 commit into
Conversation
sierraisland
requested review from
A9isha,
NuojCheng,
RissyRan,
SurbhiJainUSC,
abhinavclemson,
aireenmei,
bvandermoon,
darisoy,
dipannita08,
gagika,
gobbleturk,
hengtaoguo,
huytransformer,
igorts-git,
jiangjy1982,
jshin1394,
khatwanimohit,
liudangyi,
michelle-yooh,
richjames0,
shralex,
shuningjin,
vipannalla,
xibinliu and
zxhe-sean
as code owners
September 3, 2026 22:34
There was a problem hiding this comment.
Code Review
This pull request implements weight quantization for the fused MoE kernel under the qwix framework, adding helper functions to retrieve quantization rules, quantize expert weights, and bypass qwix interception during execution. It also introduces unit tests to verify these changes. The review feedback suggests renaming the quantized weight variables in moe.py for clarity and using jnp.expand_dims instead of jnp.reshape in quantizations.py to make the dimension expansion more explicit.
igorts-git
approved these changes
Sep 3, 2026
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
SurbhiJainUSC
approved these changes
Sep 3, 2026
sierraisland
force-pushed
the
sierraq/vllm-fused-moe-qwix-boundary
branch
from
September 3, 2026 23:56
e3a288b to
4394c98
Compare
khatwanimohit
approved these changes
Sep 4, 2026
sierraisland
force-pushed
the
sierraq/vllm-fused-moe-qwix-boundary
branch
from
September 4, 2026 01:03
4394c98 to
7b8a2e9
Compare
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.
Description
This PR addresses the compile-time Mosaic accumulator crash when serving MaxText MoE models via vLLM (
attention=vllm_rpa) underuse_qwix_quantization=Truewith an FP8 recipe:Context & Prior PRs
Initially, the attempt is in
tpu-inferenceby wrappinggmm_v2withdisable_interceptionsand forcingacc_dtype=jnp.float32globally. However, as noted during review, hardcodingf32accumulator insidetpu-inferenceimpacts performance for native models. The root cause lies on the MaxText side whereqwixleaks into the Pallas/tokamax kernel body and weights were unquantized.@wenxindongwork proposed fixing this at the caller site in MaxText by disabling
qwixinterception around the fused kernel invocation and pre-quantizing weights with blockwise/channelwise scales viaquantize_weight_for_fused_moe.Changes in this PR
This PR incorporates the solution from #5114 and further hardens it based on review feedback:
fused_moe_func:Wraps the call in
qwix.disable_interceptionsso that tokamax's tiled matmuls launched viapl.kernelare not rewritten into fake-quantizedbf16accumulators.When the active rule covers
gmm, weights are pre-quantized tofloat8_e4m3fn(orint8) with[E, blocks, 1, N]scales usingqpl.quantize.Uses
getattr(rule, ...)with fallback defaults forweight_qtype,tile_size, andweight_calibration_methodto prevent potentialAttributeErrors when custom rules or test mocks are provided.Includes full unit tests in
tests/unit/fused_moe_qwix_test.py, including verification of fallback behavior for minimal/mock rules.Tests
Qwen/Qwen3.5-35B-A3BMaxTextForCausalLM(MODEL_IMPL_TYPE=flax_nnx)quantization='fp8_e4m3',use_qwix_quantization=True,attention='vllm_rpa'MLIRErrororEngineCorecrashes.Checklist
Before submitting this PR, please make sure (put X in square brackets):
gemini-reviewlabel.