AI Infra Interviews logo

KV cache & memory-fit calculator

Estimate KV cache per token, sequence and batch for a model or custom architecture. Compare weights, cache and an adjustable reserve against total device memory, with formulas and placement limitations.

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
Aggregate memory estimate · 1 × H100 80GB SXM
EXCEEDS TOTAL CAPACITY
weightsKV cachereserveddashed line = capacity
capacity 80.0 GBreserve 10% 8.0 GBfree for KV 0.0 Bweights + reserve exceed capacity by 69.2 GB

This adds device capacities before checking weights and KV demand. Each GPU must still fit its assigned tensors in a supported parallel layout. Quantization metadata and engine allocations can change the result; throughput and latency require a workload measurement. GB and KB here use decimal units.

How this was computed
KV per token
2 × 80 × 8 × 128 × 2 B = 328 KB
KV total
327,680 B × 8,192 × 32 = 85.9 GB
Weights
70.60B × 2 B = 141 GB
KV budget / deficit
80.0 GB − weights − 8.0 GB reserve = -69.2 GB

Use the result to make a decision

Start with the model geometry and storage formats, calculate retained KV bytes, then subtract weights and runtime reserve from available memory. Check the budget on every GPU in the proposed layout. This gives a memory limit; a workload benchmark must establish throughput and latency.

Questions people ask

For full-attention MHA/GQA: 2 × layers × KV heads × head dimension × bytes per element. Llama 3.1 70B with BF16 KV uses 327,680 bytes per token: 320 KiB or 327.68 decimal KB. At 8,192 retained tokens that is 2,684,354,560 bytes, about 2.68 GB per sequence. Sliding-window, hybrid and MLA layouts need their own accounting.