KV Cache engineering: 1 GiB per 8K-token sequence, where LLM serving performance is won

techNmak · x · 2026-10-31

techNmak's deep dive on KV Cache engineering—the decisive battleground of LLM serving performance—paired with a detailed infographic.

Basics: during autoregressive generation, K/V for past tokens are cached and appended per layer; past queries aren't cached.

Memory math: raw full-attention KV ≈ 2 × layers × cached tokens × KV heads × head dim × bytes. With 32 layers, 8 KV heads, head dim 128, BF16: 128 KiB per position, 1 GiB for one 8,192-token sequence, 32 GiB for 32 unshared sequences—before weights, activations, and runtime overhead.

Levers and trade-offs:

Production signals: watch KV usage with live sequence lengths, concurrency, free blocks, prefix hit rate, preemptions, queue time, TTFT, and ITL. KV shortages can cause queueing/preemption without a GPU OOM.

Bottom line: KV optimization is simultaneously a memory-allocation, bandwidth, scheduling, and cache-reuse problem—and one limit on GPU throughput at high concurrency.

Original post →

More from Infra

Infra channel →