localaiforum
Log in
Guide โ€บ Hardware

VRAM math

Every "will this run on my card" question is arithmetic, not folklore.
Total VRAM is the weights, plus the KV cache, plus a fixed slab of
activations and engine overhead. If you can multiply parameters by bits,
you can size a machine before spending anything on it. This page gives the
formula, worked tables, and a 16 GB walkthrough you can copy for any card.

The formula

total VRAM   = weights + KV cache + overhead
weights (GB) = parameters (B) ร— bits per weight รท 8
KV cache     = bytes per token ร— context length   (see [KV cache](/guide/kv-cache))
overhead     โ‰ˆ 1โ€“2 GB (activations, driver context, buffers, fragmentation)

Effective bits per weight for the common GGUF quants: Q4_K_M โ‰ˆ 4.8,
Q5_K_M โ‰ˆ 5.7, Q6_K โ‰ˆ 6.6, Q8_0 โ‰ˆ 8.5. Multiply parameters by that, divide
by 8, and you are within a few percent of the file size on disk.

Rules of thumb worth memorizing, in GB per billion parameters:

  • Q4_K_M โ‰ˆ 0.6 GB โ€” the everyday workhorse
  • Q5_K_M โ‰ˆ 0.7 GB
  • Q6_K โ‰ˆ 0.8 GB โ€” near-lossless to most eyes
  • Q8_0 โ‰ˆ 1.1 GB โ€” transparent, roughly double Q4 cost
  • fp16/bf16 = 2.0 GB โ€” training and serious fine-tuning territory

Worked examples

KV cache size depends on the architecture. Modern GQA models run roughly
128โ€“256 KB per token at fp16 KV for the 8Bโ€“32B classes, and around 320 KB
for 70B-class. The exact formula lives on KV cache;
here we just add it in. Overhead is budgeted at 1.5 GB per row.

Q4_K_M (~4.8 bits per weight):

Model Weights KV @ 8k KV @ 32k Total @ 8k Total @ 32k
8B 4.8 GB 1.0 GB 4.2 GB 7.3 GB 10.5 GB
14B 8.4 GB 1.6 GB 6.4 GB 11.5 GB 16.3 GB
32B 19.2 GB 2.1 GB 8.4 GB 22.8 GB 29.1 GB
70B 42.0 GB 2.6 GB 10.5 GB 46.1 GB 54.0 GB

Q6_K (~6.6 bits per weight):

Model Weights KV @ 8k KV @ 32k Total @ 8k Total @ 32k
8B 6.6 GB 1.0 GB 4.2 GB 9.1 GB 12.3 GB
14B 11.6 GB 1.6 GB 6.4 GB 14.7 GB 19.5 GB
32B 26.4 GB 2.1 GB 8.4 GB 30.0 GB 36.3 GB
70B 57.8 GB 2.6 GB 10.5 GB 61.9 GB 69.8 GB

Two patterns to internalize. Q6_K costs ~35โ€“40% more than Q4_K_M โ€” often
the difference between one GPU tier and the next. And KV at 32k context is
not a rounding error: on small models it rivals the weights themselves.
Old MHA designs (Llama-2 era) carried 4โ€“8ร— larger KV caches, which is why
32k context used to demand exotic hardware and GQA models do not.

OOM at load vs OOM mid-generation

  • At load: weights alone exceed free VRAM. The engine refuses to start,
    or swaps layers to CPU and crawls. Honest, immediate, easy to diagnose.
  • Mid-generation: weights fit, but the KV cache grows token by token.
    A fresh session works fine; forty turns later, after a RAG dump or a
    pasted file, the cache eats your headroom and the process dies
    mid-answer. This is the sneaky one โ€” always size for the context you
    will actually reach, not the first prompt.

Watch it happen live:

watch -n1 nvidia-smi --query-gpu=memory.used,memory.total --format=csv

Sizing worksheet: the 16 GB walkthrough

  1. Usable budget: 16 GB ร— 0.85 โ‰ˆ 13.6 GB. Desktop, browser, and driver
    already reserve 0.5โ€“1 GB; 10โ€“20% headroom is the rule, not a nicety.
  2. Dream: 32B Q4_K_M โ€” 19.2 GB of weights alone. Dead on arrival.
  3. Realistic: 14B Q4_K_M at 8k context: 8.4 + 1.6 + 1.5 = 11.5 GB. Fits
    with ~15% headroom. Ship it.
  4. Now you want 32k context: 8.4 + 6.4 + 1.5 = 16.3 GB. Over budget.
  5. Three fixes โ€” pick one or combine:
    • Quantize the KV cache to q8_0: 6.4 โ†’ 3.2 GB, total 13.1 GB. In.
    • Drop weights to Q4_K_S or IQ4_XS, saving another ~0.5โ€“1 GB.
    • Drop to 8B Q6_K: 6.6 + 4.2 + 1.5 = 12.3 GB, roomy.

The same five steps work for an 8 GB card, a 24 GB card, or a 48 GB
dual-GPU box. Budget, dream, subtract, adjust.

Leave headroom, always

Engines allocate scratch buffers per batch slot, fragmentation accumulates
over a long-running server, and concurrency multiplies KV per active
request. A config that "just fits" in a one-shot bench test will OOM in
production. 10โ€“20% free is the tax for staying up. For what fits at each
card tier in practice, see GPU tiers; for why the
quant bits are what they are, see Quantization.

Related: Quantization ยท KV cache ยท
GPU tiers