Learn AI Math

KV Cache Size

What is KV Cache Size?

In one sentence: KV cache size is how much memory the KV cache needs, which grows with context length, layers, heads and number of users.

Every token adds keys and values for every layer. Long conversations and many users at once can make the KV cache bigger than the model itself. Tricks like GQA and KV cache quantization shrink it.

Σ Quick math / rule of thumb: KV bytes per token = 2 (K & V) × Layers × KV heads × Head size × Bytes per number. Example: Llama 3 8B in FP16 (32 layers, 8 KV heads, size 128) uses ~128 KB per token—about 16 GB for a full 128K-token context. Bigger models need more.

What does KV Cache Size look like?

A 70B model with a 128,000-token context could need tens of gigabytes just for the KV cache.

Why does KV Cache Size matter?

KV cache size often decides how long a context and how many users a server can handle.

Last updated · Fact-checked by The AI Math

Linking to this page from a lesson or article?

Like this explanation? Get one every week.

The AI Math newsletter turns confusing AI news into plain English. No hype, no jargon walls.