Skip to content

Inference EngineeringInteractive lab

Quantisation memory budget

Work out whether that model fits in your GPU

Parameter count, precision, KV cache and context length, turned into the number of gigabytes you actually need - and the precision you would have to drop to.

What this teaches

  • Precision formats
  • KV cache growth
  • VRAM budgeting

The model and the card

80 layers · 64 heads · 8 KV heads

Head dimension is 8192 / 64 = 128. This model uses grouped-query attention: 64 attention heads share 8 KV heads, so the cache is 8x smaller than the head count alone would suggest. Assuming one KV head per attention head is the commonest way to conclude a model does not fit when it does.

What serving needs

GiB, not GB
41.9
GiB needed
37.0
GiB of weights
2.5
GiB of KV cache
+38.1
GiB spare

Llama-3.1 70B at Q4_K_M with a 8,192 token context needs 41.9 GiB, which fits on H100 80GB.

  • Weights
  • KV cache
  • Activations and workspace (an allowance)

Fits on H100 80GB with 38.1 GiB to spare. The highest precision that fits here is fp8.

At Q4_K_M on H100 80GB, the longest context that still fits is 133,008 tokens at 1 concurrent sequence. That is solved by inverting the KV term rather than searched for: everything else is fixed and the cache is linear in context, so it is one division.

Every precision, same model

read the answer off the row
Total memory by weight precision for Llama-3.1 70B on H100 80GB.
PrecisionBytes/paramWeights GiBTotal GiBFits 80 GiB?
fp32 full precision4263.0281.5no
fp16 / bf16 the serving default2131.5142.1no
fp8 Hopper and newer165.872.4yes
int8 weight-only quantisation165.872.4yes
Q5_K_M 5.5 bits with block scales0.687545.250.6yes
Q4_K_M 4.5 bits with block scales0.562537.041.9yes
int4 (naive) 4 bits, scales uncounted0.532.937.6yes

Q4_K_M is 4.5 bytes per 8, not 4. A block-quantised format stores a scale, and usually a zero-point, for every block of weights it packs, so the real cost is above the nominal bit width. The naive int4 row is there for contrast: it is what a calculator that multiplies by 0.5 tells you, and it understates the weights by 11%, which is exactly the margin a borderline fit turns on.

What context costs

at Q4_K_M, batch 1
KV cache and total memory by context length for Llama-3.1 70B.
ContextKV cache GiBTotal GiBFits 80 GiB?
1k0.3139.7yes
2k0.6340.0yes
4k1.2540.7yes
8k2.5041.9yes
16k5.0044.4yes
32k10.0049.4yes
64k20.0059.4yes
128k40.0079.4yes
256k80.00119.4no

The KV column doubles when the context doubles - it is linear, and that is the whole shape of this table. Do not carry that intuition across to compute: attention cost grows with the SQUARE of the sequence length while the cache it reads grows linearly. Different quantities, and only the first one is on this page.

What is real here, and what is standing in

Real: the weights term, the KV cache term and the training terms are exact arithmetic on the architecture numbers shown, and you can redo any of them by hand. The layer, head and KV-head counts come from the models' published configuration files. The highest-precision-that-fits and longest-context-that-fits answers are solved, not approximated.

Standing in: activations and workspace are an allowance scaled off the weights and the batch, not a measurement - the real figure swings by gigabytes between one serving stack and another, and it is the reason this page reports headroom instead of a hard yes. The block-quantised rows use representative bits-per-parameter; GGUF, AWQ and GPTQ variants differ from each other. And a real deployment adds a question this page cannot answer: vLLM preallocates its KV pool from a fixed fraction of the card rather than growing it on demand, so "does it fit" there is partly a configuration setting.

Everything on this page runs in your browser. Nothing you type is sent anywhere, there is no account, and it keeps working offline.