Skip to content
Research· updated 2026.11.24· 5 min read

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.

#LLM-Systems#Quantization#On-Device-AI#Mobile
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 2.3 GB2.3\text{ GB}, an unquantized FP16 KV cache at 32k32\text{k} 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 dhd_h at decoding step tt, let qt∈Rdhq_t \in \R^{d_h} be the query vector and K1:t,V1:t∈Rt×dhK_{1:t}, V_{1:t} \in \R^{t \times d_h} be the cached key and value matrices. Exact scaled dot-product attention computes:

ot=∑i=1tαt,ivi,αt,i=softmax⁡i ⁣(qt⊤kidh)o_t = \sum_{i=1}^{t} \alpha_{t,i} v_i, \qquad \alpha_{t,i} = \softmax_i\!\left(\frac{q_t^\top k_i}{\sqrt{d_h}}\right)

When we compress each group gg of size GG along the channel or token axis via asymmetric uniform bb-bit quantization Qb(x)=sg⋅round ⁣(x−zgsg)+zg\mathcal{Q}_b(x) = s_g \cdot \mathrm{round}\!\left(\frac{x - z_g}{s_g}\right) + z_g, the perturbed attention logits incur an additive error δt,i=1dhqt⊤(k^i−ki)\delta_{t,i} = \frac{1}{\sqrt{d_h}} q_t^\top (\hat{k}_i - k_i).

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 G=64G = 64 into packed bitstreams.

Diagram
Rendering diagram...
Figure 1: Sink-preserved mixed-precision KV cache lifecycle during mobile decoding.
Figure 2: Physical byte layout of a 64-element quantized KV block aligned to 64-byte ARMv9 cache lines.
Figure 2: Physical byte layout of a 64-element quantized KV block aligned to 64-byte ARMv9 cache lines.

Reference Algorithm & Implementation#

Algorithm 1: Cache-Line Aligned Asymmetric Group Quantization
Require: Key block K in R^(G x d_h), bit-width b in {3, 4}
Ensure: Packed bitstream P, per-group scales s, zero-points z
  1. 1:for each head channel c = 1 ... d_h in parallel do
  2. 2: x_min <- min_i K[i, c], x_max <- max_i K[i, c]
  3. 3: s[c] <- max((x_max - x_min) / (2^b - 1), 1e-6)
  4. 4: z[c] <- x_min
  5. 5: q[1..G, c] <- clamp(round((K[1..G, c] - z[c]) / s[c]), 0, 2^b - 1)
  6. 6: pack q[1..G, c] into 64-byte aligned uint8 lane P[c]
  7. 7:end for
  8. 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.

kv_quant_sim.py
python
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_min

Empirical Benchmarks#

Measured across 8,1928{,}192-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 StrategyDecode Speed (tok/s)KV Memory @ 16k (GB)WikiText-2 PPLNeedle Retrieval
FP16 Baseline11.84.296.4198.4%
INT8 Symmetric18.62.186.4298.2%
INT4 Naive (Per-Token)23.11.167.1989.0%
INT4 Per-Channel + FP16 Sinks24.41.196.4897.8%
INT3 Mixed + FP16 Sinks26.20.916.7495.1%
Sustained Autoregressive Decode Throughput @ 8k Context
Tokens per second (higher is better) — memory-bandwidth limited regime on mobile LPDDR5X
FP16 KV Baseline(4.29 GB @ 16k)11.8 tok/s
INT8 Symmetric(2.18 GB @ 16k)18.6 tok/s
INT4 Per-Channel + FP16 Sinks(+0.07 PPL)24.4 tok/s
INT3 Mixed + FP16 Sinks(+0.33 PPL)26.2 tok/s

Open Questions#

  1. Can we fold RoPE rotation after dequantizing low-bit pre-RoPE keys without paying extra register pressure in mobile NEON kernels?
  2. How does sink-preserved INT3 interact with multimodal vision tokens (e.g., high-entropy image patch prefixes in Gemma 4 E4B)?

Footnotes#

  1. Autoregressive decoding has arithmetic intensity near 1 FLOP/byte1\text{ FLOP/byte} at batch size 1, meaning wall-clock latency is governed almost entirely by DRAM bandwidth rather than peak compute. ↩

  2. 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/}
}