Repository navigation
fix(quant): keep E8M0/MXFP4/EXL3 pow exponents in float32 (#5297) - #5298
Merged
Merged
Conversation
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.
Fixes #5297. Regression from #5274 (which fixed #5263).
Problem
#5274 replaced
torch.ldexp(torch.ones_like(x, dtype=torch.float32), e)withtorch.pow(2.0, e). A Python float base with an integer exponent tensorfollows the process default dtype, so the decoders returned whatever
torch.get_default_dtype()happened to be:The default dtype is float16 for the whole process while any
from_pretrained/from_configruns (transformers'local_torch_dtype), so aconcurrent
GPTQModel.load(..., dtype=torch.float16)silently zeroed MXFP4 /E8M0 source weights during another thread's dequantize.
Change
Widen the exponent to float32 before
powat every site #5274 converted:quantization/dtype.py::decode_e8m0_scaleutils/kimi_k3.py::decode_mxfp4nn_modules/exllamav3.py::ExllamaV3Linear._prescale_from_row_amax(samehazard:
2**116clipped to inf under an fp16 default, zeroing a wide bf16row's pre-scale)
The result is float32 again, bit-exact over the whole E8M0 range (including the
denormal
2**-127thatexp2rounds one ulp low on CUDA). The TT block-floatencoders were checked and already cast their exponents.
Tests
New
tests/test_e8m0_default_dtype_5297.py(20 nodes) parametrizes the processdefault dtype over float32 / bfloat16 / float16 / float64, on CPU and CUDA:
decode_e8m0_scalereturns float32 and matches the float32 baseline for all256 bytes, with
2**-127and2**127exact;decode_mxfp4returns the same weights as the float32 baseline for extremeE8M0 scales (including
2**23,infunder fp16);3e38bf16 row finite (2**116).9 of the 20 fail on
main(bfloat16 changes the dtype, float16/float64 changethe values or the dtype). The default dtype is restored by a fixture.
Existing decoders' suites still pass: 120 passed, 13 skipped
(
test_ldexp_cross_device_5263,test_kimi_k3_support,test_nvfp4_candidate_overflow,test_model_dequant_fp8,test_exl3_wide_input).