Part of the AI & Machine Learning suite · 36 calculators

KV Cache Memory Calculator

The memory a transformer’s key–value cache takes for a context length and batch — from layers, KV heads, head size and precision — and how many tokens fit in the memory left after the weights.

During generation the model keeps the keys and values of every previous token in every layer so it need not recompute them: 2 (K and V) × layers × KV heads × head dimension × bytes per element for each token.

Results update as you type
Results
KV cache for the batch
8.59 GB
Per token
Per request
Tokens that fit in the budget (total across requests)
Requests of this length the budget holds
Reviewed September 2026. Model arithmetic is the same everywhere: the same formulas in every market, in your own currency. Australia's AI Ethics Principles are voluntary; cost and sizing arithmetic carries no regulatory requirement.
No account required · Google Analytics off unless allowedCalculator arithmetic runs in your browserResults update as you type
All calculations run 100% in your browser. The calculator code does not submit your figures to GlobalCalc to obtain a result.
About kv cache memory

How the kv cache memory calculator works

During generation the model keeps the keys and values of every previous token in every layer so it need not recompute them: 2 (K and V) × layers × KV heads × head dimension × bytes per element for each token. At fp16 a 32-layer model with 8 KV heads of 128 uses 128 KB a token — a gigabyte for 8,000 tokens per request. Grouped-query attention (fewer KV heads than query heads) and 8-bit caches are how long contexts are made affordable.

Formula: bytes per token = 2 × layers × KV heads × head dim × bytes per element; total = per token × tokens × batch

Worked examples

InputsKV cache for the batchNote
32 layers, 8 KV heads of 128, fp16, 8k × 88.59 GB131 KB/token; 8.6 GB
No GQA: 32 KV heads34.36 GB34.4 GB — over budget
int8 cache, 128k context, one request8.59 GB8.6 GB

Frequently asked questions

Why does the KV cache matter more than the weights?

Weights are paid once per GPU; the cache is paid per token per request, and long contexts with many concurrent users make it the larger of the two. It is what limits how many users a serving GPU can hold.

What is grouped-query attention?

Sharing each key–value head among several query heads: a model with 32 query heads and 8 KV heads has a cache a quarter the size of one with 32 of each, at little cost in quality. Most recent models use it.

Does quantising the cache hurt?

Eight-bit KV caches are close to lossless for most models and halve the memory; four-bit caches show some degradation on long-context tasks. Serving frameworks expose it as an option.

How does paged attention help?

It allocates the cache in blocks on demand instead of reserving the maximum context per request, so memory is used for tokens that exist rather than tokens that might. The per-token figure is the same; the waste disappears.

Where these figures come from

Last checked: September 2026. The relationships here are architectural, not vendor-specific: bytes per parameter follow the numeric format, KV-cache size follows the transformer definition, and token-per-word ratios come from published tokeniser behaviour.