How LLM VRAM & Token Generation Speed Are Calculated
Sizing hardware for local or self-hosted open-weight LLMs involves three distinct memory components: static model weights, dynamic Key-Value (KV) cache, and framework runtime overhead (CUDA kernels, activation scratch buffers, and tensor-parallel communication buffers).
Memory Sizing Formulas
- Model Weights (GB):
Total_Params_B × (BPW / 8) × 1.03. Quantized formats likeQ4_K_Maverage roughly 4.85 bits per weight once scale factors and unquantized embedding/output layers are included. - KV Cache (GB):
2 × Layers × KV_Heads × Head_Dim × Context_Length × Batch × KV_Bytes / 10^9. Modern architectures use Grouped-Query Attention (GQA) or Multi-Head Latent Attention (MLA) to cut KV cache growth drastically, and quantizing KV cache toQ8_0orFP8halves KV memory with negligible quality loss. - Memory-Bandwidth Bound Decode Speed: Single-stream token generation reads all active model weights from VRAM once per generated token. Thus theoretical decode throughput scales with
(Aggregate_Memory_Bandwidth_GBs / Active_Weights_GB) × Efficiency(modeled conservatively at ~0.72 with a multi-GPU tensor-parallel communication factor).
MoE vs. Dense Models & Apple Silicon Notes
Mixture-of-Experts (MoE) models such as Llama 4 Scout (109B total / 17B active) or DeepSeek-R1 (671B total / 37B active) still require VRAM capacity for all parameters, but generate tokens at the speed of their smaller active parameter subset. On Apple Silicon Macs (M3/M4/M5/M6 unified memory), macOS reserves roughly 25% of system RAM by default, so usable GPU memory is modeled at ~75% unless adjusted via sysctl iogpu.wired_limit_mb.
Frequently Asked Questions
Why does my model slow down drastically when it barely exceeds VRAM?
When total memory exceeds physical GPU VRAM, runtimes like llama.cpp and Ollama offload remaining layers to system DDR RAM over PCIe. Because system RAM bandwidth (~50–90 GB/s) and PCIe transfer are an order of magnitude slower than GPU VRAM (500–8,000 GB/s), even 10–15% CPU offload can cut token/s speed by 3x–8x.
Should I quantize KV cache to Q8_0 or FP8?
For contexts of 8,192 tokens and above, enabling OLLAMA_KV_CACHE_TYPE=q8_0 (with Flash Attention) or vLLM --kv-cache-dtype fp8 is one of the highest-value optimizations available: it cuts KV cache memory by ~50% while preserving output fidelity.