Compare Prices
ProvidersModelsCompareCalculatorsGuides
Open-Source & Local AI6 min readUpdated 2026-11-25

How to Calculate VRAM for Local LLMs (Weights, GGUF & KV Cache)

Learn the exact memory math behind running Llama 4, Qwen4, and DeepSeek V4 locally—covering quantization bits, KV-cache growth at long context, and Apple Silicon unified memory.

Key Takeaways
  • Model weights in VRAM equal `(Parameters_B × Bits_Per_Weight) / 8` GB, plus ~15–20% overhead for KV cache and CUDA/Metal buffers.
  • 4-bit quantization (Q4_K_M / AWQ) cuts a 70B model from ~140 GB (FP16) down to ~42 GB of weights—fitting onto dual 24 GB GPUs or a 64 GB Mac.
  • Long context windows rapidly inflate KV-cache memory unless Grouped Query Attention (GQA), MLA, or KV-cache quantization is enabled.

1. Step One: Model Weight Memory by Quantization

The largest chunk of GPU VRAM goes to holding the neural network weights. In full 16-bit floating point (FP16 / BF16), each billion parameters requires 2 bytes, so a 70B model consumes ~140 GB before you process a single prompt—and massive Mixture-of-Experts models like Llama 4 Maverick (400B total / 17B active) or DeepSeek V4.1 Flash (236B total) require substantial host RAM or multi-GPU VRAM even when quantized.

Quantization compresses weights from 16 bits down to 8-bit (Q8_0), 4-bit (Q4_K_M / EXL2 / AWQ), or even 3-bit formats. For most coding and chat workloads, Q4_K_M (~4.85 bits/weight on average due to mixed-precision attention tensors) retains ~98%+ of FP16 quality while shrinking memory by roughly 3.3x.

// Practical weight memory estimate in Gigabytes
// FP16 = 2.0 GB/B | Q8_0 = 1.07 GB/B | Q4_K_M = 0.61 GB/B | Q4_0 = 0.56 GB/B
const weightsGB = paramsBillions * (bitsPerWeight / 8);

2. Step Two: Don't Forget KV Cache at Long Context

Many first-time local setups crash with `CUDA out of memory` not when loading the model, but when pasting a 64K-token file. Every token in your active context window stores Key and Value attention tensors inside VRAM (the KV cache).

Older Multi-Head Attention (MHA) models blew up KV cache fast. Modern open-weight architectures like Llama 4 Maverick (524K context), Qwen4 / Qwen3.8 Flash (1M context), DeepSeek V4 Pro, and DeepSeek V4.1 Flash (1M context) use Grouped Query Attention (GQA) or Multi-Head Latent Attention (MLA) to cut KV-cache memory by 4x–8x. Even with GQA, pushing context past 64K tokens can still demand 5–10 GB of extra VRAM just for KV cache.

  • Keep 1.5–2.5 GB of headroom for CUDA/PyTorch/llama.cpp activation buffers.
  • Enable Q8_0 KV-cache quantization in llama.cpp or Ollama (`OLLAMA_KV_CACHE_TYPE=q8_0`) to halve context memory.
  • Reduce `num_ctx` from 131K down to 16K or 32K if your GPU sits near 95% utilization.

3. Choosing Hardware: RTX GPUs vs. Apple Silicon vs. Cloud

A single 24 GB RTX 3090 or RTX 4090 comfortably runs 14B–32B models like Qwen3.8 Flash (32B) at Q4_K_M with generous context, and an RTX 5090 (32 GB) pushes Q4_K_M 32B–34B models at full speed. For 100B+ MoE weights such as Llama 4 Scout (109B), Llama 4 Maverick (400B), or DeepSeek V4.1 Flash (236B), either pair multi-GPU rigs or use Apple Silicon M-series Macs with 64 GB, 128 GB, or 192 GB of Unified Memory.

Remember that Mac Unified Memory reserves roughly 25%–30% for macOS by default (configurable via `sysctl iogpu.wired_limit_mb`), and token generation speed scales directly with memory bandwidth (e.g., M3/M4 Max at ~400–546 GB/s vs. RTX 4090 at 1,008 GB/s).

More Developer Guides

All guides