Loading diagram…

Reference

← All guides

Multi-head Latent Attention

Multi-head Latent Attention (MLA) caches a compressed vector for each token, plus a small positional key. Learned projections provide the key and value information used by each head.

Overview

How it works

The compressed vector is called a latent. MLA learns to encode the information needed by multiple heads in this smaller representation, reducing the data stored for each earlier token.

Details

Per-head storage

Standard multi-head attention saves separate key and value vectors for every head and token. The cache grows with the context. MLA reduces the size of each token’s cached representation.

Details

Compression and projection

A learned down-projection produces the latent. Separate up-projections define the content keys and values for each head. The diagrams show this expanded view. Efficient decoding can combine projections algebraically rather than explicitly rebuilding every cached head vector.

Details

A separate positional key

Rotary position encoding applies position-dependent rotations. MLA uses a small, separate positional key so those rotations do not obstruct the projection operations used for the compressed content path. Both the latent and positional key are cached.

Details

Choosing the latent dimension

A smaller latent needs less cache storage but gives the model less representational capacity. The dimension is an architectural choice learned during training. DeepSeek-V2 reported a 93.3% KV-cache reduction against its comparison model. The interactive calculator uses a smaller example.

Sources