Skip to content

Add MLX inference for ParoQuant and supported quantization formats - #3134

Merged
Qubitium merged 3 commits into
mainfrom
codex/mlx-methods-20260925
Sep 25, 2026
Merged

Qubitium merged 3 commits into
mainfrom
codex/mlx-methods-20260925

Conversation

@Qubitium

@Qubitium Qubitium commented Sep 25, 2026 •

Copy link
Copy Markdown
Collaborator

Changes

  • Add BaseQuantLinear validated MLX checkpoint holders for ParoQuant, QQQ, GGUF, FP8, bitsandbytes, AWQ GEMV, AWQ GEMV_FAST, and LLM_AWQ.
  • Transfer packed ParoQuant/AWQ/GGUF codes and run ParoQuant rotations and QQQ dynamic input quantization with native MLX operations. Fix the GEMV_FAST group-16 buffer width.
  • Decode FP8, bitsandbytes, and EXL3 once into MLX FP16 dense layers when explicitly selected. AUTO selects the supported compressed paths on Apple Silicon; it retains the existing bitsandbytes and EXL3 paths after their faster 1024×1024 decode measurements on this host. Dense FP16 conversion increases weight memory versus FP8/4-bit storage.
  • Add source credit and SPDX notes to the new files.
  • Review follow-up: dense FP8/bitsandbytes holders call BaseQuantLinear validation directly, preserving support for non-affine shapes; a 96-feature regression covers both.

Accuracy and regression coverage

  • Use every projection from the pinned Qwen3.8-27B config: full-attention Q/K/V/O, fused linear-attention QKV/O, and MLP gate/up/down.
  • Check the previously merged GPTQ and AWQ GEMM MLX kernels on all nine shapes; all GPTQ bit widths (2–8) on the K projection; and the new AWQ GEMV, shared GEMV_FAST/LLM_AWQ, QQQ, and GGUF Q4_0 inference paths on all nine shapes. Include a full-width GEMV group case. Small-shape tests cover the other supported groups and GGUF qtypes with independent Torch arithmetic and packed-code checks. The latest main also contributes full-shape random BF16 audits for merged GPTQ/AWQ and GGUF packers.
  • Nonidentity ParoQuant Qwen outputs agree with main's Torch fallback across 27 measurements; maximum absolute error 0.000871. The Qwen test matrix uses rtol/atol 0.002.
  • 621 MLX tests passed on the rebased branch. Ruff and git diff --check pass. The separate tests/test_mlx.py integration test requires a model under /monster/data/model/... and could not run here.

Performance versus main

Apple M5 Ultra, MLX 0.32.2, Torch 2.14.0, FP16 inputs, group size 128. Each value is the median of 11 timed forwards after one warmup with inputs resident on device; Torch MPS and MLX are synchronized. The baseline classes are the unchanged Torch fallbacks from main. Weights and inputs are deterministic synthetic data. These are isolated projection latencies, excluding checkpoint conversion and end-to-end generation.

Method 1 row speedup (min / median / max) 16 rows 128 rows Max absolute error
ParoQuant, identity stage 3.06 / 15.64 / 20.91× 3.97 / 8.67 / 14.61× 3.23 / 7.41 / 10.71× 0.000778
ParoQuant, eight nonidentity stages 93.22 / 104.14 / 266.40× 61.62 / 73.62 / 112.22× 32.58 / 50.57 / 68.19× 0.000871
QQQ 10.42 / 60.63 / 104.80× 10.63 / 47.00 / 73.19× 8.73 / 30.41 / 40.34× 0
GGUF Q4_0 2.92 / 14.07 / 24.54× 3.33 / 11.06 / 19.10× 2.65 / 8.04 / 11.52× 0.00003

ParoQuant's nonidentity case uses eight valid pairwise rotation stages with angle 0.01 and channel scale 1.01. The QQQ benchmark uses uniform packed codes, while the independent Qwen QQQ tests use a varied pattern. GGUF uses Q4_0 blocks; other supported qtypes have separate small-shape numerical tests.

ParoQuant, identity stage: all nine projections at 1, 16, and 128 rows
Projection Shape (out × in) Rows main Torch MPS (ms) MLX (ms) Speedup Max abs error
full_attn.q_proj 12288 × 5120 1 4.508 0.268 16.83× 0.000036
full_attn.q_proj 12288 × 5120 16 4.536 0.369 12.29× 0.000248
full_attn.q_proj 12288 × 5120 128 4.652 0.434 10.71× 0.000502
full_attn.k_proj 1024 × 5120 1 0.78 0.255 3.06× 0.000036
full_attn.k_proj 1024 × 5120 16 0.97 0.244 3.97× 0.000169
full_attn.k_proj 1024 × 5120 128 0.888 0.275 3.23× 0.000244
full_attn.v_proj 1024 × 5120 1 0.797 0.182 4.38× 0.000036
full_attn.v_proj 1024 × 5120 16 1.346 0.249 5.41× 0.000169
full_attn.v_proj 1024 × 5120 128 1.482 0.278 5.33× 0.000244
full_attn.o_proj 5120 × 6144 1 2.556 0.203 12.57× 0.000044
full_attn.o_proj 5120 × 6144 16 2.668 0.322 8.28× 0.0002
full_attn.o_proj 5120 × 6144 128 2.698 0.422 6.39× 0.000399
linear_attn.in_proj_qkv 10240 × 5120 1 3.869 0.247 15.64× 0.000036
linear_attn.in_proj_qkv 10240 × 5120 16 3.883 0.345 11.26× 0.000248
linear_attn.in_proj_qkv 10240 × 5120 128 3.924 0.414 9.49× 0.000502
linear_attn.out_proj 5120 × 6144 1 2.608 0.21 12.4× 0.000044
linear_attn.out_proj 5120 × 6144 16 2.597 0.316 8.22× 0.0002
linear_attn.out_proj 5120 × 6144 128 2.838 0.39 7.28× 0.000399
mlp.gate_proj 17408 × 5120 1 6.151 0.33 18.63× 0.000036
mlp.gate_proj 17408 × 5120 16 6.171 0.439 14.06× 0.000248
mlp.gate_proj 17408 × 5120 128 6.251 0.693 9.02× 0.000502
mlp.up_proj 17408 × 5120 1 6.148 0.294 20.91× 0.000036
mlp.up_proj 17408 × 5120 16 6.195 0.424 14.61× 0.000248
mlp.up_proj 17408 × 5120 128 6.277 0.714 8.79× 0.000502
mlp.down_proj 5120 × 17408 1 6.181 0.304 20.36× 0.00012
mlp.down_proj 5120 × 17408 16 6.214 0.716 8.67× 0.000232
mlp.down_proj 5120 × 17408 128 6.341 0.855 7.41× 0.000778
ParoQuant, eight nonidentity stages: all nine projections at 1, 16, and 128 rows
Projection Shape (out × in) Rows main Torch MPS (ms) MLX (ms) Speedup Max abs error
full_attn.q_proj 12288 × 5120 1 38.952 0.353 110.22× 0.000021
full_attn.q_proj 12288 × 5120 16 31.534 0.502 62.87× 0.000281
full_attn.q_proj 12288 × 5120 128 29.146 0.774 37.67× 0.00032
full_attn.k_proj 1024 × 5120 1 33.556 0.324 103.66× 0.000021
full_attn.k_proj 1024 × 5120 16 27.677 0.373 74.21× 0.00017
full_attn.k_proj 1024 × 5120 128 25.069 0.491 51.1× 0.00025
full_attn.v_proj 1024 × 5120 1 30.223 0.324 93.22× 0.000021
full_attn.v_proj 1024 × 5120 16 27.494 0.368 74.73× 0.00017
full_attn.v_proj 1024 × 5120 128 25.079 0.491 51.09× 0.00025
full_attn.o_proj 5120 × 6144 1 39.823 0.342 116.6× 0.000092
full_attn.o_proj 5120 × 6144 16 34.701 0.471 73.62× 0.000221
full_attn.o_proj 5120 × 6144 128 31.942 0.632 50.57× 0.000446
linear_attn.in_proj_qkv 10240 × 5120 1 37.938 0.364 104.14× 0.000021
linear_attn.in_proj_qkv 10240 × 5120 16 30.277 0.491 61.7× 0.000281
linear_attn.in_proj_qkv 10240 × 5120 128 28.246 0.717 39.42× 0.00032
linear_attn.out_proj 5120 × 6144 1 39.529 0.342 115.69× 0.000092
linear_attn.out_proj 5120 × 6144 16 35.996 0.471 76.47× 0.000221
linear_attn.out_proj 5120 × 6144 128 31.785 0.618 51.4× 0.000446
mlp.gate_proj 17408 × 5120 1 37.174 0.392 94.92× 0.000021
mlp.gate_proj 17408 × 5120 16 33.65 0.543 61.94× 0.000281
mlp.gate_proj 17408 × 5120 128 30.838 0.897 34.38× 0.00032
mlp.up_proj 17408 × 5120 1 38.974 0.409 95.19× 0.000021
mlp.up_proj 17408 × 5120 16 32.811 0.532 61.62× 0.000281
mlp.up_proj 17408 × 5120 128 30.672 0.942 32.58× 0.00032
mlp.down_proj 5120 × 17408 1 104.161 0.391 266.4× 0.000171
mlp.down_proj 5120 × 17408 16 93.465 0.833 112.22× 0.000363
mlp.down_proj 5120 × 17408 128 86.314 1.266 68.19× 0.000871
QQQ: all nine projections at 1, 16, and 128 rows
Projection Shape (out × in) Rows main Torch MPS (ms) MLX (ms) Speedup Max abs error
full_attn.q_proj 12288 × 5120 1 19.142 0.29 65.9× 0
full_attn.q_proj 12288 × 5120 16 19.371 0.357 54.3× 0
full_attn.q_proj 12288 × 5120 128 19.652 0.516 38.06× 0
full_attn.k_proj 1024 × 5120 1 2.581 0.245 10.55× 0
full_attn.k_proj 1024 × 5120 16 2.615 0.246 10.63× 0
full_attn.k_proj 1024 × 5120 128 2.785 0.314 8.88× 0
full_attn.v_proj 1024 × 5120 1 2.61 0.25 10.42× 0
full_attn.v_proj 1024 × 5120 16 2.787 0.252 11.06× 0
full_attn.v_proj 1024 × 5120 128 2.918 0.334 8.73× 0
full_attn.o_proj 5120 × 6144 1 10.212 0.242 42.16× 0
full_attn.o_proj 5120 × 6144 16 10.368 0.322 32.2× 0
full_attn.o_proj 5120 × 6144 128 10.574 0.438 24.16× 0
linear_attn.in_proj_qkv 10240 × 5120 1 16.145 0.266 60.63× 0
linear_attn.in_proj_qkv 10240 × 5120 16 16.232 0.34 47.74× 0
linear_attn.in_proj_qkv 10240 × 5120 128 16.652 0.469 35.53× 0
linear_attn.out_proj 5120 × 6144 1 10.807 0.279 38.68× 0
linear_attn.out_proj 5120 × 6144 16 10.319 0.326 31.65× 0
linear_attn.out_proj 5120 × 6144 128 10.608 0.427 24.82× 0
mlp.gate_proj 17408 × 5120 1 26.504 0.266 99.67× 0
mlp.gate_proj 17408 × 5120 16 26.634 0.364 73.19× 0
mlp.gate_proj 17408 × 5120 128 27.284 0.731 37.31× 0
mlp.up_proj 17408 × 5120 1 26.5 0.253 104.8× 0
mlp.up_proj 17408 × 5120 16 26.63 0.387 68.86× 0
mlp.up_proj 17408 × 5120 128 27.234 0.675 40.34× 0
mlp.down_proj 5120 × 17408 1 26.645 0.307 86.9× 0
mlp.down_proj 5120 × 17408 16 26.69 0.568 47× 0
mlp.down_proj 5120 × 17408 128 27.315 0.898 30.41× 0
GGUF Q4_0: all nine projections at 1, 16, and 128 rows
Projection Shape (out × in) Rows main Torch MPS (ms) MLX (ms) Speedup Max abs error
full_attn.q_proj 12288 × 5120 1 4.035 0.235 17.16× 0.000001
full_attn.q_proj 12288 × 5120 16 4.065 0.308 13.2× 0.000021
full_attn.q_proj 12288 × 5120 128 4.293 0.391 10.99× 0.000023
full_attn.k_proj 1024 × 5120 1 0.746 0.255 2.92× 0.000001
full_attn.k_proj 1024 × 5120 16 0.836 0.251 3.33× 0.000021
full_attn.k_proj 1024 × 5120 128 0.932 0.352 2.65× 0.000023
full_attn.v_proj 1024 × 5120 1 0.98 0.236 4.14× 0.000001
full_attn.v_proj 1024 × 5120 16 1.148 0.249 4.6× 0.000021
full_attn.v_proj 1024 × 5120 128 1.152 0.27 4.26× 0.000023
full_attn.o_proj 5120 × 6144 1 2.112 0.201 10.53× 0.000003
full_attn.o_proj 5120 × 6144 16 2.142 0.3 7.14× 0.000015
full_attn.o_proj 5120 × 6144 128 2.177 0.368 5.91× 0.000016
linear_attn.in_proj_qkv 10240 × 5120 1 3.499 0.249 14.07× 0.000001
linear_attn.in_proj_qkv 10240 × 5120 16 4.735 0.336 14.1× 0.000021
linear_attn.in_proj_qkv 10240 × 5120 128 3.584 0.373 9.6× 0.000023
linear_attn.out_proj 5120 × 6144 1 2.113 0.257 8.23× 0.000003
linear_attn.out_proj 5120 × 6144 16 2.134 0.297 7.18× 0.000015
linear_attn.out_proj 5120 × 6144 128 2.193 0.394 5.57× 0.000016
mlp.gate_proj 17408 × 5120 1 5.923 0.241 24.54× 0.000001
mlp.gate_proj 17408 × 5120 16 5.949 0.324 18.34× 0.000021
mlp.gate_proj 17408 × 5120 128 6.022 0.523 11.52× 0.000023
mlp.up_proj 17408 × 5120 1 5.929 0.248 23.93× 0.000001
mlp.up_proj 17408 × 5120 16 5.951 0.312 19.1× 0.000021
mlp.up_proj 17408 × 5120 128 6.016 0.568 10.58× 0.000023
mlp.down_proj 5120 × 17408 1 5.914 0.243 24.31× 0.00001
mlp.down_proj 5120 × 17408 16 5.935 0.537 11.06× 0.00003
mlp.down_proj 5120 × 17408 128 6.088 0.757 8.04× 0.000029

Reproduce: PYTHONPATH=. python tests/benchmark_mlx_qwen38_27b.py --repeats 11, PYTHONPATH=. python tests/benchmark_mlx_qwen38_27b.py --krot 8 --rotate --repeats 11, and PYTHONPATH=. python tests/benchmark_mlx_qwen38_qqq_gguf.py --method qqq --repeats 11 (or --method gguf).

@Qubitium
Qubitium force-pushed the codex/mlx-methods-20260925 branch from 6b3bc47 to 4c12fbb Compare September 25, 2026 11:55
@Qubitium
Qubitium merged commit bf2de46 into main Sep 25, 2026
6 checks passed
@Qubitium
Qubitium deleted the codex/mlx-methods-20260925 branch September 25, 2026 12:36
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.

1 participant