Tools › KV-cache

KV-cache calculator

While a transformer generates text it keeps the keys and values of every earlier token, so it does not recompute them. This cache grows with context length and is often what limits how many users one GPU can serve.

How it is calculated

For standard attention (MHA, GQA, MQA) every full-attention layer stores 2 × kv_heads × head_dim numbers per token (one key and one value vector per KV head). Multi-head latent attention (MLA) stores a compressed latent plus a small positional part, latent + rope numbers per token. Sliding-window layers only keep the last window tokens. Linear-attention or state-space layers keep a fixed-size state that does not grow with context.

cache = batch × (full_layers × tokens × per_token + window_layers × min(tokens, window) × per_token + linear_layers × state) × bytes

Some models run a block of layers several times in a row with the same weights (a looped model). Every pass produces its own keys and values, so a block of loopLayers layers that is run loopPasses times counts as loopLayers × loopPasses full-attention layers in the cache. Presets with such a block say so in the table below.

What it ignores

Model weights, activations, framework overhead, paged-attention block rounding, quantisation scales, prefix sharing between requests, and runtimes that keep the full cache although the architecture would allow evicting. Treat results as a planning estimate, usually within a few percent of the raw cache, not a guarantee.

Presets and their sources

Every number is derived from the model's published configuration; check the source before relying on it. Found a mistake or missing a model? Write to the contact address in the Impressum.

ModelAttentionLayersPer layer & tokenSpecial layersSource
DeepSeek-V3
Multi-head latent attention: per token and layer the cache holds a compressed latent (kv_lora_rank) plus a rotary key part (qk_rope_head_dim). The multi-token-prediction module is not counted.
MLA61latent 512 + rope 64—deepseek-ai/DeepSeek-V3 config.json
Falcon-7B
Multi-query attention (config: multi_query = true) shares one KV head across all query heads. head_dim = hidden_size / num_attention_heads.
MQA321 KV heads × 64—tiiuae/falcon-7b config.json
gpt-oss-20B
Alternates sliding-window and full-attention layers (layer_types in the config). Assumes the runtime evicts tokens outside the window; attention-sink tokens are ignored.
GQA248 KV heads × 6412 sliding-window layers (128 tokens)openai/gpt-oss-20b config.json
Inkling 2 Mini (26.4B-A3.4B, looped)
config.json: 24 layers, 8 KV heads, head_dim 128, sliding_window_size 1024; local_layer_ids = 20 sliding layers, so layers 5, 11, 17, 23 are full attention; loop_config: layers 6-17 run 3 times. The blog says each visit keeps its own KV, so we count 48 visits (8 full, 40 sliding) instead of 24 layers (our derivation). maxContext = model_max_length (no max_position_embeddings). Not counted: short-conv and K/V-conv state, cross-pass messages, DSpark drafter, vision encoder.
GQA488 KV heads × 12840 sliding-window layers (1024 tokens)thinkingmachines/Inkling-2-Mini config.json
Hugging Face blog: Inkling 2 Mini (KV per visit)
Kimi K3.1 Pro (2.8T, hybrid KDA + MLA)
config.json: 93 layers, kv_lora_rank 512, qk_rope_head_dim 64; linear_attn_config: 24 full-attention layers (4, 8, ..., 92, 93; MLA + DSA indexer) and 69 KDA layers. stateElements = KDA num_heads 96 x head_dim 128 x 128 per layer and sequence (our derivation; not stated directly). Not counted: DSA indexer keys (24 x 128 per token; vLLM uses FP8, 132 B/key), KDA short-conv state (kernel 4), vision encoder. Runtimes may keep KDA state in FP32.
MLA93latent 512 + rope 6469 linear-attention layersmoonshotai/Kimi-K3.1-Pro config.json
Mistral Large 4 (1T-A52B)
From text_config: num_hidden_layers = 72, kv_lora_rank = 512, qk_rope_head_dim = 64, all layer_types = indexed_attention. kv_source_layers maps layers 39, 43, 47, 51, 55, 59, 63, 67 and 71 to layer 35, so these 9 layers reuse layer 35's cache and store none of their own; 'layers' is therefore set to 63 (72 - 9), not to num_hidden_layers. Not counted: the sparse-attention indexer keys (index_n_heads 32, index_head_dim 128; storage format not documented) and the 3-layer DSpark draft head. The calculator has no field for cross-layer KV sharing yet.
MLA63latent 512 + rope 64—mistralai/Mistral-Large-4-1T-A52B config.json
Mistral-7B v0.1
Grouped-query attention with a sliding window applied in every layer. Assumes the runtime evicts tokens outside the window (a rolling buffer).
GQA328 KV heads × 12832 sliding-window layers (4096 tokens)mistralai/Mistral-7B-v0.1 config.json
OPT-6.7B
Classic multi-head attention: every query head has its own key/value head.
MHA3232 KV heads × 128—facebook/opt-6.7b config.json
Qwen2.5-7B
Grouped-query attention, full attention in all layers (use_sliding_window = false). head_dim = hidden_size / num_attention_heads.
GQA284 KV heads × 128—Qwen/Qwen2.5-7B-Instruct config.json
Qwen3-Next-80B-A3B
Hybrid: every 4th layer is full attention (12 layers), the other 36 are linear-attention (Gated DeltaNet) layers with a fixed recurrent state of linear_num_value_heads × linear_key_head_dim × linear_value_head_dim numbers per sequence. The small convolution state is ignored, and runtimes may keep states in higher precision than the cache.
GQA482 KV heads × 25636 linear-attention layersQwen/Qwen3-Next-80B-A3B-Instruct config.json