AI Infra Interviews logo

KV cache & memory-fit calculator

Compute the KV cache per token, per sequence and per batch for Llama, Qwen, DeepSeek, Mixtral and gpt-oss, or a custom architecture, then check whether weights plus cache fit on a chosen GPU. Formula shown with every result.

Model

70.6B params · 80 layers · 8 KV heads × 128 head dim

Workload

Hardware

KV cache per token
328 KB
80 layers × 2 × 8 heads × 128
Per sequence at this context
2.7 GB
8,192 tokens
KV for 32 sequences
85.9 GB
Weights
141 GB
2 B/param
Memory budget · 1 × H100 80GB SXM
DOES NOT FIT
weightsKV cachereserveddashed line = capacity
capacity 80.0 GBreserved ~10% 8.0 GBfree for KV 0.0 Bweights alone exceed capacity by 69.2 GB
How this was computed
KV per token
2 × 80 × 8 × 128 × 2 B = 328 KB
KV total
328 KB × 8,192 × 32 = 85.9 GB
Weights
70.60B × 2 B = 141 GB
Free for KV
80.0 GB − weights − 10% = -69200000000.0 B

What the interviewer is actually asking

The serving loop's opening question is some version of "will this fit, and for how many users?" The answer is two multiplications and a subtraction, and the interviewer is listening for whether you reach for the KV cache unprompted, whether you know that grouped-query attention is what makes 70B serviceable, and whether you leave headroom for the allocator.

Questions people ask

What is the KV cache size formula?

Per token: 2 × layers × KV heads × head dimension × bytes per element. Multiply by context length for one sequence and by the number of concurrent sequences for the batch. Llama 3.1 70B in bf16 is 2 × 80 × 8 × 128 × 2 = 320 KB per token, so an 8k-token sequence holds about 2.6 GB of cache.

Why is the KV cache so much smaller for DeepSeek-V3?
How much memory should I reserve beyond weights and KV cache?
Does quantizing the KV cache to fp8 halve the number?