Logit Gradient Correction: Deriving Score Centering from Logit Gradients
This post derives SCORE CENTERING from removing a bias term in the logit gradient before it is propagated through the logit Jacobian via chain rule, and then derives the corresponding surrogate objective.
Background: REINFORCE and the Logit Gradient
At a fixed prefix , a trainer with parameters produces logits over a vocabulary of size . Its probability vector defines the trainer distribution , with . A sampler at the same prefix generates token , with probabilities and . During backward, the recorded and reward are held fixed. Scalars use plain letters, vectors bold lowercase, and matrices bold uppercase.
REINFORCE wants to increase the trainerβs expected reward under the trainerβs own distribution :
Holding the reward function fixed, differentiate with respect to to obtain :
The term is REINFORCEβs per-sample gradient contribution. With held fixed, it equals the negative gradient with respect to of the reward-weighted cross-entropy loss .
We first differentiate with respect to the logits . Given that , we have
Here, is the sampled tokenβs one-hot vector. The gradient contains the derivatives of with respect to the logits of all vocabulary tokens. The mean logits contribution on the right therefore determines the mean parameter contribution.
Log-Prob Gradients Have Zero/Nonzero Bias when On/off-Policy
We consider a scenario that for every token, we have:
Thus the gradient of with respect to the model parameters will be
The matrix is the trainerβs logit Jacobian: it describes how the logits change with the model parameters. Its transpose maps a -dimensional logits gradient to a -dimensional parameter gradient, applying the chain rule through backpropagation. At a fixed prefix and parameter value, this matrix is the same for every possible sampled token, so it can be moved outside the expectation. Score Centering supplies a corrected logits gradient to this same backward pass.
If the tokens are generated by the trainer distribution , the expectation equals ,
the logits gradient is unbiased and has zero mean when the reward is constant.
Logit Gradient Correction
If tokens instead come from the sampler distribution , then . Still assuming , the mean trainer log-probability gradient becomes:
Here specifies where tokens come from; the differentiated log-probability still belongs to . This expression is the mean sampled contribution, not the gradient of the samplerβs expected reward.
Since every reward is , the trainer objective has zero gradient. We want the corrected contributions to have zero mean even when tokens come from . Shift each one-hot contribution by , giving .
Let denote the per-sample surrogate objective that we will construct in the next section. We require its expected parameter gradient to equal the corrected mean contribution. With held fixed during backward, this requirement is:
The essential of this correction is to replace each tokenβs logits gradient contribution with . Averaging under the sampler distribution then gives , restoring zero mean for constant rewards.
From Corrected Logit Gradient to a Surrogate Objective
We now construct the per-sample surrogate . For constant reward , the required relation is:
For varying rewards, we weight each corrected contribution by . The required gradient of the expected surrogate is
First, we seek a scalar surrogate objective in terms of the logits , and whose gradient with respect to the logits is:
The required gradient is constant with respect to . An intuitive antiderivative is a linear function whose gradient equals its coefficient vector:
The last line uses . The sum is the sampler-weighted average of the trainerβs logits over the entire vocabulary. The operator holds the probabilities fixed during differentiation while preserving gradients through the logits.
Second, we express the surrogate objective in terms of log-probabilities. Softmax gives for every token . Using , we obtain:
We have the surrogate objective in terms of log-probability:
The surrogate loss replaces the per-sample REINFORCE objective with times the difference between the sampled tokenβs trainer log-probability and the -weighted average of the trainerβs log-probabilities over the vocabulary.
Averaging the per-sample surrogate over tokens drawn from gives:
