EMPIRICAL HARDWARE BENCHMARKS

Measured on Apple Silicon.
Verified across 12 models.

Real causal-LM generation throughput, attention correlation accuracy, and perplexity measurements on Apple Silicon hardware (M1 through M4). Zero synthetic projections — all logs committed under figures/.

Metal GPU Kernels 14.7× Peak speedup over pure MLX at S=8,192
Attention Prediction 100% Sign accuracy across all models tested
KIVI 4-Bit Quant <1.0 pt Perplexity delta from fp16 on 135M to 8B
RaBitQ Cache Footprint 5.95× Exact memory reduction on 7B models

Metal GPU Kernel Acceleration

Hand-written Metal Shading Language (MSL) kernels vs. pure MLX operations across sequence lengths on Apple Silicon unified memory.

KEY INSIGHT

Metal threadgroup caching scales with context length: While unquantized attention stalls memory bandwidth on long sequences, our fused Metal kernels achieve 6.91× speedup at 128 tokens and scale up to 14.68× speedup at 8,192 tokens.

Execution Latency by Sequence Length (Lower is Better) Apple M3 / M4 Metal Engine
S = 128 6.91× faster
Pure MLX
3.64 ms
Metal MSL
0.53 ms
S = 512 10.70× faster
Pure MLX
13.47 ms
Metal MSL
1.26 ms
S = 1,024 12.09× faster
Pure MLX
26.97 ms
Metal MSL
2.23 ms
S = 2,048 13.17× faster
Pure MLX
55.10 ms
Metal MSL
4.18 ms
S = 4,096 13.63× faster
Pure MLX
108.82 ms
Metal MSL
7.98 ms
S = 8,192 14.68× faster
Pure MLX
228.56 ms
Metal MSL
15.57 ms

KV-Cache Kernel Roofline: What Actually Limits Decode

A self-calibrated bandwidth roofline (not spec-sheet numbers) across all four KV-cache quantize/dequantize/fused-attend Metal kernels — two are already within a few percent of this hardware's measured bandwidth ceiling, and one never becomes bandwidth-bound at all for a different, more interesting reason.

COUNTER-INTUITIVE RESULT

The fused decode+attend kernel's bottleneck isn't memory bandwidth — it's GPU occupancy. At a realistic single-token decode shape it tops out at just 6.1% of peak bandwidth, even at 16,384 cached tokens, because too few threadgroups are dispatched to fill a 10-core GPU. Routing multiple concurrent requests through that same kernel — verified end-to-end on a real model — measured a real 1.50×–3.83× decode speedup that grows with batch size.

% of Calibrated Bandwidth Peak, Largest Tested Size (Higher = Closer to Memory-Bound) Apple M4 · self-calibrated ~97–99 GB/s ceiling
kivi_group_quant_dequant 32×4096×128, group_size=32
102.2%
turboquant_scalar_dequantize N=16,000,000, b=2 (pure gather)
61.8%
turboquant_scalar_quantize N=16,000,000, b=4 (argmin, 16 centroids)
54.9%
scalar_fused_decode_attend S_kv=16,384, B=1 H=8 S_q=1 (realistic decode)
6.1%
Memory-bound (≥60% of peak) Occupancy-limited, trending toward memory-bound Occupancy/dispatch-bound — not a bandwidth problem
Occupancy Sweep — Same Kernel, Same S_kv, Only Threadgroup Count Changes scalar_fused_decode_attend, S_kv=16,384, D=128
Dispatch shape Threadgroups % of peak bandwidth
B=1, H=8, S_q=1 (realistic single request) 8 6.1%
B=1, H=32, S_q=1 32 21.8%
B=4, H=32, S_q=1 128 36.7%

Bandwidth utilization scales with threadgroup count, not with S_kv or bytes moved per threadgroup — direct evidence this kernel is occupancy/dispatch-bound, not memory- or compute-bound, at the shapes that matter for real single-token decode.

The Fix That Worked: Batch Concurrent Requests, Not Layers mlx-community/Qwen3-4B-4bit · 36 layers · real end-to-end decode
Concurrent requests (B) Baseline decode tok/s Fused-kernel decode tok/s Speedup
117.125.51.50×
425.348.11.90×
1634.3108.13.16×
3239.1149.93.83×

Real forward passes on real hardware (Apple M4, prompt_len=256, 30 decode steps) — not an isolated kernel call. Both arms decode from the identical quantized KV state and were verified to produce bit-identical tokens before timing was trusted, so this measures the fused kernel's speedup over dequantize+MLX-SDPA on the same compressed state — not a general "KIVI is faster in production" claim. The test harness behind this table also has no fp16 residual window (unlike shipping KIVI), so its generation quality isn't production-representative; only the timing comparison is.

Also Measured, Not Adopted as the Default
Approach Result Disposition
GQA head-packing (share K/V decode across query heads) 2.7×–4.7× slower Reduces threadgroup count, which is the actual bottleneck — kept as tested code, not the default.
Two-pass "decode-once" (separate decode + attend kernels) 1.1×–3.2× faster at S_kv≤2048, 0.80×–0.85× (slower) at S_kv≥3072 Real crossover, but this project's realistic decode targets sit past it — not adopted as the default.
Cross-layer batched dispatch 1.0×–4.5× faster in isolation Structural dead end for real single-request serving — a standard transformer's residual stream makes layer L+1's attention depend on layer L's full output, so layers can't be batched together without changing the model.
Reproduce the roofline measurements CLI
python scripts/kv_kernel_roofline_bench.py

Full methodology, self-calibration approach, and all four follow-up experiments (including the ones summarized above) → KV_KERNEL_ROOFLINE_FINDINGS.md on GitHub.

12-Model Quality Matrix (KIVI 4-Bit vs. 2-Bit)

Long-context causal generation (~430–500 tokens, well beyond the 128-token residual cache window) tested across 12 models spanning 135M to 8B parameters.

CRITICAL RULE

4-bit is safe across every model tested (perplexity within ~1 point of fp16). 2-bit provides an 8× compression win on 7B–8B models, but causes significant degradation under ~3B (Llama-3.2-1B perplexity triples from 22.8 → 81.3). Choose bit-width based on parameter size!

FILTER BY SCALE:
✓ Safe at 2-bit 7B Dense
Mistral-7B-v0.3
fp168.01
KIVI 4-bit7.96
KIVI 2-bit8.05
Throughput22.8 tok/s
✓ Safe at 2-bit 7B Dense
Qwen2.5-7B
fp16n/a
KIVI 4-bit9.30
KIVI 2-bit10.75
Throughput20.9 tok/s
✓ Safe at 2-bit 8B Dense
Llama-3.1-8B
fp1610.88
KIVI 4-bit11.02
KIVI 2-bit13.57
Throughput18.5 tok/s
✓ Safe at 2-bit 7B Dense
Falcon3-7B
fp1612.69
KIVI 4-bit12.63
KIVI 2-bit14.44
Throughput16.1 tok/s
✓ Safe at 2-bit 8B Dense
Qwen3-8B
fp16n/a
KIVI 4-bit9.92
KIVI 2-bit10.57
ThroughputValidated
✓ Safe at 2-bit MoE · MLA
DeepSeek-V2-Lite
fp16n/a
KIVI 4-bit15.34
KIVI 2-bit17.87
Throughput82.5 tok/s
✓ Safe at 4-bit 4B Dense
Gemma-3-4B
fp1616.00
KIVI 4-bit16.37
KIVI 2-bit17.72
ThroughputValidated
✓ Safe at 4-bit 4B Dense
Qwen3-4B
fp16n/a
KIVI 4-bit15.07
KIVI 2-bit17.21
ThroughputValidated
✓ Safe at 4-bit 3B Dense
Llama-3.2-3B
fp1615.47
KIVI 4-bit15.82
KIVI 2-bit20.93
Throughput46.2 tok/s
▲ Caution on 2-bit 1B Dense
Llama-3.2-1B
fp1622.77
KIVI 4-bit23.27
KIVI 2-bit81.30
Throughput119.7 tok/s
▲ Caution on 2-bit 0.5B Dense
Qwen2.5-0.5B
fp16n/a
KIVI 4-bit22.22
KIVI 2-bit49.08
Throughput244.3 tok/s
▲ Caution on 2-bit 135M Dense
SmolLM2-135M
fp1628.87
KIVI 4-bit29.63
KIVI 2-bit44.85
ThroughputValidated
View Complete Numerical Data Table (All 12 Models)
Model Architecture fp16 Perplexity KIVI 4-bit (4×) KIVI 2-bit (8×) Decode tok/s
SmolLM2-135M28.8729.6344.85
Qwen2.5-0.5Bn/a22.2249.08244.3 tok/s
Llama-3.2-1B22.7723.2781.30119.7 tok/s
gemma-3-4B16.0016.3717.72
Qwen3-4Bn/a15.0717.21
Llama-3.2-3B15.4715.8220.9346.2 tok/s
Mistral-7B-v0.38.017.968.0522.8 tok/s
Qwen2.5-7Bn/a9.3010.7520.9 tok/s
Llama-3.1-8B10.8811.0213.5718.5 tok/s
Falcon3-7B12.6912.6314.4416.1 tok/s
Qwen3-8Bn/a9.9210.57
DeepSeek-V2-Lite (MoE·MLA)n/a15.3417.8782.5 tok/s

Attention Scorer Correlation (Q-Filters)

Spearman rank-order correlation with genuine model attention weights. Tests whether the scorer correctly identifies which tokens are critical to retain.

PERFECT PREDICTION

100% sign-accuracy across all models tested. Q-Filters achieves roughly 2× the correlation of naive K-norm / L2Norm baselines (+0.863 vs +0.410 on Llama-3.2-3B).

Q-Filters (Query-SVD Calibrated)
Naive K-Norm / L2Norm Baseline
Llama-3.2-1B
Q-Filters
+0.783 (100% sign)
K-norm
+0.460
Llama-3.2-3B
Q-Filters
+0.863 (100% sign)
K-norm
+0.410
Qwen2.5-7B
Q-Filters
+0.850 (100% sign)
K-norm
+0.402

Generation Perplexity & Quality Gap Closed

Percentage of the fp16 degradation gap closed by Q-Filters calibration relative to naive eviction at varying memory compression budgets.

52%
Budget 256 (~4×)
8.48 vs 13.36 ppl
37%
Budget 128 (~8×)
16.31 vs 23.65 ppl
20%
Budget 64 (~16×)
25.93 vs 31.27 ppl

Measurements on Llama-3.2-1B (fp16 baseline 4.050 ppl). Llama-3.2-3B closes 55% / 42% at Budgets 256 / 128.

Real KV Cache Memory Scaling (RaBitQ on Falcon3-7B)

Measured RAM footprint of the KV cache across context lengths from 256 to 4,096 tokens.

Sequence Length Standard fp16 Cache RaBitQ MSE-4V Cache Memory Saved Compression Ratio
256 tokens 29.4 MB 4.9 MB 24.5 MB freed 5.95×
512 tokens 58.7 MB 9.9 MB 48.8 MB freed 5.95×
1,024 tokens 117.4 MB 19.7 MB 97.7 MB freed 5.95×
2,048 tokens 234.9 MB 39.5 MB 195.4 MB freed 5.95×
4,096 tokens 469.8 MB 78.9 MB 390.9 MB freed 5.95×
Reproduce these benchmarks on your Mac CLI
python -m veloxquant_mlx benchmark --all