<?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/">
  <channel>
    <title>拆解 GRPO on Njx&#39;Log</title>
    <link>https://njx-njx.github.io/series/grpo/</link>
    <description>Recent content in 拆解 GRPO on Njx&#39;Log</description>
    <image>
      <title>Njx&#39;Log</title>
      <url>https://njx-njx.github.io/blog-cover.jpg</url>
      <link>https://njx-njx.github.io/blog-cover.jpg</link>
    </image>
    <generator>Hugo</generator>
    <language>zh</language>
    <atom:link href="https://njx-njx.github.io/series/grpo/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>一票还是十票：token-mean 与 sample-mean 在争什么</title>
      <link>https://njx-njx.github.io/posts/token-mean-vs-sample-mean/</link>
      <pubDate>Sun, 30 Aug 2026 12:07:00 +0800</pubDate>
      <guid>https://njx-njx.github.io/posts/token-mean-vs-sample-mean/</guid>
      <description>500 token 和 5000 token 的回答，谁对梯度贡献更大？sample-mean 每条一票，token-mean 每个 token 一票，换法有隐藏代价。</description>
      <content:encoded><![CDATA[<p>同一个 batch 里，500 token 的回答和 5000 token 的回答，谁对梯度的贡献大？GRPO 说一样大，DAPO 说长的大十倍，两家都能给出理由。这是损失聚合方式之争——sample-mean 每条回答一票，token-mean 每个 token 一票。DAPO 论文 §3.3 说长 CoT 场景必须换 token 级，但换完会把长度倾斜从 response 级赶到 question 级。本文拆解三个公式、两家的论证和一个少有人讲的 tradeoff。</p>
<blockquote>
<p>本文有配套的<a href="https://njx-njx.github.io/reports/token-mean-vs-sample-mean/">交互报告</a>
，含三种计票规则可切换的权重计算器与公式并排拆解。</p>
</blockquote>
<h2 id="先算一票">先算一票</h2>
<p>同一个训练 batch 里有两条回答：一条 500 token，一条 5000 token。它们对这一步梯度的贡献各是多少？</p>
<ul>
<li><strong>GRPO（sample-mean）</strong>：一样大。先在每条回答内部对 token 求平均，再对 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 条回答求平均——每条回答无论长短，都是平等的一票；</li>
<li><strong>DAPO（token-mean）</strong>：长的那条大十倍。batch 内所有 token 拉平，统一除以总 token 数——每个 token 一票，5000 token 的回答拿 5000 票；</li>
<li><strong>Dr.GRPO</strong>：形式上也是每条回答一票，但除数从&quot;每条回答的实际长度&quot;换成全局常数，票的含义变了（这是 <a href="https://njx-njx.github.io/posts/dr-grpo-length-and-difficulty-bias/">Dr.GRPO 那篇</a>
的主题）。</li>
</ul>
<p>三种答案都有论文背书，而且三家处理的是<strong>同一个式子里的同一个位置</strong>——损失的聚合除数。这个旋钮和 Dr.GRPO 那篇讲的 advantage 归一化（std 那半）是正交的：那篇的问题是&quot;advantage 怎么算&quot;，本文的问题是&quot;算完之后，token 们的损失按什么规则加在一起&quot;。</p>
<h2 id="三个公式并排">三个公式并排</h2>
<p>GRPO 的目标函数（DeepSeekMath 公式 3 的省略 KL 版）：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi mathvariant="script">J</mi><mrow><mi>G</mi><mi>R</mi><mi>P</mi><mi>O</mi></mrow></msub><mo>=</mo><mi mathvariant="double-struck">E</mi><mrow><mo fence="true">[</mo><mfrac><mn>1</mn><mi>G</mi></mfrac><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>G</mi></munderover><mfrac><mn>1</mn><mrow><mi mathvariant="normal">∣</mi><msub><mi>o</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow></mfrac><munderover><mo>∑</mo><mrow><mi>t</mi><mo>=</mo><mn>1</mn></mrow><mrow><mi mathvariant="normal">∣</mi><msub><mi>o</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow></munderover><msub><mi mathvariant="normal">ℓ</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub><mo fence="true">]</mo></mrow><mo separator="true">,</mo><mspace width="1em"/><msub><mi mathvariant="normal">ℓ</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub><mo>=</mo><mi>min</mi><mo>⁡</mo><mo fence="false" stretchy="true" minsize="1.2em" maxsize="1.2em">(</mo><msub><mi>w</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi></msub><mo separator="true">,</mo><mtext> </mtext><mrow><mi mathvariant="normal">c</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">p</mi></mrow><mo stretchy="false">(</mo><msub><mi>w</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub><mo separator="true">,</mo><mn>1</mn><mo>−</mo><mi>ε</mi><mo separator="true">,</mo><mn>1</mn><mo>+</mo><mi>ε</mi><mo stretchy="false">)</mo><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi></msub><mo fence="false" stretchy="true" minsize="1.2em" maxsize="1.2em">)</mo></mrow><annotation encoding="application/x-tex">\mathcal{J}_{GRPO} = \mathbb{E}\left[\frac{1}{G}\sum_{i=1}^{G}\frac{1}{|o_i|}\sum_{t=1}^{|o_i|}\ell_{i,t}\right], \quad \ell_{i,t}=\min\big(w_{i,t}\hat{A}_i,\ \mathrm{clip}(w_{i,t},1-\varepsilon,1+\varepsilon)\hat{A}_i\big)</annotation></semantics></math></span><p>其中 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>o</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">o_i</annotation></semantics></math></span> 是第 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi></mrow><annotation encoding="application/x-tex">i</annotation></semantics></math></span> 条回答，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∣</mi><msub><mi>o</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">|o_i|</annotation></semantics></math></span> 是它的长度，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>w</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub></mrow><annotation encoding="application/x-tex">w_{i,t}</annotation></semantics></math></span> 是新旧策略对该 token 的概率比，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">\hat{A}_i</annotation></semantics></math></span> 是整条回答共享的 advantage。注意求和的结构：<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>1</mn><mrow><mi mathvariant="normal">∣</mi><msub><mi>o</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow></mfrac><msub><mo>∑</mo><mi>t</mi></msub></mrow><annotation encoding="application/x-tex">\frac{1}{|o_i|}\sum_t</annotation></semantics></math></span> 先把每条回答<strong>自己</strong>平均成一个数，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>1</mn><mi>G</mi></mfrac><msub><mo>∑</mo><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">\frac{1}{G}\sum_i</annotation></semantics></math></span> 再对 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 个数求平均。两条回答各出一票，长短无关。</p>
<p>DAPO 的改动只有一个地方（论文公式 12，红字标注的部分）：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi mathvariant="script">J</mi><mrow><mi>D</mi><mi>A</mi><mi>P</mi><mi>O</mi></mrow></msub><mo>=</mo><mi mathvariant="double-struck">E</mi><mrow><mo fence="true">[</mo><mfrac><mn>1</mn><mrow><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>G</mi></munderover><mi mathvariant="normal">∣</mi><msub><mi>o</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow></mfrac><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>G</mi></munderover><munderover><mo>∑</mo><mrow><mi>t</mi><mo>=</mo><mn>1</mn></mrow><mrow><mi mathvariant="normal">∣</mi><msub><mi>o</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow></munderover><msub><mi mathvariant="normal">ℓ</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub><mo fence="true">]</mo></mrow></mrow><annotation encoding="application/x-tex">\mathcal{J}_{DAPO} = \mathbb{E}\left[\frac{1}{\sum_{i=1}^{G}|o_i|}\sum_{i=1}^{G}\sum_{t=1}^{|o_i|}\ell_{i,t}\right]</annotation></semantics></math></span><p>内层的 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>1</mn><mrow><mi mathvariant="normal">∣</mi><msub><mi>o</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex">\frac{1}{|o_i|}</annotation></semantics></math></span> 没了，两层求和拉平，除数换成整个 group 的总 token 数。每个 token 权重完全相等，都是 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><msub><mo>∑</mo><mi>i</mi></msub><mi mathvariant="normal">∣</mi><msub><mi>o</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">1/\sum_i|o_i|</annotation></semantics></math></span>；一条回答的总权重正比于它的长度。</p>
<p>第三个是 Dr.GRPO：聚合结构与 DAPO 相同（token 拉平），但除数用全局常数（如长度上限），且 advantage 里连 std 也去掉了——Dr.GRPO 那篇展开过，本文只看除数这一项。</p>
<h2 id="dapo-为什么非要换两个罚不到">DAPO 为什么非要换：两个罚不到</h2>
<p>DAPO 论文 §3.3 给的论证很具体，针对长 CoT 场景。sample-mean 下，长样本&quot;对整体损失的贡献不成比例地低&quot;（原文：disproportionately lower contribution），引出两个恶果：</p>
<p>一、<strong>高质量长样本里的推理模式学不到</strong>。一条 5000 token 的正确推理，每个 token 分到的梯度权重是 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><mo stretchy="false">(</mo><mi>G</mi><mo>⋅</mo><mn>5000</mn><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">1/(G\cdot 5000)</annotation></semantics></math></span>，只有 500 token 短样本的十分之一。长样本承载的恰恰是复杂推理，按 sample-mean，越重要的内容单位权重越低。</p>
<p>二、<strong>超长样本里的坏模式罚不掉</strong>。论文报告了一个观察：过长的样本里常出现 gibberish（乱码）和重复词这类低质模式。这些坏 token 的惩罚同样被 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><mi mathvariant="normal">∣</mi><msub><mi>o</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">1/|o_i|</annotation></semantics></math></span> 摊薄——样本越长，每个坏 token 被罚得越轻。结果是&quot;熵和回答长度的不健康上涨&quot;（论文图 4a/4b 的实测曲线）。</p>
<p>换成 token-mean 后，单 token 不论身处长样本还是短样本，权重相同。DAPO 对效果直说不讳：长序列由此&quot;在整体梯度更新中比短序列有更大影响&quot;（原文：longer sequences can have more influence）。这不是副作用，是设计目标——长 CoT 时代，梯度本来就该主要花在长回答上。</p>
<h2 id="一个少有人讲的-tradeoff">一个少有人讲的 tradeoff</h2>
<p>但&quot;长样本拿更多票&quot;这句话值得停下来多看一眼，它有两层含义，DAPO 只讲了第一层。</p>
<p>第一层是 response 级：同一条回答内部，token 不再被长度摊薄。这是 Dr.GRPO 也赞同的方向——Dr.GRPO 批的&quot;response-level length bias&quot;（答对时短者被器重、答错时长者更安全）和 DAPO 批的&quot;坏 token 罚不到&quot;，是同一个 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><mi mathvariant="normal">∣</mi><msub><mi>o</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">1/|o_i|</annotation></semantics></math></span> 的两副面孔，两家开的药殊途同归：per-token 等权。</p>
<p>第二层是 question 级：整个 batch 里，<strong>回答长的题拿走更多总权重</strong>。一道模型的回答平均 6000 token 的题，和一道平均 600 token 的题，在 token-mean 下的 batch 权重差 10 倍；sample-mean 下两者相等。换句话说，token-mean 把长度倾斜从 response 级赶到了 question 级——长题主导梯度。这在长 CoT 场景或许正是想要的（难题、推理重的题往往回答也长），但它是个真实的偏向：题目权重不再均匀，而是正比于该题当前的长度高估。这层 tradeoff 我未在任何论文里见到量化（此点为推断，欢迎打脸）。</p>
<p>还有第二个二阶效应：DAPO 的除数 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mo>∑</mo><mi>i</mi></msub><mi mathvariant="normal">∣</mi><msub><mi>o</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">\sum_i|o_i|</annotation></semantics></math></span> 是<strong>随 batch 变化的随机变量</strong>，Dr.GRPO 的常数除数不是。除数随机的直接后果是梯度尺度随 batch 的长度构成波动；间接后果更有意思——训练后期回答普遍变长，除数变大，每个 token 的有效学习率自动衰减。也就是说 token-mean 自带一个与长度膨胀联动的隐式学习率衰减，而 sample-mean 和常数除数都没有这个性质。这是机制层面的推断，没有论文测过，但它是选聚合方式时真实存在的变量：你选的不只是权重分配，还是梯度尺度的动力学。</p>
<h2 id="两家都说回到-ppo回的不是同一个-ppo">两家都说&quot;回到 PPO&quot;，回的不是同一个 PPO</h2>
<p>一个容易被忽略的史实：PPO 的原始目标函数本来就是 per-token 聚合的（对整个 batch 的 token 求和或求均值，advantage 由 GAE 逐 token 给出）。<strong>GRPO 的 sample-mean 才是那个偏离者</strong>——因为 GRPO 的 advantage 是&quot;一条 response 一个数&quot;，把每条 response 先平均成一个数再平均，语义上最整齐。</p>
<p>然后 DAPO 和 Dr.GRPO 都宣称自己&quot;恢复了 PPO 目标&quot;：DAPO 恢复的是 <strong>PPO 的聚合方式</strong>（token 拉平，但 advantage 保留 z-score，std 还在）；Dr.GRPO 恢复的是 <strong>PPO 的目标函数形式</strong>（常数除数，advantage 退化为 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mo>−</mo><mtext>mean</mtext></mrow><annotation encoding="application/x-tex">r-\text{mean}</annotation></semantics></math></span>，std 去掉）。两个旋钮——聚合粒度、advantage 归一化——是独立的，可以自由组合：verl 等实现里这两项确实是分开配置的（Dr.GRPO 那篇的实现层讨论：trl/verl 的 <code>masked_mean</code> 默认把公式没有的 per-response 平均又加回去了，审计每个除数&quot;是变量还是常数&quot;是成本最低的检查）。这也意味着&quot;GRPO vs DAPO vs Dr.GRPO&quot;不是三个算法排排坐，而是一个 2×2 以上的配置空间，目前已知好的点都还在边界上试出来。</p>
<h2 id="什么时候哪票该大">什么时候哪票该大</h2>
<p>把场景拆开，选择并不玄：</p>
<ul>
<li><strong>短 CoT、长度方差小</strong>：两种聚合近似等价（长度差不多，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><mi mathvariant="normal">∣</mi><msub><mi>o</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">1/|o_i|</annotation></semantics></math></span> 和 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><mo>∑</mo><mi mathvariant="normal">∣</mi><msub><mi>o</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">1/\sum|o_i|</annotation></semantics></math></span> 差一个近似常数），不用纠结；</li>
<li><strong>长 CoT、坏模式藏在长样本里</strong>（重复、乱码、无效啰嗦）：token-mean 关键，否则坏 token 永远罚不到位——这是 DAPO 的核心场景；</li>
<li><strong>想要题目间的均匀权重</strong>（比如题目难度方差很大、担心长题霸榜）：sample-mean 或常数除数更可控；</li>
<li><strong>想要梯度尺度稳定、学习率行为可预测</strong>：常数除数（Dr.GRPO 路线）最干净，token-mean 的随机除数会把长度动力学混进学习率。</li>
</ul>
<p>我的判断：聚合方式之争的本质是&quot;梯度预算按什么单位分&quot;。sample-mean 按条分，隐含假设是每条回答信息量相等——短答案时代成立；token-mean 按 token 分，隐含假设是每个 token 信息量相等——长 CoT 时代更接近真相，但代价是把题间权重交给长度决定。真正缺的论文是把这个预算分配<strong>显式化</strong>的：权重既不按条也不按 token，而是按估计的信息量或不确定性分。在那之前，DAPO 的改法是长 CoT 下最务实的默认。</p>
<h2 id="未决问题">未决问题</h2>
<ul>
<li>token-mean 的 question 级长度倾斜（题间权重 ∝ 长度）对训练终局的影响，没有公开量化；</li>
<li>随机除数带来的隐式学习率衰减，与显式 LR schedule 叠加时的相互作用，没有人测过；</li>
<li>聚合粒度与 advantage 归一化两个旋钮的完整 2×2 消融（sample/token × 有 std/无 std），公开文献里只有对角线上的点。</li>
</ul>
<h2 id="参考来源">参考来源</h2>
<ul>
<li>DAPO 论文：<a href="https://arxiv.org/abs/2503.14476">arXiv:2503.14476</a>
，token-level loss 见 §3.3（公式 12），熵与长度曲线见图 4</li>
<li>Dr.GRPO 论文：<a href="https://arxiv.org/abs/2503.20783">arXiv:2503.20783</a>
，response-level length bias 与 question-level difficulty bias 原文表述</li>
<li>DeepSeekMath / GRPO：<a href="https://arxiv.org/abs/2402.03300">arXiv:2402.03300</a>
，sample-mean 目标函数（公式 3）</li>
<li>前篇（advantage 归一化那一半）：<a href="https://njx-njx.github.io/posts/dr-grpo-length-and-difficulty-bias/">Dr.GRPO 两个归一化项的两种偏差</a>
（其中 token-mean 小节号误写为 §3.2，正确为 §3.3，已顺带更正）</li>
<li>question 级长度倾斜、随机除数的隐式 LR 衰减为本文推断，文中已逐处标注</li>
</ul>
]]></content:encoded>
    </item>
    <item>
      <title>截断的回答该怎么判：DAPO Overlong 在修什么</title>
      <link>https://njx-njx.github.io/posts/dapo-overlong-reward-shaping/</link>
      <pubDate>Sun, 30 Aug 2026 12:05:00 +0800</pubDate>
      <guid>https://njx-njx.github.io/posts/dapo-overlong-reward-shaping/</guid>
      <description>截断的回答默认按答错处理，会把奖励噪声注入 advantage。DAPO 的两个修法：屏蔽截断样本的 loss，或在长度上限前加一段线性惩罚坡。</description>
      <content:encoded><![CDATA[<p>RL 训练必须有生成长度上限，被截断的回答默认按答错处理——这会把“无法判定”的样本错判成“错”样本，把奖励噪声直接注入组内 advantage。DAPO 的两个方案：Overlong Filtering 承认不可判定、屏蔽其 loss；Soft Overlong Punishment 在悬崖前修一段线性缓冲坡，让长度控制变成连续信号。本文拆解机制、公式、配置数值，并把它和 Dr.GRPO、token-mean 拼成完整的长度问题图景。</p>
<blockquote>
<p>本文有配套的<a href="https://njx-njx.github.io/reports/dapo-overlong-reward-shaping/">交互报告</a>
，含可下钻的长度标尺、Equation 13 三段拆解与三种处理方式的对比切换。</p>
</blockquote>
<h2 id="无法回避的一个工程设定">无法回避的一个工程设定</h2>
<p>RL 训练的 rollout 必须有生成长度上限。显存要按最长序列预留，batch 要等最慢的一条写完，一条失控的 response 能拖垮整批吞吐。DAPO 的配置是：预期最大长度 16,384 token，额外保留 4,096 token 的缓冲区间，硬性生成上限为 20,480（论文 §4.1）。</p>
<p>上限一设，就必然有一部分回答被截断。这些样本该怎么办？默认做法很常见：给惩罚性奖励，按答错处理（reward 记 0 或负分）。</p>
<p>DAPO 论文（arXiv:2503.14476）§3.4 指出，这个默认做法会带来问题：<strong>截断样本的错误处理会引入奖励噪声，而且是在组内归一化的放大下注入整个训练过程</strong>。原文的理由很直白：一个推理过程本身合理，仅仅因为写得太长而被惩罚，这种惩罚会让模型困惑——它无法区分推理是否有效。</p>
<h2 id="噪声是怎么进-advantage-的">噪声是怎么进 advantage 的</h2>
<p>GRPO 的 advantage 是组内相对排名：同一道题采 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 条回答，减组内均值（除以 std）。这意味着，<strong>任何一条回答的奖励一旦出错，就会影响整组</strong>。</p>
<p>举一个具体算例：一道题采 8 条回答，真实情况是 4 对 4 错，其中 2 条&quot;错&quot;其实是被截断的优质推理（如果写完很可能对）。</p>
<ul>
<li>按真实质量：组均值 0.5，答对的回答拿到正 advantage，答错的拿到负的；</li>
<li>按截断=0 分：截断样本也被算作错误的回答，组均值被拉低（错的算 6 条，均值 0.25），于是所有答对样本的 advantage 被抬高、所有答错样本的 advantage 被减轻——包括那两条真正答错的。</li>
</ul>
<p>一层扭曲还不够，还有第二层：那两条被截断的优质推理本身，会被作为负样本强化。模型从中学到的不是&quot;要写短一点&quot;，而是&quot;我这种推理方式不对&quot;——这正是论文说的会让模型产生困惑的地方。这两类惩罚混为一谈后，模型会把好的推理方式和&quot;写得长&quot;一起抛弃。</p>
<h2 id="方案一overlong-filtering认为截断样本不可判定屏蔽其-loss">方案一：Overlong Filtering——认为截断样本&quot;不可判定&quot;，屏蔽其 loss</h2>
<p>DAPO 的第一种处理方式是：不把截断样本当作错误样本，而是直接不承认它是样本。Overlong Filtering 把被截断回答的 loss 整体屏蔽——这条样本不参与 advantage 估计，也不产生梯度。</p>
<p>论文 Figure 5 给出的效果：应用 Overlong Reward Shaping 后，AIME 准确率和 actor 模型的熵都更稳定，训练稳定性明显提升。这一点值得注意：熵的稳定意味着截断噪声本身就在干扰探索动力学——并不只影响 reward 的账面数字。</p>
<p>代价同样明显，论文没有展开，我补充两点：</p>
<ol>
<li><strong>算力白费</strong>。一条截断样本的 rollout 成本已经花了（它往往是最长的那条，恰好占用最多算力），屏蔽后一条梯度都没换回来。这与 dynamic sampling 的逻辑相同——都是&quot;用算力换信号质量&quot;，DAPO 全篇都是这个取向；</li>
<li><strong>隐性的幸存者偏差</strong>。什么样的样本更容易被截断？长题、难题、需要长 CoT 的题。系统性地屏蔽截断样本，等于系统性地降低难题在训练分布中的权重。短期内，训练会更稳定，长期代价则是模型可能在最需要长推理的题目上暴露短板。论文没有讨论这个副作用，这是我自己提出的保留意见。</li>
</ol>
<h2 id="方案二soft-overlong-punishment悬崖前修一段缓冲坡">方案二：Soft Overlong Punishment——悬崖前修一段缓冲坡</h2>
<p>完全屏蔽会丢失信息：模型无法学到长度本身很重要。DAPO 的第二种处理方式是 Soft Overlong Punishment，把长度本身变成一个<strong>连续、可判别的奖励维度</strong>（论文 Equation 13）：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>R</mi><mrow><mi>l</mi><mi>e</mi><mi>n</mi><mi>g</mi><mi>t</mi><mi>h</mi></mrow></msub><mo stretchy="false">(</mo><mi>y</mi><mo stretchy="false">)</mo><mo>=</mo><mrow><mo fence="true">{</mo><mtable rowspacing="0.36em" columnalign="left left" columnspacing="1em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mn>0</mn><mo separator="true">,</mo></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mi mathvariant="normal">∣</mi><mi>y</mi><mi mathvariant="normal">∣</mi><mo>≤</mo><msub><mi>L</mi><mrow><mi>m</mi><mi>a</mi><mi>x</mi></mrow></msub><mo>−</mo><msub><mi>L</mi><mrow><mi>c</mi><mi>a</mi><mi>c</mi><mi>h</mi><mi>e</mi></mrow></msub></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mstyle displaystyle="true" scriptlevel="0"><mfrac><mrow><mo stretchy="false">(</mo><msub><mi>L</mi><mrow><mi>m</mi><mi>a</mi><mi>x</mi></mrow></msub><mo>−</mo><msub><mi>L</mi><mrow><mi>c</mi><mi>a</mi><mi>c</mi><mi>h</mi><mi>e</mi></mrow></msub><mo stretchy="false">)</mo><mo>−</mo><mi mathvariant="normal">∣</mi><mi>y</mi><mi mathvariant="normal">∣</mi></mrow><msub><mi>L</mi><mrow><mi>c</mi><mi>a</mi><mi>c</mi><mi>h</mi><mi>e</mi></mrow></msub></mfrac></mstyle><mo separator="true">,</mo></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><msub><mi>L</mi><mrow><mi>m</mi><mi>a</mi><mi>x</mi></mrow></msub><mo>−</mo><msub><mi>L</mi><mrow><mi>c</mi><mi>a</mi><mi>c</mi><mi>h</mi><mi>e</mi></mrow></msub><mo>&lt;</mo><mi mathvariant="normal">∣</mi><mi>y</mi><mi mathvariant="normal">∣</mi><mo>≤</mo><msub><mi>L</mi><mrow><mi>m</mi><mi>a</mi><mi>x</mi></mrow></msub></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mo>−</mo><mn>1</mn><mo separator="true">,</mo></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><msub><mi>L</mi><mrow><mi>m</mi><mi>a</mi><mi>x</mi></mrow></msub><mo>&lt;</mo><mi mathvariant="normal">∣</mi><mi>y</mi><mi mathvariant="normal">∣</mi></mrow></mstyle></mtd></mtr></mtable></mrow></mrow><annotation encoding="application/x-tex">R_{length}(y) = \begin{cases} 0, &amp; |y| \le L_{max} - L_{cache} \\ \dfrac{(L_{max} - L_{cache}) - |y|}{L_{cache}}, &amp; L_{max}-L_{cache} &lt; |y| \le L_{max} \\ -1, &amp; L_{max} &lt; |y| \end{cases}</annotation></semantics></math></span><p>三段分别解释：</p>
<ul>
<li><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∣</mi><mi>y</mi><mi mathvariant="normal">∣</mi><mo>≤</mo><msub><mi>L</mi><mrow><mi>m</mi><mi>a</mi><mi>x</mi></mrow></msub><mo>−</mo><msub><mi>L</mi><mrow><mi>c</mi><mi>a</mi><mi>c</mi><mi>h</mi><mi>e</mi></mrow></msub></mrow><annotation encoding="application/x-tex">|y| \le L_{max}-L_{cache}</annotation></semantics></math></span>（DAPO 配置下即 ≤ 12,288 token）：不惩罚。长度在这个阶段完全是自由的；</li>
<li>进入 cache 区间（12,288 到 16,384）：线性渐变惩罚，从 0 平滑降到 -1。每多写一个 token，惩罚就增加 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><msub><mi>L</mi><mrow><mi>c</mi><mi>a</mi><mi>c</mi><mi>h</mi><mi>e</mi></mrow></msub><mo>=</mo><mn>1</mn><mi mathvariant="normal">/</mi><mn>4096</mn></mrow><annotation encoding="application/x-tex">1/L_{cache} = 1/4096</annotation></semantics></math></span>；</li>
<li>超过 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>L</mi><mrow><mi>m</mi><mi>a</mi><mi>x</mi></mrow></msub></mrow><annotation encoding="application/x-tex">L_{max}</annotation></semantics></math></span>（被截断）：惩罚封顶为 -1。注意这一项会<strong>加到原来的对错奖励上</strong>——答对但写超了，总分照样可能被拉低。</li>
</ul>
<p>这个设计最精妙的地方在于：<strong>悬崖没有被消除，悬崖前修了一段缓冲坡</strong>。超过 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>L</mi><mrow><mi>m</mi><mi>a</mi><mi>x</mi></mrow></msub></mrow><annotation encoding="application/x-tex">L_{max}</annotation></semantics></math></span> 仍然是 -1 的硬惩罚，和 naive 做法一样狠；但模型在到达悬崖前四千 token 就开始收到连续的&quot;快超预算了&quot;的信号，而且信号强度与超预算的程度单调相关。组内归一化之后，&ldquo;12,500 token 差点超&quot;和&quot;16,300 token 即将超&quot;的两条回答会拿到可分辨的 advantage 差，模型能据此学会<strong>提前收尾</strong>，而不是到了上限才知道疼。长度控制从一个二元事件（没超/超了）变成一个连续可学习的任务。</p>
<h2 id="放进长度问题的完整图景">放进&quot;长度问题&quot;的完整图景</h2>
<p>这个系列前几篇讨论的都与长度有关，本文讨论的是最后一个方面：</p>
<ul>
<li><strong><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><mi mathvariant="normal">∣</mi><mi>y</mi><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">1/|y|</annotation></semantics></math></span> 的梯度摊薄</strong>（Dr.GRPO，见<a href="https://njx-njx.github.io/posts/dr-grpo-length-and-difficulty-bias/">归一化偏差那篇</a>
）：错误回答越长，每个 token 受的惩罚越小，模型会倾向于把错误回答写得过长。解决方式：改归一化项；</li>
<li><strong>token-mean</strong>（DAPO §3.3）：样本内先平均再对组求和改成 batch 内所有 token 统一平均，防止长回答在损失中占据过大权重。解决方式：改损失聚合；</li>
<li><strong>Overlong</strong>（DAPO §3.4，本篇）：生成长度上限产生的截断样本，其奖励不可判定。解决方式：屏蔽（filtering）或改奖励函数（soft punishment）。</li>
</ul>
<p>三者处理的是三个不同层级的长度问题：梯度权重、损失聚合、奖励判定。DAPO 同时使用 token-mean 和 overlong shaping，表示它既修梯度侧，也修奖励侧；Dr.GRPO 侧重归一化。它们并不冲突。</p>
<p>还可以看出 DAPO 的一个设计取向：<strong>与其使用不可靠的信号，不如不用</strong>。dynamic sampling 过滤没有梯度信号的 prompt（全对/全错的题），overlong filtering 屏蔽奖励不可靠的样本（截断的回答），Dataset Transformation 把答案统一转成整数以消除解析器噪声（§3.5，DAPO-Math-17K）。四项技术都指向同一个方向：训练崩溃往往不是算法不够好，而是信号中混入了噪声。</p>
<h2 id="我的三个判断">我的三个判断</h2>
<p>一、<strong>截断样本是“不可判定”样本，将其判为错误属于奖励层面上的误判</strong>。RLVR 的前提是奖励可以验证——能判对错才给分。截断样本的 verifier 根本没能执行完判定，它既不是 1 也不是 0。Overlong Filtering 承认这种不可判定性，Soft Punishment 则引入一个新的可判定维度（长度本身）。两种处理方式都符合&quot;奖励必须可验证&quot;的原则，而 naive 的 punitive reward 违反了这个原则。</p>
<p>二、<strong>Overlong 处理后熵更稳定这件事，比表面看上去更重要</strong>。Figure 5(b) 显示 shaping 后 actor 熵的曲线更平稳。这说明，长度上限附近发生的混乱（突然被惩罚的优质长推理、被迫乱收尾的回答）并不仅仅使 reward 失真，还会增加探索噪声。结合 <a href="https://njx-njx.github.io/posts/dapo-clip-higher-entropy-collapse/">Clip-Higher 那篇</a>
（熵坍缩）一起看：熵既会被优化器错误压制而坍缩，也会被奖励噪声干扰而剧烈波动。熵监控必须和奖励判定质量一起分析。</p>
<p>三、<strong>cache 宽度和屏蔽比例是需要监控的两个超参数，目前没有公开依据</strong>。4,096/16,384 = 25% 的缓冲坡长度是怎么定的，论文没有给；训练中截断率（被屏蔽样本占比）随模型长度行为漂移，屏蔽率过高时有效 batch 缩水、难题占比下降，过低则说明长度控制已经失效或上限设得太宽。这两个数字在 DAPO 论文里都没有监控曲线，复现时只能自己补。</p>
<h2 id="未决问题">未决问题</h2>
<ul>
<li>Overlong Filtering 造成的难题权重流失，在长期训练里是否需要配合长度课程（progressive length curriculum）补偿，没有公开实验；</li>
<li>cache 宽度（25%）的选取依据与消融，论文未披露；</li>
<li>Soft Punishment 的 -1 封顶与 Clip-Higher 的不对称裁剪叠加时，长但正确的探索性回答是否会被双重抑制，目前没有数据。</li>
</ul>
<h2 id="参考来源">参考来源</h2>
<ul>
<li>DAPO 论文：<a href="https://arxiv.org/abs/2503.14476">arXiv:2503.14476v2</a>
（§3.4 机制描述、Equation 13、§4.1 配置数值、Figure 5 的出处）</li>
<li>教材 <a href="https://github.com/walkinglabs/hands-on-modern-rl">hands-on-modern-rl</a>
：第 18 章 <a href="https://github.com/walkinglabs/hands-on-modern-rl/blob/main/docs/chapter18_grpo/deepseek-dapo.md"><code>docs/chapter18_grpo/deepseek-dapo.md</code></a>
 与附录 DAPO cheatsheet（<a href="https://github.com/walkinglabs/hands-on-modern-rl/blob/main/docs/en/appendix_code_cheatsheet/dapo.md"><code>docs/en/appendix_code_cheatsheet/dapo.md</code></a>
）</li>
<li>前篇：<a href="https://njx-njx.github.io/posts/dapo-clip-higher-entropy-collapse/">熵是怎么塌掉的：DAPO 的 Clip-Higher 在修什么</a>
、<a href="https://njx-njx.github.io/posts/dr-grpo-length-and-difficulty-bias/">“答错就写长一点”：GRPO 两个归一化项怎么扭曲优化方向</a>
</li>
</ul>
]]></content:encoded>
    </item>
    <item>
      <title>“答错就写长一点”：GRPO 归一化项在扭曲什么</title>
      <link>https://njx-njx.github.io/posts/dr-grpo-length-and-difficulty-bias/</link>
      <pubDate>Sat, 29 Aug 2026 12:05:00 +0800</pubDate>
      <guid>https://njx-njx.github.io/posts/dr-grpo-length-and-difficulty-bias/</guid>
      <description>R1-Zero 的长度与奖励齐涨，可能有一半是优化器的偏好：1/|y| 让答错的回答变长，除以 std 偏向极端难度的题。</description>
      <content:encoded><![CDATA[<p>R1-Zero 的‘长度与奖励齐涨’被当成了推理涌现的标志性曲线，Sea AI Lab 的 Dr.GRPO 论文指出其中一半涨幅可能是优化器自己的偏好：1/|y| 让模型在答错时倾向于写长，除以 std 让极端难度的题拿走更多权重。两个归一化项、两种偏差的机制拆解，外加一个藏在 masked_mean 里的实现层偏差。</p>
<blockquote>
<p>本文有配套的<a href="https://njx-njx.github.io/reports/dr-grpo-length-and-difficulty-bias/">交互报告</a>
，含可下钻的偏差算例、masked_mean 实现对照与整改选型矩阵。</p>
</blockquote>
<h2 id="一条被过度信任的曲线">一条被过度信任的曲线</h2>
<p>R1-Zero 训练里最有名的一张图，是回答长度和训练奖励同步上涨。社区很快给它编好了故事：模型学会了想更久，长 CoT 通过 RL 不断形成。</p>
<p>Sea AI Lab 的 Dr.GRPO 论文（arXiv:2503.20783）提出了一个更简单的疑问：在奖励已停止上涨的平台期，长度为什么仍在继续增加？论文经逐一定位后得出结论：这不是模型学会了更多推理，而是<strong>优化器会持续推动模型生成更长的回答</strong>。动机来自 GRPO 目标函数中的两个归一化项：在正确和错误两种情况下，它们会分别以相反的方式调整模型的优化方向，其中对错误回答的影响指向同一个结果：<strong>答错时，写得越长，越不容易受到惩罚。</strong></p>
<h2 id="偏差一1y按-token-平均会把惩罚变稀">偏差一：1/|y|，按 token 平均会把惩罚变稀</h2>
<p>GRPO 目标函数（论文公式 3）里有一个不显眼的分母：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi mathvariant="script">J</mi><mrow><mi>G</mi><mi>R</mi><mi>P</mi><mi>O</mi></mrow></msub><mo>=</mo><mi mathvariant="double-struck">E</mi><mrow><mo fence="true">[</mo><mfrac><mn>1</mn><mi>G</mi></mfrac><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>G</mi></munderover><mfrac><mn>1</mn><mrow><mi mathvariant="normal">∣</mi><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow></mfrac><munderover><mo>∑</mo><mrow><mi>t</mi><mo>=</mo><mn>1</mn></mrow><mrow><mi mathvariant="normal">∣</mi><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow></munderover><mi>min</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><msub><mi>w</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi></msub><mo separator="true">,</mo><mtext> </mtext><mrow><mi mathvariant="normal">c</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">p</mi></mrow><mo stretchy="false">(</mo><msub><mi>w</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub><mo separator="true">,</mo><mn>1</mn><mo>−</mo><mi>ε</mi><mo separator="true">,</mo><mn>1</mn><mo>+</mo><mi>ε</mi><mo stretchy="false">)</mo><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi></msub><mo fence="true">)</mo></mrow><mo fence="true">]</mo></mrow></mrow><annotation encoding="application/x-tex">\mathcal{J}_{GRPO} = \mathbb{E}\left[\frac{1}{G}\sum_{i=1}^{G} \frac{1}{|y_i|}\sum_{t=1}^{|y_i|}\min\left(w_{i,t}\hat{A}_i,\ \mathrm{clip}(w_{i,t},1-\varepsilon,1+\varepsilon)\hat{A}_i\right)\right]</annotation></semantics></math></span><p><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><mi mathvariant="normal">∣</mi><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">1/|y_i|</annotation></semantics></math></span> 的意思是：一条回答内部，先对所有 token 的梯度项取平均，再把 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 条回答加起来。也就是说，<strong>每个 token 实际拿到的梯度权重是 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi></msub><mi mathvariant="normal">/</mi><mi mathvariant="normal">∣</mi><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">\hat{A}_i/|y_i|</annotation></semantics></math></span></strong>。举个具体算例：同一道题采出两条回答，一条 100 token、一条 1000 token，两条回答 advantage 的绝对值都是 1（方向相反）：</p>
<ul>
<li>答对（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>A</mi><mo>^</mo></mover><mo>=</mo><mo>+</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">\hat{A}=+1</annotation></semantics></math></span>）：短回答每个 token 被强化 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><mn>100</mn><mo>=</mo><mn>0.01</mn></mrow><annotation encoding="application/x-tex">1/100 = 0.01</annotation></semantics></math></span>，长回答每个 token 被强化 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><mn>1000</mn><mo>=</mo><mn>0.001</mn></mrow><annotation encoding="application/x-tex">1/1000 = 0.001</annotation></semantics></math></span>。<strong>正确回答里，越短越被器重</strong>；</li>
<li>答错（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>A</mi><mo>^</mo></mover><mo>=</mo><mo>−</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">\hat{A}=-1</annotation></semantics></math></span>）：短回答每个 token 被惩罚 0.01，长回答每个 token 只被惩罚 0.001。<strong>错误回答里，越长越不受惩罚</strong>——相差十倍。</li>
</ul>
<p>这不是数学错误造成的异常，而是目标函数写进每个更新步骤里的内容：答对必须简洁，答错不妨冗长。训练后期奖励进入平台期后，模型在上半部分的提升空间已经用尽，下半部分仍在推动模型生成更长的回答——尤其是错误回答继续变长。论文 Figure 4 里的 Fig.5 Plot 2 清楚地展示了这一阶段：GRPO 的长度曲线在奖励进入平台期后继续上升。</p>
<h2 id="偏差二除以-std极端难度的题拿走更多权重">偏差二：除以 std，极端难度的题拿走更多权重</h2>
<p>第二个归一化项在 advantage 里：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi></msub><mo>=</mo><mfrac><mrow><msub><mi>R</mi><mi>i</mi></msub><mo>−</mo><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">n</mi></mrow><mo stretchy="false">(</mo><mo stretchy="false">{</mo><msub><mi>R</mi><mi>j</mi></msub><msubsup><mo stretchy="false">}</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>G</mi></msubsup><mo stretchy="false">)</mo></mrow><mrow><mrow><mi mathvariant="normal">s</mi><mi mathvariant="normal">t</mi><mi mathvariant="normal">d</mi></mrow><mo stretchy="false">(</mo><mo stretchy="false">{</mo><msub><mi>R</mi><mi>j</mi></msub><msubsup><mo stretchy="false">}</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>G</mi></msubsup><mo stretchy="false">)</mo></mrow></mfrac></mrow><annotation encoding="application/x-tex">\hat{A}_i = \frac{R_i - \mathrm{mean}(\{R_j\}_{j=1}^G)}{\mathrm{std}(\{R_j\}_{j=1}^G)}</annotation></semantics></math></span><p>除以组内奖励标准差，本意是让 advantage 的量纲统一（这是 RL 的常规 trick）。但论文指出一个关键差异：经典 RL 的 advantage normalization 是在<strong>整个 batch</strong>上算 std，所有样本共享一个除数；GRPO 是<strong>每道题单独算 std</strong>，每道题有自己的除数——除数不同，权重就不同。</p>
<p>再算一笔具体算例：题 1 采 8 条全对（std≈0.35，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>A</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">\hat{A}</annotation></semantics></math></span>≈+2.9 按 z-score 的尺度），题 2 采 8 条四对四错（std≈0.52，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>A</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">\hat{A}</annotation></semantics></math></span>≈±1.9）。越极端的题目——全对的送分题、全错的死题——std 越小，除完之后的权重越大。模型会把最多的更新预算花在已经全对的题（容易做题）和完全不会的题（一次都答对不了）上，而“部分对部分错、正好处于学习价值区间”的题目权重最小。这就是论文说的<strong>难度偏差（difficulty bias）</strong>。</p>
<p>需要说明边界：std 归一化并不是只有坏处，它在小方差场景下放大信号的设计初衷是让模型也能从全对的题里学到东西。论文的批评在于<strong>逐题归一化</strong>造成的权重不等，不是归一化本身。</p>
<h2 id="偏差三藏在实现里不在公式里">偏差三：藏在实现里，不在公式里</h2>
<p>第三个发现对工程师可能更有冲击力。PPO 的目标公式（论文公式 2）是对 response 的 token <strong>求和</strong>，没有除以长度的步骤。但论文检查了主流开源实现，发现 trl、verl 等框架的 loss 里都有一句 <code>masked_mean</code>：用 response 的实际 token 数当除数算平均（<code>loss.sum(dim) / mask.sum(dim)</code>）。也就是说，<strong>公式里没有长度偏差，实现却把它加上了</strong>。</p>
<p>为什么会出现这种情况？论文的推测源于历史实践：预训练阶段所有数据打包成定长 context，<code>loss.mean(-1)</code> 按 context 长度平均既方便数值又稳定，这是常数除法，没有引入偏差；这套写法延伸到 RL 阶段后，除数悄悄从“定长 context”变成了“每条回答的实际长度”——从常数变变量，效果也随之改变。Dr.GRPO 在实现上的修正只改一行：把 <code>masked_mean</code> 的除数换成全局常数（如生成长度上限 MAX_TOKENS）。</p>
<p>公式作者和框架作者可能做的是同一套测试，却得到两套梯度。这类“公式与实现不一致”的问题，比论文层面的偏差更隐蔽：读十遍论文都发现不了，只有读代码才看见。</p>
<h2 id="drgrpo-的修正与依据">Dr.GRPO 的修正与依据</h2>
<p>修正方法很简单：把 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><mi mathvariant="normal">∣</mi><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">1/|y_i|</annotation></semantics></math></span> 和 std 两项归一化都去掉，advantage 只减组内均值：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mover accent="true"><mi>A</mi><mo>~</mo></mover><mi>i</mi></msub><mo>=</mo><msub><mi>R</mi><mi>i</mi></msub><mo>−</mo><mrow><mi mathvariant="normal">m</mi><mi mathvariant="normal">e</mi><mi mathvariant="normal">a</mi><mi mathvariant="normal">n</mi></mrow><mo stretchy="false">(</mo><mo stretchy="false">{</mo><msub><mi>R</mi><mi>j</mi></msub><msubsup><mo stretchy="false">}</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>G</mi></msubsup><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\tilde{A}_i = R_i - \mathrm{mean}(\{R_j\}_{j=1}^G)</annotation></semantics></math></span><p>论文 Appendix A 给出三点理论依据：去掉两项后目标函数<strong>恢复为 PPO 目标（公式 2）</strong>，advantage 就是无 baseline 的 Monte Carlo return 加无偏 baseline；<strong>减均值不引入偏差</strong>——baseline 对梯度的期望贡献恒等于零，这是策略梯度里的标准结论；修正后的 advantage 和 RLOO（Leave-One-Out）只差一个常数因子 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mi mathvariant="normal">/</mi><mo stretchy="false">(</mo><mi>G</mi><mo>−</mo><mn>1</mn><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">G/(G-1)</annotation></semantics></math></span>，这个因子可以纳入学习率，不影响训练动力学。</p>
<p>实验在 Oat 框架、Qwen2.5-1.5B 上做对照。结果分三层：</p>
<ul>
<li><strong>训练动力学</strong>：GRPO 和 Dr.GRPO 前期都出现 R1-Zero 式的奖励、长度一起上涨，但 GRPO 在奖励平台期后长度继续攀爬，Dr.GRPO 的长度稳定下来（Fig.5 Plot 1&amp;2）；</li>
<li><strong>行为层面</strong>：Dr.GRPO 在 benchmark 上错误回答的长度显著缩短——这次改动同时缓解了过度思考（Fig.5 Plot 4）；</li>
<li><strong>可复现性</strong>：Llama-3.2-3B 数学预训练后同样出现 GRPO 的长度与奖励一起上涨，Dr.GRPO 同样能抑制长度的持续增长（Fig.7）。这套方法还能让 7B 的 Qwen2.5-Math-7B 使用 MATH level 3–5，在 8 张 A100 上训练 27 小时，AIME 2024 达到 43.3%——这是当年 7B 的 SOTA，整套方法极其简单。</li>
</ul>
<h2 id="一次教材勘误以及和前几篇的分工">一次教材勘误，以及和前几篇的分工</h2>
<p>教材 <a href="https://github.com/walkinglabs/hands-on-modern-rl">hands-on-modern-rl</a>
 的 16.4 节也讲到了这组偏差，但表述值得修正：它把“std 趋近于零时优势被放大”标成了“长度偏差”，并把长度膨胀归因于“除以 std 鼓励模型增加组内方差”。对照论文原文，这个说法有两层错位：std 造成的是<strong>难度偏差</strong>（不同题之间的权重不等），不是长度偏差；而长度偏差的直接来源是 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><mi mathvariant="normal">∣</mi><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">1/|y_i|</annotation></semantics></math></span>，与 std 无关，作用在回答内部每个 token 的权重上。两项归一化、两种偏差各自独立存在——勘误的价值在于，整改方案的选择依赖这个区分：去掉 std 解决不了长度问题。</p>
<p>这个系列已发的几篇文章，恰好分别从三个层面回应了这件事：</p>
<ul>
<li><strong>DAPO 的 token-mean</strong>（§3.3）：把“样本内先平均再对 G 条求平均”改成“batch 内所有 token 统一按总 token 数平均”，也就是 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>1</mn><mrow><msub><mo>∑</mo><mi>i</mi></msub><mi mathvariant="normal">∣</mi><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow></mfrac><msub><mo>∑</mo><mi>i</mi></msub><msub><mo>∑</mo><mi>t</mi></msub></mrow><annotation encoding="application/x-tex">\frac{1}{\sum_i|y_i|}\sum_i\sum_t</annotation></semantics></math></span>。同时所有 token 都按 token 总数加权，从形式上消除长度偏差——但 DAPO 的 advantage 保留 z-score（含 std），<strong>只解决了一半</strong>；</li>
<li><strong>GSPO</strong>：在序列级使用一个比率，且不再在目标函数里逐项对 token 求和，因此并不存在“每个 token 除以 |y|”这一平均操作——它从结构上绕开了这一偏差；</li>
<li><strong>Dr.GRPO</strong>（本篇）：不改目标函数结构，只从归一化项中去掉两个变量除数。</li>
</ul>
<h2 id="我的三个判断">我的三个判断</h2>
<p>一、<strong>RL 训练曲线必须先排除优化器引入的虚假信号</strong>。当“长度持续上涨”同时被学术界引用为“RL 生效”的现象级证据，又被工程队引用为“要干预”的异常指标时，追根溯源就格外重要。论文同时观察到，使用 template 的 Qwen2.5-Math 模型在 RL 前的能力会先被 template 破坏，再被 RL 重建（§3.3）——这是另一类需要排除的因素：一部分“RL 增益”其实就是原本就存在的能力。分析 RL 曲线前，先逐项排除优化器引入的偏差和评估口径造成的假象。</p>
<p>二、<strong>Dr.GRPO 和 dynamic sampling 解决的是不同问题，不构成替代关系</strong>。去掉 std 归一化修正的是权重<strong>失真</strong>（不该被放大的样本得到了过大的权重）；DAPO 的 dynamic sampling（std=0 的题直接丢弃重采）处理的是<strong>没有梯度信号</strong>（全对/全错/全零时，减均值后 advantage 照样是 0，什么也没学到）。注意，去掉 std 后，零信号的题还是零信号——Dr.GRPO 没有为这类题带来任何梯度。两者一个保证样本内的相对权重正确，一个保证样本整体有可学习的信号，实际训练系统里需要同时配置。</p>
<p>三、<strong>检查归一化，先查“除的是变量还是常数”</strong>。这次的三项偏差有一个共同模式：表面上是常规操作的归一化，仔细检查后会发现，用作分母的并不是常数——<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><mi mathvariant="normal">∣</mi><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">1/|y_i|</annotation></semantics></math></span> 的除数是每条回答的长度，std 的除数是每道题的组内波动，<code>masked_mean</code> 的除数是当前 batch 的掩码和。查训练代码里的每个 mean/divide，问一句“这个除数会不会随样本变化”，是成本最低的审美审计。</p>
<h2 id="未决问题">未决问题</h2>
<ul>
<li>Dr.GRPO 去掉 std 后，“极端难度题目”的权重变化对超长训练（数万步）的影响，论文的 1.5B/7B 实验时间窗口较短；</li>
<li>token-mean（DAPO）与去掉变量除数（Dr.GRPO）在同一训练栈叠加时的有效学习率换算，缺少公开的统一口径；</li>
<li>对“预训练打包阶段的 <code>loss.mean(-1)</code> 习惯还有多少残留在 RL 框架”的系统性检查，目前只有论文对 trl/verl 的抽查。</li>
</ul>
<h2 id="参考来源">参考来源</h2>
<ul>
<li>Sea AI Lab / NUS：<a href="https://arxiv.org/abs/2503.20783">Understanding R1-Zero-Like Training: A Critical Perspective</a>
（本文公式、实验与偏差定义的出处；v2）</li>
<li>教材 <a href="https://github.com/walkinglabs/hands-on-modern-rl">hands-on-modern-rl</a>
：第 16.4 节（采用勘误后的表述）与附录 DAPO cheatsheet（<a href="https://github.com/walkinglabs/hands-on-modern-rl/blob/main/docs/en/appendix_code_cheatsheet/dapo.md"><code>docs/en/appendix_code_cheatsheet/dapo.md</code></a>
，DAPO 的 z-score advantage 与 token-mean 损失粒度对照）</li>
<li>RLOO 参照：<a href="https://arxiv.org/abs/2402.14740">Back to Basics: Revisiting REINFORCE Style Optimization</a>
</li>
<li>前篇：<a href="https://njx-njx.github.io/posts/dapo-clip-higher-entropy-collapse/">熵是怎么塌掉的：DAPO 的 Clip-Higher 在修什么</a>
、<a href="https://njx-njx.github.io/posts/gspo-sequence-level-importance-sampling/">比率用错了单位：GSPO 把重要性采样提到序列级</a>
、<a href="https://njx-njx.github.io/posts/tis-train-inference-mismatch/">同一个模型，两个概率：训练推理不一致的代价</a>
</li>
</ul>
]]></content:encoded>
    </item>
    <item>
      <title>一道题采几条回答：GRPO 组大小 G 买来了什么</title>
      <link>https://njx-njx.github.io/posts/grpo-group-size-tradeoffs/</link>
      <pubDate>Sat, 29 Aug 2026 12:00:00 +0800</pubDate>
      <guid>https://njx-njx.github.io/posts/grpo-group-size-tradeoffs/</guid>
      <description>每题采 64、8 还是 2 条回答？G 是 GRPO 唯一的 baseline 来源和最大的算力开关，它到底买来了什么？</description>
      <content:encoded><![CDATA[<p>DeepSeekMath 每题采 64 条回答，教学实现默认 8 条，最新论文 2 条也声称够用——同一个旋钮差出 32 倍。G 是 GRPO 唯一的 baseline 来源和最大的算力开关，它到底买来了什么？本文拆解 G 的三重身份：控制变量的样本数、有效梯度组的覆盖率、std 归一化的分母质量，以及动态采样为什么能用过滤代替加大 G。</p>
<blockquote>
<p>本文有配套的<a href="https://njx-njx.github.io/reports/grpo-group-size-tradeoffs/">交互报告</a>
，含零梯度组概率计算器、baseline 双曲线与三家取值对照。</p>
</blockquote>
<h2 id="一个差出-32-倍的旋钮">一个差出 32 倍的旋钮</h2>
<p>GRPO 每训练一步，要为每个 prompt 采样一组 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 条回答。这个 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 取多少，各家的答案差得离谱：</p>
<ul>
<li>DeepSeekMath（GRPO 原始论文，arXiv:2402.03300 §4.2）：<strong>64</strong> 条。batch size 1024，意味着一步只覆盖 16 个 prompt；</li>
<li>RLHF Book 配套教学代码（<code>code/policy_gradients/configs/</code>）：<strong>8</strong> 条，从 GRPO 到 GSPO、CISPO 全系默认；</li>
<li>2025 年 10 月的论文 &ldquo;It Takes Two: Your GRPO Is Secretly DPO&rdquo;（arXiv:2510.00977）：<strong>2</strong> 条就够，并专门论证&quot;大组必要论&quot;是对 GRPO 成功原因的误读。</li>
</ul>
<p>32 倍的差距。更麻烦的是，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 同时是两种东西：它是 GRPO 唯一的 baseline 来源（没有 critic，组内均值就是 baseline），也是训练成本最大的乘法器（rollout 是 RL 训练的主要算力开销，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 翻倍增殖成本就翻倍）。一个旋钮同时管信号质量和算力账单，取值却从 2 到 64 都有人能跑通——说明&quot;<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 到底买来了什么&quot;这个问题本身值得拆开。</p>
<h2 id="第一重身份baseline-的样本数">第一重身份：baseline 的样本数</h2>
<p>GRPO 扔掉 critic 之后，用组内均值当 baseline：<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi></msub><mo>=</mo><msub><mi>r</mi><mi>i</mi></msub><mo>−</mo><mtext>mean</mtext><mo stretchy="false">(</mo><mo stretchy="false">{</mo><msub><mi>r</mi><mi>j</mi></msub><msubsup><mo stretchy="false">}</mo><mrow><mi>j</mi><mo>=</mo><mn>1</mn></mrow><mi>G</mi></msubsup><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\hat{A}_i = r_i - \text{mean}(\{r_j\}_{j=1}^G)</annotation></semantics></math></span>（先不看除以 std 的那一步）。用 baseline 减均值是策略梯度降方差的标准手段，教科书（RLHF Book 第 6 章）给出的合法性条件是：baseline 必须与当前动作无关，因为 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi mathvariant="double-struck">E</mi><mrow><mi>a</mi><mo>∼</mo><mi>π</mi></mrow></msub><mo stretchy="false">[</mo><mi>b</mi><mo stretchy="false">(</mo><mi>s</mi><mo stretchy="false">)</mo><msub><mi mathvariant="normal">∇</mi><mi>θ</mi></msub><mi>log</mi><mo>⁡</mo><msub><mi>π</mi><mi>θ</mi></msub><mo stretchy="false">(</mo><mi>a</mi><mi mathvariant="normal">∣</mi><mi>s</mi><mo stretchy="false">)</mo><mo stretchy="false">]</mo><mo>=</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">\mathbb{E}_{a\sim\pi}[b(s)\nabla_\theta\log\pi_\theta(a|s)] = 0</annotation></semantics></math></span> 对任何只依赖状态的 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>b</mi><mo stretchy="false">(</mo><mi>s</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">b(s)</annotation></semantics></math></span> 成立——baseline 不改变梯度的期望，只压方差。</p>
<p>这里有个很少有人提的细节：<strong>GRPO 的均值把被评估的那条回答自己也算进去了</strong>，严格说 baseline 与动作相关，无偏条件并不严格满足。对照 RLOO（REINFORCE Leave-One-Out，rlhf-book 同一章）：它的 baseline 是<strong>其余</strong> <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>K</mi><mo>−</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">K-1</annotation></semantics></math></span> 条回答的均值，特意把自己剔除，&ldquo;保持梯度估计器完全无偏&rdquo;。两种 advantage 的关系可以直接写出来：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msubsup><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi><mtext>RLOO</mtext></msubsup><mo>=</mo><msub><mi>r</mi><mi>i</mi></msub><mo>−</mo><mfrac><mn>1</mn><mrow><mi>G</mi><mo>−</mo><mn>1</mn></mrow></mfrac><munder><mo>∑</mo><mrow><mi>j</mi><mo mathvariant="normal">≠</mo><mi>i</mi></mrow></munder><msub><mi>r</mi><mi>j</mi></msub><mo>=</mo><mfrac><mi>G</mi><mrow><mi>G</mi><mo>−</mo><mn>1</mn></mrow></mfrac><mrow><mo fence="true">(</mo><msub><mi>r</mi><mi>i</mi></msub><mo>−</mo><mfrac><mn>1</mn><mi>G</mi></mfrac><munder><mo>∑</mo><mi>j</mi></munder><msub><mi>r</mi><mi>j</mi></msub><mo fence="true">)</mo></mrow><mo>=</mo><mfrac><mi>G</mi><mrow><mi>G</mi><mo>−</mo><mn>1</mn></mrow></mfrac><msubsup><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi><mtext>GRPO(去 std)</mtext></msubsup></mrow><annotation encoding="application/x-tex">\hat{A}_i^{\text{RLOO}} = r_i - \frac{1}{G-1}\sum_{j\neq i}r_j = \frac{G}{G-1}\left(r_i - \frac{1}{G}\sum_{j}r_j\right) = \frac{G}{G-1}\hat{A}_i^{\text{GRPO(去 std)}}</annotation></semantics></math></span><p>方向完全一致，只差一个 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mi mathvariant="normal">/</mi><mo stretchy="false">(</mo><mi>G</mi><mo>−</mo><mn>1</mn><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">G/(G-1)</annotation></semantics></math></span> 的尺度因子。<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mo>=</mo><mn>64</mn></mrow><annotation encoding="application/x-tex">G=64</annotation></semantics></math></span> 时这个因子是 1.016，无所谓；<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mo>=</mo><mn>8</mn></mrow><annotation encoding="application/x-tex">G=8</annotation></semantics></math></span> 时是 1.14；<strong><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mo>=</mo><mn>2</mn></mrow><annotation encoding="application/x-tex">G=2</annotation></semantics></math></span> 时是 2</strong>——GRPO 形式的 advantage 只有留一形式的一半。这个偏差不是方向性的，只是一个随 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 缩小的缩放，实际效果可以被学习率吸收（这是推断，不是哪篇论文的实验结论），但它解释了为什么小 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 的所有性质都会被放大。</p>
<p>第二笔账是 baseline 的估计噪声。组均值是真实期望值 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="double-struck">E</mi><mo stretchy="false">[</mo><mi>r</mi><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">\mathbb{E}[r]</annotation></semantics></math></span> 的 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 样本估计，噪声幅度约 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>σ</mi><mi>r</mi></msub><mi mathvariant="normal">/</mi><msqrt><mi>G</mi></msqrt></mrow><annotation encoding="application/x-tex">\sigma_r/\sqrt{G}</annotation></semantics></math></span>（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>σ</mi><mi>r</mi></msub></mrow><annotation encoding="application/x-tex">\sigma_r</annotation></semantics></math></span> 是单条回答奖励的标准差）。<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 小，这个噪声就直接混进每条回答的 advantage 里：答对的题可能因为&quot;同组碰巧都很强&quot;而拿到负 advantage。梯度方向被 baseline 噪声随机翻转的概率随 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 减小而上升——这是&quot;大 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 降方差&quot;的标准论点，也是 2510.00977 要挑战的对象，后面再说。</p>
<h2 id="第二重身份有效梯度组的覆盖率">第二重身份：有效梯度组的覆盖率</h2>
<p>RLVR 的奖励是二值的（对或错；DAPO 用 +1/−1，DeepSeekMath 用 1/0，等价）。如果一组 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 条回答全对或全错，组内奖励没有方差，advantage 全是零——这 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 条 rollout 白跑了，不给任何梯度。</p>
<p>一组全同的概率可以直接算（以下为推算）：设模型在这道题上的单次正确率为 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi></mrow><annotation encoding="application/x-tex">p</annotation></semantics></math></span>，各条独立，则</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mtext>零梯度组</mtext><mo stretchy="false">)</mo><mo>=</mo><msup><mi>p</mi><mi>G</mi></msup><mo>+</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>p</mi><msup><mo stretchy="false">)</mo><mi>G</mi></msup></mrow><annotation encoding="application/x-tex">P(\text{零梯度组}) = p^G + (1-p)^G</annotation></semantics></math></span><p>代入数值看趋势（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi></mrow><annotation encoding="application/x-tex">p</annotation></semantics></math></span> 为单次正确率，表中为该组零梯度的概率）：</p>
<table>
  <thead>
      <tr>
          <th><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi></mrow><annotation encoding="application/x-tex">p</annotation></semantics></math></span></th>
          <th><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mo>=</mo><mn>8</mn></mrow><annotation encoding="application/x-tex">G=8</annotation></semantics></math></span></th>
          <th><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mo>=</mo><mn>64</mn></mrow><annotation encoding="application/x-tex">G=64</annotation></semantics></math></span></th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>0.5</td>
          <td>0.8%</td>
          <td>≈0</td>
      </tr>
      <tr>
          <td>0.8</td>
          <td>16.8%</td>
          <td>≈0</td>
      </tr>
      <tr>
          <td>0.9</td>
          <td>43.0%</td>
          <td>0.1%</td>
      </tr>
      <tr>
          <td>0.95</td>
          <td>66.3%</td>
          <td>3.8%</td>
      </tr>
      <tr>
          <td>0.99</td>
          <td>92.3%</td>
          <td>52.6%</td>
      </tr>
  </tbody>
</table>
<p>读法：中等难度的题（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi></mrow><annotation encoding="application/x-tex">p</annotation></semantics></math></span> 在 0.3–0.7），小 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 也基本有保证；真正吃 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 的是<strong>边界难度的题</strong>——<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo>=</mo><mn>0.95</mn></mrow><annotation encoding="application/x-tex">p=0.95</annotation></semantics></math></span> 时 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mo>=</mo><mn>8</mn></mrow><annotation encoding="application/x-tex">G=8</annotation></semantics></math></span> 有三分之二的组是全对零梯度，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mo>=</mo><mn>64</mn></mrow><annotation encoding="application/x-tex">G=64</annotation></semantics></math></span> 才压到 4%。而训练曲线恰恰会推着题目往边界滑：学会的题 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo>→</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">p \to 1</annotation></semantics></math></span>，学不会的题 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo>→</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">p \to 0</annotation></semantics></math></span>，越到训练后期，处于&quot;有梯度区间&quot;的题越少。这就是 DAPO 论文在 motivation 里写&quot;training efficiency and stability&quot;问题的来源之一。</p>
<p>面对同一张表，有两种解法。一种是把 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 加大，硬压 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>p</mi><mi>G</mi></msup></mrow><annotation encoding="application/x-tex">p^G</annotation></semantics></math></span>——成本按乘法涨。另一种是 DAPO 的 <strong>Dynamic Sampling</strong>：不加大 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span>，而是直接规定零梯度组不要。DAPO 的目标函数里有一条硬约束（论文公式 8 的 s.t. 条件）：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mn>0</mn><mo>&lt;</mo><mrow><mo fence="true">∣</mo><mo stretchy="false">{</mo><msub><mi>o</mi><mi>i</mi></msub><mo>∣</mo><mtext mathvariant="monospace">is_equivalent</mtext><mo stretchy="false">(</mo><mi>a</mi><mo separator="true">,</mo><msub><mi>o</mi><mi>i</mi></msub><mo stretchy="false">)</mo><mo stretchy="false">}</mo><mo fence="true">∣</mo></mrow><mo>&lt;</mo><mi>G</mi></mrow><annotation encoding="application/x-tex">0 &lt; \left|\{o_i \mid \texttt{is\_equivalent}(a, o_i)\}\right| &lt; G</annotation></semantics></math></span><p>即组内正确回答数必须严格介于 0 和 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 之间——全对全错的组被过滤掉，过采样补齐，保证 batch 里每个 prompt 都有有效梯度。同样的有效组覆盖率，过滤的代价是加法式过采样，而不是把 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 乘上去。</p>
<p>但过滤和 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 之间还有一层耦合容易被漏掉：<strong>过滤的判定依据本身就是 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 个样本的估计</strong>。<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mo>=</mo><mn>4</mn></mrow><annotation encoding="application/x-tex">G=4</annotation></semantics></math></span> 时&quot;4 条全错&quot;不等于这道题模型不会——<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo>=</mo><mn>0.3</mn></mrow><annotation encoding="application/x-tex">p=0.3</annotation></semantics></math></span> 的题有 24% 的概率 4 条全错，被误扔进垃圾堆。小 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 配动态采样，会把一批&quot;其实有梯度价值&quot;的中等题误判成废组；误判率随 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 指数下降（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>p</mi><msup><mo stretchy="false">)</mo><mi>G</mi></msup></mrow><annotation encoding="application/x-tex"> (1-p)^G </annotation></semantics></math></span>，同一张表）。所以动态采样并没有消灭 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 的覆盖率问题，只是把它从&quot;零梯度&quot;换成了&quot;误判丢弃&quot;（此点为推断，DAPO 论文没有讨论误判率）。</p>
<h2 id="第三重身份std-归一化的分母质量">第三重身份：std 归一化的分母质量</h2>
<p>GRPO 的 advantage 还要除以组内 std：<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi></msub><mo>=</mo><mo stretchy="false">(</mo><msub><mi>r</mi><mi>i</mi></msub><mo>−</mo><mtext>mean</mtext><mo stretchy="false">)</mo><mi mathvariant="normal">/</mi><mtext>std</mtext></mrow><annotation encoding="application/x-tex">\hat{A}_i = (r_i - \text{mean})/\text{std}</annotation></semantics></math></span>。这个 std 同样是 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 个样本的估计，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 小时噪声很大；全同组 std 直接是 0，实现上要么加 eps 要么跳过（埋下除零的坑）。</p>
<p>Dr.GRPO（见<a href="https://njx-njx.github.io/posts/dr-grpo-length-and-difficulty-bias/">专门的一篇</a>
）对 std 的批评——全对全错组 std 趋零时 advantage 被放大到不合理量级——在小 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 时最严重：<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 小，std 落在小值的概率高，极端 advantage 出现得频繁。极端 advantage 又会推高 ratio 的移动幅度，间接抬高 clip 触发率（此链条为推断：<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>A</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">\hat{A}</annotation></semantics></math></span> 异常大 → 单步内 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>π</mi><mi>θ</mi></msub></mrow><annotation encoding="application/x-tex">\pi_\theta</annotation></semantics></math></span> 移动多 → <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>w</mi><mi>t</mi></msub></mrow><annotation encoding="application/x-tex">w_t</annotation></semantics></math></span> 更快碰到裁剪边界）。也就是说，&ldquo;大 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 稳定训练&quot;的说法有一部分其实不是 baseline 的事，是 std 的事——这两笔账在文献里经常被混在一起。</p>
<p>另外值得知道的一个理论结果（arXiv:2502.18548，&ldquo;What is the Alignment Objective of GRPO?&quot;）：作者给出了刻画 GRPO 稳态策略的框架，指出 GRPO 的偏好聚合方式与 RLHF 标准的对数池化有本质差异——<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 影响的不只是估计的方差，还涉及归一化目标本身的不动点。这篇是分析性工作，结论的适用边界（稳态、无穷步）与工程实践有距离，但它提醒一点：把 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 纯粹当成&quot;采样预算&quot;来理解是不完整的。</p>
<h2 id="对冲观点2-条回答也够">对冲观点：2 条回答也够？</h2>
<p>2510.00977 的论点值得正面复述：GRPO 的有效性来自<strong>隐式对比目标</strong>——两条回答一对比就有学习信号，组均值只是 control variate 降方差的工具，不需要精确的统计估计，所以 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mo>=</mo><mn>2</mn></mrow><annotation encoding="application/x-tex">G=2</annotation></semantics></math></span> 的 2-GRPO 也能工作，结构上反而和 DPO 接上了。他们的理论分析和实验（中小规模）都支持这个结论。</p>
<p>这和 DeepSeekMath 的 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mo>=</mo><mn>64</mn></mrow><annotation encoding="application/x-tex">G=64</annotation></semantics></math></span> 矛盾吗？未必。大 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 买来的东西里，baseline 精度只是其中一项，而且可能是最不重要的一项。其余几项：边界难度题的覆盖率（第二重身份）、过滤判定的可靠性（动态采样的配套）、以及探索覆盖——组内至少要有一条答对的题，模型才有&quot;好样本&quot;可学，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo>=</mo><mn>0.1</mn></mrow><annotation encoding="application/x-tex">p=0.1</annotation></semantics></math></span> 的硬题在 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mo>=</mo><mn>2</mn></mrow><annotation encoding="application/x-tex">G=2</annotation></semantics></math></span> 时有 81% 的概率组内无正样本，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mo>=</mo><mn>64</mn></mrow><annotation encoding="application/x-tex">G=64</annotation></semantics></math></span> 时只有 0.1%。这些收益与模型规模、任务难度分布强相关：小模型刷 GSM8K 级别的题，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi></mrow><annotation encoding="application/x-tex">p</annotation></semantics></math></span> 分布集中在中段，小 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 损失有限；大模型攻 AIME 级别的题，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi></mrow><annotation encoding="application/x-tex">p</annotation></semantics></math></span> 压在 0.1 附近，每一条正样本都珍贵，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 就是探索预算本身。2-GRPO 的结论能不能延伸到大模型长 CoT 场景，目前没有人能回答（其论文实验规模有限，这是边界，不是批评）。</p>
<h2 id="成本账以及我的判断">成本账，以及我的判断</h2>
<p>先把账摆明：训练一步的 rollout 量 = prompt 数 × <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span>。DeepSeekMath 的配置（batch 1024、<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mo>=</mo><mn>64</mn></mrow><annotation encoding="application/x-tex">G=64</annotation></semantics></math></span>）一步只过 16 个 prompt——prompt 多样性和回答多样性是在同一张预算表上换的。还有一个配置细节值得注意：DeepSeekMath 每个 exploration 阶段只做<strong>一次</strong>策略更新（严格 on-policy，§4.2），此时 ratio 恒为 1、clip 从不触发，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 的全部作用都体现在 baseline 和覆盖率上；而 DAPO/GSPO 式的多 mini-batch 更新里，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 还通过 std 噪声间接影响 clip 触发率。同一个 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span>，在两种训练形态里的边际收益不是一回事。</p>
<p>我的判断：<strong><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 没有普适最优，因为它同时在三张预算表上花钱</strong>——baseline 精度（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>σ</mi><mi>r</mi></msub><mi mathvariant="normal">/</mi><msqrt><mi>G</mi></msqrt></mrow><annotation encoding="application/x-tex">\sigma_r/\sqrt{G}</annotation></semantics></math></span>，收益边际递减最快）、有效组覆盖（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>p</mi><mi>G</mi></msup></mrow><annotation encoding="application/x-tex">p^G</annotation></semantics></math></span>，在边界难度上收益最持久）、探索预算（组内含正样本的概率，硬题上几乎是线性的）。实践默认值（8–16）是在&quot;中等难度分布 + 动态采样兜底&quot;下的平衡点；64 是 DeepSeekMath 时代没有动态采样、没有 clip 改造时的朴素选择；2 是&quot;对比目标&quot;视角下的理论极限值，工程上还没人敢在生产规模用。选 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 之前先问自己三张表里哪张是瓶颈：题太难（探索预算紧）就加大 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 或上动态采样，题太杂（prompt 多样性紧）就把预算让给 prompt 数，训练不稳先查 std 和 clip 触发率，别急着加 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span>。</p>
<p>这个系列的前四篇正好连成一条线：Clip-Higher 修 token 级裁剪边界，GSPO 换比率单位，TIS 堵训推数值缝，本篇回到信号的源头——采样预算怎么分。GRPO 的每个&quot;显然如此&quot;的默认配置，拆开来都有一笔自己的账。</p>
<h2 id="未决问题">未决问题</h2>
<ul>
<li><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 与学习率、clip <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ε</mi></mrow><annotation encoding="application/x-tex">\varepsilon</annotation></semantics></math></span> 的最优耦合没有公开的系统消融；小 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> + 大学习率能否等价于大 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi></mrow><annotation encoding="application/x-tex">G</annotation></semantics></math></span> 的信噪比，只有零散的民间经验；</li>
<li>动态采样在中等难度题上的&quot;误判丢弃&quot;率（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>p</mi><msup><mo stretchy="false">)</mo><mi>G</mi></msup></mrow><annotation encoding="application/x-tex">(1-p)^G</annotation></semantics></math></span>）对数据效率的实际影响，没有论文量化过；</li>
<li>2-GRPO 在大模型、长 CoT、边界难度任务上是否成立，是目前最值得做的公开复现之一。</li>
</ul>
<h2 id="参考来源">参考来源</h2>
<ul>
<li>DeepSeekMath / GRPO 原始论文：<a href="https://arxiv.org/abs/2402.03300">arXiv:2402.03300</a>
，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>G</mi><mo>=</mo><mn>64</mn></mrow><annotation encoding="application/x-tex">G=64</annotation></semantics></math></span>、batch 1024、单步 on-policy 更新见 §4.2</li>
<li>DAPO 论文：<a href="https://arxiv.org/abs/2503.14476">arXiv:2503.14476</a>
，Dynamic Sampling 约束见公式 8，奖励 ±1 见公式 7</li>
<li>It Takes Two: Your GRPO Is Secretly DPO：<a href="https://arxiv.org/abs/2510.00977">arXiv:2510.00977</a>
</li>
<li>What is the Alignment Objective of GRPO?：<a href="https://arxiv.org/abs/2502.18548">arXiv:2502.18548</a>
</li>
<li>RLHF Book 第 6 章（baseline 无偏条件、RLOO 留一公式）：<a href="https://github.com/natolambert/rlhf-book/blob/main/book/chapters/06-policy-gradients.md"><code>book/chapters/06-policy-gradients.md</code></a>
；教学代码默认 <code>num_rollouts: 8</code>：<a href="https://github.com/natolambert/rlhf-book/tree/main/code/policy_gradients/configs"><code>code/policy_gradients/configs/</code></a>
</li>
<li>零梯度组概率表、误判丢弃、clip 触发率链条为本文推算/推断，文中已逐处标注</li>
<li>前篇：<a href="https://njx-njx.github.io/posts/gspo-sequence-level-importance-sampling/">比率用错了单位：GSPO 把重要性采样提到序列级</a>
</li>
</ul>
]]></content:encoded>
    </item>
    <item>
      <title>同一个模型，两个概率：训练推理不一致的代价</title>
      <link>https://njx-njx.github.io/posts/tis-train-inference-mismatch/</link>
      <pubDate>Thu, 27 Aug 2026 13:00:00 +0800</pubDate>
      <guid>https://njx-njx.github.io/posts/tis-train-inference-mismatch/</guid>
      <description>rollout 与训练用不同引擎，同一个模型算出两个概率，on-policy 悄悄变成 off-policy。差异从哪来、代价是什么、怎么补。</description>
      <content:encoded><![CDATA[<p>rollout 用推理引擎、训练用训练引擎，同一个模型在两边的数值对不上：实际采样的分布与你假设的策略存在偏差，名义上的 on-policy 悄悄变成 off-policy。本文拆解差异来源、有偏梯度与部署差距两个后果、算法补丁谱系，以及 Sea AI Lab 归到 BF16 精度上的根源结论。</p>
<blockquote>
<p>本文有配套的<a href="https://njx-njx.github.io/reports/tis-train-inference-mismatch/">交互报告</a>
，含可下钻的双引擎机制图、补丁谱系对比与精度位域拆解。</p>
</blockquote>
<h2 id="同一类难以解释的崩溃">同一类难以解释的崩溃</h2>
<p>2025 年下半年有几个团队分别报告了同一种现象：GRPO 训练前期一切正常，奖励稳步上涨，然后在某个时间点突然掉头向下直至崩溃。崩溃前没有梯度尖峰，超参没有问题，换一批训练 query 重跑，崩溃换个时间还是会来。</p>
<p>Defog（Feng Yao，字节 Seed）2025 年 8 月的技术报告《Your Efficient RL Framework Secretly Brings You Off-Policy RL Training》给出了一个让不少人意外的解释：<strong>你以为自己在做 on-policy 训练，但 rollout 数据实际对应的分布已经偏离你正在优化的策略</strong>。问题不在算法，在数值——生成数据的引擎算出的概率，与训练数据引擎算出的概率不一致。</p>
<h2 id="同一个模型为什么算出两个概率">同一个模型为什么算出两个概率</h2>
<p>现代 LLM RL 框架被拆成两半。rollout 侧使用推理引擎（vLLM、SGLang），为高吞吐做了大量 kernel 级优化；训练侧使用训练引擎（Megatron、PyTorch FSDP、DeepSpeed），负责计算每个 token 的 log 概率和梯度。两边加载同一份权重，理论上应该是同一个策略 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>π</mi></mrow><annotation encoding="application/x-tex">\pi</annotation></semantics></math></span>。</p>
<p>但由于工程实现不同，各引擎的计算结果并不完全一致。Sea AI Lab 的 FP16 论文（arXiv:2510.26788）总结了差异的来源：</p>
<ul>
<li><strong>计算方式不同</strong>。推理是自回归逐 token 生成；训练是 teacher-forcing 下将整段序列并行前向计算。对于同一串 token，不同的计算过程采用不同的浮点归约顺序，误差累积方式也不一样。</li>
<li><strong>kernel 实现不同</strong>。推理引擎的 RMSNorm、RoPE、attention kernel 针对延迟和吞吐量做过专门调优，与训练侧实现存在微小数值差。</li>
<li><strong>并行切分不同</strong>。训练和推理采用不同的 tensor 并行与数据并行切分，跨卡归约的顺序不同会改变浮点结果。</li>
<li><strong>MoE 的 top-k 门控对细微变化敏感</strong>。专家选择对 logits 的微小波动敏感，使用同一权重、两种引擎各计算一遍，选出的专家也可能不同。<a href="https://njx-njx.github.io/posts/gspo-sequence-level-importance-sampling/">GSPO 那篇</a>
提到的 10% 专家漂移出现在“更新前与更新后”的时间维度上；这里指的是“同一权重、两种引擎”的空间维度。门控敏感性会在两个维度分别引发一次差异。</li>
<li><strong>精度格式的尾数太短</strong>。默认的 BF16 只有 7 位尾数，这些引文涉及的各处微小差异都没有足够的数值精度余量，最终造成明显偏差。这一条是全文关键，后面细说。</li>
</ul>
<p>于是推理引擎实际对应一个与训练引擎<strong>数值上不同的策略</strong>，记作 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>μ</mi></mrow><annotation encoding="application/x-tex">\mu</annotation></semantics></math></span>。数据从 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>μ</mi></mrow><annotation encoding="application/x-tex">\mu</annotation></semantics></math></span> 采样，梯度却按 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>π</mi></mrow><annotation encoding="application/x-tex">\pi</annotation></semantics></math></span> 的假设来算。on-policy 与 off-policy 的边界，最终取决于 kernel 的浮点行为。</p>
<h2 id="两个后果梯度有偏部署打折">两个后果：梯度有偏，部署打折</h2>
<p>后果一：<strong>梯度有偏</strong>。理论上的策略梯度要求从正在优化的策略 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>π</mi></mrow><annotation encoding="application/x-tex">\pi</annotation></semantics></math></span> 采样：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi mathvariant="normal">∇</mi><mi>θ</mi></msub><mi mathvariant="script">J</mi><mo stretchy="false">(</mo><mi>x</mi><mo separator="true">,</mo><mi>θ</mi><mo stretchy="false">)</mo><mo>=</mo><msub><mi mathvariant="double-struck">E</mi><mrow><mi>y</mi><mo>∼</mo><mi>π</mi><mo stretchy="false">(</mo><mo>⋅</mo><mi mathvariant="normal">∣</mi><mi>x</mi><mo separator="true">,</mo><mi>θ</mi><mo stretchy="false">)</mo></mrow></msub><mrow><mo fence="true">[</mo><msub><mi mathvariant="normal">∇</mi><mi>θ</mi></msub><mi>log</mi><mo>⁡</mo><mi>π</mi><mo stretchy="false">(</mo><mi>y</mi><mi mathvariant="normal">∣</mi><mi>x</mi><mo separator="true">,</mo><mi>θ</mi><mo stretchy="false">)</mo><mo>⋅</mo><mi>R</mi><mo stretchy="false">(</mo><mi>x</mi><mo separator="true">,</mo><mi>y</mi><mo stretchy="false">)</mo><mo fence="true">]</mo></mrow></mrow><annotation encoding="application/x-tex">\nabla_\theta\mathcal{J}(x,\theta)=\mathbb{E}_{y\sim\pi(\cdot|x,\theta)}\left[\nabla_\theta\log\pi(y|x,\theta)\cdot R(x,y)\right]</annotation></semantics></math></span><p><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>π</mi><mo stretchy="false">(</mo><mi>y</mi><mi mathvariant="normal">∣</mi><mi>x</mi><mo separator="true">,</mo><mi>θ</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\pi(y|x,\theta)</annotation></semantics></math></span> 是训练前向中该回答的似然，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>R</mi><mo stretchy="false">(</mo><mi>x</mi><mo separator="true">,</mo><mi>y</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">R(x,y)</annotation></semantics></math></span> 是奖励，期望需要在 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>π</mi></mrow><annotation encoding="application/x-tex">\pi</annotation></semantics></math></span> 的分布下计算。但实际样本来自 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>μ</mi></mrow><annotation encoding="application/x-tex">\mu</annotation></semantics></math></span>：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi mathvariant="normal">∇</mi><mi>θ</mi></msub><msub><mi mathvariant="script">J</mi><mrow><mi>b</mi><mi>i</mi><mi>a</mi><mi>s</mi><mi>e</mi><mi>d</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo separator="true">,</mo><mi>θ</mi><mo stretchy="false">)</mo><mo>=</mo><msub><mi mathvariant="double-struck">E</mi><mrow><mi>y</mi><mo>∼</mo><mi>μ</mi><mo stretchy="false">(</mo><mo>⋅</mo><mi mathvariant="normal">∣</mi><mi>x</mi><mo separator="true">,</mo><mi>θ</mi><mo stretchy="false">)</mo></mrow></msub><mrow><mo fence="true">[</mo><msub><mi mathvariant="normal">∇</mi><mi>θ</mi></msub><mi>log</mi><mo>⁡</mo><mi>π</mi><mo stretchy="false">(</mo><mi>y</mi><mi mathvariant="normal">∣</mi><mi>x</mi><mo separator="true">,</mo><mi>θ</mi><mo stretchy="false">)</mo><mo>⋅</mo><mi>R</mi><mo stretchy="false">(</mo><mi>x</mi><mo separator="true">,</mo><mi>y</mi><mo stretchy="false">)</mo><mo fence="true">]</mo></mrow><mo mathvariant="normal">≠</mo><msub><mi mathvariant="normal">∇</mi><mi>θ</mi></msub><mi mathvariant="script">J</mi><mo stretchy="false">(</mo><mi>x</mi><mo separator="true">,</mo><mi>θ</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\nabla_\theta\mathcal{J}_{biased}(x,\theta)=\mathbb{E}_{y\sim\mu(\cdot|x,\theta)}\left[\nabla_\theta\log\pi(y|x,\theta)\cdot R(x,y)\right]\neq \nabla_\theta\mathcal{J}(x,\theta)</annotation></semantics></math></span><p>期望值所基于的分布突然发生了变化，等式不再成立。偏差平时很小，但 RL 是个把分布往一侧持续推的迭代过程，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>μ</mi></mrow><annotation encoding="application/x-tex">\mu</annotation></semantics></math></span> 和 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>π</mi></mrow><annotation encoding="application/x-tex">\pi</annotation></semantics></math></span> 的小差异会随训练逐步放大。论文还观察到一个可作预警信号的现象：凡是最终崩溃的训练，崩溃前 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>π</mi></mrow><annotation encoding="application/x-tex">\pi</annotation></semantics></math></span> 和 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>μ</mi></mrow><annotation encoding="application/x-tex">\mu</annotation></semantics></math></span> 的差都在持续扩大，极端时同一份权重下同一个 token 在一个引擎里概率趋近 1、在另一个里趋近 0。</p>
<p>后果二：<strong>部署差距（deployment gap）</strong>。哪怕训练过程的梯度偏差被完全修正，优化目标仍是训练引擎的概率分布，而部署和评测跑在推理引擎上：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>arg</mi><mo>⁡</mo><munder><mrow><mi>max</mi><mo>⁡</mo></mrow><mi>θ</mi></munder><msub><mi mathvariant="double-struck">E</mi><mrow><mi>y</mi><mo>∼</mo><mi>μ</mi></mrow></msub><mi>R</mi><mo mathvariant="normal">≠</mo><mi>arg</mi><mo>⁡</mo><munder><mrow><mi>max</mi><mo>⁡</mo></mrow><mi>θ</mi></munder><msub><mi mathvariant="double-struck">E</mi><mrow><mi>y</mi><mo>∼</mo><mi>π</mi></mrow></msub><mi>R</mi></mrow><annotation encoding="application/x-tex">\arg\max_\theta \mathbb{E}_{y\sim\mu}R \neq \arg\max_\theta \mathbb{E}_{y\sim\pi}R</annotation></semantics></math></span><p>在 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>π</mi></mrow><annotation encoding="application/x-tex">\pi</annotation></semantics></math></span> 下最优的参数，在 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>μ</mi></mrow><annotation encoding="application/x-tex">\mu</annotation></semantics></math></span> 下不一定最优。论文实验里这个差距是可见的：BF16 下表现最稳定的算法补丁（序列级掩码校正），训练准确率峰值 95%、AIME 2024 得分 34%；FP16 下是 99% 和 39%。所有算法补丁在这一指标上的差距都为零——它们只解决训练过程中的偏差，无法解决这种部署差距。</p>
<h2 id="算法补丁及其局限">算法补丁及其局限</h2>
<p>本质是“从 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>μ</mi></mrow><annotation encoding="application/x-tex">\mu</annotation></semantics></math></span> 采样却按 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>π</mi></mrow><annotation encoding="application/x-tex">\pi</annotation></semantics></math></span> 求期望”，教科书解法是做重要性采样校正：给每个样本乘一个训推概率比 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>π</mi><mi mathvariant="normal">/</mi><mi>μ</mi></mrow><annotation encoding="application/x-tex">\pi/\mu</annotation></semantics></math></span>。2025 年下半年的改进主要分两步：</p>
<p><strong>补丁一，token 级截断校正（Defog）</strong>。对每个 token 计算训练概率与推理概率之比 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>ρ</mi><mi>t</mi></msub><mo>=</mo><mi>π</mi><mo stretchy="false">(</mo><msub><mi>y</mi><mi>t</mi></msub><mi mathvariant="normal">∣</mi><mi>x</mi><mo separator="true">,</mo><msub><mi>y</mi><mrow><mo>&lt;</mo><mi>t</mi></mrow></msub><mo separator="true">,</mo><msup><mi>θ</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mo stretchy="false">)</mo><mi mathvariant="normal">/</mi><mi>μ</mi><mo stretchy="false">(</mo><msub><mi>y</mi><mi>t</mi></msub><mi mathvariant="normal">∣</mi><mi>x</mi><mo separator="true">,</mo><msub><mi>y</mi><mrow><mo>&lt;</mo><mi>t</mi></mrow></msub><mo separator="true">,</mo><msup><mi>θ</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\rho_t = \pi(y_t|x,y_{&lt;t},\theta&#x27;)/\mu(y_t|x,y_{&lt;t},\theta&#x27;)</annotation></semantics></math></span>，截断到上限 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>C</mi></mrow><annotation encoding="application/x-tex">C</annotation></semantics></math></span>（实验取 3）后，乘进 GRPO 的每一项梯度。注意分母 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>μ</mi></mrow><annotation encoding="application/x-tex">\mu</annotation></semantics></math></span> 是推理引擎的概率，因此必须让训练引擎对同一条样本重新进行一次前向计算，才能得到分子，额外带来约 25% 的训练开销（按照反向传播的计算量约等于 2 倍前向计算量来估算）。效果：崩溃被推迟，峰值到 82%（VeRL）/ 88%（Oat）后照崩。</p>
<p><strong>补丁二，序列级掩码校正</strong>（《When Speed Kills Stability》，Liu 等）。作者指出 token 级校正的梯度有偏，将校正方式改为对整条序列只计算一个比率 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ρ</mi><mo>=</mo><mi>π</mi><mo stretchy="false">(</mo><mi>y</mi><mi mathvariant="normal">∣</mi><mi>x</mi><mo separator="true">,</mo><msup><mi>θ</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mo stretchy="false">)</mo><mi mathvariant="normal">/</mi><mi>μ</mi><mo stretchy="false">(</mo><mi>y</mi><mi mathvariant="normal">∣</mi><mi>x</mi><mo separator="true">,</mo><msup><mi>θ</mi><mo mathvariant="normal" lspace="0em" rspace="0em">′</mo></msup><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\rho = \pi(y|x,\theta&#x27;)/\mu(y|x,\theta&#x27;)</annotation></semantics></math></span>，超过 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>C</mi></mrow><annotation encoding="application/x-tex">C</annotation></semantics></math></span> 就把整条序列的梯度掩掉。思路与 GSPO 一脉相承（不过，GSPO 的 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>s</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">s_i</annotation></semantics></math></span> 只作为优化对象，这里的 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ρ</mi></mrow><annotation encoding="application/x-tex">\rho</annotation></semantics></math></span> 则是校正因子）。它是 BF16 下唯一未崩溃的算法补丁，代价是序列级比率方差大、收敛慢，部署差距同样原样存在——峰值只有 95%/34%。</p>
<p>两个补丁的共同点：都接受 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>μ</mi><mo mathvariant="normal">≠</mo><mi>π</mi></mrow><annotation encoding="application/x-tex">\mu \neq \pi</annotation></semantics></math></span> 的事实并逐样本补偿，而要付出新的算力成本并引入方差，而且都无法解决部署差距。</p>
<h2 id="根源bf16-的-7-位尾数">根源：BF16 的 7 位尾数</h2>
<p>Sea AI Lab 这篇论文没有继续沿着补丁方向推进，而是直接检查了数值格式。</p>
<p>BF16 与 FP16 同样 16 位，分配不同。BF16 用 8 位指数 + 7 位尾数，动态范围与 FP32 同级：预训练不怕溢出、不用 loss scaling，这是它成为标配的原因。FP16 用 5 位指数 + 10 位尾数：动态范围小得多（要靠 loss scaling 防梯度下溢），但相邻可表示数的密度是 BF16 的 8 倍（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mn>2</mn><mn>10</mn></msup></mrow><annotation encoding="application/x-tex">2^{10}</annotation></semantics></math></span> 对 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mn>2</mn><mn>7</mn></msup></mrow><annotation encoding="application/x-tex">2^7</annotation></semantics></math></span>），精度更高。</p>
<p>论文的判断：RL 微调阶段的需求变了。权重和激活的动态范围在预训练已经定型，BF16 的 FP32 级范围在这里已经没有实际用途；训练与推理中每处 kernel 差异，都需要 FP16 多出的 3 位尾数提供足够的数值精度余量。将精度统一设为 FP16 后，两个引擎的输出在绝大多数 token 上数值一致，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>μ</mi></mrow><annotation encoding="application/x-tex">\mu</annotation></semantics></math></span> 与 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>π</mi></mrow><annotation encoding="application/x-tex">\pi</annotation></semantics></math></span> 重新重合。离线分析显示：BF16 的序列级训推失配会随生成长度呈指数放大，FP16 将失配显著降低，约至 BF16 的 1/24。精度消融实验里，“训练 BF16 + 推理 FP32” 的组合也能完全稳定，但推理慢 3 倍；全部使用 FP16 是兼顾稳定性和效率的最佳组合。</p>
<p>最能说明问题的是后一组实验：<strong>采用 FP16 后，各算法性能差异几乎消失</strong>。BF16 下差异明显的 GRPO、token 级 TIS、GSPO、序列级 MIS，采用 FP16 后彼此接近，连最朴素、不带任何修正的重要性采样策略梯度也能取得最好的表现。原因不难理解：<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>μ</mi></mrow><annotation encoding="application/x-tex">\mu</annotation></semantics></math></span> 与 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>π</mi></mrow><annotation encoding="application/x-tex">\pi</annotation></semantics></math></span> 的差接近零后，训练回到近似 on-policy 状态，所有“修正不一致”的算法都失去了修正对象。（补充一个细节：GSPO 在 VeRL 上 1200 步后梯度变成 NaN，这说明在数值问题没有解决的情况下，算法层面的改进可能没有作用。）文中引用的工程路线也印证了这一点：SGLang 团队手工对齐两条计算路径的 kernel 实现（2025 年 11 月 Unified FP8 工作）、Miles/slime 从系统层面一次性对齐训练与推理：二者都有效，但需要深入的 kernel 知识和大量工程投入，且难以移植。数值格式是所有解决方案中成本最低的一条：只需修改几行配置，同时沿用现有的 loss scaling 机制。</p>
<h2 id="与前两篇对照着看">与前两篇对照着看</h2>
<p>这个系列的三篇文章恰好能从四个层面看待同一问题：</p>
<ul>
<li><strong>DAPO Clip-Higher</strong>：在假定训练与推理一致的前提下，调整算法内部的 clip 边界来解决熵坍缩；</li>
<li><strong>GSPO</strong>：将优化目标改为使用序列级单位，并对 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>μ</mi></mrow><annotation encoding="application/x-tex">\mu</annotation></semantics></math></span> 的差异具有天然鲁棒性，同时还能容忍 MoE 路由漂移；</li>
<li><strong>TIS 算法补丁</strong>（本文上半篇）：接受 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>μ</mi><mo mathvariant="normal">≠</mo><mi>π</mi></mrow><annotation encoding="application/x-tex">\mu \neq \pi</annotation></semantics></math></span> 的事实，逐样本做重要性采样补偿；</li>
<li><strong>FP16 与 kernel 对齐</strong>（本文下半篇）：让 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>μ</mi><mo>≈</mo><mi>π</mi></mrow><annotation encoding="application/x-tex">\mu \approx \pi</annotation></semantics></math></span>，直接消除不一致。</li>
</ul>
<p>对照这个脉络，GSPO §5.4 “序列级似然对训练与推理的精度差异有很高容忍度”不再只是附带好处——它是算法层面对训练与推理不一致（TIS）问题的直接回应。</p>
<h2 id="我的三个判断">我的三个判断</h2>
<p>一、<strong>从工程上看，on-policy 是一个数值问题</strong>。算法定义写“从当前策略采样”，工程上你只能从“当前策略在某个 kernel 实现下的数值近似”采样。两者差到一定量级，理论分析采用的前提已不再成立，而且现有的报警机制无法据此发出警报：训练曲线正常、loss 正常，只有训练侧与推理侧的 logprob 差在不声不响地发散。实操建议很直接：把训推 logprob 差（或 KL）设置为常规监控项，成本接近于零，而论文展示的预警价值是实测的。</p>
<p>二、<strong>BF16 的默认地位值得被质疑，但 FP16 的结论不宜过度推广</strong>。证据覆盖 1.5B 到 30B MoE、两个框架、LoRA、两个模型家族，是扎实的；论文自己也声明不主张普适：超大模型用 FP16 需要管理溢出，而行业往 FP8 走的话（尾数只有 3～4 位），训练与推理不一致的问题还会再次出现。目前 FP8 RL 路线（LMSYS、NVIDIA）是训练和推理两边统一使用 FP8，而不是回到 FP16。精度问题要么重新得到认真对待，要么以另一种形式再次出现。</p>
<p>三、<strong>部署差距是此背后最直接、研究最少的问题</strong>。虽然梯度偏差也可以修正，训练与推理不一致也可以通过同时对齐两侧的 kernel 和精度格式消除，但“训练得到的参数对部署引擎不是最优”这一问题没有消失，只是有所减小。评测时换用推理引擎，报告的分数到底属于哪个策略？多引擎混合部署时，差距如何计算？我目前没有看到系统研究。</p>
<h2 id="未决问题">未决问题</h2>
<ul>
<li>FP16 下仍然存在的少量训推差异，在数千步的超长训练中会否重新累积成问题；</li>
<li>FP8 统一精度路线与 FP16 路线在同等算力预算下的最终性能，目前没有公开的直接对比；</li>
<li>部署差距还会出现，只是有所减小：使用与训练环境不同的引擎评测时，分数应该归因于哪个策略。</li>
</ul>
<h2 id="参考来源">参考来源</h2>
<ul>
<li>Sea AI Lab / NUS：<a href="https://arxiv.org/abs/2510.26788">Defeating the Training-Inference Mismatch via FP16</a>
（本文实验、公式与数据的出处）</li>
<li>Defog（Feng Yao 等）：《Your Efficient RL Framework Secretly Brings You Off-Policy RL Training》，2025-08，Notion 发布；原报告受技术限制无法直接获取，其 token 级校正公式转述自 FP16 论文 §2.1</li>
<li>Liu 等：《When Speed Kills Stability: Demystifying RL Collapse from the Inference-Training Mismatch》，2025，Notion 发布；序列级掩码校正，同上转述</li>
<li>工程路线：<a href="https://www.lmsys.org/blog/2025-11-25-fp8-rl/">Unified FP8: Moving Beyond Mixed Precision for Stable and Accelerated MoE RL</a>
（LMSYS）；Miles/slime：All-In-One Solution to Training-Inference Mismatch</li>
<li>教材 <a href="https://github.com/walkinglabs/hands-on-modern-rl">hands-on-modern-rl</a>
 附录 B.1：rollout engine 产出 old logprob 的两种工程处理（直接采用推理端返回的结果，或在训练端重新计算并核对其准确性）</li>
<li>前篇：<a href="https://njx-njx.github.io/posts/dapo-clip-higher-entropy-collapse/">熵是怎么塌掉的：DAPO 的 Clip-Higher 在修什么</a>
 与 <a href="https://njx-njx.github.io/posts/gspo-sequence-level-importance-sampling/">比率用错了单位：GSPO 把重要性采样提到序列级</a>
</li>
</ul>
]]></content:encoded>
    </item>
    <item>
      <title>比率用错了单位：GSPO 把重要性采样提到序列级</title>
      <link>https://njx-njx.github.io/posts/gspo-sequence-level-importance-sampling/</link>
      <pubDate>Wed, 26 Aug 2026 17:40:00 +0800</pubDate>
      <guid>https://njx-njx.github.io/posts/gspo-sequence-level-importance-sampling/</guid>
      <description>GRPO 沿用 token 级重要性比率，Qwen 认为这是误用，会让 MoE 长回答训练崩溃。GSPO 把比率、裁剪和优化都提到序列级。</description>
      <content:encoded><![CDATA[<p>GRPO 沿用 PPO 的 token 级重要性比率，Qwen 团队认定这是对重要性采样的根本误用，会在 MoE 长回答训练中导致不可逆崩溃。GSPO 把比率、裁剪、优化全部提到序列级，被裁掉的 token 多两个数量级，训练反而更高效。本文拆解这条论证链，以及论文没点破的前提与代价。</p>
<blockquote>
<p>本文有配套的<a href="https://njx-njx.github.io/reports/gspo-sequence-level-importance-sampling/">交互报告</a>
，含可下钻的公式拆解、裁剪带对比与稀释效应计算器。</p>
</blockquote>
<h2 id="一个补丁暴露的问题">一个补丁暴露的问题</h2>
<p>2025 年中之前，用 GRPO 训 MoE 模型需要一个专门的补丁。</p>
<p>Qwen 团队在 GSPO 论文（arXiv:2507.18071）里交代了他们此前的办法：<strong>Routing Replay</strong>。采样时把旧策略 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>π</mi><msub><mi>θ</mi><mrow><mi>o</mi><mi>l</mi><mi>d</mi></mrow></msub></msub></mrow><annotation encoding="application/x-tex">\pi_{\theta_{old}}</annotation></semantics></math></span> 激活的专家路由缓存下来，计算重要性比率时在新策略 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>π</mi><mi>θ</mi></msub></mrow><annotation encoding="application/x-tex">\pi_\theta</annotation></semantics></math></span> 上&quot;重放&quot;这套路由，让比率的分子分母跑同一张激活网络。之所以需要这个补丁，是因为他们观察到一个数字：48 层的 Qwen3-30B-A3B，每做一次梯度更新，同一条 rollout 样本在新策略下激活的专家约有 10% 与旧策略不同。路由一变，逐 token 的概率跟着变，token 级重要性比率剧烈波动，GRPO 直接不收敛。</p>
<p>补丁能跑，但代价实打实：额外的显存和通信开销，而且强制新策略走旧路由等于限制模型的实际容量。更麻烦的是另一件事——即便有补丁，大模型长回答任务上的 GRPO 仍会发生<strong>不可逆的模型崩溃</strong>。论文的措辞很重：崩溃一旦发生，回退 checkpoint、细调裁剪范围、延长生成长度、换 RL query，全都救不回来。</p>
<p>token 级重要性比率从 PPO 时代就是标配，用了八年。为什么在 LLM 的 RL 里突然成了病灶？GSPO 的回答是：它不是突然生病的，它从一开始就用错了地方——这是对重要性采样的误用，只是在小模型、短回答、近 on-policy 的年代里，错误被掩盖了。</p>
<h2 id="重要性采样为什么会失效">重要性采样为什么会&quot;失效&quot;</h2>
<p>先把重要性采样（IS）本身写出来。要用行为分布 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>π</mi><mrow><mi>b</mi><mi>e</mi><mi>h</mi></mrow></msub></mrow><annotation encoding="application/x-tex">\pi_{beh}</annotation></semantics></math></span> 的样本，估计目标分布 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>π</mi><mrow><mi>t</mi><mi>a</mi><mi>r</mi></mrow></msub></mrow><annotation encoding="application/x-tex">\pi_{tar}</annotation></semantics></math></span> 下函数 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi></mrow><annotation encoding="application/x-tex">f</annotation></semantics></math></span> 的期望：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi mathvariant="double-struck">E</mi><mrow><mi>z</mi><mo>∼</mo><msub><mi>π</mi><mrow><mi>t</mi><mi>a</mi><mi>r</mi></mrow></msub></mrow></msub><mo stretchy="false">[</mo><mi>f</mi><mo stretchy="false">(</mo><mi>z</mi><mo stretchy="false">)</mo><mo stretchy="false">]</mo><mo>=</mo><msub><mi mathvariant="double-struck">E</mi><mrow><mi>z</mi><mo>∼</mo><msub><mi>π</mi><mrow><mi>b</mi><mi>e</mi><mi>h</mi></mrow></msub></mrow></msub><mrow><mo fence="true">[</mo><mfrac><mrow><msub><mi>π</mi><mrow><mi>t</mi><mi>a</mi><mi>r</mi></mrow></msub><mo stretchy="false">(</mo><mi>z</mi><mo stretchy="false">)</mo></mrow><mrow><msub><mi>π</mi><mrow><mi>b</mi><mi>e</mi><mi>h</mi></mrow></msub><mo stretchy="false">(</mo><mi>z</mi><mo stretchy="false">)</mo></mrow></mfrac><mi>f</mi><mo stretchy="false">(</mo><mi>z</mi><mo stretchy="false">)</mo><mo fence="true">]</mo></mrow></mrow><annotation encoding="application/x-tex">\mathbb{E}_{z\sim\pi_{tar}}[f(z)] = \mathbb{E}_{z\sim\pi_{beh}}\left[\frac{\pi_{tar}(z)}{\pi_{beh}(z)} f(z)\right]</annotation></semantics></math></span><p>这个恒等式成立不靠比率本身，靠的是<strong>大量样本的平均</strong>：<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>N</mi><mo>≫</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">N \gg 1</annotation></semantics></math></span> 时，随机比率 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>w</mi><mo stretchy="false">(</mo><mi>z</mi><mo stretchy="false">)</mo><mo>=</mo><msub><mi>π</mi><mrow><mi>t</mi><mi>a</mi><mi>r</mi></mrow></msub><mo stretchy="false">(</mo><mi>z</mi><mo stretchy="false">)</mo><mi mathvariant="normal">/</mi><msub><mi>π</mi><mrow><mi>b</mi><mi>e</mi><mi>h</mi></mrow></msub><mo stretchy="false">(</mo><mi>z</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">w(z)=\pi_{tar}(z)/\pi_{beh}(z)</annotation></semantics></math></span> 的涨落被平均掉，估计才收敛到真值。单个样本乘上 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>w</mi></mrow><annotation encoding="application/x-tex">w</annotation></semantics></math></span>，起不到任何校正作用，只是给 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>f</mi><mo stretchy="false">(</mo><mi>z</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">f(z)</annotation></semantics></math></span> 乘了一个高方差的随机数。</p>
<p>现在看 GRPO 在做什么。它对每个 token 算比率：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>w</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mo>=</mo><mfrac><mrow><msub><mi>π</mi><mi>θ</mi></msub><mo stretchy="false">(</mo><msub><mi>y</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub><mi mathvariant="normal">∣</mi><mi>x</mi><mo separator="true">,</mo><msub><mi>y</mi><mrow><mi>i</mi><mo separator="true">,</mo><mo>&lt;</mo><mi>t</mi></mrow></msub><mo stretchy="false">)</mo></mrow><mrow><msub><mi>π</mi><msub><mi>θ</mi><mrow><mi>o</mi><mi>l</mi><mi>d</mi></mrow></msub></msub><mo stretchy="false">(</mo><msub><mi>y</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub><mi mathvariant="normal">∣</mi><mi>x</mi><mo separator="true">,</mo><msub><mi>y</mi><mrow><mi>i</mi><mo separator="true">,</mo><mo>&lt;</mo><mi>t</mi></mrow></msub><mo stretchy="false">)</mo></mrow></mfrac></mrow><annotation encoding="application/x-tex">w_{i,t}(\theta)=\frac{\pi_\theta(y_{i,t}|x,y_{i,&lt;t})}{\pi_{\theta_{old}}(y_{i,t}|x,y_{i,&lt;t})}</annotation></semantics></math></span><p>其中 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>y</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub></mrow><annotation encoding="application/x-tex">y_{i,t}</annotation></semantics></math></span> 是第 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi></mrow><annotation encoding="application/x-tex">i</annotation></semantics></math></span> 条回答的第 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>t</mi></mrow><annotation encoding="application/x-tex">t</annotation></semantics></math></span> 个 token，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>y</mi><mrow><mi>i</mi><mo separator="true">,</mo><mo>&lt;</mo><mi>t</mi></mrow></msub></mrow><annotation encoding="application/x-tex">y_{i,&lt;t}</annotation></semantics></math></span> 是它前面的上下文。<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>π</mi><msub><mi>θ</mi><mrow><mi>o</mi><mi>l</mi><mi>d</mi></mrow></msub></msub><mo stretchy="false">(</mo><mo>⋅</mo><mi mathvariant="normal">∣</mi><mi>x</mi><mo separator="true">,</mo><msub><mi>y</mi><mrow><mi>i</mi><mo separator="true">,</mo><mo>&lt;</mo><mi>t</mi></mrow></msub><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\pi_{\theta_{old}}(\cdot|x,y_{i,&lt;t})</annotation></semantics></math></span> 是第 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>t</mi></mrow><annotation encoding="application/x-tex">t</annotation></semantics></math></span> 步的 next-token 分布，从里面<strong>只采了一个样本</strong> <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>y</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub></mrow><annotation encoding="application/x-tex">y_{i,t}</annotation></semantics></math></span>。也就是说，每个比率都是拿单个样本对单步分布做&quot;校正&quot;——按上面的判据，这根本不构成 IS 校正，它只是往梯度里注入了一个逐 token 的随机权重。序列越长，累积的随机权重越多；模型越大越稀疏（MoE），单个权重的方差越大。clipping 再把超出范围的 token 梯度清零，噪声就被放大成&quot;随机抹掉一部分 token 的学习信号&quot;。RLHF Book 第 6 章对失效现场有两个具体描述：单个大比率 token 可以主导整个更新；同一条 response 内部的 token 被各自独立地裁剪，学习信号被切得粉碎。</p>
<p>GSPO 论文把症结提炼成一句话：<strong>优化目标的单位应当匹配奖励的单位</strong>。RLVR 的奖励是给整条序列的（答对 1 分答错 0 分），而 GRPO 的校正和裁剪都发生在 token 级。单位错配，校正越&quot;认真&quot;，伤害越精确。</p>
<p>这里要诚实补一句：GRPO 这么写并非没有理论来源。把每个 token 看作一步 action、整条轨迹的 IS 比率分解为逐步比率，是标准 RL 的推导路径。问题出在实现层面把逐 token 比率当作独立的校正权重逐个使用、逐个裁剪——这一步近似在大词表、长轨迹、单样本的条件下不再无害。这是 GSPO 论文的批评角度，不是公理，读者可以保留自己的判断。</p>
<h2 id="gspo比率裁剪优化全部换到序列级">GSPO：比率、裁剪、优化全部换到序列级</h2>
<p>GSPO 的目标函数：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi mathvariant="script">J</mi><mrow><mi>G</mi><mi>S</mi><mi>P</mi><mi>O</mi></mrow></msub><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mo>=</mo><msub><mi mathvariant="double-struck">E</mi><mrow><mi>x</mi><mo>∼</mo><mi mathvariant="script">D</mi><mo separator="true">,</mo><mo stretchy="false">{</mo><msub><mi>y</mi><mi>i</mi></msub><msubsup><mo stretchy="false">}</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>G</mi></msubsup><mo>∼</mo><msub><mi>π</mi><msub><mi>θ</mi><mrow><mi>o</mi><mi>l</mi><mi>d</mi></mrow></msub></msub></mrow></msub><mrow><mo fence="true">[</mo><mfrac><mn>1</mn><mi>G</mi></mfrac><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>G</mi></munderover><mi>min</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><msub><mi>s</mi><mi>i</mi></msub><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi></msub><mo separator="true">,</mo><mtext> </mtext><mrow><mi mathvariant="normal">c</mi><mi mathvariant="normal">l</mi><mi mathvariant="normal">i</mi><mi mathvariant="normal">p</mi></mrow><mo stretchy="false">(</mo><msub><mi>s</mi><mi>i</mi></msub><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mo separator="true">,</mo><mn>1</mn><mo>−</mo><mi>ε</mi><mo separator="true">,</mo><mn>1</mn><mo>+</mo><mi>ε</mi><mo stretchy="false">)</mo><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi></msub><mo fence="true">)</mo></mrow><mo fence="true">]</mo></mrow></mrow><annotation encoding="application/x-tex">\mathcal{J}_{GSPO}(\theta)=\mathbb{E}_{x\sim\mathcal{D},\{y_i\}_{i=1}^G\sim\pi_{\theta_{old}}}\left[\frac{1}{G}\sum_{i=1}^G \min\left(s_i(\theta)\hat{A}_i,\ \mathrm{clip}(s_i(\theta),1-\varepsilon,1+\varepsilon)\hat{A}_i\right)\right]</annotation></semantics></math></span><p>和 GRPO 的差别一眼可见：min-clip 外面没有了 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>1</mn><mrow><mi mathvariant="normal">∣</mi><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow></mfrac><msub><mo>∑</mo><mi>t</mi></msub></mrow><annotation encoding="application/x-tex">\frac{1}{|y_i|}\sum_t</annotation></semantics></math></span> 的逐 token 求和，一条 response 整体只占目标函数里的一项。advantage 还是组内归一化的 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">\hat{A}_i</annotation></semantics></math></span>（用组内奖励的均值和标准差标准化），整条 response 共享。</p>
<p>核心是序列级比率 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>s</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">s_i</annotation></semantics></math></span> 的定义：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>s</mi><mi>i</mi></msub><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mo>=</mo><msup><mrow><mo fence="true">(</mo><mfrac><mrow><msub><mi>π</mi><mi>θ</mi></msub><mo stretchy="false">(</mo><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi><mi>x</mi><mo stretchy="false">)</mo></mrow><mrow><msub><mi>π</mi><msub><mi>θ</mi><mrow><mi>o</mi><mi>l</mi><mi>d</mi></mrow></msub></msub><mo stretchy="false">(</mo><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi><mi>x</mi><mo stretchy="false">)</mo></mrow></mfrac><mo fence="true">)</mo></mrow><mfrac><mn>1</mn><mrow><mi mathvariant="normal">∣</mi><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow></mfrac></msup><mo>=</mo><mi>exp</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><mfrac><mn>1</mn><mrow><mi mathvariant="normal">∣</mi><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow></mfrac><munderover><mo>∑</mo><mrow><mi>t</mi><mo>=</mo><mn>1</mn></mrow><mrow><mi mathvariant="normal">∣</mi><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow></munderover><mi>log</mi><mo>⁡</mo><mfrac><mrow><msub><mi>π</mi><mi>θ</mi></msub><mo stretchy="false">(</mo><msub><mi>y</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub><mi mathvariant="normal">∣</mi><mi>x</mi><mo separator="true">,</mo><msub><mi>y</mi><mrow><mi>i</mi><mo separator="true">,</mo><mo>&lt;</mo><mi>t</mi></mrow></msub><mo stretchy="false">)</mo></mrow><mrow><msub><mi>π</mi><msub><mi>θ</mi><mrow><mi>o</mi><mi>l</mi><mi>d</mi></mrow></msub></msub><mo stretchy="false">(</mo><msub><mi>y</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub><mi mathvariant="normal">∣</mi><mi>x</mi><mo separator="true">,</mo><msub><mi>y</mi><mrow><mi>i</mi><mo separator="true">,</mo><mo>&lt;</mo><mi>t</mi></mrow></msub><mo stretchy="false">)</mo></mrow></mfrac><mo fence="true">)</mo></mrow></mrow><annotation encoding="application/x-tex">s_i(\theta)=\left(\frac{\pi_\theta(y_i|x)}{\pi_{\theta_{old}}(y_i|x)}\right)^{\frac{1}{|y_i|}}=\exp\left(\frac{1}{|y_i|}\sum_{t=1}^{|y_i|}\log\frac{\pi_\theta(y_{i,t}|x,y_{i,&lt;t})}{\pi_{\theta_{old}}(y_{i,t}|x,y_{i,&lt;t})}\right)</annotation></semantics></math></span><p>即整条序列似然比的几何平均，等价于逐 token 对数比率的算术平均再取 exp。<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><mi mathvariant="normal">∣</mi><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">1/|y_i|</annotation></semantics></math></span> 这个长度归一化不能省：不归一化，几千个比率连乘，少数几个 token 的似然变化就能让总比率剧烈波动，而且不同长度的 response 需要不同的裁剪范围，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ε</mi></mrow><annotation encoding="application/x-tex">\varepsilon</annotation></semantics></math></span> 根本没法设。归一化之后，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>s</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">s_i</annotation></semantics></math></span> 的数值范围与序列长度解耦，一个 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ε</mi></mrow><annotation encoding="application/x-tex">\varepsilon</annotation></semantics></math></span> 通吃。（教材 hands-on-modern-rl 第 16.4 节介绍 GSPO 时公式漏了这个 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><mi mathvariant="normal">∣</mi><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">1/|y_i|</annotation></semantics></math></span>，以论文公式 7 为准——漏掉它，整条论证链条就断了。）</p>
<p>裁剪的含义也随之改变。GRPO 的裁剪是把单个 token 的梯度清零——信号被切碎，但样本还在；GSPO 的裁剪是把整条 response 从梯度估计中剔除——样本要么整个用，要么整个不用。这和&quot;奖励给整条序列&quot;在粒度上对齐了。</p>
<h2 id="梯度视角不等权-vs-等权">梯度视角：不等权 vs 等权</h2>
<p>把两个目标的梯度展开（论文公式 8–12），根本差别落在一个地方：逐 token 的 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi mathvariant="normal">∇</mi><mi>θ</mi></msub><mi>log</mi><mo>⁡</mo><msub><mi>π</mi><mi>θ</mi></msub></mrow><annotation encoding="application/x-tex">\nabla_\theta\log\pi_\theta</annotation></semantics></math></span> 前面乘的是什么。</p>
<p>GRPO 的梯度里，token <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>t</mi></mrow><annotation encoding="application/x-tex">t</annotation></semantics></math></span> 的 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∇</mi><mi>log</mi><mo>⁡</mo><mi>π</mi></mrow><annotation encoding="application/x-tex">\nabla\log\pi</annotation></semantics></math></span> 乘的是<strong>它自己的比率</strong> <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>w</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub></mrow><annotation encoding="application/x-tex">w_{i,t}</annotation></semantics></math></span>。经过 min-clip 后，这些逐 token 权重分布在 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">(</mo><mn>0</mn><mo separator="true">,</mo><mn>1</mn><mo>+</mo><mi>ε</mi><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">(0, 1+\varepsilon]</annotation></semantics></math></span>（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi></msub><mo>&gt;</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">\hat{A}_i&gt;0</annotation></semantics></math></span> 时）或 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">[</mo><mn>1</mn><mo>−</mo><mi>ε</mi><mo separator="true">,</mo><mo>+</mo><mi mathvariant="normal">∞</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">[1-\varepsilon, +\infty)</annotation></semantics></math></span>（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi></msub><mo>&lt;</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">\hat{A}_i&lt;0</annotation></semantics></math></span> 时）——同一条 response 内部，不同 token 拿到的梯度权重可以差出量级，且随训练步数累积，后果难以预测。</p>
<p>GSPO 的梯度里，同一条 response 的所有 token 共享<strong>同一个标量权重</strong> <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>s</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">s_i</annotation></semantics></math></span>：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi mathvariant="normal">∇</mi><mi>θ</mi></msub><msub><mi mathvariant="script">J</mi><mrow><mi>G</mi><mi>S</mi><mi>P</mi><mi>O</mi></mrow></msub><mo>=</mo><mi mathvariant="double-struck">E</mi><mrow><mo fence="true">[</mo><mfrac><mn>1</mn><mi>G</mi></mfrac><munderover><mo>∑</mo><mrow><mi>i</mi><mo>=</mo><mn>1</mn></mrow><mi>G</mi></munderover><msub><mi>s</mi><mi>i</mi></msub><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>i</mi></msub><mo>⋅</mo><mfrac><mn>1</mn><mrow><mi mathvariant="normal">∣</mi><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow></mfrac><munderover><mo>∑</mo><mrow><mi>t</mi><mo>=</mo><mn>1</mn></mrow><mrow><mi mathvariant="normal">∣</mi><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi></mrow></munderover><msub><mi mathvariant="normal">∇</mi><mi>θ</mi></msub><mi>log</mi><mo>⁡</mo><msub><mi>π</mi><mi>θ</mi></msub><mo stretchy="false">(</mo><msub><mi>y</mi><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub><mi mathvariant="normal">∣</mi><mi>x</mi><mo separator="true">,</mo><msub><mi>y</mi><mrow><mi>i</mi><mo separator="true">,</mo><mo>&lt;</mo><mi>t</mi></mrow></msub><mo stretchy="false">)</mo><mo fence="true">]</mo></mrow></mrow><annotation encoding="application/x-tex">\nabla_\theta\mathcal{J}_{GSPO} = \mathbb{E}\left[\frac{1}{G}\sum_{i=1}^G s_i(\theta)\hat{A}_i \cdot \frac{1}{|y_i|}\sum_{t=1}^{|y_i|} \nabla_\theta\log\pi_\theta(y_{i,t}|x,y_{i,&lt;t})\right]</annotation></semantics></math></span><p>每个 token 对更新的贡献只相差它们自身 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi mathvariant="normal">∇</mi><mi>log</mi><mo>⁡</mo><mi>π</mi></mrow><annotation encoding="application/x-tex">\nabla\log\pi</annotation></semantics></math></span> 的大小，不再有逐 token 的随机权重调制。论文把这称为消除 GRPO 的不稳定因素。</p>
<h2 id="证据三个实验事实">证据：三个实验事实</h2>
<p>论文的实验设置本身就值得注意：冷启动模型（Qwen3-30B-A3B-Base 经 SFT 得到），每个 rollout batch 切成 4 个 mini-batch 做梯度更新——这是标准的 off-policy 场景，也正是上一篇写 Clip-Higher 时说过的&quot;clip 真正开始工作&quot;的场景（比率才会偏离 1）。GRPO 基线的裁剪范围 0.2/0.27 是精心调过的，GSPO 用的是 3e-4 / 4e-4。</p>
<p>事实一：<strong>ε 差三个数量级，不是笔误，是平均的必然</strong>。token 级比率单个就能冲到 1.2；序列级比率是逐 token 对数比率的平均再取 exp，平均会把正负涨落抵消掉，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>s</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">s_i</annotation></semantics></math></span> 天然贴着 1 小幅波动。这笔账可以算细（以下为推算，论文没有报告这些统计量）：设一次 mini-batch 更新后，平均每个 token 的对数比率漂移标准差为 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>σ</mi></mrow><annotation encoding="application/x-tex">\sigma</annotation></semantics></math></span>（比如 5%），回答长 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>L</mi></mrow><annotation encoding="application/x-tex">L</annotation></semantics></math></span>，各 token 漂移近似独立，则平均后的漂移标准差缩到 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>σ</mi><mi mathvariant="normal">/</mi><msqrt><mi>L</mi></msqrt></mrow><annotation encoding="application/x-tex">\sigma/\sqrt{L}</annotation></semantics></math></span>——<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>L</mi><mo>=</mo><mn>2000</mn></mrow><annotation encoding="application/x-tex">L=2000</annotation></semantics></math></span> 时约为 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><mn>45</mn></mrow><annotation encoding="application/x-tex">1/45</annotation></semantics></math></span>。给这样一个几乎不动的比率配 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>±</mo><mn>0.2</mn></mrow><annotation encoding="application/x-tex">\pm 0.2</annotation></semantics></math></span> 的裁剪带，它永远也碰不到边，裁剪等于不存在，所以 GSPO 必须收到万分之几：<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>0.2</mn><mi mathvariant="normal">/</mi><mn>3</mn><mo>×</mo><msup><mn>10</mn><mrow><mo>−</mo><mn>4</mn></mrow></msup><mo>≈</mo><mn>667</mn></mrow><annotation encoding="application/x-tex">0.2 / 3\times10^{-4} \approx 667</annotation></semantics></math></span>，三个数量级的收窄就是这么来的。换个说法：3e-4 的容忍带对应平均每个 token 只允许约 0.03% 的对数漂移。还要交代假设的成色：实际训练中各 token 的漂移并不独立（一次更新会成片地抬高或压低相似上下文的概率），真实缩小倍数到不了 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msqrt><mi>L</mi></msqrt></mrow><annotation encoding="application/x-tex">\sqrt{L}</annotation></semantics></math></span>——但这只会让下面事实二的结论更强。</p>
<p>事实二：<strong>被裁的 token 多一百倍，效率反而更高</strong>。带窄了一千倍，被裁的反而多一百倍，听起来矛盾，两笔账乘起来就不矛盾了（以下推算同上）。第一笔：相对各自的波动幅度，带反而更窄了。波动只缩了约 45 倍，带缩了 667 倍，拿各自的波动当尺子量，GSPO 的带比 GRPO 窄约 15 倍（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msqrt><mi>L</mi></msqrt><mi mathvariant="normal">/</mi><mn>667</mn></mrow><annotation encoding="application/x-tex">\sqrt{L}/667</annotation></semantics></math></span>），<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>s</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">s_i</annotation></semantics></math></span> 出界比 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>w</mi><mi>t</mi></msub></mrow><annotation encoding="application/x-tex">w_t</annotation></semantics></math></span> 出界容易得多。代入具体数（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>σ</mi><mo>=</mo><mn>5</mn><mi mathvariant="normal">%</mi></mrow><annotation encoding="application/x-tex">\sigma=5\%</annotation></semantics></math></span>、漂移近似高斯）：GRPO 的 0.2 相当于 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>4</mn><mi>σ</mi></mrow><annotation encoding="application/x-tex">4\sigma</annotation></semantics></math></span>，单个 token 出界概率为万分之几；GSPO 的 3e-4 只相当于约 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>0.27</mn><mi>σ</mi></mrow><annotation encoding="application/x-tex">0.27\sigma</annotation></semantics></math></span>（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>0.0003</mn><mi mathvariant="normal">/</mi><mo stretchy="false">(</mo><mn>0.05</mn><mi mathvariant="normal">/</mi><mn>45</mn><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">0.0003/(0.05/45)</annotation></semantics></math></span>），每条 response 有过半概率整条出局。第二笔：出界按整条算账。GRPO 一个 token 出界只废它自己；GSPO 出界一次，整段几千 token 全部被剔除。两个因素相乘，被裁 token 总数就是 GRPO 的约一百倍——论文图 2 实测的裁剪比例差正好是约两个数量级，量级对得上。真正反直觉的是后半句：用于训练的 token 更少，训练效率和 benchmark 表现却更好（AIME'24 / LiveCodeBench / CodeForces 三条曲线都赢）。论文的解读：GRPO 的 token 级梯度估计本来就噪声大，被随机保留下来的那部分并不比被裁掉的部分更有用；GSPO 的序列级筛选提供了更可靠的学习信号——少而干净，胜过 多而脏。</p>
<p>事实三：<strong>MoE 不再需要 Routing Replay</strong>。序列似然 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>π</mi><mi>θ</mi></msub><mo stretchy="false">(</mo><msub><mi>y</mi><mi>i</mi></msub><mi mathvariant="normal">∣</mi><mi>x</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\pi_\theta(y_i|x)</annotation></semantics></math></span> 对路由抖动不敏感——10% 的专家换了，单个 token 的概率可能明显变化，但整条序列的似然（模型语言建模能力的体现）不会剧变。GSPO 只关心后者，所以直接正常算比率就能收敛，补丁的显存、通信开销全省了，模型也不再被旧路由束缚。</p>
<p>顺带一个基建红利（论文 §5.4）：工程上训练引擎（Megatron）和推理引擎（SGLang、vLLM）存在精度差异，GRPO 必须用训练引擎把旧策略的似然重算一遍才敢用；序列级似然对精度差异的容忍度高得多，GSPO 可以直接用推理引擎返回的似然做优化，省掉重算。对 partial rollout、多轮 RL、训推分离架构，这是实打实的吞吐红利。</p>
<h2 id="附裁剪范围-3e-44e-4-是怎么定的">附：裁剪范围 3e-4/4e-4 是怎么定的</h2>
<p>论文层面：没说。GSPO 论文只给了结果（左界 3e-4、右界 4e-4），没有选取过程，没有针对裁剪范围的消融。为什么是这个数而不是 1e-4 或 1e-3，外界无从得知；合理的猜测是作者在自家配置（Qwen3-30B-A3B 冷启动、每 batch 分 4 个 mini-batch）上试出来的，但这只是猜测。</p>
<p>原则层面（以下为推断，不是论文内容）：裁剪范围的工作是放过正常波动、拦住异常波动，所以它应当定在 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>s</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">s_i</annotation></semantics></math></span> 日常波动幅度的一个小倍数上：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>ε</mi><mo>≈</mo><mi>k</mi><mo>⋅</mo><mfrac><mi>σ</mi><msqrt><mi>L</mi></msqrt></mfrac></mrow><annotation encoding="application/x-tex">\varepsilon \approx k \cdot \frac{\sigma}{\sqrt{L}}</annotation></semantics></math></span><p>其中 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>σ</mi></mrow><annotation encoding="application/x-tex">\sigma</annotation></semantics></math></span> 是一次更新后逐 token 对数比率的漂移幅度，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>L</mi></mrow><annotation encoding="application/x-tex">L</annotation></semantics></math></span> 是回答长度，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>k</mi></mrow><annotation encoding="application/x-tex">k</annotation></semantics></math></span> 是想放过的波动倍数。把前面的演示数（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>σ</mi><mo>=</mo><mn>5</mn><mi mathvariant="normal">%</mi></mrow><annotation encoding="application/x-tex">\sigma=5\%</annotation></semantics></math></span>、<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>L</mi><mo>=</mo><mn>2000</mn></mrow><annotation encoding="application/x-tex">L=2000</annotation></semantics></math></span>）代入，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>σ</mi><mi mathvariant="normal">/</mi><msqrt><mi>L</mi></msqrt><mo>≈</mo><mn>0.0011</mn></mrow><annotation encoding="application/x-tex">\sigma/\sqrt{L} \approx 0.0011</annotation></semantics></math></span>，论文的 3e-4 相当于 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>k</mi><mo>≈</mo><mn>0.27</mn></mrow><annotation encoding="application/x-tex">k \approx 0.27</annotation></semantics></math></span>——只放过约四分之一的日常波动，是很严的筛选，与实测&quot;裁掉百分之几十 token&quot;互相印证。</p>
<p>这个框架同时说明 3e-4 不能照搬，它和三件事耦合：off-policy 程度（数据越陈旧 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>σ</mi></mrow><annotation encoding="application/x-tex">\sigma</annotation></semantics></math></span> 越大，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ε</mi></mrow><annotation encoding="application/x-tex">\varepsilon</annotation></semantics></math></span> 要相应放宽，否则样本全被裁光）；回答长度（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>L</mi></mrow><annotation encoding="application/x-tex">L</annotation></semantics></math></span> 越长平均后波动越小，同样的 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ε</mi></mrow><annotation encoding="application/x-tex">\varepsilon</annotation></semantics></math></span> 越严，32k 与 2k 的合适取值差约 4 倍）；想要的裁剪力度（最优裁剪比例没有公开数据，复现只能自己扫参）。换一套配置，这个数就要重新定。</p>
<h2 id="我的三个保留意见">我的三个保留意见</h2>
<p>一、<strong>&ldquo;单样本&quot;批评同样适用于 GSPO 自己</strong>。<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>s</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">s_i</annotation></semantics></math></span> 也是从单条样本 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>y</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">y_i</annotation></semantics></math></span> 算出的比率，同样没有 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>N</mi><mo>≫</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">N \gg 1</annotation></semantics></math></span> 的平均。所以 GSPO 的改进不宜理解为&quot;恢复了重要性采样的理论正确性&rdquo;——它没有，论文的 IS 论证是直觉性的，不是形式化的。它真正做的是三件事的合流：单位对齐（被裁的是整个&quot;坏样本&quot;而非随机 token）、方差归一（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mi mathvariant="normal">/</mi><mi mathvariant="normal">∣</mi><mi>y</mi><mi mathvariant="normal">∣</mi></mrow><annotation encoding="application/x-tex">1/|y|</annotation></semantics></math></span> 把数值范围压到统一）、等权梯度（消除逐 token 不等权的累积）。这三点都是工程论证，扎实，但不是定理。</p>
<p>二、<strong>几何平均是稀释器，好坏同体</strong>。一条一万 token 的 CoT 里，某个关键 token 的概率漂移 50%，对 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>s</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">s_i</annotation></semantics></math></span> 的贡献只有 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msup><mi>e</mi><mrow><mi>log</mi><mo>⁡</mo><mn>1.5</mn><mi mathvariant="normal">/</mi><mn>10000</mn></mrow></msup><mo>≈</mo><mn>1.00004</mn></mrow><annotation encoding="application/x-tex">e^{\log 1.5 / 10000} \approx 1.00004</annotation></semantics></math></span>，几乎不可见。对训练-推理引擎的精度噪声，稀释是特性（这正是基建红利的来源）；对&quot;关键 token 被策略更新改掉&quot;的检测，稀释是漏洞。GSPO 能正常工作，恰恰因为它配了万分之三量级的极窄裁剪带——靠平均漂移而不是单点漂移来做信任域判断。这套组合在超长 CoT 上是否会对某些失效模式失明（比如策略只在一小段推理上大幅偏离，平均后被放过），论文没有回答。</p>
<p>三、<strong>序列级裁剪放弃了&quot;部分正确&quot;样本的利用方式</strong>。一条 response 90% 的推理都对、最后一步算错，GSPO 把它整个用或整个扔。论文给的出路是 GSPO-token 变体：用 stop-gradient 把序列级权重 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>s</mi><mi>i</mi></msub></mrow><annotation encoding="application/x-tex">s_i</annotation></semantics></math></span>（只取数值、不回传梯度）与逐 token 项 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>π</mi><mi>θ</mi></msub><mi mathvariant="normal">/</mi><mrow><mi mathvariant="normal">s</mi><mi mathvariant="normal">g</mi></mrow><mo stretchy="false">[</mo><msub><mi>π</mi><mi>θ</mi></msub><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">\pi_\theta / \mathrm{sg}[\pi_\theta]</annotation></semantics></math></span> 拼起来，得到的目标、裁剪条件、理论梯度与 GSPO 完全等价，但允许逐 token 定制 advantage——为多轮 RL 和细粒度奖励留的口子。这条路线的另一端是 VAPO：干脆把 value model 请回来做 token 级信用分配。序列级与 token 级不是对错之争，而是&quot;信用分配粒度&quot;这个老问题的两种工业回答。</p>
<h2 id="和-clip-higher-的关系以及一个没人点破的细节">和 Clip-Higher 的关系，以及一个没人点破的细节</h2>
<p>上一篇写 DAPO 的 Clip-Higher：病灶同为 off-policy 下 token 级 clip 的结构性缺陷，DAPO 的解法是调边界（上界 0.2 抬到 0.28，放探索 token 一马），GSPO 的解法是换单位（整个 response 共用一个比率）。两者不互斥——Qwen 的实践就是 GSPO 叠加 Dr.GRPO 式的去归一化偏差修正。</p>
<p>还有个细节值得点破：GSPO 论文的裁剪范围 3e-4 / 4e-4 本身就是<strong>不对称的</strong>——右界比左界宽，给强化方向（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>A</mi><mo>^</mo></mover><mo>&gt;</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">\hat{A}&gt;0</annotation></semantics></math></span> 时比率向上突破）多留了 33% 的空间。这不就是序列级版本的 Clip-Higher 吗。论文没有讨论这个不对称的来历，但方向与 DAPO 的逻辑一致：好的样本，让它走得更远一点。两个团队在同一病灶上独立开出了同方向的药，这比任何单篇论文的消融都更能说明问题。</p>
<h2 id="未决问题">未决问题</h2>
<ul>
<li><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ε</mi></mrow><annotation encoding="application/x-tex">\varepsilon</annotation></semantics></math></span> 的选取方法本身没有公开：3e-4/4e-4 只有结果没有消融，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ε</mi><mo>≈</mo><mi>k</mi><mo>⋅</mo><mi>σ</mi><mi mathvariant="normal">/</mi><msqrt><mi>L</mi></msqrt></mrow><annotation encoding="application/x-tex">\varepsilon \approx k \cdot \sigma/\sqrt{L}</annotation></semantics></math></span> 只是本文的推断框架，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>k</mi></mrow><annotation encoding="application/x-tex">k</annotation></semantics></math></span> 的最优区间、与 clip-higher 式不对称边界叠加的效果，都需要公开复现；</li>
<li>几何平均的稀释效应在超长 CoT（32k token 以上）上是否会系统性放过&quot;局部剧变&quot;，需要构造性实验验证；</li>
<li>GSPO-token 在多轮 agentic RL 里与 turn 级奖励配合的实际效果，目前只有 Qwen 内部数据。</li>
</ul>
<hr>
<blockquote>
<p><strong>更新记录（2026-08-29）</strong>：据读者三轮问答回流增强——「证据」一节补入裁剪带算术的完整推导（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>σ</mi><mi mathvariant="normal">/</mi><msqrt><mi>L</mi></msqrt></mrow><annotation encoding="application/x-tex">\sigma/\sqrt{L}</annotation></semantics></math></span> 方差缩减、667 倍收窄、相对带窄约 15 倍、出界概率演算），新增「附：裁剪范围 3e-4/4e-4 是怎么定的」（论文未披露选取方法；推断框架与三个耦合），未决问题第一条随之改写。所有推演均为标注的推算，非论文原文内容。</p>
</blockquote>
<h2 id="参考来源">参考来源</h2>
<ul>
<li>GSPO 论文：<a href="https://arxiv.org/abs/2507.18071">arXiv:2507.18071v2</a>
，本文公式编号与实验数据均出自其 v2 版</li>
<li>RLHF Book 第 6 章（重要性采样背景、GSPO/CISPO 小节）：<a href="https://rlhfbook.com/">rlhfbook.com</a>
，<a href="https://github.com/natolambert/rlhf-book/blob/main/book/chapters/06-policy-gradients.md"><code>book/chapters/06-policy-gradients.md</code></a>
</li>
<li>hands-on-modern-rl 第 16.4 节（GRPO 改进家族对比；注意其 GSPO 公式遗漏长度归一化）：<a href="https://github.com/walkinglabs/hands-on-modern-rl/blob/main/docs/chapter18_grpo/grpo-family.md"><code>docs/chapter18_grpo/grpo-family.md</code></a>
</li>
<li>前篇：<a href="https://njx-njx.github.io/posts/dapo-clip-higher-entropy-collapse/">熵是怎么塌掉的：DAPO 的 Clip-Higher 在修什么</a>
</li>
</ul>
]]></content:encoded>
    </item>
    <item>
      <title>熵是怎么塌掉的：DAPO 的 Clip-Higher 在修什么</title>
      <link>https://njx-njx.github.io/posts/dapo-clip-higher-entropy-collapse/</link>
      <pubDate>Wed, 26 Aug 2026 14:30:00 +0800</pubDate>
      <guid>https://njx-njx.github.io/posts/dapo-clip-higher-entropy-collapse/</guid>
      <description>naive GRPO 训练中熵会快速坍缩。DAPO 只把裁剪上界从 0.2 抬到 0.28，背后是 PPO-Clip 在概率轴上的结构性不对称。</description>
      <content:encoded><![CDATA[<p>naive GRPO 复现 R1 时熵快速坍缩、组内样本趋同，DAPO 的 Clip-Higher 只把裁剪上界从 0.2 抬到 0.28。这一个数背后，是 PPO-Clip 在概率轴上的结构性不对称。本文拆解失效链条、机制、证据与边界。</p>
<blockquote>
<p>本文有配套的<a href="https://njx-njx.github.io/reports/dapo-clip-higher-entropy-collapse/">交互报告</a>
，含可下钻的公式拆解与消融数据图表。</p>
</blockquote>
<h2 id="一个训练现场">一个训练现场</h2>
<p>2025 年初，很多团队都在做同一件事：用 GRPO 复现 DeepSeek-R1 的训练。DAPO 论文（arXiv:2503.14476）报告了他们自己的起点——用 Qwen2.5-32B base model 跑 naive GRPO，AIME 2024 只拿到 30 分，而 DeepSeek 的 R1-Zero-Qwen-32B 是 47 分。</p>
<p>差距不是慢慢拉开的，而是一种很具体的死法：训练中 actor 模型的熵快速下降，同一道题采出来的一组回答越来越像，最后几乎一模一样。论文把这叫 <strong>entropy collapse（熵坍缩）</strong>。采样失去多样性，组内奖励趋同，GRPO 的 advantage 全部趋近于零，梯度信号自我灭绝。训练还在跑，但已经学不到东西了。</p>
<p>DAPO 给出的第一味药叫 <strong>Clip-Higher</strong>：把 PPO-Clip 的裁剪上界 ε 从默认的 0.2 抬到 0.28，下界保持 0.2 不动。改动只有一个数。为什么这一个数能拦住坍缩？答案藏在 PPO-Clip 一个很少被摊开讲的结构性质里。</p>
<h2 id="先把熵说清楚">先把&quot;熵&quot;说清楚</h2>
<p>整篇文章都绕着一个&quot;熵&quot;字转，先把它定义死。这里的熵就是信息论里那个熵，作用对象是<strong>模型每生成一个 token 时输出的、覆盖整个词表的概率分布</strong>：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>H</mi><mo>=</mo><mo>−</mo><munder><mo>∑</mo><mrow><mi>x</mi><mo>∈</mo><mtext>词表</mtext></mrow></munder><mi>p</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mi>log</mi><mo>⁡</mo><mi>p</mi><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">H = -\sum_{x \in \text{词表}} p(x) \log p(x)</annotation></semantics></math></span><p>分布越平（很多 token 概率差不多），熵越高，模型&quot;拿不定主意&quot;；分布越尖（一个 token 占 0.99，其余瓜分 0.01），熵越低，模型&quot;很确定&quot;。举个数值例子：假设词表只有 3 个 token，分布 [0.9, 0.05, 0.05] 的熵约 0.39 nat，均匀分布 [1/3, 1/3, 1/3] 的熵约 1.10 nat。从前者采样 10 次有 9 次拿到同一个 token，从后者采样结果均匀散开——<strong>熵就是&quot;采样多样性&quot;的数学度量</strong>。DAPO 论文监控的&quot;actor 模型的熵&quot;，就是 rollout 生成过程中这些逐步分布熵的平均值。</p>
<p>为什么它是 RL 训练的命门：GRPO 的全部训练信号来自组内奖励方差，而方差来自采样多样性。熵高，同一道题采 16 条回答各不相同，有对有错，advantage 非零；熵坍缩，16 条趋同，奖励全同，advantage 全零。</p>
<p>两个边界，别理解过头：一，<strong>熵不是越高越好</strong>——熵过高对应 gibberish、重复词等失控模式，论文只说熵要维持在&quot;合适区间&quot;，没给区间怎么定（本文末尾的未决问题之一）。二，<strong>别把熵和采样温度混为一谈</strong>：熵是分布的内在形状，温度是你怎么从分布里取；rollout 时用 temperature 1.0 这类参数才把熵兑现成多样性。Clip-Higher 影响的是前者——防止训练本身把分布越压越尖。</p>
<h2 id="先把-ppo-clip-的账算清楚">先把 PPO-Clip 的账算清楚</h2>
<p>PPO/GRPO 的目标函数，逐 token 看是：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>J</mi><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mo>=</mo><mi mathvariant="double-struck">E</mi><mrow><mo fence="true">[</mo><mi>min</mi><mo>⁡</mo><mrow><mo fence="true">(</mo><msub><mi>r</mi><mi>t</mi></msub><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mtext> </mtext><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>t</mi></msub><mo separator="true">,</mo><mtext> clip</mtext><mo stretchy="false">(</mo><msub><mi>r</mi><mi>t</mi></msub><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mo separator="true">,</mo><mtext> </mtext><mn>1</mn><mo>−</mo><mi>ε</mi><mo separator="true">,</mo><mtext> </mtext><mn>1</mn><mo>+</mo><mi>ε</mi><mo stretchy="false">)</mo><mtext> </mtext><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>t</mi></msub><mo fence="true">)</mo></mrow><mo fence="true">]</mo></mrow></mrow><annotation encoding="application/x-tex">J(\theta) = \mathbb{E}\left[\min\left(r_t(\theta)\,\hat{A}_t,\ \text{clip}(r_t(\theta),\ 1-\varepsilon,\ 1+\varepsilon)\,\hat{A}_t\right)\right]</annotation></semantics></math></span><p>符号逐个说清：</p>
<ul>
<li><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>r</mi><mi>t</mi></msub><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mo>=</mo><msub><mi>π</mi><mi>θ</mi></msub><mo stretchy="false">(</mo><msub><mi>o</mi><mi>t</mi></msub><mo>∣</mo><mi>q</mi><mo separator="true">,</mo><msub><mi>o</mi><mrow><mo>&lt;</mo><mi>t</mi></mrow></msub><mo stretchy="false">)</mo><mi mathvariant="normal">/</mi><msub><mi>π</mi><msub><mi>θ</mi><mrow><mi>o</mi><mi>l</mi><mi>d</mi></mrow></msub></msub><mo stretchy="false">(</mo><msub><mi>o</mi><mi>t</mi></msub><mo>∣</mo><mi>q</mi><mo separator="true">,</mo><msub><mi>o</mi><mrow><mo>&lt;</mo><mi>t</mi></mrow></msub><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">r_t(\theta) = \pi_\theta(o_t \mid q, o_{&lt;t}) / \pi_{\theta_{old}}(o_t \mid q, o_{&lt;t})</annotation></semantics></math></span>，<strong>重要性采样比率</strong>：当前策略对第 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>t</mi></mrow><annotation encoding="application/x-tex">t</annotation></semantics></math></span> 个 token 的概率，除以采样时旧策略的概率。<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mo>=</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">r=1</annotation></semantics></math></span> 表示策略没变。</li>
<li><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>t</mi></msub></mrow><annotation encoding="application/x-tex">\hat{A}_t</annotation></semantics></math></span>，<strong>advantage</strong>：这个 token 比平均水平好多少。GRPO 里它是组内归一化算出来的：<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mrow><mi>i</mi><mo separator="true">,</mo><mi>t</mi></mrow></msub><mo>=</mo><mo stretchy="false">(</mo><msub><mi>R</mi><mi>i</mi></msub><mo>−</mo><mtext>mean</mtext><mo stretchy="false">(</mo><mo stretchy="false">{</mo><mi>R</mi><mo stretchy="false">}</mo><mo stretchy="false">)</mo><mo stretchy="false">)</mo><mi mathvariant="normal">/</mi><mtext>std</mtext><mo stretchy="false">(</mo><mo stretchy="false">{</mo><mi>R</mi><mo stretchy="false">}</mo><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\hat{A}_{i,t} = (R_i - \text{mean}(\{R\})) / \text{std}(\{R\})</annotation></semantics></math></span>。</li>
<li><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ε</mi></mrow><annotation encoding="application/x-tex">\varepsilon</annotation></semantics></math></span>，<strong>裁剪范围</strong>：比率允许偏离 1 的幅度，绝大多数实现的默认值是 0.2——这个默认值来自 2017 年 PPO 原论文的 Atari 和机器人控制实验。</li>
</ul>
<p>advantage 从哪来，PPO 和 GRPO 是两条路，读材料时别混：</p>
<ul>
<li><strong>PPO</strong>：靠一个学出来的价值函数（critic），用 GAE 逐 token 估计：<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mover accent="true"><mi>A</mi><mo>^</mo></mover><mi>t</mi></msub><mo>=</mo><msub><mo>∑</mo><mi>l</mi></msub><mo stretchy="false">(</mo><mi>γ</mi><mi>λ</mi><msup><mo stretchy="false">)</mo><mi>l</mi></msup><msub><mi>δ</mi><mrow><mi>t</mi><mo>+</mo><mi>l</mi></mrow></msub></mrow><annotation encoding="application/x-tex">\hat{A}_t = \sum_{l}(\gamma\lambda)^l \delta_{t+l}</annotation></semantics></math></span>，其中 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>δ</mi><mi>t</mi></msub><mo>=</mo><msub><mi>r</mi><mi>t</mi></msub><mo>+</mo><mi>γ</mi><mi>V</mi><mo stretchy="false">(</mo><msub><mi>s</mi><mrow><mi>t</mi><mo>+</mo><mn>1</mn></mrow></msub><mo stretchy="false">)</mo><mo>−</mo><mi>V</mi><mo stretchy="false">(</mo><msub><mi>s</mi><mi>t</mi></msub><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">\delta_t = r_t + \gamma V(s_{t+1}) - V(s_t)</annotation></semantics></math></span>。critic 准，advantage 方差就低；critic 歪，整个训练跟着歪。</li>
<li><strong>GRPO</strong>：不要 critic，对同一道题采 G 条回答，拿组内奖励做归一化。本质是用组内均值当 baseline——这是 REINFORCE 的方差缩减技巧，只不过基线不用学，直接拿同组样本算。</li>
</ul>
<p>GRPO 这条路有三个直接后果，后面都会用到。一，<strong>整组同奖则全零</strong>：G 条全对或全错时，mean 等于每条自己的奖励，advantage 全是 0，这道题不贡献任何梯度。二，<strong>除 std 有隐含加权</strong>：std 小的组（比如 16 条只对 1 条）会被归一化放大权重，Dr.GRPO 批评的难度偏置就来自这一项。三，<strong>advantage 按整条回答算，同一条里每个 token 共用</strong>：答错的回答里前 80% 推理步骤可能是对的，但它们和最后算错那一步吃同一个负 advantage——GRPO 本身没有 token 级信用分配。</p>
<p><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>min</mi><mo>⁡</mo></mrow><annotation encoding="application/x-tex">\min</annotation></semantics></math></span> 的行为取决于 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>A</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">\hat{A}</annotation></semantics></math></span> 的符号，这是理解一切的钥匙：</p>
<ul>
<li><strong><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>A</mi><mo>^</mo></mover><mo>&gt;</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">\hat{A} &gt; 0</annotation></semantics></math></span>（好 token，要强化）</strong>：当 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mo>&gt;</mo><mn>1</mn><mo>+</mo><mi>ε</mi></mrow><annotation encoding="application/x-tex">r &gt; 1+\varepsilon</annotation></semantics></math></span>，clipped 支被选中，目标函数变成常数，<strong>梯度为零</strong>。也就是说，每一步更新最多把一个 token 的概率抬到采样时的 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mo>+</mo><mi>ε</mi></mrow><annotation encoding="application/x-tex">1+\varepsilon</annotation></semantics></math></span> 倍，再往上就不给梯度了。</li>
<li><strong><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>A</mi><mo>^</mo></mover><mo>&lt;</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">\hat{A} &lt; 0</annotation></semantics></math></span>（坏 token，要压制）</strong>：对称地，每步最多把概率压到采样时的 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mo>−</mo><mi>ε</mi></mrow><annotation encoding="application/x-tex">1-\varepsilon</annotation></semantics></math></span> 倍。</li>
</ul>
<p>这里有个容易误读的点，值得展开：<strong>clip 对每种符号的 advantage 都是单边的</strong>。看 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>A</mi><mo>^</mo></mover><mo>&gt;</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">\hat{A} &gt; 0</annotation></semantics></math></span> 且 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mo>&lt;</mo><mn>1</mn><mo>−</mo><mi>ε</mi></mrow><annotation encoding="application/x-tex">r &lt; 1-\varepsilon</annotation></semantics></math></span> 的情形：<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>min</mi><mo>⁡</mo></mrow><annotation encoding="application/x-tex">\min</annotation></semantics></math></span> 选中的仍然是 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mo>⋅</mo><mover accent="true"><mi>A</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">r \cdot \hat{A}</annotation></semantics></math></span>（因为它更小）。目标函数的值虽然小，但<strong>梯度是活的</strong>——<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>d</mi><mi>J</mi><mi mathvariant="normal">/</mi><mi>d</mi><mi>π</mi><mo>&gt;</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">dJ/d\pi &gt; 0</annotation></semantics></math></span>，优化器照样以全额斜率 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>A</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">\hat{A}</annotation></semantics></math></span> 把这个好 token 的概率往回拉。值小不等于抑制：<strong>值是结果，梯度才是动作</strong>。<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>min</mi><mo>⁡</mo></mrow><annotation encoding="application/x-tex">\min</annotation></semantics></math></span> 的作用是<strong>撤掉激励</strong>，从来不是<strong>施加反向激励</strong>。所以完整结构是：好 token 只封顶上涨激励（右侧平台），坏 token 只封顶压制激励（左侧平台），反方向的纠偏永远满梯度放行。</p>
<p>交互报告里那张核心机制图就是按这个逻辑画的，读法：横轴是比率 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi></mrow><annotation encoding="application/x-tex">r</annotation></semantics></math></span>，纵轴是这个 token 对目标函数的贡献 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>J</mi><mo stretchy="false">(</mo><mi>r</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">J(r)</annotation></semantics></math></span>，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>A</mi><mo>^</mo></mover></mrow><annotation encoding="application/x-tex">\hat{A}</annotation></semantics></math></span> 归一化为 1。<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mo>&lt;</mo><mn>1</mn><mo>+</mo><mi>ε</mi></mrow><annotation encoding="application/x-tex">r &lt; 1+\varepsilon</annotation></semantics></math></span> 时 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>J</mi><mo stretchy="false">(</mo><mi>r</mi><mo stretchy="false">)</mo><mo>=</mo><mi>r</mi></mrow><annotation encoding="application/x-tex">J(r)=r</annotation></semantics></math></span> 是一条上升的直线（梯度活着），<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi><mo>&gt;</mo><mn>1</mn><mo>+</mo><mi>ε</mi></mrow><annotation encoding="application/x-tex">r &gt; 1+\varepsilon</annotation></semantics></math></span> 后是水平平台（梯度到此为止）。</p>
<p>RLHF Book 第 6 章还特别提醒：clip 不是一直在工作。只有当比率真的出界、且 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>min</mi><mo>⁡</mo></mrow><annotation encoding="application/x-tex">\min</annotation></semantics></math></span> 恰好选中 clipped 支时，梯度才被掐断。裁剪分数（clip fraction）就是监控这件事的指标。记住这一点，后面会用上。</p>
<h2 id="对称裁剪不对称的效果">对称裁剪，不对称的效果</h2>
<p>现在做一道算术题。设 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>ε</mi><mo>=</mo><mn>0.2</mn></mrow><annotation encoding="application/x-tex">\varepsilon = 0.2</annotation></semantics></math></span>，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>A</mi><mo>^</mo></mover><mo>&gt;</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">\hat{A} &gt; 0</annotation></semantics></math></span>，看两个 token：</p>
<ul>
<li>一个 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>π</mi><msub><mi>θ</mi><mrow><mi>o</mi><mi>l</mi><mi>d</mi></mrow></msub></msub><mo>=</mo><mn>0.9</mn></mrow><annotation encoding="application/x-tex">\pi_{\theta_{old}} = 0.9</annotation></semantics></math></span> 的 token：概率上界是 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>0.9</mn><mo>×</mo><mn>1.2</mn><mo>=</mo><mn>1.08</mn></mrow><annotation encoding="application/x-tex">0.9 \times 1.2 = 1.08</annotation></semantics></math></span>。概率不可能超过 1，所以<strong>它实际上不受限</strong>——一轮就能从 0.9 推到 0.99 以上。</li>
<li>一个 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>π</mi><msub><mi>θ</mi><mrow><mi>o</mi><mi>l</mi><mi>d</mi></mrow></msub></msub><mo>=</mo><mn>0.01</mn></mrow><annotation encoding="application/x-tex">\pi_{\theta_{old}} = 0.01</annotation></semantics></math></span> 的 token：上界是 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>0.01</mn><mo>×</mo><mn>1.2</mn><mo>=</mo><mn>0.012</mn></mrow><annotation encoding="application/x-tex">0.01 \times 1.2 = 0.012</annotation></semantics></math></span>。<strong>绝对增量 0.002</strong>，几乎原地不动。</li>
</ul>
<p>先把&quot;一轮&quot;说准确，它指一个&quot;采样→更新&quot;循环：采完样 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>π</mi><msub><mi>θ</mi><mrow><mi>o</mi><mi>l</mi><mi>d</mi></mrow></msub></msub></mrow><annotation encoding="application/x-tex">\pi_{\theta_{old}}</annotation></semantics></math></span> 冻结成快照，之后在这批数据上跑多次梯度更新（DAPO 是 16 次，论文 §4.1），这期间 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>π</mi><mi>θ</mi></msub></mrow><annotation encoding="application/x-tex">\pi_\theta</annotation></semantics></math></span> 逐渐偏离快照，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi></mrow><annotation encoding="application/x-tex">r</annotation></semantics></math></span> 从 1 开始漂移；一旦 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi></mrow><annotation encoding="application/x-tex">r</annotation></semantics></math></span> 越过 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>1</mn><mo>+</mo><mi>ε</mi></mrow><annotation encoding="application/x-tex">1+\varepsilon</annotation></semantics></math></span>，这个 token 的梯度就断了，本轮剩下的更新不再推它。所以&quot;上界 0.012&quot;的准确含义是<strong>激励消失点</strong>，不是硬钳制——步长迈大了概率可能一步冲过去，只是冲过去之后激励归零，没人继续推，也没人拉回来。</p>
<p>而预算是<strong>每轮刷新</strong>的：下一轮重新采样，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>π</mi><msub><mi>θ</mi><mrow><mi>o</mi><mi>l</mi><mi>d</mi></mrow></msub></msub></mrow><annotation encoding="application/x-tex">\pi_{\theta_{old}}</annotation></semantics></math></span> 更新，<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>r</mi></mrow><annotation encoding="application/x-tex">r</annotation></semantics></math></span> 重置为 1，又拿到一份 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>×</mo><mn>1.2</mn></mrow><annotation encoding="application/x-tex">\times 1.2</annotation></semantics></math></span> 预算。所以低概率 token 的成长路线是乘法的：<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>0.01</mn><mo>→</mo><mn>0.012</mn><mo>→</mo><mn>0.0144</mn><mo>→</mo><mo>⋯</mo></mrow><annotation encoding="application/x-tex">0.01 \to 0.012 \to 0.0144 \to \cdots</annotation></semantics></math></span>，比率上是指数增长，前半段绝对值却爬得非常慢；高概率 token 一两轮就顶到 1.0 饱和。压制方向对称但更狠：<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mover accent="true"><mi>A</mi><mo>^</mo></mover><mo>&lt;</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">\hat{A} &lt; 0</annotation></semantics></math></span> 时每轮最多砍到 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>×</mo><mn>0.8</mn></mrow><annotation encoding="application/x-tex">\times 0.8</annotation></semantics></math></span>，五轮后剩 0.33，低概率 token 很快被打到接近 0——<strong>下行的乘法衰减比上行的乘法增长快得多</strong>。</p>
<p>问题就出在这里：**裁剪以&quot;比率&quot;为刻度，但学习效果发生在&quot;概率&quot;轴上。**同样容忍 20% 的比率变化，高概率 token 拿到的是绝对概率上接近 0.2 的空间，低概率 token 拿到的是 0.002。两种 token 的可动范围差了快一百倍。</p>
<p>而 RL 里的&quot;探索&quot;恰恰由低概率 token 承载——那些当前策略不太倾向选、但可能通向新解法的 token。DAPO 的实测印证了这一点：训练中真正被上界裁住的 token，平均概率小于 0.2（论文图 3a）。换句话说，<strong>被裁剪机制反复按住头的，正是探索 token</strong>；exploitation token（模型已经很确定的 token）几乎从不被约束。</p>
<p>长 CoT 场景把这个偏差放大了：一条推理链几千个 token，关键转折点上的探索 token 每轮只能挪 0.2%，还没等它长起来，分布其他部分已经进一步尖锐化了。</p>
<h2 id="坍缩的闭环">坍缩的闭环</h2>
<p>把上面这个微观偏差放进 GRPO 的训练动力学里，就得到一条完整的失效链：</p>
<ol>
<li>探索 token 概率长不起来，高概率 token 越长越高，分布变尖，<strong>熵下降</strong>；</li>
<li>分布变尖意味着同一道题采一组（比如 16 条）回答<strong>越来越像</strong>；</li>
<li>GRPO 的 advantage 是组内归一化算的，组内奖励趋同时 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mtext>std</mtext><mo>→</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">\text{std} \to 0</annotation></semantics></math></span>，所有 advantage 趋近于零；</li>
<li><strong>梯度信号消失</strong>，模型失去改进方向，只能继续强化已经确定的模式——回到第 1 步。</li>
</ol>
<p>RLVR 场景里这个循环尤其致命，因为它的全部训练信号就是组内奖励的方差。奖励是规则的 0/1（答对 +1，答错 -1），没有奖励模型提供连续信号。多样性一旦枯竭，信号源就断了。熵坍缩不是&quot;一个监控指标不好看&quot;，而是训练在烧掉自己的燃料。</p>
<p>这也解释了 DAPO 四个技巧的顺序感：Clip-Higher 防坍缩，Dynamic Sampling（过滤掉全对或全错的 prompt）是在坍缩已经造成零梯度组时止血。一个治本，一个治标，论文把 Clip-Higher 放在第一节。</p>
<h2 id="clip-higher只抬上界是有讲究的">Clip-Higher：只抬上界，是有讲究的</h2>
<p>Clip-Higher 的做法是把对称裁剪拆成两个超参数：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mtext>clip</mtext><mrow><mo fence="true">(</mo><msub><mi>r</mi><mi>t</mi></msub><mo stretchy="false">(</mo><mi>θ</mi><mo stretchy="false">)</mo><mo separator="true">,</mo><mtext> </mtext><mn>1</mn><mo>−</mo><msub><mi>ε</mi><mrow><mi>l</mi><mi>o</mi><mi>w</mi></mrow></msub><mo separator="true">,</mo><mtext> </mtext><mn>1</mn><mo>+</mo><msub><mi>ε</mi><mrow><mi>h</mi><mi>i</mi><mi>g</mi><mi>h</mi></mrow></msub><mo fence="true">)</mo></mrow><mo separator="true">,</mo><mspace width="1em"/><msub><mi>ε</mi><mrow><mi>l</mi><mi>o</mi><mi>w</mi></mrow></msub><mo>=</mo><mn>0.2</mn><mo separator="true">,</mo><mtext> </mtext><msub><mi>ε</mi><mrow><mi>h</mi><mi>i</mi><mi>g</mi><mi>h</mi></mrow></msub><mo>=</mo><mn>0.28</mn></mrow><annotation encoding="application/x-tex">\text{clip}\left(r_t(\theta),\ 1-\varepsilon_{low},\ 1+\varepsilon_{high}\right),\quad \varepsilon_{low}=0.2,\ \varepsilon_{high}=0.28</annotation></semantics></math></span><p>上界从 1.2 抬到 1.28，低概率探索 token 的单轮上涨空间从 +20% 变成 +28%，配合多轮预算的乘法积累，效果可观。</p>
<p>值得问的是：为什么不动下界？论文说得很直白——<strong><span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>ε</mi><mrow><mi>l</mi><mi>o</mi><mi>w</mi></mrow></msub></mrow><annotation encoding="application/x-tex">\varepsilon_{low}</annotation></semantics></math></span> 如果放宽（比如允许压到 0.6 倍），负 advantage 的梯度会以同样的比率逻辑把低概率 token 直接压到接近 0</strong>，采样空间里这些 token 等于被删掉了，坍缩只会来得更快。前面算过乘法衰减的账：下行方向本来就比上行快，压制方向的裁剪反而要收紧，不能放松。</p>
<p>所以 Clip-Higher 不是&quot;把探索空间的门开大一点&quot;这种模糊操作，它是一次精确的不对称手术：<strong>上涨方向松绑，下跌方向保持警惕</strong>。</p>
<p>效果上，论文图 2 显示应用 Clip-Higher 后熵曲线明显回升、AIME 准确率同步上升。消融链（Qwen2.5-32B，AIME 2024 avg@32）：</p>
<table>
  <thead>
      <tr>
          <th>配置</th>
          <th>AIME 分数</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td>Naive GRPO</td>
          <td>30</td>
      </tr>
      <tr>
          <td>+ Overlong Filtering</td>
          <td>36</td>
      </tr>
      <tr>
          <td>+ Clip-Higher</td>
          <td>38</td>
      </tr>
      <tr>
          <td>+ Soft Overlong Punishment</td>
          <td>41</td>
      </tr>
      <tr>
          <td>+ Token-level Loss</td>
          <td>42</td>
      </tr>
      <tr>
          <td>+ Dynamic Sampling（完整 DAPO）</td>
          <td>50</td>
      </tr>
  </tbody>
</table>
<p>要诚实地说：Clip-Higher 单项只贡献了 +2 分，不是链上最大的（Overlong Filtering +6，最后加 Dynamic Sampling +8）。但它的角色不在加分——它修的是&quot;训练能不能继续 scale&quot;的失速点。熵塌了，后面三个技巧全都无从发挥。</p>
<h2 id="两个少有人摊开讲的前提">两个少有人摊开讲的前提</h2>
<p><strong>前提一：clip 只在 off-policy 时才激活。</strong> RLHF Book 第 6 章指出，语言模型的 RL 实践里很多算法每个 batch 只跑一步梯度更新——此时比率恒等于 1，clip 永远不触发，真正起正则作用的是 KL 惩罚。而 DAPO 每个 rollout 跑 16 个梯度步（mini-batch 512，论文 §4.1），策略在 batch 内多次更新，比率才会偏离 1，clip 才真的开始工作。<strong>所以 Clip-Higher 这个旋钮的价值，和训练的 off-policy 程度是耦合的</strong>：如果你是严格的单步 on-policy 训练，这个旋钮根本不存在。反过来，异步 RL（rollout 和训练重叠、样本天然 off-policy）才是它发挥作用的土壤。</p>
<p><strong>前提二：DAPO 同时去掉了 KL 项。</strong> 先把 KL 惩罚本身说清楚。KL 散度衡量当前策略 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>π</mi><mi>θ</mi></msub></mrow><annotation encoding="application/x-tex">\pi_\theta</annotation></semantics></math></span> 和参考策略 <span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><msub><mi>π</mi><mrow><mi>r</mi><mi>e</mi><mi>f</mi></mrow></msub></mrow><annotation encoding="application/x-tex">\pi_{ref}</annotation></semantics></math></span>（通常是冻结的 SFT/base 模型）差多远：</p>
<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><msub><mi>D</mi><mrow><mi>K</mi><mi>L</mi></mrow></msub><mo stretchy="false">(</mo><msub><mi>π</mi><mi>θ</mi></msub><mi mathvariant="normal">∥</mi><msub><mi>π</mi><mrow><mi>r</mi><mi>e</mi><mi>f</mi></mrow></msub><mo stretchy="false">)</mo><mo>=</mo><msub><mi mathvariant="double-struck">E</mi><mrow><mi>x</mi><mo>∼</mo><msub><mi>π</mi><mi>θ</mi></msub></mrow></msub><mrow><mo fence="true">[</mo><mi>log</mi><mo>⁡</mo><msub><mi>π</mi><mi>θ</mi></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo>−</mo><mi>log</mi><mo>⁡</mo><msub><mi>π</mi><mrow><mi>r</mi><mi>e</mi><mi>f</mi></mrow></msub><mo stretchy="false">(</mo><mi>x</mi><mo stretchy="false">)</mo><mo fence="true">]</mo></mrow></mrow><annotation encoding="application/x-tex">D_{KL}(\pi_\theta \| \pi_{ref}) = \mathbb{E}_{x \sim \pi_\theta}\left[\log \pi_\theta(x) - \log \pi_{ref}(x)\right]</annotation></semantics></math></span><p>经典 RLHF 把它作为惩罚项放进目标函数（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo>−</mo><mi>β</mi><msub><mi>D</mi><mrow><mi>K</mi><mi>L</mi></mrow></msub></mrow><annotation encoding="application/x-tex">-\beta D_{KL}</annotation></semantics></math></span>），动机有二：一是<strong>防 reward hacking</strong>——奖励模型是有漏洞的代理，策略跑得够偏就能找到 RM 没见过、瞎打高分的输出，KL 把搜索拴在 RM 见过的分布范围内；二是保住初始模型的语言能力，防止格式崩坏。工程代价是显存里要常驻一个冻结参考模型，每个 token 算两边的前向。</p>
<p>DAPO 把它整个去掉了（<span class="katex"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>β</mi><mo>=</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">\beta=0</annotation></semantics></math></span>，参考模型不用加载），论文 §2.3 的理由：KL 惩罚的初衷是&quot;对齐但不要偏离初始模型太远&quot;，而长 CoT 训练的目的<strong>恰恰是大幅偏离初始模型</strong>——base 模型本来不会写长思维链、不会自我反思，这些行为全靠 RL 重塑分布，拴着锚等于不让船开。还有一个没明说的配套条件：RLVR 的奖励是规则判定，<strong>没有 RM 可以 hack</strong>，KL 防 hacking 的那一半动机直接消失。</p>
<p>把两个前提合起来看，能看出 DAPO 的一次隐含换挡：经典配置里防漂移靠 KL——<strong>绝对锚</strong>，不许离初始模型太远；DAPO 去掉 KL 后只剩 clip——<strong>相对锚</strong>，每步不许离上一步太远，但允许持续走远。信任区域的角色从一个锚换到了另一个锚。同时注意去 KL 和抬上界方向一致——都在给探索松绑：KL 惩罚是逐 token 把分布往参考模型拉，去掉它，策略才敢往新区域走。论文没有明说两者是协同设计，这是我的推断；但从&quot;防坍缩&quot;的目标看，它们确实是同一战壕的。当然，锚拆了不是没有代价：训练失控时没有任何东西把模型拉回来，所以 DAPO 才那么依赖监控仪表盘（熵、长度、平均概率），也才需要 clip、动态采样这些替代性稳定器。</p>
<h2 id="实现层对照">实现层对照</h2>
<p>纸面机制之外，我核对了三个实现，细节基本对齐：</p>
<ul>
<li><strong>rlhf-book</strong> 的 <code>code/policy_gradients/loss.py</code> 里 <code>DAPOLoss</code>：解耦 clip（<code>clip_eps_lo=0.2 / clip_eps_hi=0.28</code>，见 <code>configs/dapo.yaml</code>），token-level 损失归一化（损失求和后除以全 batch 的有效 token 总数，而不是 GRPO 原来的逐序列平均再平均），不加 KL。教学和论文一致。</li>
<li><strong>verl 生产实现</strong>（<code>verl/trainer/ppo/core_algos.py</code>）：<code>clip_ratio_low</code> / <code>clip_ratio_high</code> 是独立配置项，未设置时回落到对称的 <code>clip_ratio</code>——也就是说 DAPO 的非对称裁剪已经是一等公民，但默认行为仍是经典 PPO。文件里还有 dual-clip 的 <code>clip_ratio_c=3.0</code>，防的是负 advantage 样本的比率爆炸，和 Clip-Higher 解决的是不同方向的问题。</li>
<li><strong>行业佐证</strong>：MiniMax 的 CISPO 同样允许非对称裁剪界；VAPO 直接沿用了 clip-higher。这个 insight 已经不是 DAPO 独有，而是长 CoT RL 的工程共识。</li>
</ul>
<p>也提一个甄别案例：中文课程 hands-on-modern-rl 在讲 Clip-Higher 时，说&quot;0.8 的下限意味着低概率动作最多被降到 0.008，几乎被彻底压制&quot;，把下界的压制作用和上界的上涨空间混在一起讲，容易让读者以为改的是下界。论文的实际机制恰恰相反：改的是上界；下界保持 0.2，正是因为再放宽会把低概率 token 压死。该课程自声明 AI 协助生成、尚未全面审稿，读二手材料务必回对原文——这次回对就抓到了一处。</p>
<h2 id="补遗rlvr-和-grpo-不是同一层的东西">补遗：RLVR 和 GRPO 不是同一层的东西</h2>
<p>读这篇的时候很容易把 RLVR 和 GRPO 连着念，其实它们是两根正交的轴：</p>
<table>
  <thead>
      <tr>
          <th></th>
          <th>回答的问题</th>
          <th>属于哪一层</th>
          <th>同层的其他选项</th>
      </tr>
  </thead>
  <tbody>
      <tr>
          <td><strong>RLVR</strong></td>
          <td>奖励从哪来？</td>
          <td>奖励来源 / 训练范式</td>
          <td>人类偏好（RLHF 原点）、学出来的奖励模型、可验证规则奖励</td>
      </tr>
      <tr>
          <td><strong>GRPO</strong></td>
          <td>拿到奖励后怎么更新模型？</td>
          <td>策略优化算法</td>
          <td>REINFORCE、PPO、DAPO、GSPO</td>
      </tr>
  </tbody>
</table>
<p>两者可以自由组合：RLVR + PPO 完全可以（VAPO 就是 value 路线跑可验证奖励）；RM + GRPO 也成立（GRPO 出自 DeepSeekMath 时并不绑定规则奖励，组内归一化对任何标量奖励都适用）。RLVR + GRPO 之所以成为主流配方，是互相成就：RLVR 的规则奖励便宜、客观、不怕 reward hacking，但它是稀疏的 0/1 信号；GRPO 的组内归一化恰好适合 0/1——同一道题采一组，对错比例天然形成 baseline，不需要再训一个 critic 去估计&quot;这条推理值多少分&quot;。反过来，PPO 的 critic 在稀疏 0/1 奖励加几千 token 长序列上很难训准。</p>
<p>放回本文的失效链里，两者的分工也清楚：RLVR 决定<strong>信号源有多脆</strong>（0/1 奖励只有全对、全错、有对有错三种形态，前两种直接零梯度），GRPO 决定<strong>信号依赖什么</strong>（组内奖励方差，也就是采样多样性）。DAPO 的四个技巧全是在 GRPO 这个算法层打补丁，没动 RLVR 的奖励来源；另一个方向的改进——给 RLVR 造更多可验证任务、把奖励做细到过程级（PRM）——那是在奖励范式层动刀子，和算法层的补丁是正交的两条路。</p>
<h2 id="我的判断与未决问题">我的判断与未决问题</h2>
<p><strong>判断</strong>：Clip-Higher 的本质，是把&quot;探索节奏&quot;从一个历史遗留的隐式默认值（ε=0.2，来自 2017 年连续控制场景）变成面向长 CoT 推理的显式旋钮。0.28 没有理论推导，是经验值，但它背后的诊断框架——比率裁剪在概率轴上的不对称——是有普适解释力的。以后看到任何&quot;训练好好的突然熵崩了&quot;，先查被 clip 按住的 token 的概率分布，应该成为标准动作。</p>
<p><strong>未决问题</strong>，按我在乎的程度排序：</p>
<ol>
<li><strong>熵没有目标区间。</strong> 论文的经验结论是&quot;熵缓慢上升有利&quot;，但同样承认熵过高对应 gibberish 和重复。那么 ε_high 是否应该跟着熵曲线自适应调整，而不是固定 0.28？我没看到有人系统做过。</li>
<li><strong>消融的顺序效应。</strong> 表 1 是累加链，Clip-Higher 排在 Overlong Filtering 之后测，+2 分是在已有改动的底座上量的。它干净的独立贡献是多少，未知。</li>
<li><strong>和序列级裁剪的兼容性。</strong> GSPO 把重要性采样比率提到序列级（解决 MoE 模型 token 级比率的数值不稳），那时&quot;抬 token 级上界&quot;的逻辑还成不成立？<a href="https://njx-njx.github.io/posts/gspo-sequence-level-importance-sampling/">GSPO 那篇</a>
专门拆了这个问题。</li>
<li><strong>异步训练下的稳健性。</strong> 异步 RL 的比率分布漂移更大、更偏，固定 0.28 在不同 off-policy 程度下是否都合适，论文没有覆盖。</li>
</ol>
<h2 id="参考来源">参考来源</h2>
<ul>
<li>DAPO 论文：<a href="https://arxiv.org/abs/2503.14476">arXiv:2503.14476</a>
（机制、数值例子、消融数据、训练细节的一手来源）</li>
<li>RLHF Book 第 6 章及配套实现：<a href="https://github.com/natolambert/rlhf-book/blob/main/code/policy_gradients/loss.py"><code>code/policy_gradients/loss.py</code></a>
、<a href="https://github.com/natolambert/rlhf-book/blob/main/code/policy_gradients/configs/dapo.yaml"><code>code/policy_gradients/configs/dapo.yaml</code></a>
（<a href="https://github.com/natolambert/rlhf-book">natolambert/rlhf-book</a>
）</li>
<li>verl 生产实现：<a href="https://github.com/volcengine/verl/blob/main/verl/trainer/ppo/core_algos.py"><code>verl/trainer/ppo/core_algos.py</code></a>
（clip_ratio_low/high、dual-clip）</li>
<li>B 站视频：<a href="https://www.bilibili.com/video/BV1LgXbY5EFD">GRPO loss/objective 分析及 biases 分析（DAPO，Dr. GRPO），BV1LgXbY5EFD</a>
（注意：该集主要讲动态采样与长度 bias、Dr. GRPO 的标准差问题，Clip-Higher 着墨很少）</li>
<li>hands-on-modern-rl <a href="https://github.com/walkinglabs/hands-on-modern-rl/blob/main/docs/chapter18_grpo/deepseek-dapo.md"><code>docs/chapter18_grpo/deepseek-dapo.md</code></a>
（中文讲解，Clip-Higher 一节有表述混乱，正文已标注）</li>
<li>Notion「共同语言」笔记页（GRPO 三轮工业改造线：DAPO / Dr.GRPO / GSPO）</li>
</ul>
<hr>
<blockquote>
<p>更新记录：2026-08-26 初版发布；同日根据读者问答补充——&ldquo;熵&quot;的定义与边界、PPO 与 GRPO 两种 advantage 来源及其后果、min 的单边裁剪读法（值 vs 梯度）、&ldquo;单轮预算&quot;的准确含义与乘法积累、RLVR 与 GRPO 的分层、KL 惩罚详解与绝对锚/相对锚的换挡。</p>
</blockquote>
]]></content:encoded>
    </item>
  </channel>
</rss>
