Repository navigation
[CPU] Support global scale in qqmm/quantize/dequantize - #4923
Merged
Merged
Conversation
zcbenz
requested changes
Nov 22, 2026
zcbenz
left a comment
Member
There was a problem hiding this comment.
Can you please rebase the PR on main branch?
Yunt1
force-pushed
the
fix/4800-cpu-qqmm-global-scale
branch
from
November 23, 2026 02:12
67a9731 to
fac202d
Compare
zcbenz
requested changes
Nov 23, 2026
zcbenz
left a comment
Member
There was a problem hiding this comment.
I would say the quantize/dequantize should get global scale support first and only then could we properly do tests.
Yunt1
force-pushed
the
fix/4800-cpu-qqmm-global-scale
branch
from
November 23, 2026 06:44
fac202d to
06041db
Compare
Contributor
Author
|
Rebased on |
zcbenz
force-pushed
the
fix/4800-cpu-qqmm-global-scale
branch
from
November 24, 2026 02:03
06041db to
a7035b7
Compare
zcbenz
approved these changes
Nov 24, 2026
1 task
rcfa
pushed a commit
to cubiculum-ai/mlx
that referenced
this pull request
Nov 26, 2026
Co-authored-by: Yunt1 <Yunt1@users.noreply.github.com> Co-authored-by: Cheng <git@zcbenz.com> Ported: Apple's fix for ml-explore/mlx issue 4800 replaces the fork's own, osaurus-ai/mlx PR 31, which applied the nvfp4 global scales the same way (g_x in x's round trip, g_w / 2688 on each block scale) with other names (scale_dec for inv_scale_enc). The fork now has Apple's code. Kept from the fork: QQMatmul returns first for empty inputs (osaurus-ai/mlx PR 30), and the fork's tests. "test qqmm with an unquantized weight" now expects Apple's message, "[QQMatmul] Weights must be quantized.", which the Highway backend's own QQMatmul now raises too. Removed: the fork's dequantize_scale(s, scale_dec), now unused. Not taken from the test file: test_qqmm_matrix_kernels and test_qmv_fast_unaligned_n, context from ml-explore/mlx PRs the fork does not have. (cherry picked from commit 3fe3cbc)
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 #4800.
Summary
QQMatmul::eval_cpu(mlx/backend/cpu/quantized.cpp), handle the optionalglobal_scale_x(inputs[3]) andglobal_scale_w(inputs[4]) tensors whenmode_ == QuantizationMode::Nvfp4 && inputs.size() == 5.fp_quantize_dequantize/dispatch_quantize_dequantizeto applyscale_enc = (448.0f * 6.0f) / global_scale_xbefore quantizing group scales to FP8 E4M3 and divide back byscale_encon dequantization, matching the Metalfp_quantize_dequantizekernel.inv_scale_enc = global_scale_w / (448.0f * 6.0f)intofp_qmm_dispatch(fp_qmm_t_simdandfp_qmm_t) and apply it infloat32before casting to the output dtype to avoid inner-loop overhead andfp16/bf16underflow.test qqmm nvfp4 global scaleintests/ops_tests.cpp) coveringfloat32,float16, andbfloat16.Testing
Built with
-DMLX_BUILD_METAL=OFF -DMLX_BUILD_TESTS=ONon macOS arm64:./build/tests/tests -tc="*qqmm nvfp4*,*quantize*": 2/2 test cases passed (21/21 assertions)./build/tests/tests -sf="*ops_tests.cpp": 95/95 test cases passed (2632/2632 assertions)