BestLLMfor EN Your hardware. Your LLM. Your call.
FRQuelLLM.fr
Guide · 2026-05-16

LLM Context Window vs VRAM Cost — 128k vs 32k Compared

Quadrupling context typically quadruples the KV cache. Here is the actual VRAM bill for 128k vs 32k on the open models people run locally in 2026.

By Mohamed Meguedmi · 9 min read

Key takeaways

  • Going from 32k to 128k context quadruples the KV cache. For Llama 3.1 70B at FP16 that is +31.5 GB of VRAM dedicated to context alone.
  • 32k is the right default for roughly 95% of single-user local inference. 128k only pays off for full-codebase refactors, long-document review, and persistent agent loops.
  • KV cache quantization (Q8 or Q4) recovers 50–75% of the cost with under 2–5% perplexity impact on most Llama- and Qwen-family models.
  • A 24 GB consumer GPU cannot run a 70B model at 128k under any realistic configuration. 48 GB is the practical floor.
  • Cloud APIs hide this cost via batching. Local users pay it up-front in hardware.

Most VRAM calculators stop at the model weights. They report a Q4_K_M Llama 3.1 70B at ~42 GB and call the job done. In production that figure is barely half the story, because the KV cache — the rolling buffer of every previous token's keys and values — grows linearly with context length and routinely matches or exceeds the weight footprint. This guide breaks down the actual VRAM cost of 128k versus 32k on the open models people actually deploy in May 2026, with the formula, the dollars, and an unambiguous verdict.

Why context length is the silent VRAM killer

When a transformer generates a token, it re-attends to every previous token's keys (K) and values (V). To avoid recomputing those tensors at each step, the model caches them. That cache scales linearly with sequence length, layer count, and KV-head count. The formula is:

KV_cache_bytes = 2 × layers × kv_heads × head_dim × context_tokens × bytes_per_element

The leading 2 separates K and V. bytes_per_element is 2 for FP16/BF16, 1 for Q8, 0.5 for Q4. The single most important architectural lever is Grouped Query Attention (GQA): Llama 3.1, Qwen3, and Mistral Large 2 all share a small number of KV heads (typically 8) across many attention heads (64–96), shrinking the KV cache by an order of magnitude versus older multi-head designs. Without GQA, 128k local inference would be a non-starter outside data-center GPUs.

The actual VRAM bill: 32k vs 128k head-to-head

Table 1 applies the formula to the open models most local users deployed during 2025–2026. All figures are FP16 KV cache, batch size 1, single user.

ModelLayersKV headsHead dimKV @ 32kKV @ 128kDelta
Llama 3.1 8B3281284.2 GB16.8 GB+12.6 GB
Qwen3-Coder 32B6481288.4 GB33.6 GB+25.2 GB
Llama 3.1 70B80812810.5 GB42.0 GB+31.5 GB
Mistral Large 2 (123B)88812811.5 GB46.1 GB+34.6 GB
Gemma 3 27B621612816.3 GB65.0 GB+48.7 GB

The Gemma 3 row is the cautionary tale: doubling KV heads doubles the cost. Gemma compensates with sliding-window attention on most layers, but the raw arithmetic explains why architectural decisions matter more than parameter count for context economics.

Stack the KV cache on top of quantized weights and the picture becomes concrete:

Model + quantWeightsTotal @ 32k FP16 KVTotal @ 128k FP16 KVActivations
Llama 3.1 8B Q4_K_M4.7 GB~10 GB~23 GB+1–2 GB
Qwen3-Coder 32B Q4_K_M19 GB~29 GB~55 GB+2 GB
Llama 3.1 70B Q4_K_M42 GB~55 GB~87 GB+3 GB

A single RTX 4090 (24 GB) cannot serve a 70B at any meaningful context. A single H100 (80 GB) handles 70B at 32k comfortably but is tight at 128k FP16 KV. The BestLLMfor VRAM and cost calculator exposes the same math for any model–context combination.

Translating VRAM into hardware dollars

US street prices, May 2026, for the configurations needed to host Llama 3.1 70B Q4_K_M with FP16 KV cache:

ContextRequired VRAMCheapest single GPUCheapest multi-GPUUnified-memory option
32k~55 GBRTX 6000 Ada 48 GB + offload, ~$6,8002× RTX 4090, ~$3,200 usedM3 Max 64 GB, ~$3,500
128k~87 GBH100 80 GB, ~$25,0002× RTX 6000 Ada, ~$13,600M3 Ultra 128 GB, ~$5,800

Doubling context from 32k to 128k roughly doubles the hardware bill at the same quality tier. For most teams that is the threshold at which a remote API or a single-card setup with KV quantization becomes the rational choice.

KV cache quantization: the cheat code

llama.cpp, vLLM, and ExLlamaV2 all support quantizing the KV cache to Q8 or Q4 independently of the weight quant. The perplexity hit is small — typically under 2% at Q8 and around 4–5% at Q4 on Llama- and Qwen-family models. See the llama.cpp project for current flag syntax (--cache-type-k q8_0 --cache-type-v q8_0).

KV quantBytes/elementLlama 3.1 70B @ 128kSaving vs FP16
FP162.042.0 GBbaseline
Q8_01.021.0 GB−50%
Q4_00.510.5 GB−75%

With Q4 KV cache, a 70B at 128k drops from ~87 GB to ~55 GB total — back to single-48-GB-card territory. FlashAttention-2 further reduces peak activation memory during attention compute (though not the persistent cache), and is standard on every modern inference backend.

The practical floor for 128k local inference on a 70B is 48 GB of VRAM with Q4 KV cache, or 80 GB with FP16 KV cache. Below that, drop to 32k or pick a smaller model.

When 128k actually earns its keep

Long context is not free, but it is the right tool for a narrow set of jobs:

  • Codebase-level refactors: 60k–120k tokens to load a mid-size monorepo end-to-end without RAG.
  • Long-form fiction and legal review: full novels, briefs, or contracts in a single pass with cross-reference resolution.
  • Agent loops with persistent scratchpads: chained tool calls where every step re-pastes prior reasoning.
  • RAG-free document Q&A: when maintaining a vector store costs more engineering than running long context.

Community testing also shows most open models lose substantial recall quality past 32k regardless of advertised window. The Llama 3.1 70B model card documents needle-in-haystack performance dropping outside the dense training distribution. Advertised 128k is a ceiling, not a guarantee.

When 32k is the smart default

For single-user local inference, 32k delivers:

  • Higher throughput — KV cache lookups scale with size, so generation slows as the cache grows.
  • Better recall on most open models, where post-training data above 32k is sparse.
  • Single-card deployments on 24 GB and 32 GB consumer GPUs.
  • Lower idle power and faster prompt-processing.

A Qwen3-Coder 32B Q4_K_M at 32k with Q8 KV cache fits in 24 GB with headroom for the OS — the most common local coding deployment observed by the editorial team in early 2026. The BestLLMfor benchmark methodology page documents the test harness used for the throughput claims.

Hardware tier verdict

TierCardsBest fitRealistic max context
24 GBRTX 4090, 508032B Q4_K_M32k FP16 KV, 64k with Q8 KV
32 GBRTX 509032B Q4_K_M; 70B Q3 with offload64k on 32B; 32k on 70B with Q4 KV
48 GBRTX 6000 Ada, 2× 409070B Q4_K_M32k FP16 KV, 128k with Q4 KV
80 GBH100, A10070B Q4_K_M; 123B Q4 with offload128k FP16 KV on 70B
128+ GB unifiedM3 Ultra, Strix Halo70B–123B Q4_K_M128k FP16 KV; bandwidth-bound

For builders who want to script these decisions, the BestLLMfor public API exposes the same model–context–VRAM dataset under CC BY 4.0, and the open-source quelllm-mcp server lets local agents query it directly. The French-language sister site quelllm.fr mirrors the same data for EU readers.

Conclusion: 32k unless proven otherwise

The editorial position is unambiguous. Default to 32k. Reach for 128k only when the workload genuinely demands it — and when it does, quantize the KV cache to at least Q8. Treat the advertised context window of any open model as a marketing ceiling, not a usable plateau; measure recall on a representative sample of your actual workload before paying the VRAM bill.

ScenarioVerdict
Single-user coding assistant on 24 GB32k, Q8 KV, 32B model
Local document-review pipeline on 48 GB128k with Q4 KV, 70B model
Multi-user serving on H100 80 GB32k FP16 KV to maximize concurrency
Agent framework on Mac M3 Ultra 192 GB128k FP16 KV viable, bandwidth-limited

Frequently asked questions

Does 128k context use 4× the VRAM of 32k?

The KV-cache portion does, yes — it scales linearly with sequence length. Total VRAM also includes constant model weights and activations, so the multiplier on overall usage is typically 1.5×–2× depending on weight size and quantization.

Can I run Llama 3.1 70B at 128k on a single RTX 4090?

No. Even at Q4_K_M weights and Q4 KV cache the model exceeds 24 GB. The practical minimum is 48 GB of VRAM with aggressive KV quantization, or 80 GB at FP16 KV cache.

What is the perplexity cost of Q4 KV cache?

Roughly 4–5% on most Llama- and Qwen-family models, and under 2% at Q8. The hit is workload-dependent — long-context retrieval suffers more than chat.

Does FlashAttention reduce KV cache size?

No. FlashAttention reduces peak activation memory during attention computation, not the persistent cache. It is complementary to KV quantization, not a substitute.

Why do cloud APIs offer 200k+ but local feels harder?

Cloud providers amortize KV cache across batched users on H100/H200 clusters and aggressively quantize the cache. Single-user local inference cannot share that overhead.

Is 32k always enough for coding?

For single-file or small-module work, yes. For monorepo-wide refactors or codebase Q&A without RAG, 128k earns its cost — but most coders should profile their actual token usage before paying for it.

Recommended hardware

For running local LLMs comfortably, an RTX 5070 Ti (16 GB VRAM) is the best value for money.

Amazon Check RTX 5070 Ti price →

As an Amazon Associate, BestLLMfor earns from qualifying purchases, at no extra cost to you. It does not influence our independent rankings.