fix: propagate quantization mode in QuantizedAllToShardedLinear / QuantizedShardedToAllLinear#3133
Merged
angeloskath merged 1 commit intoml-explore:mainfrom Feb 16, 2026
Conversation
QuantizedAllToShardedLinear and QuantizedShardedToAllLinear did not
accept, store, or forward the `mode` parameter to `mx.quantized_matmul`.
When a non-affine QuantizedLinear (e.g. mode="mxfp8") was converted via
`shard_linear()`, the mode was silently lost and `quantized_matmul`
defaulted to "affine", producing garbage output with no error.
Additionally, MXFP8 does not use biases, but both classes
unconditionally accessed `self["biases"]` which would fail once the mode
fix was applied because `mx.quantize` does not return biases for mxfp8.
Changes:
- Add `mode` parameter (default "affine") to both __init__ methods
- Store `self.mode` and pass it to `mx.quantize` and `mx.quantized_matmul`
- Use `*biases` unpacking to handle modes that don't produce biases
- Use `self.get("biases")` instead of `self["biases"]` for safe access
- Propagate mode from source layer in `from_quantized_linear`
- Include mode in `_extra_repr` output
- Add distributed test for mxfp8 quantized shard_linear
Fixes ml-explore#3132
Co-authored-by: Cursor <cursoragent@cursor.com>
angeloskath
approved these changes
Feb 16, 2026
Member
angeloskath
left a comment
There was a problem hiding this comment.
Thank you that looks great!
I'll merge after the tests pass.
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
Fixes #3132
QuantizedAllToShardedLinearandQuantizedShardedToAllLinearinmlx/nn/layers/distributed.pydo not accept, store, or pass themodeparameter tomx.quantized_matmul. When an MXFP8-quantizedQuantizedLinearis converted viashard_linear(), themodeis silently lost. The resulting sharded layer callsquantized_matmulwithoutmode=, which defaults to"affine"— interpreting FP8 packed weights as affine int8, producing garbage output with no error.Additionally, MXFP8 does not use biases, but both classes unconditionally accessed
self["biases"], which would raiseValueErroronce the mode fix is applied.Changes
modeparameter (default"affine") to both__init__methodsself.modeand pass it tomx.quantizeandmx.quantized_matmul*biasesunpacking to handle modes that don't produce biases (mxfp8, mxfp4)self.get("biases")instead ofself["biases"]for safe access (consistent withQuantizedLinear)modefrom source layer infrom_quantized_linearmodein_extra_reproutputshard_linearImpact
This unblocks tensor parallel inference for all MXFP8-quantized models (and likely mxfp4). Confirmed working: GLM-5 754B (
mlx-community/GLM-5-8bit-MXFP8, mode=mxfp8, group_size=32, bits=8) on 2× M3 Ultra 512GB at ~14 tok/s with tensor parallel.No changes to the affine (default) code path — full backward compatibility.
Test plan
test_shard_lineartest for affine quantization is unchanged and should still passtest_shard_linearverifies mode propagation, biases=None, and output correctnessblackMade with Cursor