Repository navigation
Integrate upstream Metal fixes (affine quantization of all-negative groups, FFT over many axes) - #77
Merged
Merged
Conversation
…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)
(cherry picked from commit 8feb9fe)
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.
Branch
apple/r4-metal, 2 commits onorigin/main23f364e (tip c257e3b).Two Metal bug fixes from ml-explore/mlx main: ml-explore#4775, one of the fixes in the fork's own quantization kernels that the
first intake rounds left for later, and ml-explore#4968, which landed on 2026-11-26. The code is Apple's and its contributors':
each commit is a
git cherry-pick -xof the upstream commit, with the upstream author kept and the(cherry picked from commit …)line recording provenance. ml-explore#4775 is ported (below); ml-explore#4968 applies cleanly.test_affine_quantize_signed_groups(bits 1 to 8, group sizes 32 to 128; 1-bit is skipped on CUDA).fftn,ifftn,rfftnandirfftnover four or more axes reused their temporary buffers in place also for sizes whose kernels replace the output buffer (size 1, and the multi-upload Bluestein path), and gave wrong results. Addstest_fftn_many_axes.The port
mlx/backend/metal/kernels/quantized.h: this fork's kernel already started the maximum at -max, but for1-bit only (
bits == 1 ? -Limits<T>::max : 0, from the fork's own one-bit fix). Apple's line, which does it forevery bit width, replaces that line and its 1-bit comment. The CUDA kernel and the test are as in Apple's commit.
The commit message says so.
Not included
gated_delta_update_nax.h; the rest of PR 4594 is in the gated-delta VJP code of PR 4565, which comes with that.PR 4787), which this fork holds back.
M6) is already in the fork.
Validation
Compared with
main(23f364e), built and run the same way:test_fft,test_quantized), on the GPU and withDEVICE=cpu: GPU 73 pass, 3 skip, 2 fail; CPU 65 pass, 10 skip, 1 fail, 2 errors.main: GPU 71 pass,3 skip, the same 2 failures; CPU 63 pass, 10 skip, the same failure and errors. The branch adds
test_affine_quantize_signed_groupsandtest_fftn_many_axes. Withmain's build, both fail on the GPU; on theCPU, where quantization and the FFT were right, both pass.
main's own failures: on the GPUtest_qmm_mid_mandtest_qmm_splitk_precision; on the CPUtest_fft_too_large, andtest_gather_qmm_global_scaleandtest_qqmm_global_scale_matrix_kernels(errors: the CPU qqmm global scales,which osaurus-ai/mlx PR 57 brings).
main.tests/tests): 390 of 390 cases on the CPU and on Metal, asmain.way: GCC, Debug, Highway,
DEVICE=cpu,python/testsmodule by module, torch 2.15 for the CPU), then CI'sdistributed step (
mlx.launch -n 8 python/tests/ring_test_distributed.py): 883 pass, 92 skip, 2 fail; ring 8 of 8 ranks pass (14 tests).main: 881 pass, 92 skip,2 fail, ring 8 of 8 ranks pass (14 tests). The two failures are
main's own:test_compile_sigmoid_matches_eager(bfloat16: the compiled CPU sigmoid is less accurate than the eager Highway kernel) and bfloat16
test_torch_conv_2D, where torch 2.15's own aarch64 bfloat16 conv2d is wrong.main.quantized/affine_quantize.cucompiles with no errors, onmainand on this branch. Not run.its Linux and macOS jobs.
Validation of the batch in
sharedThis batch has five PRs:
apple/r4-python,apple/r4-cuda,apple/r4-distributed,apple/r4-metalandfix/erf-relative-accuracy. Merged onmain23f364e with the open osaurus-ai/mlx PRs 57 to 73 and their two overlapresolutions, they give mlx 3898182. The five merge with no conflict, with each other and with PRs 57 to 73.
vmlx-swift c0f6255f0 builds on mlx 3898182 (it is osaurus-ai/vmlx-swift
main06e3aa2c7 with our open vmlx-swiftpatches). Built and run, compared with
main:main390 of390). vmlx-swift builds. Its suite (
swift test --no-parallel, 1046 tests) fails no test that passes on vmlx-swiftmain9bda77d3.main412 of 412). vmlx-swift's Linux CI steps pass:
VMLXLinuxTests37 of 37, and the CPU kernel tests 61 of 61 at boththread settings.
DEVICE=cpu,python/testsmodule by module, torch 2.15 for the CPU), then CI's distributed step(
mlx.launch -n 8 python/tests/ring_test_distributed.py):main881 pass, 92 skip, 2 fail; the batch 915 pass, 96 skip, 2 fail.main882 pass, 92 skip, 1 fail; the batch 916 pass, 96 skip, 1 fail.mainon arm64: 14).mainfails on the batch. The failures aremain's own:test_compile_sigmoid_matches_eager(bfloat16: the compiled CPU sigmoid is less accurate than the eager Highwaykernel) and, on arm64 only, bfloat16
test_torch_conv_2D, where torch 2.15's own aarch64 bfloat16 conv2d iswrong.
mainthat fail at random:test_double.TestDouble.test_unary_ops: float32erfagainst float64 atrtol1e-5, failing in 16 of 200random draws on Linux arm64.
fix/erf-relative-accuracyfixes it.test_ops.TestOps.test_divmod: about 1% of runs. PR 72 fixes it.test_async_eval_error_in_synchronizeon amd64: about 1 run in 5 onmain. It passed in this run.its Linux and macOS jobs.
🤖 Generated with Claude Code