Master Local AI
  1. 0Load
  2. 1You type
  3. 2Tokenize
  4. 3To the GPU
  5. 4Prefill
  6. 5Decode
  7. 6Show text
Can it run?

Chapter 4 · Practitioner

Will It Fit? Sizing Models for VRAM

Weights + KV cache + overhead must fit in VRAM.

  1. 0Loadonce: file → VRAM
  2. 1You typetext in the app
  3. 2TokenizeCPU: text → IDs
  4. 3To the GPUIDs cross PCIe
  5. 4Prefillwhole prompt, one pass
  6. 5Decoderead all weights → 1 token
  7. 6Show textID → word · repeat 5

1Watch

Now

Press a step on the right, or change any control under the machine.

Readout

Key to the machine

Seven glass tanks, one per device. Grey weight blocks float on green KV-cache liquid; overflow falls into a slow RAM tray. A red lamp means it won't load.
How the numbers work

Memory needed = weights (parameters × bits ÷ 8) + KV cache (2 × layers × KV heads × head size × bytes × context × users) + about 1 GB of runtime. Each tank is as tall as its device's memory and receives the same workload. The scale is linear up to 32 GB, then compressed four times above the zigzag marked ÷4, so a 16 GB card and a 128 GB DGX Spark both stay readable and one workload stands at the same height in every tank. The runtime plate and the KV cache stay in fast memory; when the total passes a tank's capacity line, weight blocks are pushed over the weir and down the glass downpipe into the drip tray: on a discrete card the runtime keeps those layers in system RAM (dual-channel DDR5, 96 GB at 89.6 GB/s) and every token waits on them. If even the tray would overflow, or on unified memory (DGX Spark, the Mac), where the weir is blanked off because there is no slower tier, the gate shuts and the model does not load. Decode speed assumes 70% of peak bandwidth, re-reading the active weights plus every user's KV cache for each token.

  • Grey blocks = model weights
  • Green liquid = KV cache
  • Flat plate = 1 GB runtime
  • Lower tray = system RAM overflow
  • Red lamp = won't load
  • Needle = decode tok/s
Speed
Open full screen ↗

2Try this

Then change anything yourself.

3Read on ↓

The budget

Memory needed is weights plus KV cache plus overhead.

\text{memory} \approx \underbrace{N\cdot\frac{\text{bits}}{8}}_{\text{weights}} \;+\; \underbrace{2\,L\,H_{kv}\,d\cdot\frac{\text{kv bits}}{8}\cdot \text{context}\cdot\text{users}}_{\text{KV cache}} \;+\; \underbrace{0.5\text{–}1.5\ \text{GB}}_{\text{runtime overhead}}
  • Weights use the total parameter count, MoE included. Every expert must be in memory.
  • KV cache (the model's short-term memory) scales with context × concurrent users.
  • A runtime allocates the KV cache at start for the full context. A 128k setting costs 128k even for short chats. The settings are --ctx-size (llama.cpp), num_ctx (Ollama) and max_model_len (vLLM).
  • Overhead is the CUDA context, prefill scratch buffers and allocator slack.
  • On Windows, leave 5–10% free for the desktop.
Model · weights Context · KV Device Weights KV cache Overhead Total Verdict
Llama 3.1 8B · Q4_K_M 8k · 16-bit RTX 5090 (32 GB) 4.9 GB 1.1 GB 1.0 GB 6.9 GB fits
Qwen3 32B · Q4_K_M 8k · 16-bit RTX 5090 (32 GB) 19.9 GB 2.1 GB 1.0 GB 23.0 GB fits
Qwen3 32B · Q4_K_M 32k · 8-bit RTX 5090 (32 GB) 19.9 GB 4.3 GB 1.0 GB 25.2 GB fits
Gemma 3 27B · Q4_K_M 8k · 16-bit RTX 5060 Ti 16GB (16 GB) 16.4 GB 1.1 GB 1.0 GB 18.5 GB does not fit
Gemma 3 27B · Q4_K_M 8k · 16-bit RTX PRO 4000 Blackwell SFF (24 GB) 16.4 GB 1.1 GB 1.0 GB 18.5 GB fits

The fit map

Find your device and model; the cell is the largest context that fits. It assumes Q4_K_M, one user, an FP16 KV cache and 1 GB of overhead. A dash means the weights alone don't fit.

Largest context (tokens) that fits beside Q4_K_M weights · 1 user · FP16 KV · 1 GB overhead · 5% headroom
ModelRTX 5060 Ti 16GBRTX 5070RTX 5080RTX 5090 LaptopRTX 5090RTX PRO 4000 Blackwell SFFRTX PRO 6000 BlackwellDGX Spark (GB10)Apple M4 (this Mac)
Qwen3 0.6B121k88k121k187k253k187k783k>1M253k
Llama 3.2 3B107k74k107k173k239k173k770k>1M239k
Llama 3.1 8B71k42k71k129k187k129k651k883k187k
Qwen3 8B63k37k63k114k166k114k578k784k166k
Mistral Small 3.1 24B———44k91k44k462k647k91k
Gemma 3 27B———61k154k61k896k>1M154k
Qwen3 32B———7k36k7k268k384k36k
Llama 3.1 70B——————145k237k—
Qwen3 30B-A3B (MoE)———34k111k34k729k>1M111k
gpt-oss-20b (MoE)60k—60k369k678k369k>1M>1M678k
gpt-oss-120b (MoE)——————523k>1M—

To test Macs and this year's open models, use the Can it run? tool.

A model's trained context limit can bind first (128k for Llama 3.1, 32k native for Qwen3 8B).

Sliding-window models (Gemma 3, gpt-oss) cache only the last window on most layers. Their numbers are high.

Choosing hardware

Capacity decides what loads; bandwidth decides how fast it runs.

If the workload is… Prefer Because
A ≤14B chat or coding assistant, single user, speed matters GeForce RTX 5070 Ti / 5080 / 5090 everything fits; bandwidth gives 100–250 tok/s
24–32B dense models, long context RTX 5090 (32 GB) fits Q4 weights plus a usable KV cache at 1.8 TB/s
70B dense, multi-user, or fine-tuning RTX PRO 6000 Blackwell (96 GB) the 5090's bandwidth with 3× the capacity, plus ECC
100B+ MoE, big-memory prototyping, the NVIDIA software stack on a desk DGX Spark (128 GB unified) capacity first; MoE keeps decode tolerable at 273 GB/s
Frontier-scale local work DGX Station (GB300) 252 GB of HBM3e at 7.1 TB/s plus 496 GB of LPDDR5X
Laptops RTX 5090 Laptop (24 GB) / 5080 Laptop portable; plan for 8–14B models with room for context

Explain it

  1. "Can a 16 GB RTX 5080 run Qwen3 32B?" Not on the GPU alone: Q4_K_M weights are about 20 GB. Use a 3-bit quant, offload part of it (Chapter 9), or get a 32 GB GPU. Even the MoE Qwen3 30B-A3B (about 18.5 GB at Q4_K_M) is slightly too big.
  2. "I want 128k context on a laptop." An 8B GQA model needs about 17 GB of KV at FP16 for 128k. Use an FP8 or Q8 KV cache, a smaller context, or retrieval.
  3. "Why does Ollama use more VRAM than the formula?" Its defaults allocate KV for several parallel sequences plus compute buffers. The server log prints the exact allocation.

Exercises

  1. Recompute the fit map with an FP8 KV cache and Q8_0 weights; which pairs change category?
  2. Write recommend(model, context, users) returning the cheapest device that fits with 10% headroom.