Skip to content

Fuse QQQ decode output finalization on MLX - #3233

Merged
Qubitium merged 1 commit into
mainfrom
codex/mlx-qqq-inference-opt
Sep 27, 2026
Merged

Qubitium merged 1 commit into
mainfrom
codex/mlx-qqq-inference-opt

Conversation

@Qubitium

Copy link
Copy Markdown
Collaborator

Summary

  • fuse QQQ decode output finalization into one MLX Metal dispatch after the native packed matmul
  • combine the per-token input scale, per-channel output scale, required FP16 rounding, optional bias, and final FP16/BF16 store
  • preserve the previous MLX arithmetic order and output dtype exactly
  • leave the prefill path and backend-selection policy unchanged

This PR is intentionally limited to QQQ inference.

Performance vs main

Qwen3.8-27B decode shapes, batch/token rows = 1, QQQ packed 4/8-bit weights, group size 128, bias enabled. Each of the 36 cases uses five warmups and 301 paired alternating samples. Values below aggregate the nine projection-shape medians.

Packed bits Output dtype Main median (ms) PR median (ms) Geomean speedup Shape range
4 FP16 0.258042 0.253791 1.0207x 0.9933-1.0466x
4 BF16 0.256291 0.251042 1.0317x 0.9988-1.0476x
8 FP16 0.255750 0.248750 1.0221x 1.0010-1.0311x
8 BF16 0.263375 0.255167 1.0298x 1.0194-1.0385x
Overall (36 cases) FP16 + BF16 — — 1.0261x 0.9933-1.0476x

Benchmark: tests/benchmark_mlx_qwen38_qqq_finalize.py --samples 301.

Host: Apple M5 Ultra, 256 GB, macOS 27.0, MLX 0.32.2.

Accuracy

All nine Qwen3.8-27B projection shapes were tested across 4/8-bit packed storage, FP16/BF16 activations, and bias/no-bias: 72 decode cases.

Packed bits Output dtype Max abs vs previous MLX path Max abs vs rounded Torch oracle
4 FP16 0.0 0.0
4 BF16 0.0 0.0
8 FP16 0.0 0.0
8 BF16 0.0 0.0

The fused kernel intentionally performs the FP16 rounding before optional bias, matching the existing path. FP16 and BF16 outputs remain FP16 and BF16; there is no persistent FP32 output upcast.

Validation

License and credits

All changed/new files retain or add SPDX Apache-2.0 headers. QQQ arithmetic is credited to the vLLM contributors, and the benchmark credits the Qwen projection-shape source.

@Qubitium
Qubitium merged commit badeed3 into main Sep 27, 2026
6 checks passed
@Qubitium
Qubitium deleted the codex/mlx-qqq-inference-opt branch September 27, 2026 10:46
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