How it works
Weights are model size times bytes per weight. The KV cache keeps two tensors per layer per token: 2 x layers x KV heads x head dimension x 2 bytes for FP16. About 1 GB goes to the runtime. Adding the three gives the memory you need.
Formula
KV (GB) = 2 x layers x kv_heads x head_dim x ctx x 2 / 1e9.
Total = weights + KV + 1.
Example
Model size (billion parameters): 7; Context length (tokens): 8,192; Layers: 32; KV heads: 8. VRAM needed: 5.57
Frequently asked questions
Why 2 bytes in the KV cache?
The cache is usually kept in FP16, so each value is 2 bytes. Halve it for an 8-bit cache.
Does this include the operating system?
No. It is GPU memory only, for one request at one context length.