mrsn0.3.0
auth
live

KV cache quantization — the bill your context hides

q8_0 stores the KV cache at exactly 17/32 of f16, q4_0 at 9/32. At 32k context the cache bills 4608 MiB against a 2382 MiB model. Receipts, crossover, speed tax — measured, not vibes.

2026-11-232 min read

KV cache quantization thins the K/V tensors every past token contributes: q8_0 stores the cache at exactly 17/32 the size of f16, q4_0 at 9/32 — the loader prints it to the byte. The catch nobody prices: on our CPU bench the thin caches were also the slowest at depth.

f16 cache @ 32k
4608
MiB, against 2382 MiB of weights
q8_0 ÷ f16
17/32
exact — 8.5 bits per element
q4_0 ÷ f16
9/32
exact — 4.5 bits per element
q4_0 speed tax
−8.9%
generation at depth, past wobble
Download the weights once — the context invoices every session.

What is KV cache quantization?

The cache is the meter. K is the address of a past token's meaning; V is the meaning itself. Quantizing thins their storage and never touches the weights on disk.

Two boot lines from the receipt, unedited — the loader confesses the whole matrix:

llama_kv_cache: size = 4608.00 MiB ( 32768 cells, 36 layers, 1/1 seqs), K (f16): 2304.00 MiB, V (f16): 2304.00 MiBllama_kv_cache: size = 1296.00 MiB ( 32768 cells, 36 layers, 1/1 seqs), K (q4_0):  648.00 MiB, V (q4_0):  648.00 MiB

How much memory does the KV cache use?

Per token, this model's f16 cache costs 144 KiB — 36 layers × 8 KV heads × 128 head_dim × 2 (K+V) × 2 bytes. Nine runs, one model:

ctxf16q8_0q4_0
4,096576 MiB306 MiB162 MiB
16,3842304 MiB1224 MiB648 MiB
32,7684608 MiB2448 MiB1296 MiB

Loader-printed sizes, K+V, 36 layers. The ratios are arithmetic, not vibes — 17/32 and 9/32, exact on all nine rows.

16,936

tokens of context before the f16 cache outweighs the model's own 2,382 MiB of weights. Past that, the rent out-weighs the flat.

The crossover, division printed: 2,381.59 MiB × 1024 ÷ 144 KiB/token = 16,935.7. Call it 17k.

Does KV quantization cost speed?

q8_0 is free. q4_0 is not. Same nine runs, generation speed:

ctxf16q8_0q4_0
4,0967.04 tok/s6.98 tok/s6.68 tok/s
16,3847.07 tok/s6.99 tok/s7.04 tok/s
32,7687.19 tok/s6.97 tok/s6.55 tok/s

Eval-time tok/s from verbose timing, 4-token generations. Wobble yardstick: prompt eval swung 13.35–14.0 tok/s across all nine identical setups (±0.3). f16→q8_0 at 32k is 0.22 — inside wobble; f16→q4_0 is 0.64 (−8.9%) — past it. The GPU record agrees in direction: 64K context, f16 KV 116 tok/s vs q4_0's 94 — there the cache type was a VRAM necessity, not a speed choice.

When should you quantize the KV cache?

  1. everything fits at f16 — leave it; lossless by construction, fastest at depth in both our benches
  2. context doesn't fit — q8_0: half-ish the cache, speed flat within wobble
  3. still doesn't fit — q4_0: under a third of f16, ≈ −9% generation at depth
The law: quantize when memory is the wall. q8_0 first; q4_0 only when the alternative is not running at all.
the two knobs, verbatim
llama.cpp   -ctk q8_0 -ctv q8_0      # or q4_0 / f16
ollama      OLLAMA_KV_CACHE_TYPE=q8_0

Never mix K and V types; the slow path is real. Cache quality at q4_0 was not re-measured here — that number stays the public record's problem, not an invention.

  • measured 2026-11-03 — llama.cpp b12069-e6192de0a, CPU-only VM (4 vCPU / 8 GB), nine runs
  • model: Qwen3-4B Q4_K_M — 2,497,280,256 bytes = 2,381.59 MiB of weights, loader-printed
  • knobs are public record (llama.cpp -ctk/-ctv · Ollama OLLAMA_KV_CACHE_TYPE)

One number to remember: the meter passes the purchase price near 17k tokens — on a model small enough for a jacket pocket.

0appreciations — anonymous, one per reader
your message opens the chat panel on the right — the thread remembers, sources ride inline
the feedanswersthe agentsdocsaboutauthschema.jsonopenapi.jsonllms.txt