VRAM Calculator: GPU Memory for Running an LLM
By FindMySum · Last reviewed
A VRAM calculator estimates how much GPU memory a large language model needs to answer requests. Three things fill that memory: the model's weights, the key-value (KV) cache that holds the conversation in progress, and working space for the runtime. The first two can be calculated from published numbers; the third depends on your software, so this page treats it as a stated assumption you can change. The worked example uses the defaults: Llama 3.1 8B in BF16 with an 8,192-token context on a 24 GiB card.
The formula
weights = parameters × bits per weight ÷ 8
KV cache = 2 × layers × KV heads × head dimension × context tokens × batch × KV bits ÷ 8
total = (weights + KV cache) × (1 + overhead %)
The 2 in the KV cache is one key vector and one value vector per token, per layer, per KV head.
Worked example: Llama 3.1 8B
Meta's published architecture for Llama 3.1 8B has 32 layers, 32 attention heads, 8 key-value heads and a model dimension of 4,096, so each head has 4,096 ÷ 32 = 128 dimensions.
- Weights: 8 billion × 16 bits ÷ 8 = 16,000,000,000 bytes (14.9 GiB).
- KV cache per token: 2 × 32 × 8 × 128 × 2 bytes = 131,072 bytes (128 KiB).
- KV cache for 8,192 tokens: 131,072 × 8,192 = 1,073,741,824 bytes (exactly 1 GiB).
- With a 10% overhead assumption: (16,000,000,000 + 1,073,741,824) × 1.1 = 18,781,116,006 bytes, 17.49 GiB.
That fits a 24 GiB card with about 6.5 GiB to spare, and the calculator shows the longest context that would fit with the same settings: about 56,700 tokens.
Precision changes everything
| Weights | Bytes per parameter | 8B model | 70B model |
|---|---|---|---|
| FP32 | 4 | 32 GB | 280 GB |
| FP16 / BF16 | 2 | 16 GB | 140 GB |
| FP8 / INT8 | 1 | 8 GB | 70 GB |
| 4-bit | 0.5 | 4 GB | 35 GB |
Quantised formats also store scale factors for each small block of weights, so a "4-bit" file often works out at 4.5 to 5 bits per weight. Choose the custom option and enter the effective figure, which you can get by dividing the file size in bits by the parameter count.
The KV cache grows with use
Weights are fixed; the KV cache grows with every token of context and every sequence served at once. Models with grouped-query attention, like Llama 3.1, share each KV head among several attention heads, which is why 8 KV heads appear in the formula rather than 32. Even so, at 128,000 tokens the cache for one Llama 3.1 8B sequence is 15.6 GiB in BF16, nearly as much as the weights. Serving four sequences at once multiplies it by four. Servers that store the cache in 8-bit halve it.
The overhead assumption
Every runtime needs memory beyond weights and cache: the CUDA context, temporary activations during each step, buffers and fragmentation. There is no single published figure, because it depends on the GPU, driver, inference engine and batch size. The calculator applies a percentage, 10% by default, as a visible assumption rather than a hidden constant. Load the model once, read the memory in use from your monitoring tool, and adjust.
GB or GiB?
GPU memory comes in binary sizes, so a card sold as "24 GB" holds 24 GiB, 25.8 billion bytes, and monitoring tools report MiB. The calculator defaults to GiB for that reason and offers decimal GB as a labelled choice; the byte counts never change.
Beyond inference
Training and fine-tuning need far more: gradients, optimizer states and saved activations can take several times the weights. This calculator covers inference only. Once the model fits, the tokens per second calculator estimates how quickly it answers, and the vector storage calculator sizes the embeddings a retrieval system keeps beside it.
More questions
Can I run a model that does not fit in VRAM?
Some runtimes can keep part of the model in system RAM and move layers to the GPU as needed. It works, but generation slows sharply, often by several times, because system memory and the PCIe link are much slower than GPU memory.
Does a longer context need more VRAM even if I send short prompts?
Many inference servers reserve KV cache memory for the full configured context length when they start. Lowering the maximum context in the server settings frees that memory if your prompts are short.
How much does 8-bit KV cache save?
Half of the KV cache. For Llama 3.1 8B at 32,768 tokens that is 2 GiB instead of 4 GiB per sequence, at a small cost in accuracy that many servers find acceptable for long contexts.
Do two 12 GB cards equal one 24 GB card?
For capacity, roughly, if the inference software splits the model across both. Each card also keeps its own runtime buffers, and the cards exchange data during generation, so expect a little less usable memory and some speed loss compared with one larger card.
Why does the same model need different memory in different tools?
Tools differ in how they store quantised weights, how much KV cache they reserve in advance, and how big their workspace buffers are. That variation is what the overhead percentage stands for; measure your tool once and set it accordingly.
Sources
This article explains how the calculator works and is general information, not financial, tax, legal or medical advice. Rules change; check the sources above or a qualified professional before you act.