Repository navigation
Fix Metal and CUDA affine quantization for all-negative groups - #4775
Merged
zcbenz merged 3 commits intoOct 28, 2026
Merged
Conversation
Contributor
Author
|
@zcbenz Could you take a look at this Metal affine quantization fix? All-negative groups retain the initial zero maximum. This PR fixes the initialization and adds regression coverage. |
zcbenz
approved these changes
Oct 28, 2026
zcbenz
left a comment
Member
There was a problem hiding this comment.
Thanks a lot for locating the bug!
magicnight
pushed a commit
to magicnight/mlx
that referenced
this pull request
Oct 29, 2026
…plore#4775) Co-authored-by: Garry Ling <4526646+lgyStoic@users.noreply.github.com> (cherry picked from commit 32a183e)
1 task
1 task
rcfa
pushed a commit
to cubiculum-ai/mlx
that referenced
this pull request
Nov 26, 2026
…plore#4775) Co-authored-by: Garry Ling <4526646+lgyStoic@users.noreply.github.com> Ported: this fork's Metal affine_quantize started w_max at -max for 1-bit only (bits == 1 ? -Limits<T>::max : 0), from the fork's own one-bit fix. Apple's line, for every bit width, replaces it. The CUDA kernel and the test are as in Apple's commit. (cherry picked from commit 32a183e)
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 #4777
All-negative affine quantization groups on Metal and CUDA retain the initial
0as their maximum, expanding the quantization range and increasing reconstruction error. Initialize the maximum with negative infinity in both kernels:-Limits<T>::maxon Metal and-Limits<float>::max()on CUDA. These floating-point limits return positive infinity, so the new values match the CPU maximum-reduction identity.Add exact-grid regression coverage with an independent absolute error bound of
1e-5, covering negative, positive, mixed, constant-negative, and zero groups. CPU and Metal cover 7 bit widths (1, 2, 3, 4, 5, 6, 8) × 3 group sizes (32, 64, 128) × 5 patterns = 105 groups. CUDA GPU covers its 6 supported widths × 3 group sizes × 5 patterns = 90 groups; only unsupported 1-bit execution is excluded there. CPU retains 1-bit coverage on CUDA-enabled hosts.Validation:
python/tests/test_quantized.pyon GPU: 57 passed, 1 skipped, usingMLX_ENABLE_TF32=0as in the repository test runner.git diff --checkpassed.This patch, tests, validation records, and PR text were prepared with AI assistance.