View all articles
VRAMHardwareQuantizationLocal AIOllama

How much VRAM do I need for a local LLM? The maths, step by step

JG
Jacobo González Jaspe
|

Reviewed:

How much VRAM do I need for a local LLM? The maths, step by step Models

By the end of this post you will be able to work out, with pen and paper, how much memory a model needs before you download it. An 8 GB laptop is enough to start, and the same sum tells you when you need more.

Measured first: one 7B at three quantisations

On 2026-11-05 we loaded Qwen2.5-7B-Instruct (7.6B parameters) as three files on our DGX Spark (GB10, Ollama 0.30.10), one at a time, and read the size from /api/ps, the number ollama ps shows. Raw files: 32k context, 4k context.

QuantisationFileWeights by the sum belowLoaded, 4kLoaded, 32k
Q4_K_M4.68 GB4.61 GB4.75 GB6.59 GB
Q8_08.10 GB8.08 GB7.89 GB9.74 GB
FP1615.24 GB15.20 GB14.52 GB16.36 GB

The weights sum (7.6 × bits ÷ 8) lands within 0.07 GB of each file. Going from 4k to 32k added 1.84 or 1.85 GB to all three: the context cache ignores quantisation. (At 4k, Ollama reported Q8 and FP16 below their file size; we print what it reported.) FP16 takes 2.5 times the memory of Q4_K_M; whether that buys anything is in Q4_K_M vs Q8_0 vs FP16, measured, and how the cache grows to 128k in Ollama num_ctx memory usage, measured.

What you need

  • A calculator, and the model’s config.json on Hugging Face (for the cache).
  • Optional: Ollama, to compare the sum with what your machine loads.

The calculator on each page of our product catalogue uses the same formula, so your numbers will match the site’s.

Step 1: work out what the weights weigh

A model is a list of numbers. The name tells you how many (8B is 8 billion). The quantisation tells you how much each one takes:

text
weights (GB) = parameters (billions) × bits per weight ÷ 8
QuantisationBits per weightWhat it is
Q4_K_M4.854 bits with a few layers kept more precise. Ollama’s default
Q8_08.58 bits, practically the original
FP1616the original weights

The Q4_K_M and Q8_0 values are llama.cpp’s figures for those GGUF types. Why 4 bits is usually enough: how to pick the right GGUF file.

An 8B at Q4_K_M: 8.0 × 4.85 ÷ 8 = 4.85 GB. The same model at FP16 is 16 GB (what that extra memory buys you). Quantisation is the biggest lever you have.

Step 2: add the context cache

While you chat, the model stores two vectors (K and V) per token, in every layer. That is the context cache. It does not depend on the file’s quantisation. It depends on the architecture and on how many tokens you allow:

text
cache per token (bytes) = layers × KV heads × head dimension × 4
cache (GB) = cache per token × context tokens ÷ 1,000,000,000

The 4 is 2 vectors (K and V) times 2 bytes at FP16. All three values are in the model’s config.json: num_hidden_layers, num_key_value_heads and head_dim. If head_dim is missing, divide hidden_size by num_attention_heads.

ModelLayersKV headsHead dimCache per tokenSource (read 2026-10-06)
Llama 3.1 8B3281280.131 MBconfig.json
Qwen 2.5 32B6485,120 ÷ 40 = 1280.262 MBconfig.json
Llama 3.3 70B8081280.328 MBconfig.json

We read both Llama configs from unsloth’s copy because Meta’s repository asks you to register. The architecture is identical.

KV heads are 8 in all three. Without that trick (grouped-query attention), a 70B with 64 heads would store eight times as much cache.

Step 3: add the runtime and compare with your usable memory

Add 1.5 GB of runtime (compute buffers and the engine itself). Then subtract what the system keeps:

  • Dedicated VRAM (a graphics card): total memory minus 0.5 GB.
  • Unified memory or system RAM: minus 3 GB up to 16 GB, minus 4 GB up to 32 GB, minus 6 GB above that.

That gives you usable memory. The calculator’s rule: it fits comfortably if the need is 85% of usable memory or less. Between 85% and 100% it is a tight fit. Above that, it does not fit.

Three worked examples

These are the site’s own functions (memoryNeededGb, usableMemoryGb and fitStatus in src/lib/hardware-math.ts), run with Node on 2026-10-06 and rounded.

ExampleWeightsCacheRuntimeTotal
Llama 3.1 8B, Q4_K_M, 8k8.0 × 4.85 ÷ 8 = 4.85 GB0.131 × 8,192 = 1.07 GB1.5 GB7.42 GB
Qwen 2.5 32B, Q4_K_M, 8k32.8 × 4.85 ÷ 8 = 19.88 GB0.262 × 8,192 = 2.15 GB1.5 GB23.53 GB
Llama 70B, Q4_K_M, 8k70.6 × 4.85 ÷ 8 = 42.80 GB0.328 × 8,192 = 2.69 GB1.5 GB46.99 GB

A note on the 32B: the calculator uses 32.8 billion parameters and Qwen’s model card says 32.5. The difference is 0.2 GB. For the 70B we use 70.6, the Llama 3.1 70B figure, which shares its architecture with Llama 3.3.

Now against real machines:

MemoryUsable85% line8B32B70B
8 GB GPU7.5 GB6.38 GBtightnono
12 GB GPU11.5 GB9.78 GBcomfortablenono
24 GB GPU23.5 GB19.98 GBcomfortableno (by 0.03 GB)no
32 GB unified28 GB23.8 GBcomfortablecomfortableno
64 GB unified58 GB49.3 GBcomfortablecomfortablecomfortable

The 32B on a 24 GB card is the case that teaches most. At 8k context it misses by 30 MB. Drop to 4k and the cache falls to 1.07 GB: total 22.46 GB, a tight fit. Context decides.

Why context weighs so much

The cache grows in a straight line with tokens. For the 8B above:

ContextCacheTotal at Q4_K_M
4k0.54 GB6.89 GB
8k1.07 GB7.42 GB
32k4.29 GB10.64 GB
128k17.17 GB23.52 GB

Accepting 128k tokens does not mean reserving them: ask for the context your task uses.

Unified memory versus dedicated VRAM

A graphics card has its own memory (VRAM); whatever does not fit there runs on the CPU, much more slowly.

Apple silicon Macs, the DGX Spark (GB10, 128 GB) and AMD Strix Halo machines use unified memory: CPU and GPU share one pool, so a 64 GB machine can give almost all of it to the model. The reserve is larger because the operating system lives there too.

What the spec sheet won’t tell you: fitting is not running fast. Speed depends on memory bandwidth, where a dedicated GPU usually wins; see the hardware catalogue by budget.

Check real usage

The sum is an estimate. Your machine has the last word:

bash
ollama ps
# NAME           SIZE      PROCESSOR    CONTEXT
# llama3.1:8b    9.2 GB    100% GPU     32768

SIZE is the memory the loaded model takes. If PROCESSOR is not 100% GPU, part of it is on the CPU: lower the quantisation or the context.

On a dedicated NVIDIA card, nvidia-smi confirms it:

bash
nvidia-smi --query-gpu=memory.used,memory.total --format=csv

On the GB10 it returns [N/A] (unified memory); use ollama ps there.

The sum against our GB10 with llama3.1:8b at Q4_K_M (PRIME, Ollama 0.30.10, one slot, 2026-11-02, raw file):

ContextSite’s sumMeasured (ollama ps)
4,0966.89 GB5.27 GB
32,76810.64 GB9.21 GB
131,07223.52 GB22.79 GB

The sum came out high every time, by 0.7 to 1.6 GB: we would rather you had memory to spare.

When not to trust the sum

  • Mixture-of-experts (MoE) models. All parameters count for memory, even if only a few work on each token. Plan with the file size plus the slots: our gemma4:26b (17.99 GB file) loaded at 17.47 GB with one 32k slot and 22.64 GB with 8 slots of 16k (2026-11-02, raw files for PRIME and spark2).
  • Quantised cache. Some engines store the cache in 8 bits. It then takes half, and the formula overestimates.
  • Other services on the same machine. If another model is already loaded, subtract it from usable memory.
  • Images and vision. Multimodal models add an encoder. Allow an extra margin.

Parallel slots multiply the cache

The sum above is for one conversation. Ollama reserves a separate context for every parallel slot (OLLAMA_NUM_PARALLEL), so the cache multiplies by the slots. On 2026-11-02 we loaded llama3.1:8b at Q4_K_M on our two GB10 boxes: at 32k, one slot took 9.21 GB, four took 22.38 GB and eight took 39.27 GB (raw file).

Set each model’s size with PARAMETER num_ctx in a Modelfile so the server default never decides for you. The full tables, and the day this broke our second box: Ollama num_ctx memory usage, measured.

Next steps

Let’s talk for 15 minutes

We run this sum with your team’s real documents and context, and measure it on hardware before recommending anything. If you want it for your company, ask for a 15-minute call or see how we work in consulting.

Diagram
Share: LinkedIn X
Veredicto semanal

Get new guides before anyone else

Subscribe and we tell you when new guides, templates and workflows go up. One email a week, no spam.

Already published: 91 guides and 25 templates. All free, no signup.

Bonus: the local-AI starter pack PDF when you subscribe
Once a week No spam Unsubscribe anytime

See what you get