128k context on a desktop is a lease — the KV cache is the bill, counted live
Two tensors per layer per token: 16 GiB for an 8B at full window. Pick a model, dial the context, and watch the tenant ledger tot up the formula live.
■ space · the machine shop · fig 1
Llama 3.1 8B at 131,072 tokens in fp16: KV cache ≈ 16 GiB — as big as the weights.
The "8B that fits in 16 GiB" becomes a 32 GiB problem.
The cache is linear in context and allocated up front — RAM pays for 128k whether or not you fill it.
The fix is boring: set context to what you actually use — a 32k window costs a quarter of the 128k cache.
01THE METER DESK
the tenant is the kv cache — the wheels spin the bill the card never prints
CACHE = WEIGHTSat full window the cache is as big as the model it belongs to — a 32 GiB tenancy now
TENANT LLAMA 3.1 8B · WINDOW 128k · 131,072 TOKENS · CACHE 16.00 GiB · WEIGHTS 16.0 GiB · SHARE 100% · FED 0
the wheels billed before the odometer moved — allocation is up front, filling is optional
02THE FORMULA THE CARDS OMIT
one public formula drove every digit on those wheels
cache_bytes = 2 × layers × context × kv_heads × head_dim × bytes_per_element
"The context window is not a feature you toggle. It is a memory lease you pay every second the server runs."
def kv_cache_gib(layers, kv_heads, head_dim, ctx, bytes_per=2):
return 2 * layers * ctx * kv_heads * head_dim * bytes_per / 2**30
print(kv_cache_gib(32, 8, 128, 131_072)) # Llama 3.1 8B -> 16.0
print(kv_cache_gib(28, 4, 128, 131_072)) # Qwen2.5 7B -> 7.0
verify: kv_cache_gib(32, 8, 128, 131_072) → 16.0 · kv_cache_gib(28, 4, 128, 131_072) → 7.0
03TWO TENANTS, ONE DESK
a formula is arithmetic until it prices two real model cards side by side
| Model (fp16) | Layers × KV heads | KV cache @ 128k | Weights | Cache vs weights |
|---|---|---|---|---|
| Llama 3.1 8B | 32 × 8 | ~16 GiB | ~16 GiB | ~100% |
| Qwen2.5 7B | 28 × 4 | ~7 GiB | ~15 GiB | ~47% |
press key 1 on the desk — the same 128k window re-meters at 7.0 GiB for qwen2.5 7b
config.json to find them, which tells you how the number was meant to be read04WHERE THE BILL BENDS
the meter is honest for full attention — four bends before you sign anything
Nobody reads 128,000 tokens. Your RAM pays for every one of them anyway.
config.json files (layers, KV heads, head_dim), as laid out in Transformer Inference Arithmetic — the desk's meter is that same formula in JavaScript; no benches to buy, one print away from your own terminal.
end of the tenant ledger · nothing fetched · everything local