Why it matters

KV cache is the memory workhorse of decode. Understanding size shapes serving cost.

Advertisement

The architecture

K, V stored per layer per head.

Decode reads all past K/V.

Grows linearly with tokens.

KV cache mathStore K, Vper layer per headDecode readsall pastSize2LHd·seq·bytesFor 70B FP16 with 8k context, KV can exceed 100 GB per request in worst case
KV cache math.
Advertisement

How it works end to end

Sized per layer × heads × dim.

Grows with tokens.

Read every step of decode.