LLM VRAM Calculator

How much GPU memory does a local LLM actually need? This calculator estimates the total VRAM for running a model with llama.cpp, Ollama or LM Studio: the weights at your chosen quantization, the KV cache sized from the model's real architecture (layers, KV heads and head dimension) at your chosen context length, plus runtime overhead. Pick a preset model or enter your own numbers, choose a quantization, set your context length and your GPU — and see instantly whether it fits, how much headroom you have, the largest context that would fit, and which quantization is the best one your card can run.

100% private. Every estimate on this page is computed in your browser with plain JavaScript. No model parameters, file names or hardware details are sent to any server — you could even cut the network cable after the page loads and it would keep working.

1 · Model

Architecture (edit for a custom model)

KV heads is the grouped-query head count from the model's config.json (num_key_value_heads). Models with multi-head attention (Llama 2, Phi-3) use the full attention-head count instead. Head dimension is usually hidden_size ÷ num_attention_heads.

2 · Quantization & file size

Leave empty to estimate from parameters × bits-per-weight. If you already know the real download size of your GGUF file, enter it here and the calculator uses that number instead — actual files run a few percent larger than the pure math because of scale tensors and metadata.

3 · Context & KV cache

The KV cache grows linearly with context length and sequence count. Quantizing it (llama.cpp's --cache-type-k/v) cuts its footprint by up to 4× with negligible quality loss for most local workloads.

4 · Your hardware

Result

—
weights + KV cache + overhead
Weights KV cache Overhead
ComponentSize

Solvers

Largest context that fits your VRAM (this quantization) —
KV cache per 1,000 tokens —

Which quantization fits?

At your current context length and hardware:

QuantizationWeightsTotalVerdict

Ready-to-run command

How the LLM VRAM Calculator works

Running a local LLM needs three separate pools of GPU memory, and most "will it fit?" questions go wrong because only the first one is considered. This calculator adds all three, using the model's real architecture rather than rules of thumb:

weights (GB)   = parameters × bits-per-weight ÷ 8
kv cache (GB)  = 2 × layers × kv_heads × head_dim × context × bytes-per-element
overhead (GB)  ≈ max(1, 3% of weights)   # framework buffers, CUDA/Metal context, logits
total          = weights + kv cache + overhead

The weights term is the model file itself. The bits-per-weight values are the effective llama.cpp sizes including scale tensors (Q4_K_M ≈ 4.84, Q6_K ≈ 6.56, Q8_0 ≈ 8.5), and if you know your actual GGUF file size you can override the estimate with it — real files run a few percent larger than the pure math because of scales and metadata. The KV cache is the per-token key/value memory the attention layers append to as the conversation grows. It is sized by the model's KV head count, not its attention head count: a Llama 3.1 8B has 32 attention heads but only 8 KV heads (grouped-query attention), so its cache is four times smaller than naive math would predict. The overhead covers the runtime's working buffers, the GPU context and the logits buffer — typically around 1 GB for small models, scaling gently with model size. The assumption is stated next to the number in the breakdown table.

Worked example: Llama 3.1 8B on a 12 GB card

Say you want to run Llama-3.1-8B-Instruct at an 8,192-token context with the recommended Q4_K_M quantization, on an RTX 3060 with 12 GB of VRAM. The calculator breaks it down like this:

  • Weights: 8.03B parameters × 4.84 bits ÷ 8 ≈ 4.86 GB. (The actual GGUF download is about 5.0 GB — enter that in the file-size field if you want the estimate to match the file exactly.)
  • KV cache: 2 × 32 layers × 8 KV heads × 128 head dim × 8,192 tokens × 2 bytes (F16) ≈ 1.07 GB.
  • Overhead: ≈ 1.0 GB for the runtime buffers and GPU context.
  • Total: ≈ 6.9 GB — it fits in 12 GB with roughly 5 GB to spare, which is also why you could push the context much further or keep a second small model resident.

Now the trap: the same model at its advertised 128k context would need about 17.2 GB of KV cache alone in F16 — more than double the card. The "max context that fits" solver shows you the honest number (around 50–55k tokens on this hardware, and much more if you quantize the KV cache to Q8_0), instead of letting you discover it as an out-of-memory crash.

Which quantization should I pick?

The "which quantization fits" table answers this directly for your hardware: it lists the total footprint of every quantization at your current context length and marks each one as fitting, tight or overflowing. As a rule of thumb, Q4_K_M is the sweet spot for most local LLMs — quality close to Q5/Q6 at roughly half the memory of F16. Move up to Q5_K_M or Q6_K when you have headroom and the task is quality-sensitive (code, long-form reasoning); move down to Q3_K_M only when a bigger model at lower quality beats a smaller one at higher quality, which is usually true above about 14B parameters. F16 weights are rarely worth it outside of fine-tuning — an 8B model in F16 needs ~16 GB just for the weights, which a Q4_K_M 70B-class model would use for its entire footprint.

Common mistakes when estimating VRAM

  • Counting only the weight file size. A 5 GB GGUF on a 6 GB card sounds like it fits — until the KV cache and runtime overhead push you over. Budget at least ~1–2 GB beyond the file for anything longer than a few thousand tokens.
  • Using attention heads instead of KV heads. With grouped-query attention the cache is sized by num_key_value_heads, which is often ¼ or ⅛ of the attention-head count. Using the full head count overestimates the cache (harmless but pessimistic); using KV heads when a model has plain MHA underestimates it.
  • Planning around the advertised max context. "Up to 128k tokens" describes the architecture's limit, not your card's. The KV cache is linear in context length — double the context, double that slice of VRAM.
  • Forgetting Apple Silicon's memory cap. On Macs the GPU shares unified memory and macOS limits its share by default; a 32 GB M1 Max does not hand all 32 GB to llama.cpp unless you raise iogpu.wired_limit_mb.
  • Treating partial CPU offload as free. Offloading some layers to system RAM works and prevents a crash, but throughput drops sharply — often into single-digit tokens per second. The VRAM math still applies to whatever fraction you keep on the GPU.
  • Leaving the KV cache in F16 when you don't need it. Quantizing K and V to Q8_0 (llama.cpp's --cache-type-k q8_0 --cache-type-v q8_0) roughly halves that slice with no perceptible quality loss for chat workloads — frequently the cheapest way to double your context.

Related tools

If you're setting up a local LLM stack, these pair well with the calculator:


Luke Keam
Spot a bug or want a custom utility built? I'd love to hear from you. Get in touch
Luke Keam | techgeek.biz