Skip to content

TurboQuant: Apple Accelerate + norm correction for CPU dequant#21817

Closed
sachmans wants to merge 5 commits into
ggml-org:masterfrom
sachmans:pr-turboquant-cpu-optimizations
Closed

TurboQuant: Apple Accelerate + norm correction for CPU dequant#21817
sachmans wants to merge 5 commits into
ggml-org:masterfrom
sachmans:pr-turboquant-cpu-optimizations

Conversation

@sachmans

Copy link
Copy Markdown

Summary

Two CPU-side improvements to the TurboQuant KV cache dequant path (builds on PR #21089):

  1. Apple Accelerate cblas_sgemv: Replace the hand-rolled matrix-vector multiply in TBQ dequant with cblas_sgemv from Apple's Accelerate framework, which routes to AMX on M-series silicon. 2× faster dequant on Apple Silicon. Guarded by #ifdef GGML_USE_ACCELERATE, zero impact on other platforms.

  2. Norm correction: Re-normalize the unit vector after Householder inverse rotation to correct accumulated floating-point error. Halves the PPL gap vs F16 (from +0.6% to +0.3% on Qwen3-32B wikitext-2).

Benchmark results (Qwen3-32B Q4_K_M, Mac Studio M3 Ultra 96GB)

Config PPL vs F16 Compression TG speed
F16 K+V 2.716 baseline 1.0× 16.4 t/s
TBQ4_0 K + F16 V 2.724 +0.3% ~2× 14.0 t/s
TBQ4_0 K+V 2.733 +0.6% 3.94× ~10 t/s
TBQ4_0 K + TBQ3_0 V 2.730 +0.5% 4.5× ~10 t/s

Max context (Qwen3-32B on 96GB)

  • F16: 278K tokens
  • TBQ4_0 K+V: 1.1M tokens (4× more)

Files changed

  • ggml/src/ggml-turboq.c — Accelerate cblas_sgemv + norm correction
  • ggml/src/CMakeLists.txt — Accelerate framework link (if not already linked)

Test plan

  • PPL benchmark on Qwen3-32B Q4_K_M (wikitext-2, 8 chunks) — results above
  • Generation quality check on Gemma 3 4B — correct factual answers, coherent output
  • Build and run on Apple Silicon (M3 Ultra)
  • Verify no regression on non-Apple platforms (cblas path is #ifdef guarded)

Depends on: #21089

🤖 Generated with Claude Code

elusznik and others added 5 commits April 8, 2026 11:28
Replace scalar/AVX2 matrix-vector multiply in TurboQuant rotation
with cblas_sgemv from Apple's Accelerate framework. This uses the
AMX coprocessor on Apple Silicon for the 128x128 dense rotation
matrix multiply during dequantization.

Results on Mac Studio M3 Ultra, Qwen3-32B Q4_K_M:
  TBQ4_0 K + F16 V:  7.40 → 14.00 t/s  (1.89x faster, 86% of F16)
  TBQ4_0 K + TBQ4_0 V:  5.32 → 11.04 t/s  (2.07x faster, 67% of F16)

Quality unchanged (PPL within noise margin).
After inverse rotation, re-normalize the reconstructed unit vector
to unit length before scaling by the original norm. This removes
magnitude bias from codebook quantization error.

Results on Qwen3-32B Q4_K_M (PPL, lower is better):
  TBQ4_0 K+V:       2.751 → 2.733  (+1.3% → +0.6% vs F16)
  TBQ4_0 K+F16 V:   2.733 → 2.724  (+0.6% → +0.3% vs F16)
  TBQ4_0 K+TBQ3_0 V: 2.767 → 2.730  (+1.9% → +0.5% vs F16)

4.5x compression at +0.5% quality loss (TBQ4_0 K + TBQ3_0 V).
@github-actions github-actions Bot added testing Everything test related examples server ggml changes relating to the ggml tensor library for machine learning labels Apr 12, 2026
@ggml-gh-bot

ggml-gh-bot Bot commented Apr 12, 2026

Copy link
Copy Markdown

Hi @sachmans, thanks for your contribution!

Per our contribution guidelines, the automated PR checker found the following issue(s) that need your attention:

  • Multiple open PRs from a new contributor: We limit new contributors (those without a previously merged PR) to 1 open PR at a time. You currently have 2 open PRs.

  • AI-generated content: This project does not accept PRs, descriptions or commit messages that are fully or predominantly AI-generated. If you have used AI to assist you in writing code, please make sure to disclose that explicitly.

  • Large PR: Large changes require prior discussion (e.g. an issue or RFC) and maintainers may not be able to review this PR as-is. Consider splitting it into smaller, focused PRs.


Please note that maintainers reserve the right to make final decisions on PRs. If you believe there is a mistake, please comment below.

@ngxson ngxson closed this Apr 13, 2026
@sachmans sachmans deleted the pr-turboquant-cpu-optimizations branch May 14, 2026 11:20
@sachmans sachmans restored the pr-turboquant-cpu-optimizations branch May 14, 2026 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

examples ggml changes relating to the ggml tensor library for machine learning server testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants