How much memory does a local model need?
Three numbers decide whether a model runs on your machine: the weights, the KV cache for the context you actually use, and the runtime’s own overhead. This calculator shows all three separately, because a single total hides the one that will hurt you.
| Weights (file size estimate) | 0.87 GB |
|---|---|
| KV cache at 4,096 tokens | 0.12 GB |
| Runtime overhead (your input) | 0.35 GB |
| Headroom against 8 GB | +6.67 GB |
Comfortable
The formulas, and what they do not tell you
Weights = parameters × bits-per-weight ÷ 8. The bits-per-weight figures are typical GGUF file sizes, not a specification: the same Q4_K_M can differ a few percent between models because the token embedding and output layers are stored at higher precision.
KV cache = 2 (keys and values) × layers × KV heads × head dimension × bytes per element × context length. Grouped-query attention is why this is far smaller than the weight file at short context — and why it grows linearly and can dominate a long one.
What this ignores: attention workspace, the compute buffer the runtime allocates per batch, and fragmentation. A real run on a 4-core VPS with Qwen2.5 0.5B Q4 and a 2,048-token context peaked well above the weights alone; the measured figure is in the Labs article, and that gap is the reason the overhead field exists.
GB vs GiB: both are shown because model sizes are usually quoted in decimal GB while operating systems and container limits report GiB. 8 GB is 7.45 GiB, and that difference is enough to turn a fit into an out-of-memory kill.
Questions this page gets
- Why is my measured usage higher than this estimate?
- The estimate covers weights, KV cache and the overhead you enter. A real runtime also allocates an attention and compute buffer that scales with batch size and context, and memory fragmentation grows with uptime. On a 4-core VPS our Qwen2.5 0.5B Q4 run peaked above the weights alone; that measured gap is why the overhead field is editable.
- Does a model run just because the weights fit in RAM?
- No. The weights are the floor, not the requirement. You also need the KV cache for the context you actually use, plus the runtime’s own allocations. A model whose weights fill 90% of memory will be killed at the first long prompt.
- What is the KV cache and why does context length multiply it?
- Every layer stores keys and values for every token in the context. That is 2 × layers × KV heads × head dimension × bytes per element × tokens. Grouped-query attention shrinks the head count, which is why a 7B model with 4 KV heads is far cheaper per token than one with 32.
Related reading
- What a 4-core VPS can actually do with a local modelLab · measured tokens/s, RAM and time to first token
- How much RAM does a local AI model actually need?Guide · the maths, with a real run to check it against
- Local vs cloud cost calculatorTool · once it fits, is it worth running?