Search

Search papers and lessons

DeepSeek-V3 Technical Report

DeepSeek-AI, Aixin Liu, Bei Feng et al. · 2024

DeepSeek-V3 is a 671-billion-parameter mixture-of-experts language model that uses 37 billion parameters per token, trained on 14.8 trillion tokens for a reported 2.788 million H800 GPU hours.

On this page

  • Colour = topic mix
  • Discrete math
  • Calculus
  • Neural network basics
  • Linear algebra
  • Probability
  • Architectures
  • ReadReady to readNot yet

TL;DR

DeepSeek-V3 is a large open language model with 671 billion parameters in total, of which 37 billion are switched on for each token. The authors report that it was pre-trained on 14.8 trillion tokens, then fine-tuned and trained with reinforcement learning, for a total of 2.788 million H800 GPU hours. On standard benchmarks it is reported to beat the other open models they tested and to be comparable with leading closed models on many tasks.

Builds on: KV Cache, Mixed-Precision Training, Load-Balancing Loss · Leads to: DeepSeek-R1 (whose reasoning the authors distil into it)

Why it mattered

The model's checkpoints were released publicly, so other teams could run and study a model at this scale without access to a closed API. Its reported cost drew attention: the authors estimate the official training run at 5.576 million dollars, assuming a rental price of 2 dollars per H800 GPU hour, and they state that this excludes earlier research and ablation runs.

It also showed that a mixture-of-experts design, where most parameters sit idle for any one token, can match dense models that use every parameter. The authors compare it with LLaMA-3.1 405B, a dense model with about 11 times as many activated parameters, and report that DeepSeek-V3 is better on most of the benchmarks they chose.

The problem

A dense language model uses all of its weights for every token, so doubling its size roughly doubles the compute per token. Mixture-of-experts layers break that link: a router sends each token to a few specialised feed-forward networks, the experts, so the total capacity can grow while the work per token stays fixed.

Three problems stand in the way. First, the router can send most tokens to a few favourite experts, which the authors call routing collapse, and leaves the others idle; the usual fix is an auxiliary loss, which can hurt the model. Second, when experts sit on different GPUs, moving tokens between them is expensive. Third, during generation the attention cache for long inputs takes a lot of memory. The paper's aim is efficient inference and cheap training at this scale, with the best possible quality.

How it works

Follow one token through the model, using the paper's design.

  1. Attention with a small cache. The token's hidden vector ht\mathbf{h}_t is compressed into a latent vector ctKV\mathbf{c}_t^{KV} of 512 numbers. Only this latent, plus a 64-number positional key, is stored for later tokens. Check: the full keys and values for 128 heads of 128 numbers each would need far more storage.
  2. Expert scoring. The token's vector is compared with one centroid vector per routed expert, using a sigmoid, which gives an affinity score si,ts_{i,t} for each of the 256 routed experts. Check: each score lies between 0 and 1.
  3. Choosing experts. Each token is sent to the 8 routed experts with the highest biased scores, and to one shared expert that always runs. Check: 9 expert computations per token, out of 257 expert networks.
  4. Weighting the outputs. The gate for each chosen expert is its original score divided by the sum of the chosen scores, and the layer output is the token plus the weighted expert outputs. Check: the gates of the chosen experts add up to 1.
  5. Balancing the load. The bias added in step 3 is not part of the gate. After each step the bias of an overloaded expert goes down by a small amount γ\gamma, and an underloaded expert's goes up. Check: this changes which experts are picked, not how strongly they count.
  6. Predicting ahead during training. One extra module predicts the token after next and adds its loss to the training objective. At inference the module is dropped. Check: the model still predicts one token at a time.
  7. Running it across GPUs. The layers are split into pipeline stages, the experts are spread across many GPUs, and matrix multiplications run in FP8 precision, with communication overlapped with computation. Check: the paper reports that no tokens are dropped during training.
flowchart TD
  A[Token embedding] --> B[Multi-head latent attention, small KV cache]
  B --> C[Sigmoid affinity to 256 routed experts]
  C --> D[Pick top 8 by biased score]
  D --> E[Gate by original scores, add 1 shared expert]
  E --> F[Layer output to next block]
  C -. bias update per step .-> D

The toy routing below shows step 3 and step 5 with four experts and K = 2, with made-up numbers. Scores for the token are 0.9, 0.2, 0.7 and 0.5. The bias is −0.3-0.3 for expert 1 and 0 for the rest. Biased scores are 0.6, 0.2, 0.7 and 0.5, so the top two are experts 3 and 1. The gates come from the original scores 0.7 and 0.9, giving 0.9/1.6=0.56250.9/1.6 = 0.5625 for expert 1 and 0.7/1.6=0.43750.7/1.6 = 0.4375 for expert 3. The bias changed who was chosen, but the gate values use the original scores.

The math

Definition: Mixture-of-experts layer (DeepSeek-V3 form)
For a token with FFN input ut\mathbf{u}_t, the output is ht′=ut+∑i=1NsFFNi(s)(ut)+∑i=1Nrgi,t FFNi(r)(ut)\mathbf{h}'_t = \mathbf{u}_t + \sum_{i=1}^{N_s} \mathrm{FFN}^{(s)}_i(\mathbf{u}_t) + \sum_{i=1}^{N_r} g_{i,t}\,\mathrm{FFN}^{(r)}_i(\mathbf{u}_t), where the NsN_s shared experts always run and the NrN_r routed experts are gated by gi,tg_{i,t}. Only the KrK_r routed experts with the highest biased affinities receive a nonzero gate.

Step 1 in symbols: the cache per token

Standard multi-head attention with nh=128n_h = 128 heads of dimension dh=128d_h = 128 stores keys and values, which is 2nhdh=2×128×128=327682 n_h d_h = 2 \times 128 \times 128 = 32768 numbers per layer per token. Under the paper's multi-head latent attention, only ctKV\mathbf{c}_t^{KV} of dimension dc=512d_c = 512 and the decoupled RoPE key of dimension dhR=64d_h^R = 64 are cached, which is 512+64=576512 + 64 = 576 numbers. The ratio is 576/32768≈0.018576/32768 \approx 0.018, about one fifty-seventh of the standard cache. This is a count derived from the hyper-parameters in Section 4.2 of the paper, not a figure the paper states.

Step 2 and 4 in symbols: affinities and gates

The affinity is si,t=Sigmoid(utTei)s_{i,t} = \mathrm{Sigmoid}(\mathbf{u}_t^{T}\mathbf{e}_i), where ei\mathbf{e}_i is the centroid of expert ii. Selection uses si,t+bis_{i,t} + b_i, and the gate is

gi,t=gi,t′∑jgj,t′,gi,t′={si,t,si,t+bi∈Topk({sj,t+bj},Kr)0,otherwiseg_{i,t} = \frac{g'_{i,t}}{\sum_{j} g'_{j,t}}, \qquad g'_{i,t} = \begin{cases} s_{i,t}, & s_{i,t} + b_i \in \mathrm{Topk}(\{s_{j,t} + b_j\}, K_r) \\ 0, & \text{otherwise} \end{cases}

The toy example gives g′g' equal to 0.9 for expert 1 and 0.7 for expert 3, so the gates are 0.56250.5625 and 0.43750.4375.

Step 5 in symbols: the bias update

At the end of each step, for each expert ii, bi←bi−γb_i \leftarrow b_i - \gamma if the expert is overloaded and bi←bi+γb_i \leftarrow b_i + \gamma if underloaded. The paper sets γ=0.001\gamma = 0.001 for the first 14.3 trillion tokens and 0 for the rest.

Step 6 in symbols: the prediction loss

Each extra prediction depth kk has a cross-entropy loss LMTPk\mathcal{L}^k_{\text{MTP}}, and the total extra loss is LMTP=λD∑k=1DLMTPk\mathcal{L}_{\text{MTP}} = \frac{\lambda}{D}\sum_{k=1}^{D}\mathcal{L}^k_{\text{MTP}}. The paper uses D=1D = 1, and the weight λ\lambda is 0.3 for the first 10 trillion tokens and 0.1 afterwards.

Step 7 in symbols: the cost arithmetic

Pre-training costs 2.664 million H800 GPU hours for 14.8 trillion tokens, which is 2.664×106/14.8=1802.664 \times 10^6 / 14.8 = 180 thousand GPU hours per trillion tokens. Adding 119 thousand hours for context extension and 5 thousand for post-training gives 2.664M+0.119M+0.005M=2.788M2.664\text{M} + 0.119\text{M} + 0.005\text{M} = 2.788\text{M} hours. At 2 dollars per hour the total is 2.788×2=5.5762.788 \times 2 = 5.576 million dollars.

Worked examples

Example
1. Tiny: one token, four experts

Setup: four routed experts, K=2K = 2, scores 0.9, 0.2, 0.7, 0.5 and biases 0, 0, 0, 0.

  1. Biased scores equal the scores, so the top two are experts 1 (0.9) and 3 (0.7).
  2. Gates: the sum of the two scores is 0.9+0.7=1.60.9 + 0.7 = 1.6.
  3. Gate for expert 1: 0.9/1.6=0.56250.9/1.6 = 0.5625. Gate for expert 3: 0.7/1.6=0.43750.7/1.6 = 0.4375.
  4. The gates add to 1, as expected.

Interpretation: with no bias, the two highest-scoring experts share the work in proportion to their scores.

Example
2. Standard: the attention cache and the cost per token

Setup: the hyper-parameters in Section 4.2 of the paper, with 61 layers.

  1. Standard cache per token per layer: 2×128×128=327682 \times 128 \times 128 = 32768 numbers.
  2. Latent cache per token per layer: 512+64=576512 + 64 = 576 numbers.
  3. Ratio: 576/32768≈0.0176576 / 32768 \approx 0.0176.
  4. Over 61 layers, the standard cache is 61×32768=1,998,84861 \times 32768 = 1{,}998{,}848 numbers per token, and the latent cache is 61×576=35,13661 \times 576 = 35{,}136 numbers per token.
  5. Interpretation: the latent cache is about 57 times smaller, so a long conversation fits in much less memory.

Note that this count ignores the precision of each number and the extra projection cost, so it is a storage comparison, not a total memory figure.

Example
3. Realistic: what a training run costs

Setup: a team wants to estimate the pre-training cost of a run on 4 trillion tokens, using the paper's rate of 180 thousand H800 GPU hours per trillion tokens and a rental price of 2 dollars per hour.

  1. GPU hours: 4×180,000=720,0004 \times 180{,}000 = 720{,}000.
  2. Cost: 720,000×2=1,440,000720{,}000 \times 2 = 1{,}440{,}000 dollars.
  3. Time on the paper's cluster of 2048 GPUs: 720,000/2048≈351.6720{,}000 / 2048 \approx 351.6 hours, about 14.7 days.
  4. Check against the paper: 14.8 trillion tokens took less than two months and 2.664 million hours, so 4 trillion tokens at the same rate is about a quarter of that.

Interpretation: the rate turns token counts into hours and dollars, but it assumes the same cluster, efficiency and rental price. It does not include the earlier research and ablation runs the authors exclude.

Try it: a run uses 10 trillion tokens at the same rate and price. How many dollars is the pre-training cost?

Answer: 10×180,000=1,800,00010 \times 180{,}000 = 1{,}800{,}000 hours, and 1,800,000×2=3,600,0001{,}800{,}000 \times 2 = 3{,}600{,}000 dollars, or 3.6 million dollars.

Results

The paper reports two kinds of results. Base-model results (Table 3) compare pre-trained models under the authors' internal evaluation setup. Chat results (Table 6) compare the fine-tuned model, with output length capped at 8K tokens.

Benchmark (metric)DeepSeek-V2 baseQwen2.5 72B baseLLaMA-3.1 405B baseDeepSeek-V3 base
MMLU (5-shot, EM)78.485.084.487.1
MMLU-Pro (5-shot, EM)51.458.352.864.4
MATH (4-shot, EM)43.454.449.061.6
HumanEval (0-shot, Pass@1)43.353.054.965.2
Benchmark (metric)GPT-4o 0513Claude-3.5-Sonnet-1022DeepSeek-V3 chat
MMLU (EM)87.288.388.5
MMLU-Pro (EM)72.678.075.9
GPQA-Diamond (Pass@1)49.965.059.1
MATH-500 (EM)74.678.390.2
SWE-bench Verified (resolved)38.850.842.0

The numbers are copied from the paper's tables. The chat comparison is not uniform: the Claude-3.5-Sonnet column is higher on MMLU-Pro, GPQA-Diamond and SWE-bench Verified. On the ablations, the multi-token objective helps the small model on most benchmarks (MMLU 50.0 to 53.3 for the 15.7B-parameter model), but on the large 228.7B-parameter model MMLU drops slightly (67.5 to 66.6) while HumanEval rises (44.5 to 53.7). The auxiliary-loss-free balancing shows the same mixed pattern: MMLU for the large model goes from 68.3 to 67.2, while HumanEval goes from 40.2 to 46.3.

The paper's limits are its own: most evaluations come from an internal framework, the recommended deployment unit is large, and the authors note the risk of tuning to a fixed set of benchmarks.

Reading guide

Check yourself

QuestionWhy does a mixture-of-experts model with 671 billion parameters use only 37 billion for each token?Show answer

The router sends each token to a small subset of experts, here 8 of 256 routed experts plus one shared expert. The other expert weights are not used for that token, so the compute per token depends on the activated parameters, not the total.

QuestionUsing the paper's Section 4.2 settings, how many numbers per layer per token does the latent cache store, and how many would standard multi-head attention store?Show answer

The latent cache stores 512+64=576512 + 64 = 576 numbers. Standard multi-head attention stores 2×128×128=327682 \times 128 \times 128 = 32768 numbers. The latent cache is about 1/57 of the standard size.

QuestionThe paper's pre-training used 2.664 million H800 GPU hours and the authors assume 2 dollars per hour. What is the pre-training cost they state?Show answer

2.664×2=5.3282.664 \times 2 = 5.328 million dollars. The paper's Table 1 gives this figure as $5.328M.

QuestionIn the bias-based balancing, a bias changes which experts are chosen. Why does it not change how much each chosen expert contributes?Show answer

The bias is added to the score only when choosing the top-K experts. The gate value comes from the original affinity score, normalised over the chosen experts. Balancing therefore changes the routing decision without distorting the weight that each expert's output receives.

Sources

Read the full paper

DeepSeek-AI, Aixin Liu, Bei Feng et al., 2024. arXiv:2412.19437