Manuscript Offprint

arXiv:2610.33076

Double KV Cache Optimization on Apple Silicon: Block-FP4, Radial Quantization, and Fused Metal Kernels

Ibrokhimsho Abduchaborov

Open access. PaperVantage converted this article to text, so layout and figures may differ from the original.

Abstract

Key-value (KV) cache capacity and memory traffic are primary bottlenecks in long-context autoregressive inference [14, 15]. We evaluate five cache paths on an Apple Silicon M5 Max using MLX: a native bf16 baseline, block-scaled E2M1 FP4, a Python reference implementing radial quantization with a QJL-style residual, sequential FP4-to-Polar composition, and a fused Metal Polar kernel. On Apple Silicon M5 Max, fused Metal PolarQuant achieves 46.8 tok/s at 3,456 B/token—3.64× compression versus the bf16 baseline and 1.84× faster than the Python Polar reference (25.4 tok/s), while slightly outperforming block-FP4 (41.5 tok/s at 3.62× compression). Sequential composition of FP4 and Polar (Double Optimization) yields no additive benefit: 4,241 B/token at 15.1 tok/s, worse than FP4 alone on both axes. The fused path establishes that radial coding can be competitive when packing, rotation, and reconstruction are placed in one device kernel, but this result does not extend to longer contexts. At 32K and above, all compressed variants collapse to 1.5–14 tok/s because the current attention path repeatedly reconstructs the full cache, retaining cumulative O(N2)O(N^2) decode work. At 64K, the Metal variant runs out of memory when a 33.5 GB allocation exceeds MLX's 22.6 GB Metal buffer limit. Fused scaled dot-product attention operating directly on compressed KV, together with chunked pre-allocation, is required for long-context viability. These results separate representation-level compression from kernel and allocator effects and identify the conditions under which low-bit KV caching helps on unified memory hardware.

1 Introduction

Autoregressive Transformer inference reuses the key and value tensors produced for earlier tokens. This KV cache avoids recomputing the entire prefix at every generation step, but its capacity grows linearly with sequence length and batch size. The cache is read repeatedly during decoding, so its footprint is also a bandwidth cost rather than merely a storage cost. Analytical and empirical studies of Transformer serving identify this state as a central constraint on long-context inference [14]. Multi-query attention reduces the number of key/value heads [15], and grouped-query attention interpolates between multi-head and multi-query designs [1], yet large contexts still leave substantial persistent state.

KV compression addresses the remaining state without changing model weights. The design space includes scalar and group-wise quantization, sparse outlier retention, token eviction, cross-layer sharing, geometric transforms, and compressed-domain attention. These approaches make different tradeoffs. A compact representation can save memory but lose throughput if every decode step reconstructs the entire cache. Conversely, a specialized kernel can make a less compact layout faster by avoiding framework dispatch, intermediate tensors, and repeated format conversion. The representation and the consuming attention kernel therefore have to be evaluated together.

Apple Silicon is a useful target for this comparison. CPU and GPU allocations share physical memory, MLX schedules lazy array graphs onto Metal, and the device exposes large unified-memory capacity without a discrete-host transfer. Those properties remove one class of PCIe bottlenecks while exposing allocator behavior and kernel granularity more directly. They also make it possible to test whether a custom Metal implementation changes the practical ranking of KV formats that look similar from byte accounting alone.

We study a 4-bit block representation, a radial representation motivated by PolarQuant [6], a QJL-style residual [21], their sequential composition, and a fused Metal radial kernel. The baseline is the model's native bf16 cache. All reported numbers use the same M5 Max system and fixed context configurations. Cache bytes are normalized by the effective number of cached tokens; decode throughput is measured after warmup.

The main findings are as follows.

  • At 8K, fused Metal Polar reaches 46.8 tok/s and 3,456 B/token. It is 1.84×1.84\times faster than Python Polar, 13% faster than block-FP4, and nearly identical to block-FP4 in compression.

  • The 8K bf16 baseline remains fastest at 171.4 tok/s. Compression saves capacity but does not automatically accelerate decode when the cache is reconstructed before standard attention.

• Sequential FP4-to-Polar composition is Pareto-dominated: 3,473 B/token and 41.5 tok/s for FP4 alone versus 4,241 B/token and 15.1 tok/s for the double path.

  • At 32K, compressed decode falls to 1.5–14 tok/s while the baseline reaches 91.8 tok/s. Fusion reduces a constant factor at 8K but does not change the current algorithm’s cumulative O(N2)O(N^{2}) work.

  • At 64K, Python Polar completes at 0.47 tok/s and 3,072 B/token, whereas fused Metal Polar requests a 33.5 GB buffer and exceeds MLX's 22.6 GB per-buffer limit.

These results provide both a positive kernel result and two negative system results. Fusion makes radial quantization competitive at moderate context, but codec stacking does not yield multiplicative savings, and whole-cache reconstruction prevents the compressed layouts from remaining competitive at long context. The paper consequently treats bytes/token, decode throughput, prefill throughput, and allocation failure as separate outcomes.

References (22)