Servingcore
GPU memory maths
Weights + KV cache + activations must fit; whatever’s left decides how many users you can serve.
What it is and why it exists
Weights = parameters × bytes per parameter. KV cache per token = 2 × layers × KV heads × head dim × bytes; multiply by context length and concurrent sequences. Add activation and framework overhead (~10–20%). If it doesn’t fit, use quantisation, smaller context, tensor parallelism across GPUs or a bigger GPU.
Quick prototype
Try it and see if it OOMs.
In production, at scale
Write the budget down before choosing instance types: model weights, target context, target concurrency, KV dtype — then pick GPUs and tensor-parallel degree.
Vendors and tools
| NVIDIA H100/H200 80–141 GB, A100 40/80 GB, L40S 48 GB, L4 24 GB | Common inference GPUs |
|---|---|
| Hugging Face accelerate estimate-memory | Quick estimates |
On AWS: p5 (H100), p5e/p5en (H200), p4d (A100), g6e (L40S), g6 (L4), g5 (A10G) instances; Inferentia2 (inf2).
How it fails
- Budgeting weights only and forgetting KV cache
- Max context set to the model maximum with high concurrency
What the interviewer asks next
Can an 8B FP16 model serve 32 concurrent 8k-token sequences on one 80 GB GPU?
Weights ≈ 16 GB. KV at 128 KB/token (32 layers, 8 KV heads, dim 128, FP16) × 8,192 × 32 ≈ 34 GB. ~50 GB plus overhead — yes, with room to spare.