Skip to content

[CPU] Fix accumulation precision in fp quantized matmul - #4879

Merged
zcbenz merged 1 commit into
ml-explore:mainfrom
kadyrbekovhamit-cyber:fix-cpu-fp-qmm-accum
Nov 22, 2026
Merged

zcbenz merged 1 commit into
ml-explore:mainfrom
kadyrbekovhamit-cyber:fix-cpu-fp-qmm-accum

Conversation

@kadyrbekovhamit-cyber

Copy link
Copy Markdown
Contributor
  • CPU FP kernels (mxfp4, ​​nvfp4, mxfp8) in quantized_matmul and gather_qmm
    previously performed accumulation in bf16/fp16;

  • this fix switches to float32 accumulators, consistent with the approach used for affine in [CPU] Fix accumulation precision in affine quantized matmul #4803;

  • result: bf16, K=4096, mxfp4: CPU 2.6e-2 → 3.0e-3 (GPU 3.1e-3);

  • added a new test: test_fp_qmm_accumulation_precision;

  • tests passed on the CPU build; I didn't create a Metal build.

  • ☑️ I understand it is strictly prohibited to use AI to write PR description

  • AI usage disclosure: AI helped find the error

@zcbenz
zcbenz marked this pull request as ready for review November 22, 2026 03:46
@zcbenz zcbenz changed the title CPU fp qmm: accumulate sums in float32, similar to #4803 for affine; … [CPU] Fix accumulation precision in fp quantized matmul Nov 22, 2026
@zcbenz
zcbenz force-pushed the fix-cpu-fp-qmm-accum branch from 16733d5 to 33b0930 Compare November 22, 2026 03:55
@zcbenz
zcbenz merged commit 07fff01 into ml-explore:main Nov 22, 2026
24 checks passed
rcfa pushed a commit to cubiculum-ai/mlx that referenced this pull request Nov 26, 2026
)

Ported onto the fork's nvfp4 global scales (osaurus-ai/mlx PR 31):
scale_dec stays the last argument and acc follows transposed_w. The
row accumulator acc is used for GatherQMM and QQMatmul too. Of the
test changes, only test_fp_qmm_accumulation_precision is taken; its
context, test_qmv_affine_bias_sum_precision, is not in the fork.

The fork's Highway backend (quantized_highway_backend.cpp, used when
MLX_USE_HIGHWAY_KERNELS is set) has its own non-transposed fp_qmm. It
now also accumulates each row in float32, in a local buffer, as its
affine _qmm does since ml-explore#4803. Before, the Linux build failed
test_fp_qmm_accumulation_precision with transpose=False.

(cherry picked from commit 07fff01)
inureyes added a commit to lablup/mlxcel that referenced this pull request Nov 29, 2026
Advance the reproducible MLX pin from fc344c98 to 5a48f9cc, the head of upstream main on 2026-11-28 (87 commits, past v0.32.5). Review record: docs/mlxcelverse/mlx-pin-2026-11-28.md.

- The CPU quantized-matmul overlay (#2248) is retired: upstream now accumulates the fp qmm loops in float (ml-explore/mlx#4879), and cpu_qmm_accum_tests guard the upstream loops.
- 24 Metal and CUDA overlays are rebased onto the pin. SDPA threads upstream's window_size through the deterministic and bucketed plan paths. The CUDA grouped_gemm.h overlay includes <cstdint>, and device/unary_ops.cuh (added on main by #3540 at the old pin) carries upstream's new SignBit functor.
- The #637 sm_120/121 qmm tile cap is dropped for upstream's #4851 rule (large_tiles ? 128 : 64). A GB10 A/B on llama-3.1-8b-4bit and qwen2.5-7b-4bit showed no prefill gain from the cap at 2048 or 8192 tokens and byte-identical greedy output; the 512-token qwen gain (about 10%) is recorded in the pin doc. TILE_M_CAP_BLACKWELL is 64.
- ROCm overlay retargeted: the fork's fusion limits move to mlx/compile/fuse.cpp, the new allocator hooks are inert, GroupedMM and SignBit get NO_GPU stubs, and HIP sources compile as C++20 because the pin's scheduler.h uses std::atomic::notify_all (LOCAL_FIXES 77 to 80, after main's 76).
- The MiniCPM5 and Qwen3 DSpark exactness gates require MLXCEL_SDPA_DETERMINISTIC=1 on CUDA, where decode attention otherwise takes cuDNN stream-K and its engine choice depends on what ran earlier in the process.
- A clippy needless_range_loop in the router WebUI harness test from #3552 is fixed; main's clippy job had not run on that change.

Validation: on M3 Ultra, make verify-test (17374 passed). On GB10 (spark-102), make verify-test-cuda-qmm-determinism (5 passed) and make verify-test-cuda (17741 passed, 3 failed, none from this change: a DeepSeek-OCR CLIP parity failure identical on main, and two port or timing flakes that pass alone), check_nvrtc_headers.py with NVRTC against the new-pin build tree, make verify-rocm-overlay, and both real-checkpoint DSpark gates. CI passes except binary assets, which fails on main for the undeclared tests/fixtures/audio/speech.flac from #3533. No ROCm host was available: the HIP C++20 change is covered by the Windows compile-only job only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants