Skip to content

VRAM arithmetic for local models

How much memory a model and its context actually need, derived rather than guessed, and what happens at the moment it does not fit.

Almost every VRAM table on the web is somebody’s recollection. They disagree with each other by a factor of two, they rarely say which model of a given size they mean, and none of them shows the arithmetic — so when your card is 2 GiB short there is nothing to reason with. The numbers are not mysterious. A model’s weights occupy its parameter count times its bits per weight, divided by eight. Its context occupies two tensors per layer, sized by the number of key/value heads and the head dimension, times the context length. The runtime takes a fixed amount before either of those loads. That is the whole model of memory, and every page here is that equation with different numbers in it.

Both inputs are published. Parameter counts fall out of the shapes in a model’s own config; bits per weight is documented per quantization type by the tool that produces the file. So these pages derive rather than assert, and where a figure is an approximation they say which term was approximated. Nothing here was benchmarked — where a page needs a speed, it gives the bandwidth-bound ceiling and the command to measure the real thing on your own machine.

How Much VRAM a 7B Model Needs at Q4, Q5 and Q8

The weights term, the KV-cache term and the runtime term for a 7B-class model, each derived from published parameter shapes and llama.cpp's own bits-per-weight table.

10 min read

How Much VRAM a 13B Model Needs at Each Quant Level

Weights per quantization level for a 13B, and why the context term rather than the weights is what pushes it off a 12 GiB card.

10 min read

How Much VRAM a 34B Model Needs at Each Quant Level

Two different architectures are both called 34B; their weights differ by 2% and their context cost by 25%, and only one of them fits a 24 GiB card usefully.

10 min read

How Much VRAM a 70B Model Needs at Each Quant Level

Weights, context and per-card overhead for a 70B, checked against llama.cpp's own published file size, and the card counts each quant implies.

10 min read

Why a Mixture-of-Experts Model's VRAM Need Isn't Its Total Parameter Count

Active parameters set the speed and total parameters set the memory, and the gap between the two is why a sparse model is cheap to run and expensive to hold.

9 min read

Fitting a Model and Its Context Window in 8GB of VRAM

The budget equation solved for context length on an 8 GiB card, at each quant, with the runtime reserve stated as an assumption rather than hidden.

9 min read

Fitting a Model and Its Context Window in 12GB of VRAM

Why the extra 4 GiB over an 8 GiB card is better spent raising the quant of a smaller model than on stepping up to a 13B.

9 min read

Fitting a Model and Its Context Window in 24GB of VRAM

The three regimes a 24 GiB card supports — a 34B with short context, a 13B at full precision, or an 8B with a hundred thousand tokens — with the arithmetic for each.

10 min read

What Happens When a Model Doesn't Fit in VRAM

The two failure modes — a hard allocation error and a silent spill to system RAM — how to tell them apart, and the arithmetic behind the throughput cliff.

10 min read

How Much VRAM CUDA Reserves Before Your Model Even Loads

What occupies the card before any weights arrive, why the figure is machine-specific rather than a constant, and how to measure your own in two commands.

9 min read

Quantifying the Memory You Save Going From FP16 to Q4

The 4x reduction is 3.27x once the block overhead and the tensor mix are counted, and less again once the KV cache is in the total.

10 min read

How Many Parameters Fit in 16GB of Unified Memory at Q4

Inverting the weights formula gives a parameter ceiling, but the usable fraction of unified memory is machine-set and much less than the total.

9 min read

Why Local Inference Never Saturates a GPU at Batch Size One

Single-stream decode is bandwidth-bound by two orders of magnitude, so a GPU running flat out is doing almost no arithmetic — and the utilisation number you are reading does not measure arithmetic.

10 min read

The Memory Cost of Keeping a Context Window Full During a Long Chat

KV memory grows linearly with every token in the session, but under llama.cpp it is allocated up front — so the ceiling arrives as truncation, not as an out-of-memory error.

10 min read

Other topics