Highlights

Contents

Part V
05

Comparing what the cache stores

A memory saving depends on its baseline. GQA already shares much of the history. Compare the complete latent representation and positional branch against the architecture the deployment actually uses.

THE ARCHITECTURE INVESTIGATIONCost + future tokens01Sparse connections02Compressed history03Latent memory04Compare KV designs05Speculative decoding06Controlled experiment07Interpret + decide08

#Section 14MLA vs MHA

Two models have the same number of query heads, yet one cache is far smaller. The cache stores keys and values, so counting query heads misses the difference.

EIGHT QUERY HEADS, FOUR WAYS TO STORE WHAT THEY READMHA1,024 cached featuresGQA256 cached featuresMQA128 cached featuresMLAlatent 64R 1680 cached featuresper token per layer, Finch head width 64; orange is what the cache keeps
Figure 6.16Computed cached widths for four attention designs with eight query heads of width 64. Lines show which stored state each query head reads; the MLA row adds a 16-feature rotary key beside its 64-feature latent.

Full independent KV heads and cache size

Multi-head attention, or MHA, gives every query head its own key and value projections. For HH heads of width dhd_h the cache holds 2Hd_h features per token per layer: 2 × 8 × 64 = 1,024. Our MLA fixture stores r+d_R=64+16=80.

SAME WORKLOAD, DIFFERENT PERSISTENT KV REPRESENTATIONSMHA128 MiB1024 features / token / layerGQA32 MiB256 features / token / layerMQA16 MiB128 features / token / layerMLA fixture10 MiB80 features / token / layerB = 2, L = 8, T = 4,096, 2-byte elements; tensor payload only
Figure 6.17Computed payloads use the same batch, layers, sequence length, and element size. The MLA bar includes its positional key; its illustrative rank is not a measured optimum.

Representation capacity

MHA's projected states are free of a joint low-rank constraint. MLA can produce different head features, but all of them come from one latent, and being able to write the reconstruction does not make quality equal. MHA heads are "independent" only in having separate projections; they all read the same hidden vector.

#Section 15MLA vs MQA

One shared key and value can serve every query head. The heads still ask different questions, but they search the same keys and retrieve the same values.

Shared KV and latent compression

Multi-query attention, or MQA, uses one KV head for all query heads, so the cache holds 2d_h = 128 features and the fixture payload is 2 × 8 × 4,096 × 128 × 2 = 16,777,216 bytes, or 16 MiB. Shazeer proposed it in 2019 to cut the memory bandwidth spent on K/V during incremental decoding. Multi-query attention paper.

MLA is smaller than MQA only when its latent and positional widths together are smaller than the shared key/value representation.

Quality vs memory

MQA shares explicit head states; MLA shares a latent but transforms it per head. These are different restrictions, so cache size cannot rank their quality. Compare trained models at a declared budget on the runtime you will actually use.

#Section 16MLA vs GQA

Finch-24 already shares KV across query groups. Comparing MLA only against MHA would overstate its saving against the model we actually start from.

Grouped KV heads and compressed latent KV

Grouped-query attention, or GQA, uses fewer KV heads than query heads, each KV head serving a group. Finch has 8 query heads and 2 KV heads, so groups of 4, a cached width of 2 × 2 × 64 = 256, and a 32 MiB fixture payload. Ainslie and colleagues (2023) studied it as the middle ground between MHA and MQA. GQA paper.

Cache-size differences and computational trade-offs

The MLA fixture is 256/80=3.2 times smaller than GQA. The crossover is

r+dR<2HKVdh.r+d_R<2H_{KV}d_h.

A latent cache saves payload only while its content and positional features together remain narrower than the baseline keys and values.

THE BASELINE IS GQA, NOT AN UNCOMPRESSED STRAW MODELGQA: 256 features3264128240256MLA: rank + 16cachedfeatureslatent rank
Figure 6.18Computed cache dimensions cross the Finch GQA baseline at rank 240. Rank sets both capacity and persistent storage.

GQA reuses familiar head layouts; MLA moves work into latent projections and absorbed paths. Strong GQA kernels against a slow MLA reference can favor GQA despite the larger payload, so compare prefill and decode separately at equal context and batch, and report the kernels.

Design Cached features per token/layer Payload in the fixture Main sharing rule
MHA 1,024 128 MiB Separate K/V per query head
GQA 256 32 MiB One KV head per query group
MQA 128 16 MiB One KV head for all queries
MLA fixture 80 10 MiB Shared content latent plus positional key

#Section 17MLA and RoPE

The absorption identity in Section 13 worked because the up-projection was one fixed linear map. A key rotated by its position applies a different map at every historical position, which changes what can be moved onto the query.

Positional information and the difficulty with naive compression

Rotary position embedding, or RoPE, rotates paired query and key coordinates by position-dependent angles. With key rotation RtR_t and query rotation RsR_s, a naive rotated-content score is

(Rsq)⊤RtWUKct=q⊤Rs⊤RtWUKct.(R_s q)^\top R_t W_U^K c_t =q^\top R_s^\top R_t W_U^K c_t.

Read this as the relative rotation sits between the query and the key up-projection. It depends on the historical position tt, so no single query transform can absorb it for every cached token. Compression is still possible; this simple absorption is what fails.

Separating positional and content components

Decoupled RoPE splits a content-key path from a rotary positional-key path, and each head's score adds the two:

scores,t,i=(qs,iC)⊤kt,iC+(qs,iR)⊤ktRdC+dR.\mathrm{score}_{s,t,i} =\frac{(q^C_{s,i})^\top k^C_{t,i} +(q^R_{s,i})^\top k^R_t}{\sqrt{d_C+d_R}}.

Read this as add the content and positional dot products, then apply the declared scale. CC marks content, RR the rotary branch, ii a head, and s,ts,t the query and key positions. The content term keeps the absorption identity; the rotary key is cached explicitly and shared across heads.

KEEP CONTENT ABSORPTION AND POSITIONAL ROTATION SEPARATEcontentabsorbed querycached latentdotpositionrotated querycached rotary keydotsum / sqrt(80)softmaxthe positional key costs real cache bytes
Figure 6.19The illustrative content branch reads the latent through an absorbed query; the positional branch compares separately rotated features. The two score contributions add before softmax.

#Section 18DeepSeek architecture connection

Many readers, many tokens, and a cache fetched for every new query: cutting bytes per historical token is the architectural case for MLA, strongest when context and batch grow together.

Why MLA is used and architectural motivation

DeepSeek-V2 combines joint low-rank KV compression with a separate rotary branch, keeping head-specific content transforms with a small cache. It also uses mixture-of-experts feed-forward layers, so its throughput cannot be credited to MLA alone. DeepSeek-V2 architecture and evaluations.

KV-cache efficiency and long-context inference

Fewer cache bytes help when cache reads dominate. Projection work, kernel overhead, or weight reads can reduce or eliminate that advantage.

MLA compresses features per token; it does not bound the number of tokens. The latent cache still grows linearly with length and dense prefill is still quadratic. Sparse patterns and latent memory attack different dimensions of the problem.