Glossary · Attention

Multi-head latent attention (MLA)

Also: MLAkv_lora_ranklatent attention

Read it at the depth you need: one sentence · a paragraph · the math · in the models here

1In one sentence

DeepSeek's attention: keys and values are compressed into one small latent vector per token, which is all that is cached, and expanded per head when needed.

2In a paragraph

Instead of caching keys and values for every head (or every KV head, as in GQA), MLA projects each token down to a small latent vector and caches only that. Each head's keys and values are rebuilt from the latent by a learned up-projection. RoPE does not survive that compression, so a small separate key carries the position. The result is a cache smaller than GQA's while every head keeps its own keys and values.

3The math, shapes and parameters

Per layer, with latent rank rkv, a RoPE part of size hr, and per-head sizes hn (query/key without RoPE) and hv (value):

c = WDKV x  [rkv]  (cached),   kR = RoPE(WKR x)  [hr]  (cached, shared by all heads)
[kC; v] = WUKV c  [H·(hn+hv)]

In the checkpoint the first two are one matrix, kv_a_proj_with_mqa [rkv+hr, d], and the up-projection is kv_b_proj. Queries can be compressed the same way (q_lora_rank). The cache per token is

L × (rkv + hr) × bytes

At inference the up-projection can be folded into the query and output matrices, so attention runs directly on the latents. Runtimes that do not do this expand the cache back to full keys and values and lose the saving.

4In the 96 models on this site

Models here with MLA, per token in BF16, against caching every head's keys and values in full:

Modelr_kv + h_rHeadsLatent cacheExpandedSaving
DeepSeek-V2-Lite512 + 641631.1 KB276.5 KB9×
DeepSeek-V3512 + 6412870.3 KB5.0 MB71×
DeepSeek-R1512 + 6412870.3 KB5.0 MB71×
DeepSeek-V3.1512 + 6412870.3 KB5.0 MB71×
DeepSeek-V3.2512 + 6412885.9 KB5.0 MB58×
GLM-5.2512 + 6464109.8 KB5.1 MB47×
Kimi K2512 + 646470.3 KB2.5 MB36×

Introduced in DeepSeek-AI, “DeepSeek-V2: A Strong, Economical, and Efficient Mixture-of-Experts Language Model” (2024).

Related

Grouped-query attention (GQA) · KV cache · RoPE (rotary position embedding) · Mixture of experts (MoE) · every term