Fix fp8 MoE on the sparse_matmul path - #4957
Open
gulsumgudukbay wants to merge 1 commit into
Open
Conversation
`get_quantization_dtypes` reads `self.quant.quant_dg` whenever a quantization is set, but only AQT carries one, so a MoE model with `sparse_matmul=True` dies before it ever reaches the gmm: fp8 AttributeError: 'Fp8Quantization' object has no attribute 'quant_dg' nanoo_fp8 AttributeError: 'NANOOFp8Quantization' object has no attribute 'quant_dg' 55c368d already settled what should happen here: schemes that define no gmm quantization rule "execute unquantized GMM". That change handled the qwix side and left this read alone, so fp8 crashes instead of taking the fallback it was given. Read `quant_dg` defensively so it gets there. Expert matmuls running in the compute dtype while the dense layers run fp8 is easy to miss from the config alone, so the layer says so once when it is built. The two new tests carry no hardware marker: the fp8 schemes are emulated in XLA, so a tiny Mixtral trains on CPU in seconds. Both fail before this change.
gulsumgudukbay
requested review from
A9isha,
NuojCheng,
RissyRan,
SurbhiJainUSC,
abhinavclemson,
aireenmei,
bvandermoon,
darisoy,
dipannita08,
gagika,
gobbleturk,
hengtaoguo,
huytransformer,
igorts-git,
jiangjy1982,
khatwanimohit,
michelle-yooh,
richjames0,
shralex,
shuningjin,
vipannalla,
xibinliu and
zxhe-sean
as code owners
August 21, 2026 01:52
There was a problem hiding this comment.
Code Review
This pull request introduces safety checks and integration tests for Mixture of Experts (MoE) models using the sparse_matmul path with FP8 quantization. It adds a warning log when FP8 quantization is combined with sparse_matmul because the expert matmuls remain unquantized on this path. It also updates get_quantization_dtypes to safely access quant_dg using getattr to prevent errors when using FP8 schemes. Finally, it adds integration tests to ensure that the MoE layer builds and trains successfully under these configurations. There are no review comments, so I have no feedback to provide.
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.
Problem
Any MoE model with
sparse_matmul=Trueand an fp8 quantization crashes while the layer is being traced:get_quantization_dtypesreadsself.quant.quant_dgwhenever a quantization is configured, butquant_dgis an AQTnotion — the fp8 classes have never had one. Since
sparse_matmul=Trueis the default, this is what a user hits firstwhen combining fp8 with a MoE model.
Fix
55c368d already decided what should happen for schemes that define no gmm quantization rule: they "execute
unquantized GMM". That change handled the qwix rule and left this read untouched, so fp8 crashes instead of taking the
fallback it was given. Reading
quant_dgdefensively is enough to get it there.Expert matmuls silently running in the compute dtype while the dense layers run fp8 is easy to miss from the config
alone, so the layer logs that once when it is built, pointing at
sparse_matmul=Falsefor anyone who wants the expertsquantized too.
Not addressed here: actually quantizing the gmm for
fp8/nanoo_fp8. That needs kernel support, andfp8_fullremains the scheme that quantizes the expert matmuls.
Tests
Two tests on a tiny Mixtral,
sparse_matmul=Truewithfp8andnanoo_fp8. No hardware marker, since the fp8schemes are emulated in XLA and the failure is backend independent; they run on CPU in about 14s together, and both
fail before this change.
Related
dense_matmulpath, where every quantization fails for an unrelated reason(Linen einsums with no scope to bind to after the NNX migration). The two are independent, but together they make
quantized MoE work on both paths. There is a small textual overlap in
tests/integration/train_tests.py; happy torebase whichever lands second.