KV-cache numbers are easy to compare incorrectly. The 144 KiB listed for Qwen3 8B, for example, is the logical cache added by one token for one sequence. The gallery uses bf16 (16-bit bfloat), so every cached element occupies 2 bytes.

During autoregressive generation, an attention layer reuses the keys and values from earlier tokens. Keeping these tensors avoids recomputing them at every decoding step. Prompt tokens populate the cache during prefill, and each decoded token appends another entry.

I chose a per-token value because it makes architectures with very different attention stacks comparable on one card. Runtime memory will usually be higher due to allocator padding, serving buffers, and kernel-specific layouts.

What it means

Logical cache added by one retained token

Fixed assumptions

Batch size 1, bf16, and 2 bytes per cached element

Important caveat

Logical architecture estimate, separate from measured serving memory

Start with one attention layer

The most general form of the calculation is:

bytes_per_layer_per_token
= cached_tensors 脳 num_kv_heads 脳 head_dim 脳 bytes_per_element

Standard attention stores a key tensor and a value tensor. When their head dimensions are equal, the bf16 formula simplifies to

bytes_per_layer_per_token
= 2 脳 num_kv_heads 脳 head_dim 脳 2
= 4 脳 num_kv_heads 脳 head_dim

The query-head count enters indirectly through the attention type. Multi-head attention (MHA) has one KV head per query head. Grouped-query attention (GQA) uses fewer KV heads, and multi-query attention (MQA) uses one. This is why GQA and MQA reduce the cache without changing the number of query heads.

When the key and value widths differ, add the two widths explicitly. Xiaomi MiMo-V2-Flash and MiMo-V2.5 use 192-dimensional keys and 128-dimensional values. With 8 KV heads in 39 local layers and 4 KV heads in 9 global layers, each token adds (39 脳 8 + 9 脳 4) 脳 (192 + 128) 脳 2 = 222,720 bytes, or 217.5 KiB before window eviction. Step 3.5 Flash uses 128 dimensions for both K and V and 8 KV heads in each of its 45 main decoder layers. That gives 180 KiB per token. Its three optional MTP layers have a separate cache. MiMo-V2-Flash configuration 路 MiMo-V2.5 configuration 路 Step decoder

For the model-wide value, I add the contribution from every distinct layer that produces cache tensors:

bytes_per_model_per_token
= sum(bytes_per_layer_per_token across cache-producing layers)
Comparison of float32, float16, and bfloat16 bit layouts
Figure 1. Bfloat16 uses 16 bits per element, the same storage size as float16. Its exponent occupies 8 bits and its fraction occupies 7 bits. The gallery uses 2 bytes per cached bf16 value.

Retention and sharing affect different factors

Sliding-window attention uses the same cost per stored token as its underlying MHA, GQA, or MQA layer. It changes how long a token remains in the cache. Once the window is full, an old entry can be removed when a new one arrives.

Cross-layer KV sharing changes the number of distinct cache-producing layers. A layer that reuses keys and values from an earlier layer does not append another pair of tensors. The Gemma 4 E2B and E4B models use this approach.

Looped depth needs an additional recurrence factor when every pass retains its own cache. Ouro-Thinking 2.6B maps each of its four passes to separate cache entries across the shared 48-layer stack:

4 passes 脳 48 layers 脳 16 KV heads 脳 128 head_dim 脳 4
= 1,572,864 bytes
= 1.5 MiB per token

The Ouro paper also evaluates decoding-time cache reuse that retains only one pass, reducing this logical growth to 384 KiB/token. The released Hugging Face implementation keeps the full four-pass cache by default.

Dory1.0 4B repeats only its middle 20-block stack. Its default configuration uses two passes with separate caches, plus 8 input and 8 output blocks:

(8 + 20 脳 2 + 8) 脳 4 KV heads 脳 256 head_dim 脳 4
= 229,376 bytes
= 224 KiB per token

This is the gallery鈥檚 full-retention estimate before sliding-window eviction. Dory鈥檚 optional last_loop cache mode shares the recurrent cache across passes, reducing the same estimate to 36 脳 4 脳 256 脳 4 = 147,456 bytes, or 144 KiB/token.

Gemma 4 E2B and E4B use separate projections for K and V. In E2B, 12 local and 3 global layers produce the cache. Each has one KV head, with 256 dimensions locally and 512 globally. E4B has 20 local and 4 global producers with two KV heads each. Counting both K and V gives

E2B: (12 脳 256 + 3 脳 512) 脳 1 脳 2 脳 2 = 18 KiB/token
E4B: (20 脳 256 + 4 脳 512) 脳 2 脳 2 脳 2 = 56 KiB/token

At 131,072 tokens and batch size 1, those rates give 2.25 GiB for E2B and 7 GiB for E4B before sliding-window eviction. The larger 31B, 26B-A4B, and 12B checkpoints share a projection between K and V in their global layers. That gives a different calculation below. E2B configuration 路 E4B configuration 路 Gemma 4 technical report

MLA stores a compressed latent

Multi-head latent attention (MLA) keeps a compressed KV latent and a separate rotary-key component. For DeepSeek-style MLA, the gallery uses the compact representation described by the architecture:

Per MLA layer:

bytes_per_layer_per_token
= (kv_lora_rank + qk_rope_head_dim) 脳 2

Across the model, this gives:

bytes_per_model_per_token
= num_mla_layers 脳 (kv_lora_rank + qk_rope_head_dim) 脳 2

The cache now depends on the latent dimensions and the number of MLA layers. Query-head count no longer appears in this compact formula. A serving implementation that expands the latent into full key and value tensors will have a different memory footprint.

Hybrids need a layer inventory

Hybrid models are where a single layer count becomes misleading. I count only the layers that append to a growing KV cache.

  • Qwen3-Next and Qwen3.5 contribute cache through their full-attention layers.
  • Kimi Linear and Ling 2.5/2.6 contribute cache through MLA layers in the main decoder. Ling 2.6鈥檚 optional MTP path can add a small MLA cache when used.
  • Nemotron hybrids contribute cache through their explicit GQA layers.
  • DeltaNet, Lightning Attention, Mamba-2, and xLSTM layers add 0 B/token to a growing KV cache.

The last group still needs inference state. Its state has a fixed size with respect to sequence length, so I keep it outside a metric that measures growth per token.

sum(per-layer cache growth over the cache-growing layers only)

Checks against published configurations

I verified the gallery values against the corresponding configuration files. These examples cover the main cases above.

Qwen3 8B has 36 GQA layers, 8 KV heads, and a head dimension of 128:

36 layers 脳 8 KV heads 脳 128 head_dim 脳 4
= 147,456 bytes
= 144 KiB

DeepSeek V3 has 61 MLA layers, a KV latent rank of 512, and a 64-dimensional rotary-key component:

61 layers 脳 (512 kv_lora_rank + 64 qk_rope_head_dim) 脳 2
= 70,272 bytes
= 68.6 KiB

DeepSeek V3.2 also stores a 128-dimensional key for its sparse indexer in each of the 61 layers. Under the gallery鈥檚 bf16 convention, that gives 61 脳 (512 + 64 + 128) 脳 2 = 85,888 bytes, or 83.875 KiB per token. DeepSeek鈥檚 inference code quantizes the indexer keys and stores scales, so its actual allocation differs. DeepSeek V3.2 indexer

GLM-5 and GLM-5.1 use the same geometry across 78 layers, or 107.25 KiB per token. GLM-5.2 and Tencent Hy4-preview share token selections across layers and keep just 21 independent indexer histories. Their total is [78 脳 (512 + 64) + 21 脳 128] 脳 2 = 95,232 bytes, or 93 KiB. GLM-5 configuration 路 GLM-5.1 configuration 路 GLM-5.2 configuration 路 Hy4-preview configuration

GLM-5.3-Flash pools four tokens into each indexer key. Its 11 sparse attention layers each keep a 512-dimensional KV latent per token and a 128-dimensional indexer key per group of four. Over complete groups, the average is 11 脳 (512 + 128 / 4) 脳 2 = 11,968 bytes, or 11.6875 KiB per token. GLM-5.3-Flash configuration 路 SGLang pooled indexer

Qwen3-Next 80B-A3B has 48 decoder layers with full attention every fourth layer. Only 12 layers enter the growing KV-cache calculation:

12 full-attention layers 脳 2 KV heads 脳 256 head_dim 脳 4
= 24,576 bytes
= 24 KiB

Gemma 4 31B has 50 sliding-window layers and 10 global layers. Each global head shares a 512-dimensional projection between K and V. RoPE transforms a quarter of the key, so a compact cache stores 512 shared entries and another 128 rotated entries per head. A separate full K and V would take 1,024 entries per head. Gemma 4 technical report, section 2

50 sliding-window layers 脳 16 KV heads 脳 256 head_dim 脳 4
+ 10 global layers 脳 4 KV heads 脳 (512 + 128) 脳 2
= 819,200 + 51,200 bytes
= 870,400 bytes
= 850 KiB

The gallery uses this compact layout for all three checkpoints. It gives 850 KiB for 31B, 212.5 KiB for 26B-A4B, and 330 KiB for 12B. The Transformers implementation materializes separate key and value tensors. With that layout, the same three models use 880, 220, and 336 KiB per token. Both sets of numbers assume full retention before sliding-window eviction. 26B-A4B configuration 路 12B configuration 路 Transformers implementation

xLSTM 7B has no attention layers, so its growing KV-cache value is 0 B/token. Its recurrent matrix state is still present.

Mistral Large 4 shares latent caches and sparse indices

Mistral Large 4 has 72 attention layers, but nine NoPE layers reuse the KV cache from layer 35 (using zero-based layer indices). Its configuration therefore gives 63 distinct main caches, with rotary keys in 54 of them. There are also 44 independent sparse indexers, each caching one 128-dimensional key per token.

54 RoPE caches 脳 (512 latent + 64 rotary entries) 脳 2 bytes
+ 9 NoPE caches 脳 512 latent entries 脳 2 bytes
+ 44 indexer caches 脳 128 key entries 脳 2 bytes
= 82,688 bytes
= 80.75 KiB per token

This estimate includes the indexer keys and counts shared KV caches once. Selecting the top 2,048 tokens reduces attention work; it does not limit the retained history to 2,048 tokens. The optional DSpark draft head, vision encoder, temporary index buffers, and runtime overhead are excluded.

LongCat-2.5 reuses sparse indices across attention pairs

LongCat-2.5 has 38 blocks with two MLA sublayers each. Its configuration and inference implementation give 76 main KV caches and 38 independent indexer-key caches. Each attention pair reuses the selected token positions.

76 MLA caches 脳 (512 latent + 64 rotary entries) 脳 2 bytes
+ 38 indexer caches 脳 128 key entries 脳 2 bytes
= 97,280 bytes
= 95 KiB per token

The top-2,048 selection limits attention work while the full history remains stored. This estimate includes main KV and indexer keys across host and device memory. The vision encoder, optional MTP module, temporary buffers, and runtime overhead are excluded.

DeepSeek V4 compresses the global cache

DeepSeek V4-Pro and V4-Flash use two compression ratios. Each group of 4 tokens produces a 512-dimensional global cache entry and a 128-dimensional indexer key. Each group of 128 tokens produces one 512-dimensional global entry. V4-Pro has 30 layers of the first kind and 31 of the second, giving (30 脳 640 / 4 + 31 脳 512 / 128) 脳 2 bytes, or about 9.62 KiB per token. V4-Flash has 21 and 20 such layers, respectively, giving 6.72 KiB. These are averages for the growing global cache. Both models also keep recent tokens and unfinished compression groups, so the calculator leaves their total cache unspecified. V4-Pro configuration 路 V4-Flash configuration 路 Released inference code

CSA2 shares compressed global caches

DeepSeek V4.1-Flash has three distinct encoder global caches at compression ratio 2 and one decoder global cache at ratio 1. Reindex and Reuse layers share these caches. From the released configuration, I calculate the growing global cache in bf16 as follows.

(3 encoder caches / 2 + 1 decoder cache / 1)
脳 (512 main-KV entries + 128 indexer-key entries) 脳 2 bytes
= 3,200 bytes
= 3.125 KiB per token

The 512-dimensional main cache uses a joint KV representation and already includes its rotary components. This estimate excludes the bounded per-layer sliding-window caches, sparse-index buffers, and runtime overhead. It also uses bf16 throughout. The technical report鈥檚 890 bytes per token uses FP4 main KV and indexer keys with quantization scales. The memory calculator leaves total cache memory unspecified for this architecture because the growing global component alone does not describe its full cache state.

GQA-based DSA also stores indexer keys

Naive-N0.5-Flash uses 8 KV heads in each of its 39 sliding-window layers and 4 KV heads in each of its 9 DSA layers. The configuration gives key and value dimensions of 192 and 128. Each DSA layer also caches one 128-dimensional indexer key per token.

39 SWA layers 脳 8 KV heads 脳 (192 + 128) 脳 2 bytes
+ 9 DSA layers 脳 4 KV heads 脳 (192 + 128) 脳 2 bytes
+ 9 DSA layers 脳 128 indexer-key entries 脳 2 bytes
= 225,024 bytes
= 219.75 KiB per retained token

This bf16 estimate includes 217.5 KiB of main KV cache and 2.25 KiB of indexer keys. It assumes full retention across all layers. Sliding-window eviction can reduce the total, while DSA鈥檚 top-2,048 selection limits attention work without capping the stored history. The released model uses FP8 indexer activations; the gallery estimate uses bf16 consistently for comparison.

From one token to a context

For a full-attention model, multiply the gallery number by the number of retained tokens. At 32,768 tokens, the 144 KiB/token value for Qwen3 8B corresponds to 4.5 GiB of logical bf16 KV cache for batch size 1.

Mixed stacks require the layer-wise form because different layers may retain different numbers of tokens:

total_cache_bytes
= sum(bytes_per_layer_per_token 脳 retained_tokens_for_that_layer)

A larger batch adds the cache for every active sequence. Paged serving, padding, cache quantization, and temporary buffers can move the measured memory above or below a simple bf16 estimate. This is why the gallery field is best read as an architecture comparison value.

The gallery and model-comparison tool attach a rough label to each numeric value:

  • 0 B -> No cache
  • > 0 and <= 24 KiB -> Very low
  • > 24 KiB and <= 72 KiB -> Low
  • > 72 KiB and <= 160 KiB -> Moderate
  • > 160 KiB and <= 300 KiB -> High
  • > 300 KiB -> Very high

These labels are only for quick scanning. Use the numeric value for calculations.