How much memory does a 70B model need?
Work out the memory a language model needs from its parameter count: weights, quantization and the context cache, with the arithmetic for Llama 3.1 70B.
2 min readPart 9 of 21
On this page
Before downloading a model to run on your own hardware, you can work out whether it will fit. Two things need memory: the model's parameters, which is a fixed amount, and the conversation, which grows with its length.
Weights: parameters × bytes
The rule is one multiplication. Most models are published with 16-bit numbers, which take 2 bytes each. Llama 3.1 70B has 70,553,706,496 parameters, so:
python3 -c "print(70_553_706_496 * 2 / 1e9, 'GB')"141.107412992 GBThat's more than any single consumer graphics card holds. Storing each parameter in fewer bits, called quantization, shrinks it in proportion:
A shortcut: at 8 bits, the number of billions is the number of gigabytes. Double it for 16-bit, halve it for 4-bit.
What quantization costs
Rounding the parameters loses detail. In general, 8-bit versions behave much like the original, 4-bit versions lose some quality, and below that the loss becomes easy to notice. How much depends on the model, the method and the task, so test on your own work instead of trusting a single benchmark number.
Between a smaller model at high precision and a larger one at low precision of the same memory size, there's no universal winner. They're the two to compare.
The conversation: the key-value cache
While reading and writing, the model keeps the keys and values of every token so far, so it doesn't have to compute them again. This KV cache grows with every token. Its size also follows from the published dimensions. For Llama 3.1 70B: 80 layers × 8 key-value heads × 128 numbers × 2 (key and value) × 2 bytes:
python3 -c "per_token = 80 * 8 * 128 * 2 * 2print(per_token / 1024, 'KiB per token')print(per_token * 131072 / 1024**3, 'GiB at 131,072 tokens')"320.0 KiB per token40.0 GiB at 131,072 tokensOther models differ: the number of layers and key-value heads is in each model's config.json, as num_hidden_layers and num_key_value_heads. DeepSeek-V3 uses a different design that compresses the cache, so this formula doesn't apply to it.
This explains a common surprise: a model that loads fine and then runs out of memory in a long chat. Setting a shorter context is often the easiest fix.
Adding it up
Weights + cache + a margin for the software itself. For a 4-bit 70B model with 8,192 tokens of context: 35.3 GB + 2.7 GB (2.5 GiB) ≈ 38 GB, before the margin.
Then look at where the memory is. Speed depends mostly on how fast the memory can be read, because every token requires reading all the active weights. As an upper bound, tokens per second can't exceed memory bandwidth divided by the size of the weights used. With 35 GB of weights, memory that reads 100 GB per second can't produce more than about 3 tokens per second in one conversation, whatever the processor.
If a model doesn't fit on the graphics card, software can split it with ordinary memory. It runs, but at the pace of the slower part.