Round mxfp8 block scales up to avoid saturation - #4353
Open
dhiltgen wants to merge 1 commit into
Open
Conversation
Member
|
Can you rebase on main? Your branch seems to be ancient. |
dhiltgen
force-pushed
the
mxfp8-mx-scale-no-clip
branch
from
August 19, 2026 20:26
51e8524 to
e73e87d
Compare
Contributor
Author
|
Oops, cherry-picked on the wrong base, fixed. |
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.
Proposed changes
MX block scales are
amax / max_element, converted to E8M0. Metal and the CPUfallback round to nearest, which lands below the request about half the time;
the block's largest elements then fall outside the element format and saturate.
CUDA already rounds up —
cutlass::float_ue8m0_tusescvt.rp.satfinite.ue8m0x2.f32on device and an explicit exponent bump on host,for both 4- and 8-bit. So
mx.quantizeon an MX mode gives different resultsper backend today. This aligns Metal and CPU with CUDA; no CUDA code changes.
For mxfp8, an in-range element loses at most half a step, 6.25%; anything
larger is saturation. On 512x32 synthetic blocks:
29.27% is
1 - 1/sqrt(2), the worst case for round-to-nearest in log2 space.CUTLASS v4.3.5 on the same inputs: max
amax/scale447.88, nothing over 448.Real weights behave the same. On a Gemma 4 26B expert tensor,
amax/scalespans 318-632 against a 448 ceiling, and rel RMSE goes 7.11% -> 2.68%.
mxfp4 improves too, by less: on four Gemma 4 26B tensors, rel RMSE drops
0.8-2.5% relative and block-maximum clipping goes from about half of all blocks
to none. Round-up costs some underflow there, but it is the smaller effect.
Fixed in all three implementations: the
ops.cppfallback (the path CPU takesfor
mx.quantize),fp_quantize_dequantize, and both Metal quantize kernels.The test asserts the 6.25% property rather than a golden number and pins no
device. It fails on
mainand on the 0.31.0 wheel, and passes here.Checklist
Put an
xin the boxes that apply.pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes