Sub-4-Bit KV-Cache Quantization on Mobile Silicon
Analyzing asymmetric group quantization and attention-sink preservation when running 4B-class transformers locally on smartphone memory budgets.
Contents (5)
Running a 4-billion-parameter language model entirely inside a mobile device's unified memory shifts the primary bottleneck from weight storage to key–value (KV) cache bandwidth during long-context autoregressive decoding1. While 4-bit weight quantization (Q4_K_M or INT4 group-wise) reduces parameter memory to roughly , an unquantized FP16 KV cache at context length can quietly exceed the memory footprint of the model weights themselves.
This note formalizes the quantization error introduced across key and value projections, evaluates sink-preserving mixed precision on mobile ARMv9 CPUs, and documents the memory layout used in my on-device assistant experiments.
Quantization Error Formulation#
For a single attention head of dimension at decoding step , let be the query vector and be the cached key and value matrices. Exact scaled dot-product attention computes:
When we compress each group of size along the channel or token axis via asymmetric uniform -bit quantization , the perturbed attention logits incur an additive error .
Memory Layout & Inference Pipeline#
Rather than quantizing tokens immediately upon arrival, we maintain a small FP16 ring buffer for the sliding recent window and flush evicted blocks in chunks of into packed bitstreams.
Reference Algorithm & Implementation#
- 1:for each head channel c = 1 ... d_h in parallel do
- 2: x_min <- min_i K[i, c], x_max <- max_i K[i, c]
- 3: s[c] <- max((x_max - x_min) / (2^b - 1), 1e-6)
- 4: z[c] <- x_min
- 5: q[1..G, c] <- clamp(round((K[1..G, c] - z[c]) / s[c]), 0, 2^b - 1)
- 6: pack q[1..G, c] into 64-byte aligned uint8 lane P[c]
- 7:end for
- 8:return (P, s, z)
Below is the reference PyTorch simulation alongside the inner dequantization loop structure used when prototyping for ARM NEON:
Per-channel asymmetric group quantization along the sequence dimension avoids outlier-channel collapse caused by RoPE frequency spikes.
import torch
def quantize_kv_group(x: torch.Tensor, bits: int = 4) -> tuple[torch.Tensor, torch.Tensor, torch.Tensor]:
"""Asymmetric per-channel quantization across a sequence block [G, H, D]."""
qmax = (1 << bits) - 1
x_min = x.amin(dim=0, keepdim=True)
x_max = x.amax(dim=0, keepdim=True)
scale = (x_max - x_min).clamp_min(1e-6) / qmax
q = torch.round((x - x_min) / scale).clamp(0, qmax).to(torch.uint8)
dequant = q.to(x.dtype) * scale + x_min
err = (x - dequant).pow(2).mean().sqrt().item()
return q, scale, x_minEmpirical Benchmarks#
Measured across -token synthetic long-context prompts on an ARMv9 mobile SoC (8-core CPU, LPDDR5X unified memory, 4B-class GQA model with 4-bit weights)2:
| KV Cache Strategy | Decode Speed (tok/s) | KV Memory @ 16k (GB) | WikiText-2 PPL | Needle Retrieval |
|---|---|---|---|---|
| FP16 Baseline | 11.8 | 4.29 | 6.41 | 98.4% |
| INT8 Symmetric | 18.6 | 2.18 | 6.42 | 98.2% |
| INT4 Naive (Per-Token) | 23.1 | 1.16 | 7.19 | 89.0% |
| INT4 Per-Channel + FP16 Sinks | 24.4 | 1.19 | 6.48 | 97.8% |
| INT3 Mixed + FP16 Sinks | 26.2 | 0.91 | 6.74 | 95.1% |
Open Questions#
- Can we fold RoPE rotation after dequantizing low-bit pre-RoPE keys without paying extra register pressure in mobile NEON kernels?
- How does sink-preserved INT3 interact with multimodal vision tokens (e.g., high-entropy image patch prefixes in Gemma 4 E4B)?
Footnotes#
-
Autoregressive decoding has arithmetic intensity near at batch size 1, meaning wall-clock latency is governed almost entirely by DRAM bandwidth rather than peak compute. ↩
-
Benchmark numbers in this template note illustrate the scientific layout and table/chart components; replace with live profiling traces as new hardware runs complete. ↩
Cite this thought
Academic BibTeX entry for referencing this note.
@misc{ali2026_kv_cache_quantization,
author = {Ali, MD Ahad},
title = {{Sub-4-Bit KV-Cache Quantization on Mobile Silicon}},
howpublished = {aliahadmd.github.io},
year = {2026},
month = nov,
url = {https://aliahadmd.github.io/thoughts/2026-11-kv-cache-quantization-on-edge/}
}