Score Centering: Drift, Policy Gradients, and the Off-Policy Debate

Imagine rewarding every generated answer with exactly one point. There is no better answer to discover. Should reinforcement learning still systematically change the model? If the model generating answers and the model computing gradients disagree, the answer can be yes.

This is the entry point to Score Centering Stabilizes Off-policy Reinforcement Learning, by Martin Marek and Max Ryabinin. We will derive the mechanism ourselves, first with two possible answers, then with an entire generated sequence. The crucial distinction is between removing an unwanted average push, recovering a particular target gradient, and making training work better. They are three different claims.

The discussion starts from Nan Jiang’s post. The complete reply chain was not accessible during preparation; the later exchange is reconstructed from the supplied discussion, not presented as a verbatim transcript or verified chronology. Mathematical counterexamples and judgments below are this article’s analysis.

想象我们给每个生成的回答都奖励 1 分。既然所有回答一样好,就没有需要模型学习的偏好。此时 reinforcement learning 还应该系统性地改变模型吗?如果负责生成回答的模型与负责计算梯度的模型不一致,答案竟然可能是“会”。

这是理解 Martin Marek 与 Max Ryabinin 的 Score Centering Stabilizes Off-policy Reinforcement Learning 的入口。我们会从只有两个答案的小例子开始,自己推导发生了什么,再推广到完整生成序列。全文最重要的区分是:消除一种不需要的平均推力、恢复指定目标的正确梯度、让训练实际表现更好,是三个不同的命题。

来源说明:讨论入口是 Nan Jiang 的原帖。写作时无法完整读取回复链,后续交锋根据提供的讨论记录整理,不作为逐字实录或已核实的发言时间线。下文的数学反例与观点判断是本文的分析。

1. One Training Loop, Two Distributions

1.1 Who Generates, and Who Learns?

A policy is a rule that assigns probabilities to possible actions. For an LM, the action is usually the next token. At a fixed prefix $h$, the training model assigns probability $p_\theta(a\mid h)$ to token $a$. The vector $\theta$ contains the parameters that the optimizer will update.

But the probabilities that actually produce the token may be $q(a\mid h)$. A faster rollout engine can use quantized weights, different numerical kernels, or an older checkpoint. Here rollout means generating a response or trajectory to be scored. Training–inference mismatch (TIM) means the sampling probabilities and training probabilities disagree; it is not merely that two random draws happened to differ.

1. Sample under qA rollout engine generates tokens and records their sampling probabilities.
2. EvaluateThe environment or reward function scores the completed response.
3. Differentiate through pThe trainer recomputes token probabilities and builds an update.
4. SynchronizeUpdated weights eventually reach the sampler; numerical differences can remain.

We hold the collected sampling distribution fixed when computing one training update. Even if $q$ came from $\theta$, a saved rollout does not change retroactively when the trainer changes. This bookkeeping does not claim that $q$ is unrelated to $p$ across training iterations.

Policy(策略)规定各种动作被选择的概率。在 LM 中,动作通常就是下一个 token。固定一个前缀 $h$,训练模型认为 token $a$ 的概率是 $p_\theta(a\mid h)$;$\theta$ 是 optimizer 将要更新的参数向量。

但真正生成这个 token 的概率可能是 $q(a\mid h)$。为了更快生成,rollout engine 可能使用量化权重、不同数值计算 kernels,或旧 checkpoint。Rollout 指生成一条准备接受评分的回答或轨迹。Training–inference mismatch(TIM)指两个执行端的概率不一致,不是指两次随机抽样恰好抽出了不同 token。

1. 按 q 采样Rollout engine 生成 tokens,记录实际使用的采样概率。
2. 给回答评分环境或 reward function 评价生成的完整回答。
3. 通过 p 求导Trainer 重新计算 token 概率,根据奖励构造更新。
4. 同步回采样器更新后的权重最终传给 sampler,但数值执行差异可能仍存在。

在计算某一次更新时,我们把已经收集数据所对应的采样分布视为固定量。即使 $q$ 原本来自 $\theta$,trainer 改变也不会追溯性地改变旧数据的生成概率。这不代表不同训练轮次中的 $q$ 与 $p$ 毫无关系。

1.2 What Does “The Correct Gradient” Mean?

Start with one decision and two outcomes, $y=1$ and $y=0$. Write $p=p_\theta(1)$ and $q=q(1)$; the other probabilities are $1-p$ and $1-q$. This scalar shorthand is only for the binary example. Later, $p_\theta$ and $q$ denote full distributions.

Let $r_1$ and $r_0$ be the rewards of the two outcomes, fixed independently of $\theta$. The trainer’s objective is

\[J(\theta)=\mathbb E_{y\sim p_\theta}[R(y)]=p\,r_1+(1-p)r_0.\]

The expectation means “average using the frequencies the current training policy would produce.” We want $\nabla_\theta J$, not the gradient of average reward under an arbitrary other policy.

We use gradient ascent, $\theta_{\rm new}=\theta+\eta\widehat g$, because larger reward is better. Here $\widehat g$ is a sampled update estimate and $\eta>0$ is the learning rate. A loss-minimizing implementation uses the negative objective. Expectation calculations below concern $\mathbb E[\widehat g]$, before multiplication by the learning rate or processing by Adam. Gradient basics are developed in Basics of Optimizers, §1.

For now there is no KL penalty, PPO clipping, learned reward dependence on $\theta$, or group normalization. These alter the objective or estimator and must not be silently included in a claim about the gradient of $J$.

先只做一次选择,结果只有 $y=1$ 和 $y=0$。把 $p_\theta(1)$ 简写成 $p$,把 $q(1)$ 简写成 $q$;另一个结果的概率分别是 $1-p$、$1-q$。这个标量简写只用于二分类例子;后面 $p_\theta$ 和 $q$ 会重新表示完整分布。

两个结果的奖励分别是 $r_1,r_0$,暂时假设奖励不直接依赖参数 $\theta$。训练模型想最大化:

\[J(\theta)=\mathbb E_{y\sim p_\theta}[R(y)]=p\,r_1+(1-p)r_0.\]

这个 expectation 是“按照当前训练策略本来会产生的频率求平均”。因此我们要的是 $\nabla_\theta J$,不是任意其他策略的平均奖励梯度。

因为奖励越大越好,本文采用 gradient ascent:$\theta_{\rm new}=\theta+\eta\widehat g$。$\widehat g$ 是从样本算出的更新估计,$\eta>0$ 是 learning rate;代码若使用最小化 loss 的 optimizer,就取负号。后文讨论的是乘 learning rate、经过 Adam 等处理之前的 $\mathbb E[\widehat g]$。梯度的基础解释见 Basics of Optimizers,第 1 节。

目前先不加 KL penalty、PPO clipping、直接依赖 $\theta$ 的奖励或 group normalization。它们会改变目标或 estimator,不能悄悄混进“$J$ 的正确梯度”这句话中。

2. From a Probability to a Policy Gradient

2.1 Why Is the Score y − p?

A parameter must be free to move without making probabilities negative or larger than one. Use a real-valued logit $\theta$, converted to a probability by the sigmoid:

\[p=\sigma(\theta)=\frac1{1+e^{-\theta}},\qquad \frac{dp}{d\theta}=p(1-p).\]

A logit is not a log-probability. The log-probability of the observed binary outcome is

\[\log p_\theta(y)=y\log p+(1-y)\log(1-p).\]

The score is the derivative of that log-probability with respect to the trainable parameter. It is not the reward assigned by a judge. With natural logarithms,

\[\begin{aligned} s_p(y) &=\frac{d}{d\theta}\log p_\theta(y)\\ &=y\frac{p(1-p)}p-(1-y)\frac{p(1-p)}{1-p}\\ &=y(1-p)-(1-y)p\\ &=\boxed{y-p}. \end{aligned}\]

If $y=1$, the score is $1-p>0$: increasing the logit would make that sampled answer more likely. If $y=0$, the score is $-p<0$: decreasing it would make zero more likely. In a full network, this derivative becomes a vector over parameters; it supplies a local direction, not a command to move a fixed distance.

Why does differentiating the sigmoid give p(1 − p)?

Differentiating $(1+e^{-\theta})^{-1}$ gives $e^{-\theta}/(1+e^{-\theta})^2$. Meanwhile $p=1/(1+e^{-\theta})$ and $1-p=e^{-\theta}/(1+e^{-\theta})$. Multiplying them gives exactly the derivative. The two factors also explain why changing a logit has little effect on probability near either endpoint.

参数需要能自由变化,却不能让概率变成负数或超过 1。因此先用一个可以取任意实数的 logit $\theta$,再通过 sigmoid 得到概率:

\[p=\sigma(\theta)=\frac1{1+e^{-\theta}},\qquad \frac{dp}{d\theta}=p(1-p).\]

Logit 不是 log-probability。对于实际抽到的二分类结果 $y$,它的 log-probability 是:

\[\log p_\theta(y)=y\log p+(1-y)\log(1-p).\]

Score 是这个 log-probability 对可训练参数的导数,不是裁判给回答打的 reward。本文使用自然对数:

\[\begin{aligned} s_p(y) &=\frac{d}{d\theta}\log p_\theta(y)\\ &=y\frac{p(1-p)}p-(1-y)\frac{p(1-p)}{1-p}\\ &=y(1-p)-(1-y)p\\ &=\boxed{y-p}. \end{aligned}\]

若 $y=1$,score 是正的 $1-p$:增大 logit 会提高这个已采样答案的概率。若 $y=0$,score 是负的 $-p$:减小 logit 会提高零的概率。完整网络中的 score 是关于所有参数的向量;它提供局部方向,并不直接规定移动距离。

数学补充:为什么 sigmoid 的导数是 p(1 − p)?

对 $(1+e^{-\theta})^{-1}$ 求导,得到 $e^{-\theta}/(1+e^{-\theta})^2$。另一方面,$p=1/(1+e^{-\theta})$,$1-p=e^{-\theta}/(1+e^{-\theta})$,两者相乘恰好是该导数。这两个因子也解释了:概率接近 0 或 1 时,改变 logit 对概率的影响较小。

2.2 Derive the Target Gradient in Two Ways

First differentiate the objective directly:

\[\begin{aligned} J(\theta)&=r_0+p(r_1-r_0),\\ g_p=\frac{dJ}{d\theta}&=\boxed{p(1-p)(r_1-r_0)}. \end{aligned}\]

The reward difference determines which outcome should become more likely. The factor $p(1-p)$ converts a change in logit to a change in probability. If both rewards are equal, the objective is constant and its gradient must be zero.

Second, weight each score by its reward and average under p:

\[\begin{aligned} \mathbb E_p[R\,s_p] &=p\,r_1(1-p)+(1-p)r_0(-p)\\ &=p(1-p)(r_1-r_0)=g_p. \end{aligned}\]

This is the policy-gradient identity in miniature. Its general finite-action derivation is just a rearrangement:

\[\nabla_\theta\sum_a p_\theta(a)R(a) =\sum_a R(a)\nabla_\theta p_\theta(a) =\sum_a p_\theta(a)R(a)\nabla_\theta\log p_\theta(a).\]

The equality uses $\nabla p=p\nabla\log p$, valid for positive probabilities. Instead of differentiating a random discrete sample, we differentiate its log-probability and use samples to estimate the sum. The distribution specifying the frequencies is therefore part of the mathematics, not an implementation detail.

第一种方法,直接对目标求导:

\[\begin{aligned} J(\theta)&=r_0+p(r_1-r_0),\\ g_p=\frac{dJ}{d\theta}&=\boxed{p(1-p)(r_1-r_0)}. \end{aligned}\]

奖励差决定应该提高哪个结果的概率;$p(1-p)$ 把 logit 的变化换算为概率变化。两个奖励相同时,目标是常数,梯度必然为零。

第二种方法,让每个 score 乘上对应 reward,然后按照 p 的频率求平均:

\[\begin{aligned} \mathbb E_p[R\,s_p] &=p\,r_1(1-p)+(1-p)r_0(-p)\\ &=p(1-p)(r_1-r_0)=g_p. \end{aligned}\]

这就是最小版本的 policy-gradient identity。对于一般有限动作空间,推导只是重排求和:

\[\nabla_\theta\sum_a p_\theta(a)R(a) =\sum_a R(a)\nabla_\theta p_\theta(a) =\sum_a p_\theta(a)R(a)\nabla_\theta\log p_\theta(a).\]

中间使用正概率下的 $\nabla p=p\nabla\log p$。我们不是对“抽出某个离散结果”这件事直接求导,而是对该结果的 log-probability 求导,再用抽样估计整个和。所以决定出现频率的分布本身就是公式的一部分,不是无关紧要的实现细节。

2.3 Keep the Score, Change the Sampling Frequencies

Now draw $y$ from $q$, but keep computing the trainer’s score $y-p$. The expectation becomes

\[g_{\rm raw}=\mathbb E_q[R(y-p)] =q\,r_1(1-p)-(1-q)r_0p.\]

There is nothing wrong with the derivative of $\log p_\theta(y)$. The problem is that we average its possible values with $q$ rather than $p$. More data from the same sampler makes the estimate converge more accurately to $g_{\rm raw}$, not to $g_p$. This systematic difference in means is bias, as distinct from finite-sample randomness.

Set $r_1=r_0=1$. Then $g_p=0$, but

\[g_{\rm raw}=q(1-p)-(1-q)p=q-p.\]

If the sampler favors outcome one more strongly than the trainer, the trainer receives a positive average push despite the reward expressing no preference. This is the constant-reward diagnostic, not yet a proof that every such mismatch causes collapse.

现在改为从 $q$ 抽取 $y$,但仍计算 trainer 的 score $y-p$。平均更新变成:

\[g_{\rm raw}=\mathbb E_q[R(y-p)] =q\,r_1(1-p)-(1-q)r_0p.\]

$\log p_\theta(y)$ 的导数没有算错;问题是它的不同取值被按照 $q$ 而不是 $p$ 加权。增加同一 sampler 的数据量,只会让估计更准确地收敛到 $g_{\rm raw}$,不会自动收敛到 $g_p$。这种均值的系统性偏差叫 bias,不同于有限样本随机波动。

令 $r_1=r_0=1$,此时 $g_p=0$,但:

\[g_{\rm raw}=q(1-p)-(1-q)p=q-p.\]

若采样器比训练器更喜欢结果 1,即使 reward 没有表达任何偏好,训练器也会受到平均的正向推力。这是 constant-reward 诊断;它本身还不是“所有这类 mismatch 都必然导致 collapse”的证明。

3. What Score Centering Removes

3.1 Separate the Common Push from Reward Differences

For the next calculation, fix one prefix and suppress $h$ in the notation. Write $s_p(a)=\nabla_\theta\log p_\theta(a)$ and $\bar s=\mathbb E_q[s_p]$. Under the trainer’s own distribution,

\[\mathbb E_p[s_p] =\sum_a p_\theta(a)\nabla_\theta\log p_\theta(a) =\nabla_\theta\sum_a p_\theta(a)=0.\]

Under $q$, the same zero-mean identity need not hold. Let $\mu_R=\mathbb E_q[R]$. Split a reward into its common level and deviation: $R=\mu_R+(R-\mu_R)$. Multiplying by the score and taking expectations gives

\[\boxed{\mathbb E_q[R s_p] =\underbrace{\mu_R\bar s}_{\text{drift}} +\underbrace{\operatorname{Cov}_q(R,s_p)}_{\text{reward--score association}}}.\]

Here covariance means $\mathbb E_q[(R-\mu_R)(s_p-\bar s)]$, evaluated component by component if the score is a vector. The extra $-\bar s$ does not change the answer because $\mathbb E_q[R-\mu_R]=0$.

Intuitively, drift asks only “what was the average reward?” and multiplies that number by the sampler’s average score. It does not ask which action earned more. Covariance does ask that: do above-average rewards occur together with a particular update direction? Calling it “signal” does not make it the correct signal for $p$; its average is still taken under $q$.

For our binary model, $\bar s=q-p$, $\mu_R=qr_1+(1-q)r_0$, and direct substitution gives

\[\boxed{g_{\rm raw} =\underbrace{[qr_1+(1-q)r_0](q-p)}_{\text{drift}} +\underbrace{q(1-q)(r_1-r_0)}_{\text{covariance}}}.\]

下面先固定一个前缀,把 $h$ 暂时从记号中省略。记 $s_p(a)=\nabla_\theta\log p_\theta(a)$,并把采样分布下的平均 score 记为 $\bar s=\mathbb E_q[s_p]$。按照 trainer 自己的分布求平均:

\[\mathbb E_p[s_p] =\sum_a p_\theta(a)\nabla_\theta\log p_\theta(a) =\nabla_\theta\sum_a p_\theta(a)=0.\]

换成 $q$ 后,这个零均值性质不一定成立。令 $\mu_R=\mathbb E_q[R]$,把 reward 写成“共同水平 + 相对偏差”:$R=\mu_R+(R-\mu_R)$。乘上 score 再求平均:

\[\boxed{\mathbb E_q[R s_p] =\underbrace{\mu_R\bar s}_{\text{drift}} +\underbrace{\operatorname{Cov}_q(R,s_p)}_{\text{reward--score association}}}.\]

这里 covariance(协方差)就是 $\mathbb E_q[(R-\mu_R)(s_p-\bar s)]$;score 是向量时,对各个 component 分别算。额外减去 $\bar s$ 不影响结果,因为 $\mathbb E_q[R-\mu_R]=0$。

直观上,drift 只问“平均奖励是多少”,然后用它乘采样器的平均 score;它不区分哪个动作得分更高。Covariance 才关心:高于平均的奖励,是否总与某个更新方向一起出现?但把它称为“signal”,不等于它就是 $p$ 需要的正确 signal,因为它仍然按照 $q$ 的频率计算。

在二分类例子中,$\bar s=q-p$,$\mu_R=qr_1+(1-q)r_0$。代入可得:

\[\boxed{g_{\rm raw} =\underbrace{[qr_1+(1-q)r_0](q-p)}_{\text{drift}} +\underbrace{q(1-q)(r_1-r_0)}_{\text{covariance}}}.\]

3.2 Subtract the Average Score, Not the Average Reward

Score centering replaces $s_p(y)$ by

\[\widetilde s(y)=s_p(y)-\bar s,\qquad \mathbb E_q[\widetilde s]=0.\]

At a fixed prefix, $\bar s$ is the same vector regardless of which next token is sampled. Different prefixes generally have different vectors. It is an expectation over possible next tokens, not a mean across the coordinates of one gradient.

The reward-weighted expectation becomes

\[g_{\rm SC}=\mathbb E_q[R(s_p-\bar s)] =\mathbb E_q[Rs_p]-\mathbb E_q[R]\bar s =\operatorname{Cov}_q(R,s_p).\]

In the binary case, every sampled update simplifies:

\[\boxed{R(y-p)\ \longrightarrow\ R[(y-p)-(q-p)]=R(y-q)}.\]

Consequently $g_{\rm SC}=q(1-q)(r_1-r_0)$. For constant rewards this is zero. More generally, adding the same constant $c$ to every reward leaves the expected SC update unchanged, since $\mathbb E_q[c\widetilde s]=0$. The raw update changes by $c\bar s$.

This is an expectation statement. With reward one, a single centered sample can still be nonzero, and a finite minibatch can move randomly. Zero mean does not mean zero variance or guaranteed optimization stability.

Score centering 把 $s_p(y)$ 替换为:

\[\widetilde s(y)=s_p(y)-\bar s,\qquad \mathbb E_q[\widetilde s]=0.\]

在同一个前缀下,无论实际抽到哪个 next token,减去的 $\bar s$ 都是同一个向量;不同前缀通常对应不同向量。这是在可能的 next tokens 上求期望,不是对一条梯度的所有 coordinates 求均值。

乘上 reward 之后,期望更新为:

\[g_{\rm SC}=\mathbb E_q[R(s_p-\bar s)] =\mathbb E_q[Rs_p]-\mathbb E_q[R]\bar s =\operatorname{Cov}_q(R,s_p).\]

二分类时,连单个样本的更新都能直接化简:

\[\boxed{R(y-p)\ \longrightarrow\ R[(y-p)-(q-p)]=R(y-q)}.\]

因此 $g_{\rm SC}=q(1-q)(r_1-r_0)$。所有奖励相同时,它等于零。更一般地,给所有奖励同时加常数 $c$,不会改变 SC 的期望更新,因为 $\mathbb E_q[c\widetilde s]=0$;未修正的期望更新则会增加 $c\bar s$。

注意这是 expectation 的结论。奖励恒为 1 时,单个 centered sample 仍可能非零,有限 minibatch 仍可能让参数随机移动。零均值不等于零方差,更不等于保证训练稳定。

3.3 Why Might a Small Drift Matter over Training?

For fixed $q$, the mean score is

\[\bar s=\nabla_\theta\sum_a q(a)\log p_\theta(a).\]

It is the direction used to fit the trainer to the sampler by maximum likelihood. With a positive mean reward, drift points toward this fitting direction; with a negative mean reward, it reverses it. This is a distribution-matching pressure, not evidence from relative action quality.

A simple constructed loop illustrates accumulation. Suppose at iteration $n$ the sampler uses logit $\theta_n+\delta$ with a persistent $\delta>0$, so $p_n=\sigma(\theta_n)$ and $q_n=\sigma(\theta_n+\delta)$. With reward always one, the raw expected update is positive at every finite $\theta_n$:

\[\theta_{n+1}=\theta_n+\eta(q_n-p_n).\]

The sampler is then refreshed from the new trainer, retaining the offset. The target it pushes toward keeps moving. SC eliminates this particular expected push. This example demonstrates a mechanism, not that real quantization behaves as a fixed scalar offset, or that every mismatch produces divergent rewards.

It also explains why “SFT uses off-policy data too” is not a rebuttal. Fitting a fixed dataset is SFT’s intended objective. Here the intended objective is reward under $p$, and the effective teacher changes with the learner. Neither statement implies that SFT or a moving teacher is universally stable or unstable.

固定 $q$,平均 score 可以写成:

\[\bar s=\nabla_\theta\sum_a q(a)\log p_\theta(a).\]

它正是通过 maximum likelihood 让 trainer 拟合 sampler 的方向。平均 reward 为正,drift 沿这个拟合方向;平均 reward 为负,方向反过来。这是一种分布拟合压力,不是不同动作谁更好的奖励证据。

用一个人为构造的循环看积累过程。假设第 $n$ 轮 sampler 使用 $\theta_n+\delta$,始终带着正偏移 $\delta>0$;于是 $p_n=\sigma(\theta_n)$、$q_n=\sigma(\theta_n+\delta)$。所有奖励恒为 1 时,对任何有限的 $\theta_n$,原始期望更新都为正:

\[\theta_{n+1}=\theta_n+\eta(q_n-p_n).\]

Sampler 随后从新的 trainer 同步,又保留这个偏移。它推动 trainer 追逐的目标一直在移动。SC 会消除这种特定的平均推力。这个例子展示一种机制,不意味着真实量化就是固定标量偏移,也不证明任何 mismatch 都会让 reward 崩溃。

这也解释了为什么“SFT 同样使用 off-policy 数据”不能直接反驳:拟合固定数据本来就是 SFT 的目标,而这里的目标是 $p$ 下的 reward,且有效的 teacher 会跟着 learner 改变。这两点都不意味着 SFT 或移动 teacher 必然稳定或必然不稳定。

4. The Disagreement: Correcting toward What?

4.1 The Strongest Diagnostic: p Disappears

Return to $R(y-p)\to R(y-q)$. Hold $q$ and the observed outcome fixed, and replace the trainer by a different $p$. The centered update is unchanged, although the correct gradient $p(1-p)(r_1-r_0)$ generally changes. This is the strongest reading of Nan’s objection: the correction does not use the target-policy difference to recover the target gradient.

“Does nothing,” in this reading, does not mean the original and corrected formulas are equal. Their difference is $R(q-p)$, usually nonzero. Nor does it refer to the special case where one-step group centering already cancels a shared correction. It means “does not perform the claimed target-directed correction.” The phrase is too broad if interpreted as “removes no bias component” or “has no practical effect.”

Let $q=\sigma(\phi)$. The expected centered update is exactly $dJ_q/d\phi=q(1-q)(r_1-r_0)$ in this binary parameterization. That is a derivative with respect to a sampler logit at $q$, applied as a direction to the trainer logit. It is not the derivative of a fixed $q$ with respect to $\theta$, which would be zero.

重新看 $R(y-p)\to R(y-q)$。保持 $q$ 和采样结果不变,把 trainer 换成另一个 $p$,SC 算出的更新仍相同;但正确梯度 $p(1-p)(r_1-r_0)$ 一般已经变了。这是 Nan 的质疑最有力的解读:修正没有利用目标策略的差别,去恢复目标梯度。

在这个解读中,“does nothing”不是说原始公式与修正后公式一样;它们相差 $R(q-p)$,通常不为零。它也不是指单步 group-centering 已经让共同修正项抵消的特殊情形,而是指“没有做所声称的、指向目标策略的校正”。如果把这句话读成“没有删除任何偏差项”或“没有实际作用”,就过度了。

令 $q=\sigma(\phi)$,这个二分类参数化下,SC 的期望恰好是 $dJ_q/d\phi=q(1-q)(r_1-r_0)$。这是在 $q$ 处对 sampler logit 的导数,被作为方向应用到 trainer logit。它不是“把固定 $q$ 对 $\theta$ 求导”;后者当然为零。

4.2 What Does the Linear-Softmax Qualification Exclude?

For more than two outcomes, let $x$ be a fixed feature vector and let $p=\operatorname{softmax}(Wx)$. Let $e_y$ be a vector with one at the sampled token and zeros elsewhere. Differentiating with respect to the weight matrix gives

\[s_W(y)=(e_y-p)x^\top,\qquad \mathbb E_q[s_W]=(q-p)x^\top.\]

Thus the centered score is $(e_y-q)x^\top$. If the sampler is another linear softmax with the same fixed features and parameter coordinates, this is its score evaluated at its own weights. This is a precise equivalence, not a universal description of neural networks.

In a nonlinear network, let $z_\theta(h)$ be the logit vector and let $J_z=\partial z_\theta(h)/\partial\theta$ be its Jacobian: each entry records how one logit changes when one parameter changes. The chain rule gives

\[s_\theta(y)=J_z^\top(e_y-p),\qquad \widetilde s_\theta(y)=J_z^\top(e_y-q).\]

The explicit probability vector $p$ cancels, but the trainer still appears through $J_z$. A quantized or stale sampler can have a different Jacobian, or no useful ordinary derivative through its discrete quantization operation. So one cannot generally call this the true sampler-parameter gradient. The linear example establishes a limitation of target correction; it does not prove that all trainer information disappears in a full LM.

推广到多个结果,令 $x$ 是固定 feature vector,$p=\operatorname{softmax}(Wx)$。$e_y$ 是只在采样 token 处为 1、其余为 0 的向量。对权重矩阵求导:

\[s_W(y)=(e_y-p)x^\top,\qquad \mathbb E_q[s_W]=(q-p)x^\top.\]

两者相减得到 $(e_y-q)x^\top$。如果 sampler 也是 linear softmax,且使用相同固定 features 与参数坐标,这正是 sampler 在自身权重处的 score。这是有条件的严格等价,不是所有神经网络都满足的描述。

完整非线性网络中,令 $z_\theta(h)$ 为 logits 向量,$J_z=\partial z_\theta(h)/\partial\theta$ 为 Jacobian:其中每个数记录某个参数改变时,某个 logit 改变多少。链式法则给出:

\[s_\theta(y)=J_z^\top(e_y-p),\qquad \widetilde s_\theta(y)=J_z^\top(e_y-q).\]

显式的概率向量 $p$ 消失了,但 trainer 仍通过 $J_z$ 出现。量化或旧 sampler 的 Jacobian 可能不同;离散量化操作甚至未必具有有用的普通导数。因此一般不能把它称为真正的 sampler 参数梯度。线性反例足以揭示目标校正的局限,却不证明完整 LM 的 trainer 信息全部消失。

4.3 Removing Drift Can Increase the Total Bias

Use raw rewards and one decision:

\[p=0.9,\qquad q=0.8,\qquad r_1=1,\quad r_0=0.\]
Update Expected value Distance from the target
Correct gradient at $p$ $p(1-p)=0.09$ $0$
Raw off-policy update $q(1-p)=0.08$ $0.01$
Score-centered update $q(1-q)=0.16$ $0.07$

Here the mean reward is $0.8$, so drift is $0.8(0.8-0.9)=-0.08$. Covariance is $0.16$, while the target is $0.09$. The covariance’s error is therefore $+0.07$. Before correction, the two errors largely cancel:

\[g_{\rm raw}-g_p=-0.08+0.07=-0.01.\]

SC deletes the $-0.08$ term and leaves the $+0.07$ error. Deleting one component of a sum does not guarantee reducing the magnitude of the sum.

This counterexample concerns expected gradients, not one lucky minibatch. It disproves a universal closeness guarantee, but does not predict which estimator has better finite-sample mean squared error or better long-run reward. Those also depend on variance, learning rate, optimizer, and changing policies.

There is also a useful favorable fact in this particular binary setting: for interior $p,q$, both $g_p$ and $g_{\rm SC}$ have the sign of $r_1-r_0$. Their magnitudes can differ, but SC is still a local ascent direction when that difference is nonzero. The counterexample says “not closer,” not “necessarily the wrong direction.” This sign guarantee does not automatically survive shared parameters across many states or actions.

使用原始奖励,且只做一次选择:

\[p=0.9,\qquad q=0.8,\qquad r_1=1,\quad r_0=0.\]
更新 期望值 与目标的距离
当前 $p$ 的正确梯度 $p(1-p)=0.09$ $0$
原始 off-policy 更新 $q(1-p)=0.08$ $0.01$
Score centering $q(1-q)=0.16$ $0.07$

平均奖励为 $0.8$,所以 drift 为 $0.8(0.8-0.9)=-0.08$。Covariance 是 $0.16$,而目标是 $0.09$,所以 covariance 本身的误差为 $+0.07$。修正前,两项误差大部分抵消:

\[g_{\rm raw}-g_p=-0.08+0.07=-0.01.\]

SC 删除 $-0.08$,留下 $+0.07$。删除一个和式中的某一项,不保证让整个和式的绝对值变小。

这个反例比较的是期望梯度,不是某个幸运 minibatch。它推翻“修正后必定更接近”的普遍保证,但不直接判断哪个 estimator 的有限样本 mean squared error 更小,或长期 reward 更高;后两者还取决于方差、learning rate、optimizer,以及不断变化的策略。

同时,这个二分类设定也有一个有利性质:只要 $p,q$ 都在 0 与 1 之间,$g_p$ 和 $g_{\rm SC}$ 的符号都由 $r_1-r_0$ 决定。它们大小可能不同,但奖励差非零时,SC 仍是局部上升方向。所以反例说明的是“不一定更接近”,不是“方向必然错误”。这种符号保证不能直接推广到许多 states/actions 共享参数的情况。

Figure 1. Change the trainer, sampler, and rewards. Bars show exact expected updates, not sampled estimates. “Constant reward” tests drift; “Counterexample” tests target-gradient accuracy.
图 1:改变 trainer、sampler 与奖励。柱子展示精确期望,不是随机抽样结果。“恒定奖励”检查 drift;“反例”检查目标梯度准确性。

4.4 Two Different Meanings of Correction

The exchange beginning at Nan’s post, as reconstructed from the supplied follow-up, admits a clear distinction. Nan’s target-gradient objection survives the calculation: centering does not generally recover $g_p$, nor guarantee moving closer to it. You Jiacheng’s drift-removal defense survives too: with exact centering, the defined drift really is removed. It is not an unchanged estimator.

The defense that $q$ is derived from $p$ supplies an engineering reason the update might be useful. A nearby or slightly older policy’s update may remain informative. But provenance is not an equality of gradients. For our binary example,

\[g_{\rm SC}-g_p=(q-p)(1-p-q)(r_1-r_0).\]

Hence $\lvert g_{\rm SC}-g_p\rvert\leq\lvert q-p\rvert\,\lvert r_1-r_0\rvert$. Closeness of $q$ to $p$ helps in this toy model. It does not prove SC is closer than the raw estimator, and “derived from” alone supplies no numerical closeness bound.

Our assessment is therefore specific: Nan has the stronger argument about recovering the current trainer’s gradient; You correctly defends removing a particular drift term. Comparing training stability or final reward against IS-based methods is meaningful. Interpreting superior reward as proof of more accurate target-gradient recovery is not.

从 Nan 的原帖 出发,结合所提供的后续讨论,可以明确区分两个问题。Nan 关于目标梯度的质疑经得起计算:centering 一般不恢复 $g_p$,也不保证更接近它。You Jiacheng 对 drift removal 的辩护也经得起计算:精确 centering 确实删除了所定义的 drift,不是原封不动的 estimator。

“$q$ 来自 $p$”提供了一个合理的工程理由:邻近或稍旧策略的更新可能仍然有用。但来源关系不等于梯度相等。二分类例子中:

\[g_{\rm SC}-g_p=(q-p)(1-p-q)(r_1-r_0).\]

所以 $\lvert g_{\rm SC}-g_p\rvert\leq\lvert q-p\rvert\,\lvert r_1-r_0\rvert$。在这个 toy model 中,$q$ 接近 $p$ 确实有帮助;但它不证明 SC 比原始 estimator 更接近,而且仅仅“来自”也没有给出数值上的接近程度。

因此本文的判断是有明确范围的:讨论是否恢复当前 trainer 的梯度时,Nan 更占上风;讨论是否消除了一个特定 drift 项时,You 的辩护成立。与 IS 类方法比较训练稳定性和最终 reward 是合理的;把 reward 更高进一步解释为“目标梯度恢复得更准确”,则没有依据。

5. How Importance Sampling Restores the Target Average

5.1 Correct Frequencies, Keep the Trainer's Score

If outcome one should appear 90% of the time but appears only 80%, each observed one can count as $0.9/0.8=1.125$ target samples. Zeros appear 20% rather than 10%, so each zero counts as $0.1/0.2=0.5$ samples. We do not need to change the sampled token; we change how much it contributes.

In general, define the importance weight

\[w(y)= \begin{cases} p/q,&y=1,\\ (1-p)/(1-q),&y=0. \end{cases}\]

Use $\widehat g_{\rm IS}=w(y)R(y)(y-p)$, retaining the trainer’s score:

\[\begin{aligned} \mathbb E_q[\widehat g_{\rm IS}] &=q\frac pq r_1(1-p) +(1-q)\frac{1-p}{1-q}r_0(-p)\\ &=p\,r_1(1-p)-(1-p)r_0p\\ &=\boxed{p(1-p)(r_1-r_0)}. \end{aligned}\]

The sample frequencies $q$ cancel the denominators. For the counterexample, this is $0.8\times1.125\times0.1=0.09$. SC changed each sample’s score; IS changes its contribution to the average.

For any integrable function $f$, the underlying identity is $\sum_a q(a)[p(a)/q(a)]f(a)=\sum_a p(a)f(a)$. It requires support coverage: whenever $p(a)>0$, we need $q(a)>0$. An action the sampler never produces cannot be recovered merely by assigning weights to observed actions.

如果结果 1 本应出现 90%,实际只出现 80%,可以让每个观察到的 1 算作 $0.9/0.8=1.125$ 个目标样本。结果 0 实际出现 20%,但目标只需要 10%,就让每个 0 算作 $0.1/0.2=0.5$ 个样本。我们不修改抽到的 token,而是修改它的贡献权重。

一般地,定义 importance weight:

\[w(y)= \begin{cases} p/q,&y=1,\\ (1-p)/(1-q),&y=0. \end{cases}\]

使用 $\widehat g_{\rm IS}=w(y)R(y)(y-p)$,注意保留的是 trainer 的 score:

\[\begin{aligned} \mathbb E_q[\widehat g_{\rm IS}] &=q\frac pq r_1(1-p) +(1-q)\frac{1-p}{1-q}r_0(-p)\\ &=p\,r_1(1-p)-(1-p)r_0p\\ &=\boxed{p(1-p)(r_1-r_0)}. \end{aligned}\]

出现频率 $q$ 与分母抵消。在反例中,结果就是 $0.8\times1.125\times0.1=0.09$。SC 改了每个样本的 score;IS 改了每个样本在平均值中的贡献。

背后的通用恒等式是 $\sum_a q(a)[p(a)/q(a)]f(a)=\sum_a p(a)f(a)$,要求 $f$ 可积,并满足 support coverage:只要 $p(a)>0$,就必须有 $q(a)>0$。Sampler 从不产生的动作,无法仅靠重新加权已有动作恢复。

5.2 Unbiased Does Not Mean Easy to Optimize

Suppose $p=0.5$, $q=0.001$, $r_1=1$, and $r_0=0$. The correct logit gradient is $0.25$. The IS estimator is 250 on the rare draw $y=1$, and zero otherwise:

\[\mathbb E[\widehat g_{\rm IS}]=0.001\times250=0.25,\qquad \operatorname{Var}(\widehat g_{\rm IS})=0.001\times250^2-0.25^2=62.4375.\]

An expectation can be correct while most batches miss the informative action and a few batches receive an enormous update. Increasing batch size helps if variance is finite, but costs computation and does not solve missing support.

Truncated IS replaces $w$ by, for example, $\min(w,c)$. Masked IS sets weights outside an accepted range to zero. Both suppress extreme contributions but generally break the exact cancellation above. Self-normalizing weights by their batch sum is also generally biased at finite sample size. These may be worthwhile tradeoffs; they are not the exact identity.

Nor is there a theorem that IS always has higher variance than every unweighted estimator, or SC always lowers variance. With constant reward, subtracting a deterministic score mean changes the mean but leaves the score variance unchanged. A claim about stability needs more than the word “centering.”

For independent scalar estimates averaged over $N$ samples, the mean squared error is

\[\mathbb E[(\widehat g_N-g_p)^2] =(\mathbb E[\widehat g_N]-g_p)^2+\frac{\operatorname{Var}(\widehat g_1)}N.\]

This separates squared bias from variance. Long-run learning quality is a further question: the objective and both policies evolve after each step.

设 $p=0.5$、$q=0.001$、$r_1=1$、$r_0=0$,正确的 logit 梯度为 $0.25$。IS estimator 在极少抽到 $y=1$ 时等于 250,其余时候为零:

\[\mathbb E[\widehat g_{\rm IS}]=0.001\times250=0.25,\qquad \operatorname{Var}(\widehat g_{\rm IS})=0.001\times250^2-0.25^2=62.4375.\]

期望可以完全正确,但多数 batches 根本没有关键动作,少数 batches 突然收到巨大更新。方差有限时,增大 batch 可以缓解,却需要额外计算,也不能解决 support 缺失。

Truncated IS 例如用 $\min(w,c)$ 代替 $w$;masked IS 把区间外的权重设为零。它们削弱极端贡献,也通常破坏上面的精确抵消。用 batch 内权重之和做 self-normalization,在有限样本下也通常有偏。这些可能是值得做的折中,但不再是精确恒等式。

也不能反过来宣称:IS 方差一定比任意未加权方法都大,或 SC 一定降低方差。恒定 reward 时,减去确定的 score 均值,只改变均值,不改变 score 的方差。“Centering”这个名字本身不能证明稳定性。

对于 $N$ 个独立标量估计的平均值,mean squared error 为:

\[\mathbb E[(\widehat g_N-g_p)^2] =(\mathbb E[\widehat g_N]-g_p)^2+\frac{\operatorname{Var}(\widehat g_1)}N.\]

它把 squared bias 与 variance 分开。长期学习效果又是下一层问题,因为每步之后目标所处位置和两个策略都会变化。

6. From One Decision to an Entire LM Response

6.1 Why the Exact Ratio Is a Product

Fix a prompt $x$. Let $\tau=(y_1,\ldots,y_T)$ be a generated response, including a stopping token when relevant. The prefix before token $t$ is $h_t=(x,y_{<t})$. A trajectory is simply all these decisions together. Autoregressive generation means

\[p_\theta(\tau\mid x)=\prod_{t=1}^T p_\theta(y_t\mid h_t), \qquad q(\tau\mid x)=\prod_{t=1}^T q(y_t\mid h_t).\]

Taking a logarithm turns the product into a sum, so the response score is

\[\nabla_\theta\log p_\theta(\tau\mid x) =\sum_{t=1}^T s_\theta(y_t,h_t).\]

For a terminal reward $R(\tau)$ independent of $\theta$, the exact objective gradient is

\[\boxed{\nabla_\theta J =\mathbb E_{\tau\sim p_\theta} \left[R(\tau)\sum_t s_\theta(y_t,h_t)\right]}.\]

Changing the sampling measure to $q$ requires the probability ratio of that same random object, the entire trajectory:

\[\boxed{w(\tau)=\frac{p_\theta(\tau\mid x)}{q(\tau\mid x)} =\prod_t\frac{p_\theta(y_t\mid h_t)}{q(y_t\mid h_t)}}.\]

Then $\mathbb E_q[w(\tau)R(\tau)\sum_t s_\theta]=\nabla_\theta J$, assuming support coverage and integrability. Variable response lengths must be accounted for through stopping probabilities, not silently dropped. With environment transitions shared by the two policies, their factors cancel in the trajectory ratio. Different prompt distributions or environments require additional accounting.

Each denominator must be the probability actually used when that token was sampled, including any temperature or sampling filter. Recomputing it later under an updated sampler does not describe the original data. Top-$k$ or top-$p$ sampling can remove support altogether, making exact recovery of an unfiltered target impossible from those samples alone.

固定 prompt $x$,把回答写成 $\tau=(y_1,\ldots,y_T)$;需要时把停止 token 也包括进去。第 $t$ 个 token 前的前缀是 $h_t=(x,y_{<t})$。Trajectory(轨迹)就是这些连续决策合在一起。自回归生成意味着:

\[p_\theta(\tau\mid x)=\prod_{t=1}^T p_\theta(y_t\mid h_t), \qquad q(\tau\mid x)=\prod_{t=1}^T q(y_t\mid h_t).\]

取对数把连乘变成求和,因此整条回答的 score 是:

\[\nabla_\theta\log p_\theta(\tau\mid x) =\sum_{t=1}^T s_\theta(y_t,h_t).\]

若完整回答的 terminal reward $R(\tau)$ 不直接依赖 $\theta$,精确目标梯度为:

\[\boxed{\nabla_\theta J =\mathbb E_{\tau\sim p_\theta} \left[R(\tau)\sum_t s_\theta(y_t,h_t)\right]}.\]

要把采样分布换成 $q$,必须使用同一个随机对象——整条轨迹——的概率比:

\[\boxed{w(\tau)=\frac{p_\theta(\tau\mid x)}{q(\tau\mid x)} =\prod_t\frac{p_\theta(y_t\mid h_t)}{q(y_t\mid h_t)}}.\]

满足 support coverage 与可积性时,$\mathbb E_q[w(\tau)R(\tau)\sum_t s_\theta]=\nabla_\theta J$。可变回答长度也要通过停止概率计入,不能直接忽略。若两个策略面对相同环境转移,轨迹比值中的环境概率因子会抵消;若 prompt 分布或环境不同,还需要另外处理。

每个分母都必须是生成该 token 当时真正使用的概率,包括 temperature 或 sampling filter 的影响。之后用更新后的 sampler 重算,不代表旧数据的真实生成概率。Top-$k$/top-$p$ sampling 还可能直接去掉某些 support;这时仅靠已有样本,无法精确恢复未截断目标的平均值。

6.2 Why One Token's Ratio Is Usually Insufficient

At a fixed prefix, a ratio $p(a\mid h)/q(a\mid h)$ corrects the next-action frequencies. But a response-level gradient also depends on how often we reach that prefix and what happens afterward.

A two-token example isolates the first problem. Only the first token “A” allows a reward; otherwise reward is zero. Under $p$, A appears with probability $0.9$; under $q$, with probability $0.5$. At prefix A, the second token is binary with the same probability $0.5$ under both policies, and reward equals that second binary outcome. Let $\theta$ affect only this second decision.

The correct derivative is $0.9\times0.5(1-0.5)=0.225$. The current-token ratio at the second step is exactly one, yet the corresponding estimate under $q$ has mean $0.5\times0.25=0.125$. It is wrong because A appears too rarely. The first-step ratio $0.9/0.5$ restores the missing frequency.

There is a second issue for terminal rewards. Define $Q^p(h,a)$ as the expected eventual reward after choosing $a$ at $h$ and continuing with $p$. Rollouts continued under $q$ generally estimate $Q^q(h,a)$ instead. Correcting only the action at $h$ fixes neither the preceding prefix distribution nor this future continuation distribution.

More formally, if $d_t^p(h)$ is the probability of prefix $h$ at step $t$ under $p$, the exact gradient is

\[\nabla_\theta J =\sum_t\mathbb E_{h\sim d_t^p,\ a\sim p(\cdot\mid h)} \left[Q^p(h,a)s_\theta(a,h)\right].\]

Exact alternative estimators can use appropriate prefix ratios, per-decision weighting, or a correct target-policy value function. The point is not that full-trajectory weighting is the only possibility. It is that a local token ratio alone is not an exact full-trajectory correction in general.

For long responses, products of ratios can become extremely uneven; computing the product via sums of log-ratios avoids numerical underflow but does not fix statistical variance. Clipping, filtering, and token-local surrogates address practical difficulties at the price of changing the estimator.

固定前缀时,$p(a\mid h)/q(a\mid h)$ 能修正下一个动作的频率。但完整回答的梯度还依赖这个前缀出现得有多频繁,以及后面如何继续生成。

一个两 token 的例子可以单独暴露第一个问题。只有第一个 token 为 A 才可能得到奖励,否则奖励为零。$p$ 以 $0.9$ 的概率产生 A,$q$ 以 $0.5$ 的概率产生 A。在前缀 A 后,第二个 token 是二分类;两策略选择 1 的概率都为 $0.5$,reward 等于这个第二步结果。令 $\theta$ 只影响第二步。

正确梯度为 $0.9\times0.5(1-0.5)=0.225$。第二步的 token 概率比恰好为 1,但 $q$ 数据上的估计均值是 $0.5\times0.25=0.125$。错误来自 A 出现得太少。补上第一步的概率比 $0.9/0.5$ 才恢复所缺的频率。

Terminal reward 还有第二个问题。定义 $Q^p(h,a)$:在 $h$ 选择 $a$,后续按 $p$ 继续时,最终 reward 的期望。后续按 $q$ 生成的 rollouts 一般估计的是 $Q^q(h,a)$。只修正 $h$ 处的动作,既不修正此前的前缀分布,也不修正之后的 continuation 分布。

更正式地,若 $d_t^p(h)$ 是 $p$ 在第 $t$ 步到达前缀 $h$ 的概率,则:

\[\nabla_\theta J =\sum_t\mathbb E_{h\sim d_t^p,\ a\sim p(\cdot\mid h)} \left[Q^p(h,a)s_\theta(a,h)\right].\]

其他精确 estimator 可以使用合适的 prefix ratios、per-decision weighting,或正确的目标策略 value function。这里不是说完整轨迹权重是唯一方法,而是说:单独一个局部 token ratio,一般不等于完整轨迹的精确校正。

长回答中的概率比连乘可能非常不均匀。用 log-ratios 求和可以避免数值下溢,却不解决统计方差。Clipping、filtering、token-local surrogate 可以缓解实际困难,但也改变了 estimator。

6.3 Why GRPO's Group Centering Does Not Settle the Problem

For $G$ responses to one prompt, simple group centering forms $A_i=R_i-\bar R$, where $\bar R=G^{-1}\sum_iR_i$. The advantage $A_i$ says whether response $i$ scored above the group average. Thus $\sum_i A_i=0$. GRPO variants may additionally divide by a group standard deviation; we isolate mean subtraction first.

At the shared first prefix, a correction vector $c$ really does cancel from this finite group:

\[\sum_i A_i(s_i-c)=\sum_i A_i s_i-c\underbrace{\sum_i A_i}_{0}.\]

This is a valid special case, not an explanation of the general linear-softmax critique. After responses branch, their prefixes differ, so their correction vectors $c(h_{i,t})$ differ. Then $\sum_i A_i c(h_{i,t})$ need not vanish.

Here is a concrete conditional example. Half the sampled responses enter a “good” prefix whose eventual reward is always one; half enter a “bad” prefix whose reward is always zero. Subtract the exact prompt-level mean, $0.5$. At the good prefix, expected advantage is $+0.5$; at the bad prefix it is $-0.5$. Suppose an irrelevant next token has $q=0.8$, $p=0.6$. Its average score is $0.2$, although its choice does not affect reward. Raw local pushes are therefore $+0.1$ and $-0.1$ at the two prefixes; local SC removes both. If the prefixes use different parameter directions, even their global vector sum need not cancel.

The exact prefix baseline $b(h)=\mathbb E_q[R\mid h]$ would instead yield

\[\mathbb E_q[(R-b(h))s_p\mid h] =\operatorname{Cov}_q(R,s_p\mid h).\]

This equals the expected SC update at that prefix. But it requires the correct prefix-specific expected return, not just a group mean at the initial prompt. It still gives a $q$-covariance, not a recovered $p$-gradient.

Finite groups: subtracting a sample mean is not quite an independent baseline

For independent, identically distributed one-step pairs $(R_i,s_i)$, including the current reward in $\bar R$ gives

\[\mathbb E\!\left[\frac1G\sum_i(R_i-\bar R)s_i\right] =\left(1-\frac1G\right)\operatorname{Cov}(R,s).\]

To see this, $\mathbb E[\bar R s_i]=G^{-1}\mathbb E[R_i s_i]+(G-1)G^{-1}\mathbb E[R]\mathbb E[s]$. Subtracting it leaves the factor above. A leave-one-out mean uses only other independent rewards and removes this factor. Dividing by a random group standard deviation is another change; neither calculation by itself describes every GRPO implementation.

同一 prompt 生成 $G$ 个回答,简单的 group centering 使用 $A_i=R_i-\bar R$,其中 $\bar R=G^{-1}\sum_iR_i$。Advantage $A_i$ 表示第 $i$ 条回答是否比组内平均更好,因此 $\sum_i A_i=0$。GRPO 的一些版本还除以组内 standard deviation;我们先只研究减均值。

在所有回答共享的第一个前缀,一个相同的修正向量 $c$ 的确会在有限组内抵消:

\[\sum_i A_i(s_i-c)=\sum_i A_i s_i-c\underbrace{\sum_i A_i}_{0}.\]

这是正确的特殊情形,却不是一般 linear-softmax 质疑的含义。回答分叉之后,各自前缀不同,修正向量 $c(h_{i,t})$ 也不同,$\sum_i A_i c(h_{i,t})$ 不再必然为零。

看一个条件分布例子:一半回答进入“好”前缀,最终 reward 恒为 1;另一半进入“坏”前缀,reward 恒为 0。即使减去精确的 prompt 平均奖励 $0.5$,好前缀下的期望 advantage 仍是 $+0.5$,坏前缀下是 $-0.5$。假设接下来一个与 reward 无关的 token 有 $q=0.8,p=0.6$,平均 score 为 $0.2$。于是两前缀分别产生 $+0.1$、$-0.1$ 的局部推力,虽然这个 token 选什么根本不改变 reward;逐前缀 SC 会消除这两项。若两个前缀对应不同参数方向,就连全局向量求和也未必抵消。

如果使用精确的逐前缀 baseline $b(h)=\mathbb E_q[R\mid h]$,则:

\[\mathbb E_q[(R-b(h))s_p\mid h] =\operatorname{Cov}_q(R,s_p\mid h).\]

它在该前缀下的期望等于 SC,但需要正确的 prefix-specific expected return,不是初始 prompt 上的一个 group mean。它仍然给出 $q$ 下的 covariance,不是恢复了 $p$ 的梯度。

有限样本补充:组内均值不是独立于当前样本的 Baseline

对独立同分布的单步 $(R_i,s_i)$,若 $\bar R$ 包含当前样本自己的 reward,则:

\[\mathbb E\!\left[\frac1G\sum_i(R_i-\bar R)s_i\right] =\left(1-\frac1G\right)\operatorname{Cov}(R,s).\]

因为 $\mathbb E[\bar R s_i]=G^{-1}\mathbb E[R_i s_i]+(G-1)G^{-1}\mathbb E[R]\mathbb E[s]$,相减就得到这个系数。Leave-one-out mean 只使用其他独立样本的奖励,会消除该系数。再除随机的组内 standard deviation 是另一项变化;这些推导都不能直接等同于所有 GRPO 实现。

7. Turning the Update into a Loss

7.1 One Scalar Loss, No Per-Token Parameter Jacobians

The formula $\bar s=\sum_a q(a)\nabla_\theta\log p_\theta(a)$ may appear to require one enormous parameter-gradient vector for every vocabulary entry. Linearity of differentiation avoids that. At a fixed prefix, define a scalar surrogate loss:

\[L_{\rm SC} =-\operatorname{sg}(R) \left[\log p_\theta(y)-\sum_a\operatorname{sg}(q(a))\log p_\theta(a)\right].\]

Here $\operatorname{sg}$ means stop-gradient: keep the numerical value but do not differentiate through its calculation. Differentiating the scalar produces

\[-\nabla_\theta L_{\rm SC}=R(s_p(y)-\bar s).\]

Thus gradient descent on this loss implements the desired ascent update in one backward pass. “Surrogate” matters: its gradient specifies a local update; the scalar is not necessarily the original expected-reward objective or an unbiased estimate of its value.

Rewards or advantages are treated as fixed multipliers. Logged sampler probabilities are fixed too. If a coefficient is calculated using current trainer probabilities, it may still need to be detached to implement a specified update. Numerical dependence and differentiation paths are different questions.

For IS there are two valid scalar constructions when $q$ is fixed. Differentiating $-R\,p_\theta(y)/q(y)$ gives $-Rw s_p$. Alternatively, differentiating $-\operatorname{sg}(Rw)\log p_\theta(y)$ gives the same gradient at the evaluation point. But leaving $w$ differentiable in the latter expression adds an unwanted product-rule term:

\[\nabla_\theta[w\log p_\theta(y)] =w(1+\log p_\theta(y))s_p(y).\]

The snippet uses the detached-weight surrogate convention consistently.

$\bar s=\sum_a q(a)\nabla_\theta\log p_\theta(a)$ 看起来像是要给每个词表项保存一个巨大的参数梯度向量。其实求导的线性性质可以避免这一点。固定前缀,定义标量 surrogate loss:

\[L_{\rm SC} =-\operatorname{sg}(R) \left[\log p_\theta(y)-\sum_a\operatorname{sg}(q(a))\log p_\theta(a)\right].\]

$\operatorname{sg}$ 即 stop-gradient:保留数值,但不沿其计算过程求导。对这个标量求导:

\[-\nabla_\theta L_{\rm SC}=R(s_p(y)-\bar s).\]

所以一次 backward,对 loss 做 gradient descent,就实现了所需的 ascent 更新。“Surrogate”很重要:它的梯度规定局部更新,但这个标量本身不一定等于原始 expected reward,也不一定是该目标值的无偏估计。

Reward/advantage 作为固定乘数,记录的 sampler 概率也固定。即使某个系数使用当前 trainer 概率计算,为实现指定更新也可能必须 detach。数值上依赖某个量与求导时沿哪条路径传播是两个问题。

对 IS,固定 $q$ 后有两种有效写法。对 $-R\,p_\theta(y)/q(y)$ 直接求导,会得到 $-Rw s_p$;对 $-\operatorname{sg}(Rw)\log p_\theta(y)$ 求导,也在当前求值点得到相同梯度。但若在后一种写法中不 detach $w$,乘法求导会引入多余项:

\[\nabla_\theta[w\log p_\theta(y)] =w(1+\log p_\theta(y))s_p(y).\]

下面 snippet 始终采用 detached-weight surrogate 的约定。

7.2 Combining SC with IS: Center the Weighted Score

Let $u(a)$ be an action weight: one for plain SC, the exact ratio for IS, or a clipped/masked ratio. Start from the weighted score $u(a)s_p(a)$, and compute its mean

\[c_u=\mathbb E_q[u(a)s_p(a)].\]

The centered weighted update is

\[\boxed{\widehat g_{u+\rm SC} =R(y)\left[u(y)s_p(y)-c_u\right]}.\]

Its conditional expectation is $\operatorname{Cov}_q(R,u s_p)$, so constant reward again gives zero. A full-vocabulary surrogate is

\[L_{u+\rm SC} =-\operatorname{sg}(R)\left[ \operatorname{sg}(u(y))\log p_\theta(y) -\sum_a\operatorname{sg}(q(a)u(a))\log p_\theta(a) \right].\]

For exact, untruncated local IS, $u=p/q$, and $c_u=\sum_a p(a)s_p(a)=0$. There is no remaining local drift for SC to remove. Clipped or masked weights generally have $c_u\neq0$, so an additive correction can still change their update. This local identity does not remove the trajectory issues in §6.

It would be a different operation to multiply an already centered score by IS:

\[\mathbb E_q[wR(s_p-\bar s)] =g_p-\bar s\,\mathbb E_p[R]\]

in the one-step setting. The extra term generally destroys exact recovery. “Combine SC and IS” therefore needs an explicit formula; the order is not interchangeable.

令 $u(a)$ 是动作权重:普通 SC 时取 1,精确 IS 时取概率比,也可以取 clipped/masked ratio。先从加权 score $u(a)s_p(a)$ 出发,计算它的均值:

\[c_u=\mathbb E_q[u(a)s_p(a)].\]

然后进行 centering:

\[\boxed{\widehat g_{u+\rm SC} =R(y)\left[u(y)s_p(y)-c_u\right]}.\]

条件期望为 $\operatorname{Cov}_q(R,u s_p)$,所以恒定奖励再次给出零。对应的完整词表 surrogate 是:

\[L_{u+\rm SC} =-\operatorname{sg}(R)\left[ \operatorname{sg}(u(y))\log p_\theta(y) -\sum_a\operatorname{sg}(q(a)u(a))\log p_\theta(a) \right].\]

精确、未截断的局部 IS 中,$u=p/q$,所以 $c_u=\sum_a p(a)s_p(a)=0$,没有剩余局部 drift 需要 SC 移除。但 clipped/masked 权重一般使 $c_u\neq0$,加法修正仍会改变更新。这个局部恒等式不会解决第 6 节的完整轨迹问题。

如果反过来,先 center 再乘 IS,则是另一种操作。在单步情形:

\[\mathbb E_q[wR(s_p-\bar s)] =g_p-\bar s\,\mathbb E_p[R].\]

多余项一般破坏精确恢复。因此“把 SC 与 IS 结合”必须写明具体公式,顺序不是随意的。

Snippet 1. Full-vocabulary, one-step teaching implementation. Hover, focus, or click highlighted expressions for shapes and gradient-path notes. Token-local application is not full-trajectory IS.
Snippet 1:完整词表、单步教学实现。Hover、键盘选中或点击高亮表达式,可查看 shape 与求导路径。逐 token 使用不等于完整轨迹 IS。

7.3 What Changes When Only Top-k Probabilities Are Logged?

Logging every vocabulary probability at every generated position is expensive. The supplied discussion describes the paper’s top-$k$ approach; the official implementation specifies $k=128$ and a tail proportional to trainer probabilities. Here is why that approximation yields a short correction.

Let $H$ be the saved token set, $P_T=1-\sum_{a\in H}p(a)$, $Q_T=1-\sum_{a\in H}q(a)$, and $\rho=Q_T/P_T$, assuming $P_T>0$. Define

\[\widehat q(a)= \begin{cases} q(a),&a\in H,\\ \rho p(a),&a\notin H. \end{cases}\]

The tail has the right total mass but assumes the trainer has the right relative probabilities within it. Using $\sum_a p(a)s_p(a)=0$,

\[\begin{aligned} \widehat{\bar s} &=\sum_{a\in H}q(a)s_p(a)+\rho\sum_{a\notin H}p(a)s_p(a)\\ &=\sum_{a\in H}[q(a)-\rho p(a)]s_p(a). \end{aligned}\]

Detach the coefficient $q(a)-\rho p(a)$ when using it in a log-probability surrogate. Do not renormalize the saved head to sum to one: that would erase tail mass. The actually sampled token can lie outside the head and still needs its own logged sampling probability for IS.

Exact zero drift now holds under $\widehat q$, not automatically under the actual $q$. Under actual sampling, the residual is $\mathbb E_q[s_p]-\mathbb E_{\widehat q}[s_p]$. Near-zero trainer tail mass also needs numerical handling; an epsilon prevents invalid division but does not make a wrong tail model correct. If the whole vocabulary is saved, use the full sum rather than computing an unnecessary $0/0$ tail ratio.

每个生成位置都记录整个词表的概率,存储开销很大。前面的讨论提到了论文的 top-$k$ 方法;官方实现 使用 $k=128$,并用与 trainer 概率成比例的 tail。下面推导为什么能把修正压缩成一个短和式。

令 $H$ 为保存的 token 集合,$P_T=1-\sum_{a\in H}p(a)$、$Q_T=1-\sum_{a\in H}q(a)$,$\rho=Q_T/P_T$,暂假设 $P_T>0$。定义:

\[\widehat q(a)= \begin{cases} q(a),&a\in H,\\ \rho p(a),&a\notin H. \end{cases}\]

Tail 的总概率是对的,但其内部相对概率假设与 trainer 相同。利用 $\sum_a p(a)s_p(a)=0$:

\[\begin{aligned} \widehat{\bar s} &=\sum_{a\in H}q(a)s_p(a)+\rho\sum_{a\notin H}p(a)s_p(a)\\ &=\sum_{a\in H}[q(a)-\rho p(a)]s_p(a). \end{aligned}\]

在 log-probability surrogate 中,要 detach 系数 $q(a)-\rho p(a)$。不要把保存的 head 重新归一化到和为 1,否则会抹掉 tail mass。实际抽到的 token 可能不在 head 内;使用 IS 时仍需要单独保存它当时的采样概率。

现在精确零 drift 对 $\widehat q$ 成立,不自动对真实 $q$ 成立。真实采样下,剩余均值是 $\mathbb E_q[s_p]-\mathbb E_{\widehat q}[s_p]$。Trainer tail mass 接近零时还需数值处理;epsilon 可以防止非法除法,却不能让错误的 tail 模型变正确。如果保存的是整个词表,就直接算完整和式,不必构造 $0/0$ 的 tail ratio。

8. What the Evidence Supports—and What It Does Not

The paper compares corrections on shared group-centered REINFORCE training with SGD. It reports useful SC behavior under quantization and stronger SC-plus-IS behavior under severe staleness. Tests deliberately amplify mismatch and use short sequences; these are limits on extrapolation, not hidden guarantees for long agentic runs. See §5 and the limitations. The supplied discussion’s stability interpretation is consistent with those reported results.

Our independent calculations separate the claims:

Question Conclusion
Does exact SC remove the defined conditional drift? Yes, when the mean score uses the actual sampler distribution.
Does it recover the current trainer’s gradient? Not generally; the binary example already disproves it.
Is it guaranteed closer than the raw update? No; drift and covariance error can cancel.
Does exact IS recover the target gradient? Yes, with the right sampling object, support, and integrability.
Are clipped or token-local IS automatically exact? No. Their scope and bias must be analyzed.
Does failure of target recovery imply no practical value? No. Stability and finite-sample tradeoffs remain meaningful.

The shortest intuition is this: SC recenters the arrows produced by the sampler; IS changes how frequently those arrows count toward the target average. Recentring can remove a harmful common push without relocating the entire average to the trainer’s objective. In the binary case, the distinction is visible in four numbers: target $0.09$, raw $0.08$, SC $0.16$, exact IS $0.09$.

That is why the debate should not be summarized as either “SC fixes off-policy gradients” or “SC does nothing.” A more defensible description is a drift-removing update with possible stability benefits, whose remaining target-gradient bias must be acknowledged.

论文在共享的 group-centered REINFORCE 与 SGD 设定中比较不同修正;量化实验显示 SC 的作用,严重 staleness 下 SC 与 IS 组合更有利。实验刻意放大 mismatch,并使用较短序列;这限制了向长 agentic 训练的外推,不是长期训练的隐藏保证。见第 5 节及局限。所提供讨论将其理解为稳定化方法,与这些实验结果相符。

本文的独立计算把几个命题分开:

问题 结论
精确 SC 是否移除了定义中的条件 drift? 是,前提是平均 score 使用真实 sampler 分布。
是否恢复当前 trainer 的梯度? 一般没有,二分类反例已经足够说明。
是否保证比原始更新更接近目标? 没有;drift 与 covariance 误差可能相互抵消。
精确 IS 能否恢复目标梯度? 能,但要使用正确采样对象,并满足 support 与可积性条件。
Clipped/token-local IS 是否自动精确? 不是,需要分别检查适用范围和 bias。
不能恢复目标梯度是否意味着没有实际价值? 不是;稳定性与有限样本折中仍有意义。

最短的直觉是:SC 把 sampler 产生的更新箭头重新居中;IS 改变这些箭头在目标平均值中应占的份额。 重新居中可以消除一个有害共同推力,却没有因此把整个平均值搬到 trainer 的目标上。二分类中,四个数就能看见区别:目标 $0.09$、原始 $0.08$、SC $0.16$、精确 IS $0.09$。

所以这场争论不应总结为“SC 修好了 off-policy gradient”,也不应总结为“SC 什么都没做”。更准确的定位是:一种消除特定 drift、可能改善稳定性的更新方法,但仍须承认它与目标梯度之间的剩余 bias。