- Key idea
- Model size = parameters × bits ÷ 8, the KV cache, VRAM vs disk, and why generation speed is limited by memory bandwidth
- Real world
- Moving house: what matters isn’t just whether your furniture fits in the van, but how many trips it takes. Smaller boxes mean fewer trips.
- In an LLM
- Llama 3.1 8B in bf16 is 16 GB, too big for a 12 GB gaming GPU. In 4-bit it is about 4.6 GB: it fits, and it generates text roughly three times faster because there are fewer bytes to read per token.
The one formula
A model’s weights take
So for an 8-billion-parameter model:
| Format | Bits | Size |
|---|---|---|
| fp32 | 32 | 32 GB |
| bf16 / fp16 | 16 | 16 GB |
| 8-bit | about 8.5 | about 8.5 GB |
| 4-bit | about 4.5 | about 4.5 GB |
| 2-bit | about 2.6 | about 2.6 GB |
The “about” is because quantized formats also store scales, which add a fraction of a bit per weight: see granularity.
Disk size for any model
Pick a model size and read off how big its file is in each format. A 4B model, for example, is 16 GB in fp32, 8 GB in bf16, 4 GB in int8 and about 2.5 GB as a 4-bit GGUF.
The KV cache
While generating, a transformer keeps the keys and values of every previous token so it doesn’t recompute them: the KV cache. Its size grows with the length of the conversation and the number of users:
For Llama 3.1 8B in bf16 that is bytes, 128 KiB per token. A 32,000-token conversation needs 4 GB of KV cache, a quarter of the bf16 weights.
Try it
Speed: every token reads every weight
To generate one token, the GPU must read every weight from memory once. For a single user, the arithmetic is quick; the reading is slow. So a rough ceiling on speed is
An RTX 4090 reads about 1 TB/s. With 16 GB of bf16 weights that is at most about 60 tokens per second; with 4.6 GB of 4-bit weights, over 200. This is why quantization is about speed as much as size: what to quantize shows when this stops being true.
You have 16 m³ of belongings and a van that holds 20 m³, but the van takes an hour per round trip. Pack the same things into 4.5 m³ (vacuum bags, flat-packing) and they still fit, but now everything goes in one trip with room to spare for a friend’s boxes. Compression helps whether the bottleneck is space or trips.
Llama 3.1 70B in bf16 is 141 GB: no single consumer GPU comes close. At about 4.5 bits per weight it is around 40 GB: two 24 GB GPUs, or one Mac with 64 GB of unified memory. At about 2.5 bits, 22 GB fits a single 24 GB card, at a real cost in quality. Choosing that trade-off is what the GGUF and choosing pages are about.
Disk, RAM and VRAM
- Disk holds the file. A quantized GGUF or safetensors file is roughly the size of its weights.
- VRAM (GPU memory) is where weights must live to run fast. It is the scarce resource.
- RAM can hold weights that don’t fit in VRAM (llama.cpp can split layers between them), but CPU memory bandwidth is much lower, so those layers run much slower.
Training needs far more memory than inference: gradients, optimizer states (Adam keeps two extra numbers per weight, usually in fp32) and saved activations. A rough rule is 16 bytes per parameter for mixed-precision training with Adam, which is why QLoRA freezes a 4-bit base model and only trains small adapters.
Where this shows up
- Bits and bytes: bits, bytes and integers.
- Memory-bound vs compute-bound: what to quantize.
- Shrinking the KV cache: quantizing the KV cache.
The arithmetic
For parameters at bits per weight (including scale overhead), weights take bytes. The KV cache for batch and context is
with layers, key/value heads (grouped-query attention makes this smaller than the number of query heads) and head size .
A decoding step at batch size costs about floating-point operations and reads bytes. Its time is roughly
The ratio of FLOPs to bytes is the arithmetic intensity; at small it is far below what a GPU can sustain, so decoding is memory-bound.
Training memory
Mixed-precision training with Adam typically keeps bf16 weights (2 bytes), bf16 gradients (2), an fp32 master copy (4) and two fp32 Adam moments (8): 16 bytes per parameter before activations. A 7B model therefore needs over 110 GB to fully fine-tune, versus about 4 GB of frozen 4-bit weights plus small trainable adapters under QLoRA (Dettmers et al., 2023).