LocalLLMBench

How much VRAM does a 128K context use?

By Local AI Math. Updated 1 December 2026.

Short answer. With the usual 16-bit cache, a full 128K context (131,072 tokens) takes 17.18 GB on Llama 3.1 8B and 42.95 GB on Llama 3.1 70B, on top of the weights. For the 8B model that is more than three times the 4.85 GB its Q4_K_M weights need. An 8-bit cache halves those figures and a 4-bit cache quarters them.

The context is the part of local LLM memory people most often underestimate, because the model download does not include it. Your runtime sets the memory aside when it loads the model, sized for the context length you asked for. The VRAM calculator adds it to the weights for you; this page shows what it costs model by model, and what to change when it does not fit.

Cache size per model

For every token in the context, every layer stores one key and one value vector. With a 16-bit cache each number takes 2 bytes:

bytes per token = 2 × layers × key/value heads × head size × 2

Models that share key/value heads between attention heads (grouped-query attention, used by all the models below) store far less than older designs. The layer and head counts come from each model's published configuration: Qwen2.5's model cards and config.json files, and Meta's llama-models reference list for Llama 3.1. All use a head size of 128.

16-bit cache. 32K = 32,768 tokens, 128K = 131,072 tokens. GB = 1,000,000,000 bytes.
Model (layers, KV heads)Per 1,000 tokens32K128K
Qwen2.5 7B (28, 4)0.057 GB1.88 GB7.52 GB
Llama 3.1 8B (32, 8)0.131 GB4.29 GB17.18 GB
Qwen2.5 14B (48, 8)0.197 GB6.44 GB25.77 GB
Qwen2.5 32B (64, 8)0.262 GB8.59 GB34.36 GB
Llama 3.1 70B, Qwen2.5 72B (80, 8)0.328 GB10.74 GB42.95 GB

Two things stand out. The cache grows in a straight line, so 64K costs exactly half of 128K. And it does not scale with parameter count: Llama 3.1 8B needs more than twice the cache of Qwen2.5 7B, because it has 8 key/value heads to Qwen's 4 and 32 layers to its 28. Two models of similar size can differ by 10 GB at a long context.

Worked example: Llama 3.1 8B at 128K

Llama 3.1 supports 128K tokens of context, as its model card states. At Q4_K_M (about 4.85 bits per weight) its weights take 8 × 4.85 ÷ 8 = 4.85 GB. With 1 GB of runtime buffers and the full context:

Cache precisionTotal16 GB card24 GB card
16-bit23.03 GBdoes not fittight
8-bit14.44 GBtightfits
4-bit10.14 GBfitsfits

The cards are counted as 15.5 GB and 23.5 GB usable, with 0.5 GB kept free for the display. "Tight" means less than 10% of usable memory is left over.

Most people do not need all 131,072 tokens, and it pays to ask how much you do. On a 12 GB card (11.5 GB usable) the same model at Q4_K_M with a 16-bit cache reaches about 43,000 tokens before the memory runs out: (11.5 − 4.85 − 1) ÷ 0.131 GB per 1,000 tokens. That is roughly a 30,000-word document plus the conversation about it.

Try it in the calculator: choose "Llama 3.1 8B" from the model list, which sets the cache cost to 0.131 GB per 1,000 tokens. Enter 131,072 tokens, pick a graphics card with 24 GB, and switch the cache precision under the allowances between 16-, 8- and 4-bit. For the longest context that fits, set the memory to 12 GB and read the hint below the result.

Bigger models: where 128K stops being practical

For a 70B model the cache alone at 128K, 42.95 GB, is more than the Q4_K_M weights (about 42.5 GB). Add the two and the 1 GB buffer and you need roughly 86 GB, which rules out any single consumer graphics card and most Macs. With a 4-bit cache the cache drops to 10.74 GB, the total to about 54 GB. Even 32K is a stretch for a 70B on modest hardware: 10.74 GB of cache at 16-bit is a whole mid-range card's worth of memory. If you are trying to fit a 70B model on one card in the first place, running Llama 70B on a 24 GB GPU works through the options.

Qwen2.5 32B sits in between. At 32K tokens its cache is 8.59 GB, so Q4_K_M weights (19.70 GB) plus cache plus buffers come to 29.29 GB: too much for a 24 GB card at 16-bit, but 24.99 GB with an 8-bit cache and 22.85 GB with a 4-bit one. Only the 4-bit cache gets it inside 23.5 GB, and only just.

Shrinking the cache

Quantize the cache

llama.cpp stores the cache at 16 bits unless told otherwise. Its server takes --cache-type-k and --cache-type-v, with q8_0 and q4_0 among the allowed values, according to the llama.cpp server documentation. Ollama exposes the same choice through the OLLAMA_KV_CACHE_TYPE setting (f16, q8_0 or q4_0); its FAQ says q8_0 uses about half the memory of f16 and q4_0 about a quarter, and that the cache can be quantized only when Flash Attention is enabled. An 8-bit cache is the usual compromise. A 4-bit cache saves more but loses more precision; check its answers on your own long documents before relying on it.

Set the context you will use

Runtimes reserve the cache for the configured context when the model loads, not for the tokens you actually send. That cuts both ways:

Long contexts on Qwen2.5 need a setting

Qwen2.5 7B's card gives a full context of 131,072 tokens, but its default configuration handles 32,768; longer inputs need a YaRN scaling entry added to the configuration, and the card advises adding it only when you need long texts. The memory cost per token in the table is the same either way.

When the formula overstates

The formula assumes every layer keeps the whole context. Some newer designs do not. Gemma 3, for example, uses mostly local attention layers with a short window, which its authors describe in the Gemma 3 technical report as a change made to cut KV-cache memory at long context. For such models the formula gives an upper bound, and the runtime's own log at load time is the better figure. For the standard grouped-query models above, the formula should land close to what the runtime allocates for the cache.

Running several conversations at once multiplies the cache, since each request keeps its own. The figures here are for one.

A quick way to size it

Look up three numbers in the model's config.json: num_hidden_layers, num_key_value_heads and the head size (often head_dim, otherwise hidden size ÷ attention heads). Multiply them together and by 4 for bytes per token at 16-bit. Multiply by your context length. Halve it for an 8-bit cache. The calculator's architecture helper does the same from those numbers; the older article how much VRAM do I need puts the cache together with weights and buffers for complete totals.

These are estimates from published configurations, not measurements of a particular runtime version. When the margin is a few hundred megabytes, load the model and read what the runtime reports.