<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DeepSeek on KbWen Blog</title>
    <link>https://www.kbwen.com/tags/deepseek/</link>
    <description>Articles and notes on AI systems, machine learning, Python, data engineering, and software development.</description>
    <generator>Hugo</generator>
    <language>zh-tw</language>
    <image>
      <url>https://www.kbwen.com/images/og-default.png</url>
      <title>KbWen Blog</title>
      <link>https://www.kbwen.com/</link>
    </image>
    
    <lastBuildDate>Tue, 20 Oct 2026 10:15:00 +0800</lastBuildDate><atom:link href="https://www.kbwen.com/tags/deepseek/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>DeepSeek-V3&#39;s auxiliary-loss-free load balancing and multi-token prediction</title>
      <link>https://www.kbwen.com/deepseek-v3-moe-architecture-efficiency/</link>
      <pubDate>Tue, 20 Oct 2026 10:15:00 +0800</pubDate><dc:creator>KbWen</dc:creator>
      <guid>https://www.kbwen.com/deepseek-v3-moe-architecture-efficiency/</guid>
      <description>A look at how DeepSeek-V3 keeps load even across its experts during training, and what its multi-token prediction module is for.</description>
      <content:encoded><![CDATA[<p><a href="https://github.com/deepseek-ai/DeepSeek-V3">DeepSeek-V3</a> has 671B parameters, 37B of which are activated for each token, and its full training took 2.788M H800 GPU hours. The gap between 671B and 37B comes from the Mixture-of-Experts (MoE) design: each token is routed to a small subset of feed-forward experts, so the parameter count can grow without a matching jump in compute. But the routing is also where MoE training goes wrong. If the gate keeps sending a large share of tokens to a few experts, the remaining parameters sit idle, and the GPUs that host the busy experts slow everything else down. The <a href="https://arxiv.org/abs/2412.19437">technical report</a> calls the extreme case routing collapse.</p>
<p>The usual fix is an auxiliary load-balancing loss added to the training objective, which penalizes the model when expert loads drift apart. The penalty&rsquo;s gradient reaches the same weights as the language-modeling loss, though, so if it is set too large it hurts model performance, as the report says.</p>
<h2 id="a-bias-term-for-each-expert">A bias term for each expert</h2>
<p>DeepSeek-V3 moves most of the balancing out of the loss. Each expert gets a bias term that is added to its affinity score, and the top-K experts for a token are picked from those biased scores. The bias is used only for that choice: the gating value that weights the expert&rsquo;s output still comes from the original score.</p>
<p>The bias changes once per training step. DeepSeek monitors the expert load over the whole batch of the step, and at the end of it lowers the bias of every overloaded expert by a fixed amount and raises the bias of every underloaded one by the same amount. An overloaded expert then needs a higher raw score to make a token&rsquo;s top-K, and an underused one starts to win tokens that sat near the cutoff. The report sets that amount to 0.001 for the first 14.3T training tokens and to 0.0 for the remaining 500B.</p>
<p>Because the bias never enters the loss, it adds no gradient of its own. But it does not remove every balancing term. The report keeps a complementary sequence-wise balance loss to prevent extreme imbalance within any single sequence, with its weight set to an extremely small 0.0001. So &ldquo;auxiliary-loss-free&rdquo; in the <a href="https://github.com/deepseek-ai/DeepSeek-V3/blob/main/README.md">README</a> means the bias does the balancing work instead of a large loss term, and the README says this keeps down the performance degradation that comes from encouraging load balancing.</p>
<p>Load stayed even enough that DeepSeek-V3 did not drop any tokens during training. The report also tested the bias method against baselines balanced purely by auxiliary losses, at 15.7B and 228.7B total parameters, and it did better on most of the evaluation benchmarks. On the Pile test set, a 16B model trained with the bias showed greater expert specialization by domain than its auxiliary-loss counterpart.</p>
<h2 id="multi-token-prediction">Multi-token prediction</h2>
<p>DeepSeek-V3 also trains with a Multi-Token Prediction (MTP) objective. A standard language model is trained to predict only the next token, at position $t+1$. DeepSeek-V3 adds one MTP module after the main model, so each position is trained to predict the next two tokens. The module is a single Transformer block that shares the embedding layer and the output head with the main model. It predicts sequentially: it takes the main model&rsquo;s representation of the current token together with the embedding of the next one, which keeps the complete causal chain at each prediction depth.</p>
<p>The report gives two reasons this could help. The extra target densifies the training signal and may improve data efficiency, and the model may learn to pre-plan its representations for tokens further ahead. In its ablations, adding the module improved the main model on most of the evaluation benchmarks, at both 15.7B and 228.7B total parameters. The module ships with the weights, which is why the <a href="/llm-parameter-count-model-names/">files on Hugging Face total 685B</a>: 671B for the main model and 14B for the MTP module.</p>
<p>At inference the module is optional. The main model works normally without it, and the module can also be reused for speculative decoding, where it proposes the second token and the main model checks it. Speculative decoding usually pairs a large model with a separately trained small draft model; here the draft comes with the weights. The report measures the acceptance rate of the second token at 85% to 90% across generation topics, and puts the resulting decoding speed at 1.8 times the tokens per second. A runtime has to support the module to use it that way, and the README says MTP support is currently under active development within the community.</p>
<p>This post is put together from the DeepSeek-V3 README and technical report.</p>
]]></content:encoded>
    </item>
    
    <item>
      <title>DeepSeek-V3 的 Multi-head Latent Attention 如何壓縮 KV 快取</title>
      <link>https://www.kbwen.com/deepseek-v3-multi-head-latent-attention-kv-cache/</link>
      <pubDate>Tue, 20 Oct 2026 10:10:00 +0800</pubDate><dc:creator>KbWen</dc:creator>
      <guid>https://www.kbwen.com/deepseek-v3-multi-head-latent-attention-kv-cache/</guid>
      <description>我們來看看 DeepSeek-V3 如何利用 MLA 的低維潛在向量壓縮 KV 快取，解決長序列推論時的記憶體瓶頸。</description>
      <content:encoded><![CDATA[<p>DeepSeek 在發布 DeepSeek-V3 時，<a href="https://raw.githubusercontent.com/deepseek-ai/DeepSeek-V3/main/README.md">開源 README</a> 總參數 671B、每個 token 啟用 37B 的混合專家（MoE）架構（&ldquo;We present DeepSeek-V3, a strong Mixture-of-Experts (MoE) language model with 671B total parameters with 37B activated for each token.&quot;）。關於總參數量與啟動參數的差別，可以參考之前寫的相關文章：<a href="/what-does-7b-mean-model-parameters/">7B、70B 是什麼意思？看懂模型名字裡的參數量</a>。在這樣的大規模模型下，除了訓練成本之外，實際部署時更直接的負擔其實落在推論階段的顯存容量。</p>
<p>為了提升推論效率，官方說明他們採用了 Multi-head Latent Attention（MLA）架構（&ldquo;To achieve efficient inference and cost-effective training, DeepSeek-V3 adopts Multi-head Latent Attention (MLA) and DeepSeekMoE architectures, which were thoroughly validated in DeepSeek-V2.&quot;）。這項設計的核心目標，在於緩解自回歸生成時持續膨脹的鍵值快取（KV cache）記憶體佔用。</p>
<h2 id="kv-快取的記憶體瓶頸">KV 快取的記憶體瓶頸</h2>
<p>大型語言模型在自回歸生成文字的過程中，每計算一個新 token，注意力機制都需要回頭查詢先前所有 token 的 Key 與 Value。為了避免重複運算，推論系統會把先前步驟產生的鍵值向量暫存在顯存當中，也就是常見的 KV 快取。</p>
<p>在標準的多頭注意力（Multi-Head Attention，MHA）當中，每個注意力頭都各自擁有一組 Key 與 Value 向量。當模型層數增加、上下文長度拉長，或是同時處理多個請求時，快取所消耗的顯存容量會迅速累積，變成限制批次大小和序列長度的主要瓶頸（來自 V2 論文）。常見的分組查詢注意力（GQA）透過讓多個 Query 頭共用同一組 Key 與 Value 來縮減體積，不過每一組存的仍然是完整的 Key 與 Value，這類做法雖然讓快取變小，效果卻比不上 MHA（來自 V2 論文）。</p>
<h2 id="壓縮至低維潛在向量">壓縮至低維潛在向量</h2>
<p>但是 MLA 採取了不同的處理方式，不再只是減少 Key 與 Value 的組數，而是引入低秩壓縮機制。在計算注意力之前，模型先透過投影矩陣，將隱藏狀態壓縮成維度小得多的低維潛在向量（latent vector）。</p>
<p>到了自回歸生成階段，顯存中不必再為每個注意力頭保留完整的 Key 與 Value，而是只需要儲存這個緊湊的潛在向量，另外再加上一小段帶有位置資訊、所有頭共用的 Key。當新的 token 需要計算注意力分數時，直覺的做法是把潛在向量還原成每個頭的 Key 與 Value。不過 V2 的論文則說明，還原用的矩陣可以事先併進 Query 和輸出的矩陣裡，所以推論時其實不必把 Key 和 Value 重新算出來，也就省下了這段重複的計算。</p>
<h2 id="實際推論時的影響">實際推論時的影響</h2>
<p>這種結構大幅減輕了長文本生成時的記憶體壓力。當每個 token 佔用的快取空間縮小，相同的顯存容量就能支撐更長的文件輸入，或是提高系統並行處理的吞吐量。</p>
<p>而且這是從架構層面縮小快取，並不和數值量化衝突，DeepSeek 在 V2 就兩個一起用（KV 快取平均量化到 6 bits）。至於效果，V3 的報告則說明能和標準的 MHA 維持相近的表現。最後說明，這篇是根據 DeepSeek-V3 公布的架構資料整理而成，提供給想了解大型模型推論優化方向的朋友參考。</p>
]]></content:encoded>
    </item>
    
  </channel>
</rss>
