Running Large Language Models locally using Ollama, vLLM, or llama.cpp requires precise memory sizing. Running out of VRAM (Out-Of-Memory / OOM) halts inference or forces slow CPU offloading over PCIe lanes, reducing token throughput by 15x to 30x.
1. Model Weight Memory Formulation
Model weights represent static memory allocated at startup:
VRAM_weights (GB) = (Parameters_billions × Bits_per_weight) ÷ 8 × 1.05
The 1.05 multiplier accounts for unquantized output classification tensors and normalization layer weights which remain in FP16.
2. Dynamic KV Cache Allocation Equation
During autoregressive decoding, every generated token caches key and value tensors:
KV_cache (GB) = 2 × n_layers × n_kv_heads × d_head × Context_length × Bytes_per_element ÷ 10^9
For a 70B parameter model with 8,192 context tokens, uncompressed FP16 KV cache consumes approximately 1.3GB. At 128K context, the KV cache expands to over 20GB, frequently exceeding the size of the model itself.