Skip to content

fix(macaq): stop the amplitude floor flushing representable values (#5627) - #5666

Merged
Qubitium merged 1 commit into
mainfrom
fix/5627-macaq-amplitude-floor
Nov 20, 2026
Merged

Qubitium merged 1 commit into
mainfrom
fix/5627-macaq-amplitude-floor

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

mxfp4_rtn_signed_index clamped every block peak to 1e-12 before taking
floor(log2(amax)). That conflates a genuinely small block with a zero block:
a constant block of 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, 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 actual
range (-127..127) before the codes are computed, as the issue suggests.
Non-finite peaks are left untouched so the packer still writes the 0xFF NaN
byte. 2 ** exponent replaces exp2 for the scale because exp2(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.py follow the same change.

Tests

Fixes #5627.

…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.
@Qubitium
Qubitium merged commit 5d2e3d1 into main Nov 20, 2026
6 checks passed
@Qubitium
Qubitium deleted the fix/5627-macaq-amplitude-floor branch November 20, 2026 05:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] MACaQ MXFP4's 1e-12 amplitude floor flushes exactly representable nonzero weight and activation blocks

1 participant