Local LLM VRAM Calculator: Model and Context Needs
The calculator for this page is switched off while it is checked. The formula is below, and the worked example in the article shows how to use it by hand.
Estimate the VRAM a local language model needs by entering its parameter count, weight precision, context length, and batch size; the calculator adds an allowance for runtime overhead and reports an approximate total in gigabytes. Treat the result as a planning estimate: actual use varies with the model architecture, software, and features enabled.
Formula
This estimate adds model-weight memory, a simplified key-value (KV) cache estimate, and a user-supplied runtime allowance:
Total VRAM ≈ P × B + (2 × L × H × D × C × S ÷ 1,000,000,000) + A
- P is parameter count in billions.
- B is the selected approximate bytes per parameter: 2 for FP16, 1 for 8-bit, 0.75 for 6-bit, or 0.5 for 4-bit.
- L is the number of transformer layers; H is the number of KV heads; D is the head dimension; and C is context length in tokens.
- S is bytes per KV-cache value. This calculator assumes 2 bytes, corresponding to a common FP16 cache.
- A is additional runtime allowance in decimal gigabytes (GB).
The weight estimate uses decimal GB (1 GB = 1,000,000,000 bytes), not binary GiB (1 GiB = 1,073,741,824 bytes). Quantized formats also store scales and other metadata, so their effective memory use may exceed the simple bytes-per-parameter estimate.
Worked Example
Using the calculator defaults—an 8-billion-parameter model, 4-bit weights, 8,192 tokens, 32 layers, 8 KV heads, head dimension 128, and 2 GB of allowance:
- Weights: 8 × 0.5 = 4.00 GB.
- KV cache: 2 × 32 × 8 × 128 × 8,192 × 2 ÷ 1,000,000,000 = 1.07 GB.
- Total: 4.00 + 1.07 + 2.00 = 7.07 GB.
This is an estimate, not a guarantee that a model will fit in a card with exactly 7.07 GB free. A practical setup needs headroom, and the software may allocate memory differently.
How Model and Context Use VRAM
Model weights are the stored numerical parameters used during inference. Their memory requirement is broadly proportional to parameter count and precision: halving the bytes per weight roughly halves the weight storage, before quantization metadata and other implementation details. A model described as 8B has about eight billion parameters, but its actual file size and loaded VRAM use depend on its format.
The KV cache holds attention data for tokens already processed so the model can continue generating without recomputing the full history each time. Its size generally grows with context length, layer count, KV-head count, head dimension, and cache precision. Therefore, a model that fits at a short prompt may run out of memory at a much longer context.
Batch size matters too. Processing multiple prompts or sequences together can increase cache and temporary activation memory. This calculator assumes one sequence and does not include a batch-size input, so increase the allowance or use a more detailed model-specific estimate for batched serving.
Choosing Inputs and Reading the Estimate
- Parameter count: use the model’s stated size, such as 8B or 13B. For a mixture-of-experts model, do not assume that only the active parameters determine memory; implementations commonly need to load the expert weights too.
- Precision: select the format actually used at inference. “4-bit” is a useful approximation, not a universal exact size; quantization schemes differ.
- Architecture values: find layer count, KV heads, and head dimension in the model configuration. Do not substitute total attention heads for KV heads when the model uses grouped-query attention.
- Allowance: reserve memory for the inference engine, temporary buffers, CUDA or other compute libraries, and the desktop display if the same GPU drives it. The default 2 GB is only a starting point.
GPU utilities may report capacity in GiB while product specifications use GB. Compare the estimate with usable free memory, not just the card’s advertised capacity. If the estimate is close to the limit, choose a smaller model, lower weight precision, shorter context, or a more memory-efficient cache setting.
Common Limits and Misconceptions
“Four-bit means exactly half a byte per parameter” is an approximation. Quantized models need additional information for scaling and may include unquantized layers. File size is a useful first clue, but loading can require more VRAM than the file alone suggests.
The cache formula assumes a conventional transformer cache with two stored values per element (keys and values), an FP16 cache, and one sequence. Architectures can use different cache layouts, sliding windows, or other optimizations. Some software supports lower-precision KV caches, which can reduce memory, while temporary buffers or parallel processing can increase it.
Finally, fitting is not the same as running well. A model may fit but leave too little room for long prompts, generation, or other GPU workloads. If VRAM is insufficient, some tools can offload layers to system RAM, but this can reduce speed and is outside this estimate.
Frequently Asked Questions
How much VRAM does an 8B model need?
It depends mainly on weight precision and context. The example here estimates 7.07 GB for 4-bit weights, an 8,192-token context, the stated architecture, and a 2 GB runtime allowance. Other formats and software can change the result.
Does context length use VRAM?
Yes. The KV cache usually grows with the number of tokens retained, so doubling context can roughly double cache memory when other settings remain unchanged.
Why does the model need more VRAM than its file size?
The loaded weights are only part of memory use. The runtime also needs cache storage, temporary working buffers, and sometimes quantization metadata or display memory.
What is the difference between GB and GiB?
GB is decimal: one billion bytes. GiB is binary: 1,073,741,824 bytes. Hardware software may display either, so leave extra room when comparing a calculator result with a GPU’s reported capacity.
Can I run a model if the estimate is slightly above my VRAM?
Possibly, if the software offloads some layers to system RAM or uses another memory-saving method, but performance and feasibility vary. The estimate alone cannot predict those results.
Related
Formula used
in p | Model parameters | billion | 8 | 0 sel b | Weight precision | FP16=2, 8-bit=1, 6-bit=0.75, 4-bit=0.5 in c | Context length | tokens | 8192 | 0 in l | Layers | count | 32 | 0 in h | KV heads | count | 8 | 0 in d | Head dimension | elements | 128 | 0 in a | Runtime allowance | GB | 2 | 0 out v | Estimated VRAM | GB | p * b + (2 * l * h * d * c * 2 / 1000000000) + a | 2 out w | Weight memory | GB | p * b | 2 out k | KV cache memory | GB | 2 * l * h * d * c * 2 / 1000000000 | 2
Each line is one input (in, sel, list) or one result (out: label, unit, formula, decimals). How the calculators work
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.