Capacity planning tool
LLM GPU memory and KV cache calculator
Estimate dense model weight storage and standard attention KV-cache tensors. Load a published model preset or enter custom architecture, precision, context, and concurrency values to plan GPU sizing.
Model and workload
GPU capacity and concurrency comparison
Planning estimate assuming 90% usable GPU memory minus your additional runtime allowance. Verify actual startup block counts in your serving engine logs.
| GPU | Advertised VRAM | Memory bandwidth | Max 4,096-token sequences (1 GPU) | Min GPUs for 1 sequence |
|---|---|---|---|---|
| NVIDIA RTX 4090 | 24 GB | 1,008 GB/s | 10 seq | 1 GPU |
| NVIDIA L40S | 48 GB | 864 GB/s | 50 seq | 1 GPU |
| NVIDIA A100 80GB | 80 GB | 2,039 GB/s | 104 seq | 1 GPU |
| NVIDIA H100 SXM | 80 GB | 3,350 GB/s | 104 seq | 1 GPU |
| NVIDIA H200 | 141 GB | 4,800 GB/s | 206 seq | 1 GPU |
| AMD Instinct MI300X | 192 GB | 5,300 GB/s | 292 seq | 1 GPU |
Formulas and worked example
Weight bytes = parameters × bits per weight ÷ 8
KV bytes = 2 × layers × KV heads × head dimension
× cached tokens × concurrent sequences × bytes per value
GiB = bytes ÷ 1,073,741,824With 8 billion parameters at 16 bits, weights occupy about 14.901 GiB. At 32 layers, 8 KV heads, head dimension 128, 4,096 cached tokens, one sequence, and two bytes per KV value, the cache needs 0.5 GiB. The combined tensor estimate is 15.401 GiB before overhead.
Use KV heads, not query heads, for grouped-query attention (GQA). Cached tokens include both the prompt and generated continuation. Multi-head latent attention (MLA) models compress the cache; read MLA vs. GQA for their exact latent storage math.
What this estimate leaves out
Quantization scales, runtime allocations, CUDA graphs, temporary prefill activations, paged block fragmentation, and non-model processes require extra memory. Set a realistic additional allowance (typically 1.5–4 GiB per GPU) before choosing hardware. Mixture-of-Experts (MoE) weights depend on total resident parameters, not active parameters per token.
Next, estimate latency and tokens/s in the roofline latency calculator, price replicas in the cost per million tokens calculator, or generate flags in the vLLM & SGLang command builder.
Understand, practice, and verify the estimate
- Free lesson: The KV cache and its memory cost
- Free lesson: Quantization formats, scale math, and error
- Coding problem: Grouped-Query KV Storage in Python
- Coding problem: Token-to-Page Address Translation
- KV-cache formula, diagram, and memory examples
- GPU memory sizing guide for L40S, H100, and H200
- Check documented model and engine compatibility
Frequently asked questions
How do you calculate LLM KV cache memory per token?
Standard GQA and MHA caches store two tensors per attention layer (Key and Value): 2 × layers × KV heads × head dimension × bytes per KV value. Use KV heads rather than query heads when sizing grouped-query attention models like Llama 3.1 or Qwen3.
Why do quantized weights still need extra VRAM headroom?
Group-wise INT4 formats like AWQ and GPTQ store per-group scales and zero points alongside packed weights, and engines allocate workspace buffers for dequantization kernels, activations, and CUDA graphs.
How should I estimate memory for Mixture-of-Experts (MoE) models?
Enter total resident parameters across all routed and shared experts, not active parameters per token. All expert weights must stay in GPU VRAM unless you offload inactive experts.
Does Multi-Head Latent Attention (MLA) use the same KV formula?
No. MLA architectures such as DeepSeek-V3 and DeepSeek-R1 compress keys and values into a single shared low-rank latent vector plus a small decoupled RoPE key per token, reducing per-token KV storage sharply.