Repository navigation
fix(macaq): stop the amplitude floor flushing representable values (#5627) - #5666
Merged
Merged
Conversation
…5627) `mxfp4_rtn_signed_index` clamped every block peak to 1e-12 before `floor(log2(amax))`. A nonzero block with peak 2**-50 is exactly representable as E2M1 value 4 times the E8M0 scale 2**-52 (byte 75), but the floor moved the scale to 2**-42 and rounded every code to zero. The W4A4 activation quantizers carried the same floor at 1e-20. Only an exact-zero block now takes the historical floor, so its packed byte does not move. A nonzero peak goes straight to the E8M0 exponent, which is clamped to the format's real range (-127..127) before the codes are computed; non-finite peaks are left alone so the packer still emits the 0xFF NaN byte. `2 ** exponent` replaces `exp2` because the latter rounds 2**-127 one ulp low on CUDA and would change the codes of a block at the bottom of the range. Regress the issue's weight and W4A4 repros, every power of two down to 2**-128, the exponent screen, zero-block byte stability, and the accelerated activation kernels.
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.
Summary
mxfp4_rtn_signed_indexclamped every block peak to1e-12before takingfloor(log2(amax)). That conflates a genuinely small block with a zero block:a constant block of
2**-50is exactly representable as E2M1 value4timesthe E8M0 scale
2**-52(byte 75), but the floor moved the scale to2**-42and rounded every code to zero. The W4A4 activation quantizers carried the
same floor at
1e-20, in Torch and in the Triton kernels.Only an exact-zero block now takes the historical floor, so its packed
scale byte does not move. A nonzero peak goes straight to
floor(log2(amax)) - 2, and the finite exponent is clamped to E8M0's actualrange (
-127..127) before the codes are computed, as the issue suggests.Non-finite peaks are left untouched so the packer still writes the
0xFFNaNbyte.
2 ** exponentreplacesexp2for the scale becauseexp2(2**-127)rounds one ulp low on CUDA and would change the codes of a block at the bottom
of the range; the dequantizers and the reference implementation in
tests/test_macaq.pyfollow the same change.Tests
tests/test_macaq_amplitude_floor_5627.py(new, 14 passed): both reprosfrom the issue (scale byte 75 / decoded
2**-50, W4A4 forward1.0), everypower of two from
2**-39down to2**-128round-tripping exactly, theexponent-screen path, activation quantizer, zero-block byte stability, a
zero block next to a tiny block, and the Triton activation quantizers.
tests/test_macaq.py tests/test_macaq_*.py: 171 passed, 1 skipped.upstream/main(which alreadycontains the sibling [BUG] MACaQ W4A16 Torch narrows finite MXFP4 weights before the dot: a bias-free FP16 output is NaN instead of 16384 #5631/fix(macaq): keep the wide bias through pack and load (#5632) #5656 MACaQ changes): 113 passed, 1 skipped.
uvx [email protected] check gptqmodel tests: All checks passed!Fixes #5627.