TL;DR
DeepSeek-V2 is a large language model with 236 billion parameters in total, of which only 21 billion are used for each token. It makes two architectural changes. Multi-head Latent Attention stores a small compressed vector per token instead of the full keys and values, which shrinks the memory needed while generating text. DeepSeekMoE splits the feed-forward layers into many small experts and sends each token to only a few of them, which keeps training cheap. The paper reports that the model is stronger than its own dense predecessor, DeepSeek 67B, while cutting training cost by 42.5 percent (measured in GPU hours per trillion training tokens) and a 93.3 percent smaller key-value cache.
Builds on: Multi-Head Attention, KV Cache, Rotary Position Embedding, Mixture of Experts, DeepSeekMoE · Leads to: later open models that combine compressed attention with sparse experts
Why it mattered
Serving a large language model is limited by memory. During generation the model keeps a key-value cache for every token it has seen, so long conversations and large batches compete for GPU memory. DeepSeek-V2 attacks that cost directly, and it reports serving more than 50,000 generated tokens per second on one node of eight H800 GPUs, which the paper says is 5.76 times the maximum generation throughput of DeepSeek 67B.
The paper also made a public case for sparse models. A mixture-of-experts model holds far more parameters than it uses for each token, so it can be trained and run for a fraction of the compute of a dense model of the same total size. DeepSeek-V2 released its base and chat models, along with a smaller 15.7-billion-parameter sibling, DeepSeek-V2-Lite, so other groups could study the two architectural ideas.
The problem
Two costs pull against each other. Attention needs a cache that grows with the sequence length and the number of heads. The usual fixes, Grouped-Query Attention and Multi-Query Attention, share keys and values across heads to shrink the cache, but the paper's Table 1 rates their performance as moderate (GQA) and weak (MQA), against strong for full multi-head attention. Feed-forward layers, meanwhile, dominate the compute. A dense layer uses all its weights for every token, so a bigger model costs more per token. A mixture-of-experts layer uses only a few experts per token, but earlier designs with a few large experts specialise poorly, and when experts are spread across devices, routing a token to many of them creates heavy communication.
DeepSeek-V2 tries to solve both with one budget: keep the quality of full multi-head attention, store far less per token, and spread the feed-forward work over many small experts while limiting how many devices each token must reach.
How it works
Take one tiny instance of Multi-head Latent Attention. Let the hidden state of a token be the four numbers . Standard attention would store a key and a value for this token, each of length four. MLA stores only a latent vector of length two.
- Compress the token. Multiply the hidden state by a down-projection matrix with two rows, and . The latent is . Check: the latent has two numbers, and it is the only thing stored in the cache.
- Expand it into a key when needed. An up-projection with rows , , and turns the latent into a key of length four: . Check: the third row gives and the fourth gives .
- Do the same for values. A second up-projection rebuilds the values from the same latent. Only the latent sits in memory, and both keys and values are recreated from it.
- Attend as usual. The query of the new token is dotted with each stored key, the scores go through a softmax, and the values are averaged. Check: nothing about the attention step itself has changed, only what is kept in memory.
- Keep position separate. The paper applies rotary position embedding to a small separate set of query and key dimensions, not to the compressed keys. Otherwise the up-projection could not be folded into the query matrix at inference. Check: the content keys stay position-free, so the compression still works.
Now the feed-forward side. For each token, a router gives a score to each expert, the top few experts are chosen, and their outputs are added with weights. The paper adds two refinements. Some experts are shared and always run, which frees the routed experts from learning common knowledge. And the router is limited so that each token reaches at most a few devices.
flowchart LR H["Token hidden state"] --> C["Down-project to small latent"] C --> K["Cache only the latent"] K --> U["Up-project to keys and values when attending"] H --> R["Router scores 160 routed experts"] R --> T["Keep top 6 experts on at most 3 devices"] H --> S["2 shared experts always run"] T --> O["Weighted sum added to output"] S --> O
The math
Step 1 in symbols: standard attention and its cache
Standard multi-head attention caches a key and a value for every head and every layer. With heads of dimension over layers, the cache holds numbers per token. Its cost is the bottleneck during generation.
Step 2 in symbols: the latent
MLA computes one latent vector per token and layer:
where has dimension , which is much smaller than . Only is cached, so the cache holds numbers per token. Because can be absorbed into the query projection, the full keys never need to be built at inference.
Step 3 in symbols: the decoupled position part
Rotary position embedding would sit between the query and the key up-projection and block that absorption. So the paper adds separate query and key components that carry position, , and concatenates them:
The shared positional key is cached too, so the total cache per token and layer is numbers. The paper's settings give and , so the total is per layer, which the paper says is equal to grouped-query attention with 2.25 groups.
Step 4 in symbols: the routed feed-forward layer
For token with input , the layer output is
where shared experts always run, and the routed experts are gated by
Here is a learned centroid for expert , and is the number of routed experts each token activates. The gate is the softmax score itself, not renormalised over the chosen experts, as written in the paper's formula.
Step 5 in symbols: the cost counts
With routed experts and activated per token, each token uses percent of the routed experts. The paper's device limit is : each token reaches at most 3 of the devices. The balance losses push the router toward even use of experts, devices and communication, using expert, device and communication terms of the form , where is how often expert is used and is the average router probability it receives.
Worked examples
Use the toy numbers from How it works. The hidden state is , the latent is , and the reconstructed key is .
- Standard attention would cache the key and a value of the same length. Together that is 8 numbers.
- MLA caches only the latent . That is 2 numbers.
- The cache is 2 divided by 8, which is one quarter of the standard size.
- The reconstructed key is exactly what standard attention would have stored, so the attention scores do not change.
- The price is the up-projection work done at each step, which the paper avoids at inference by folding the matrices into the query and output projections.
The toy cache is four times smaller. The paper's real ratio is far larger, as Example 3 shows.
Suppose a router has four routed experts and keeps the top two. For a token, its affinity scores before softmax are .
- Exponentiate each score: , , , .
- Sum them: .
- Divide each by the sum to get the softmax scores: , , and . Check: they sum to 1.
- Keep the top two scores, for expert 1 and for expert 3. The others get gate 0.
- The routed part of the output is , with no renormalisation.
Only two of the four experts run for this token, so half the routed compute is skipped. The paper's version does the same with 6 of 160.
Use the figures the paper reports for training on the H800 cluster. Training DeepSeek 67B takes 300.6 thousand GPU hours per trillion tokens, and DeepSeek-V2 takes 172.8 thousand.
- The saving per trillion tokens is thousand GPU hours.
- As a share of the dense cost, the saving is , so 42.5 percent. This matches the paper.
- The pretraining corpus has 8.1 trillion tokens. For DeepSeek-V2 that is thousand GPU hours, about 1.4 million.
- For DeepSeek 67B the same corpus is thousand GPU hours, about 2.4 million.
- Per layer and per token, standard attention with the paper's 128 heads of dimension 128 stores numbers. MLA stores . The ratio is . The paper's 93.3 percent figure is a different comparison, against DeepSeek 67B, so the two numbers should not be mixed.
Try it: if the saving had been 30 percent instead of 42.5 percent, how many GPU hours would DeepSeek-V2 need per trillion tokens, given that DeepSeek 67B needs 300.6 thousand? Answer: thousand GPU hours per trillion tokens.
Results
Headline numbers. The abstract reports 236 billion total parameters, 21 billion activated per token, a 128,000-token context, pretraining on 8.1 trillion tokens, and a 93.3 percent smaller key-value cache with 5.76 times the maximum generation throughput of DeepSeek 67B. The training cost saving is 42.5 percent.
Benchmarks. On the internal evaluation, DeepSeek-V2 scores 78.5 on MMLU with 5 shots, against 71.3 for DeepSeek 67B. Its scores are close to larger or more-active models: LLaMA 3 70B scores 78.9, Mixtral 8x22B scores 77.6, and Qwen1.5 72B scores 77.2. The paper's stated reading is that DeepSeek-V2 is top-tier among open models with only 21 billion activated parameters.
Where it is weaker. On English commonsense and trivia tasks, such as TriviaQA and NaturalQuestions, DeepSeek-V2 trails Mixtral 8x22B, and the paper acknowledges a slight gap in basic English against LLaMA 3 70B. The paper notes that DeepSeek-V2 was trained on fewer than a quarter of LLaMA 3's English tokens. On Chinese benchmarks it leads most of the compared open models, for example C-Eval at 81.7 against 66.1 for DeepSeek 67B.
Chat models. The paper's aligned model, DeepSeek-V2 Chat (RL), reaches a 38.9 length-controlled win rate on AlpacaEval 2.0, 8.97 on MT-Bench and 7.91 on AlignBench. These are the paper's own evaluation numbers.
Limits. The benchmark table was run in the authors' internal framework, so the comparisons are against their setup rather than public leaderboards. The efficiency numbers come from H800 clusters and a specific deployment workload. During training the paper drops the lowest-affinity tokens on each device until the device reaches a fixed compute budget, while always keeping the tokens of about 10 percent of training sequences. At inference, the paper says, whether to drop tokens is chosen according to efficiency needs.
Reading guide
- Abstract and Introduction. Gives the size, context length, cost claims and the two architectural ideas. Read with Mixture of Experts and KV Cache in mind.
- Section 2.1, multi-head latent attention. Needs Multi-Head Attention and Attention Mechanism. Section 2.1.2 is the core, and Table 1 compares the cache per token. Section 2.1.3 needs Rotary Position Embedding.
- Section 2.2, DeepSeekMoE. Needs DeepSeekMoE: Towards Ultimate Expert Specialization in Mixture-of-Experts... and Switch Routing for the router. Section 2.2.3 needs Load-Balancing Loss.
- Section 3.1, setup. Hyper-parameters and the parallel layout. Model Parallelism and Data Parallelism explain the device placement.
- Section 3.1.4, long context. Uses YaRN to extend the context from 4K to 128K tokens.
- Section 3.2, evaluation. Table 2 and the efficiency results. Section 3.2.3 covers FP8 weights and the Quantization of the cache to about 6 bits.
- Section 4, alignment. Supervised fine-tuning follows Instruction Tuning, and the reinforcement learning step uses Group Relative Policy Optimization (GRPO).
Check yourself
QuestionRecall: what exactly does DeepSeek-V2 store in its cache for each token and layer, and why is that enough?Show answer
It stores the compressed latent vector of dimension , plus a small shared positional key of dimension . Keys and values are rebuilt from the latent through up-projections, and the up-projections can be folded into the attention matrices at inference, so the full keys and values never need storing.
QuestionComputation: a router keeps the top 6 of 160 routed experts for each token, and each token also uses 2 shared experts. What fraction of the routed experts runs for a token?Show answer
The fraction is , which is 3.75 percent. The two shared experts always run, so they are not part of this fraction.
QuestionWhy: the paper says the MLA cache is equal to grouped-query attention with 2.25 groups, yet it performs better than standard multi-head attention. Why would a smaller cache not hurt quality here?Show answer
The latent is a learned low-rank compression, so the model learns to put the information attention needs into the compressed vector, and the up-projections give each head its own keys and values from that shared latent. Grouped-query attention instead shares a full key and value across several heads, which removes distinct per-head information. The paper's claim is that the learned compression keeps more of this information for the same cache size, which is why MLA performs better in its experiments.
QuestionApplied: a team wants to serve a model with a long context and a large batch on a fixed GPU budget. Their current model has a standard multi-head attention cache that fills memory. What does this paper suggest, and what must they check before switching?Show answer
The paper suggests replacing the cache with a latent cache like MLA, which can cut the stored numbers per token by a large factor, so more sequences fit in memory. Before switching, the team must train or convert the model to use the latent attention, since a standard model cannot simply be swapped, and must check quality on their own benchmarks, because the paper's gains come from its own training run and evaluation setup.