Highlights

Contents

Part IV
04

Storing a latent instead of full heads

Shared latent features can represent several heads’ content memory. Linear reassociation lets attention use that representation directly. The saving disappears if decoding reconstructs and retains every expanded historical head.

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

#Section 12Multi-head latent attention

Every generated token adds a key and value per stored KV head. At long context and large batch, reading that cache can limit decoding even when the weights fit. Could the decoder keep a smaller vector per position and still serve several heads?

KV-cache bottleneck and latent KV representations

Multi-head latent attention, or MLA, learns a low-dimensional vector from which keys and values are derived. A latent is an internal feature vector rather than explicit K/V head states. The idea is joint compression: a token’s keys and values both come from the same smaller vector.

MLA is a trained parameterization, not a file compressor applied to an existing Finch GQA cache. Finch-24 stays the baseline; the dimensions below describe an illustrative variant that would need training and evaluation.

ONE TOKEN: SEPARATE HEAD STATES OR ONE SHARED LATENTMHA: K and V per headMLA: joint content latentKVKVKVKVKVKVKVKVc KV: 64 featurespositional key: 168 x (64 + 64) = 1,02464 + 16 = 80bars show storage organization; widths are schematic
Figure 6.13Illustrative per-token storage compares separate full K/V features with a shared latent. The positional-key branch is shown separately because the decoupled RoPE design in Part V cannot cache the content latent alone.

Low-dimensional compression and reconstructing attention information

For hidden vector ht∈R512h_t\in\mathbb R^{512}, choose latent rank r=64r=64 and down-projection WD∈R64×512W_D\in\mathbb R^{64\times512}:

ct=WDht,kt,iC=WU,iKct,vt,i=WU,iVct.c_t=W_D h_t,\qquad k^C_{t,i}=W^K_{U,i}c_t,\qquad v_{t,i}=W^V_{U,i}c_t.

The down-projection produces one latent per token; head-specific up-projections derive content keys and values from it. Positional information is handled separately.

Reconstructed keys and values lie in a learned subspace of rank at most 64. That is a representational restriction, and whether it is adequate is a training result, not something the algebra proves.

DeepSeek introduced MLA in DeepSeek-V2 (2024), with learned joint compression and an inference form that keeps compact states. DeepSeek-V2 architecture paper.

#Section 13MLA internals

The cache stores 64 content features, but the equations rebuild 512 key and 512 value features. If inference materializes those full histories, it spends the memory it claimed to save.

Latent projection and compressed KV representation

An input batch [2,8,512] projects to [2,8,64], one latent per item and token. Training can expand keys and values explicitly to check the math. Cached decoding instead stores [B,T,64] per layer.

THE SHARED LATENT HAS TWO DISTINCT EXPANSION MAPSh: [2, 8, 512]W D64 x 512c: [2, 8, 64]K content: [2, 8, 512]W UK: 512 x 64V: [2, 8, 512]W UV: 512 x 64expand for a reference check; persist the compact cache
Figure 6.14Computed illustrative shapes show the down-projection and two up-projections. Orange marks the latent that persists in the cache; expanded training intermediates need not be stored during decoding.

Query interaction and reconstructed keys/values

Let qiq_i be a content query for head ii. Ignoring position for now:

qi⊤WU,iKct=((WU,iK)⊤qi)⊤ct.q_i^\top W^K_{U,i}c_t =\left((W^K_{U,i})^\top q_i\right)^\top c_t.

Read this as move the key up-projection onto the query once, then compare that 64-feature query with every cached latent. Folding linear maps into neighboring projections this way is called weight absorption.

MOVE THE LINEAR MAP FROM EVERY KEY TO THE QUERYexpand keyc = 4k = [4, 8]q dot k = 20transform queryq = [1, 2]q latent = 55 x 4 = 20same score, different persistent storage
Figure 6.15Both routes through this illustrative one-dimensional latent produce score 20 in exact arithmetic. This checks algebra, not task quality.

Values work the same way. With normalized attention weights ai,ta_{i,t} for head ii:

∑tai,tWU,iVct=WU,iV(∑tai,tct).\sum_t a_{i,t}W^V_{U,i}c_t =W^V_{U,i}\left(\sum_t a_{i,t}c_t\right).

Read this as form the weighted latent sum first, then expand it once. The value up-projection can be merged into the matching output-projection slice. Each head keeps its own attention weights; shared storage does not mean a shared attention pattern.

Cache savings

The cache also needs the decoupled positional key. Compare that complete representation with the actual GQA baseline, rather than counting only the content latent.

Absorbed queries still do head-specific work, and kernel layout, projection cost, rank, and the positional path all affect speed. A Python version that caches reconstructed K/V can verify the math while showing none of the memory saving.