Author: Jian Hu

First published on: 2026/11/25

1. The problem in one paragraph

When we train a language model with reinforcement learning, the model writes a response, the response gets a reward, and we nudge the model so that tokens appearing in well-rewarded responses become more likely.

In practice this takes two engines. The sampler (an inference engine) generates the tokens. The trainer computes gradients and updates the weights. They are supposed to be the same model, but the sampler may be quantized, may use different numerical kernels, or may be running weights that are a few updates old. So the two engines assign slightly different probabilities to the same token. This is called training–inference mismatch.

This note compares the two standard corrections. For each one we ask two questions: is its average right (bias), and how much does it jump around from sample to sample (variance)?

2. Notation

Fix one prefix, meaning everything generated so far, including the prompt. All quantities below live at that prefix.

Symbol Meaning
$N$ Vocabulary size. Tokens are numbered $1$ to $N$. The subscripts $k$, $j$, $v$ always mean “which token”.
$z=(z_1,\dots,z_N)$ The trainer’s logits: one number per token.
$\tilde z=(\tilde z_1,\dots,\tilde z_N)$ The sampler’s logits. A tilde always means “the sampler’s version”.
$p_k$ The trainer’s probability of token $k$: $p_k = e^{z_k} / \sum_{j=1}^N e^{z_j}$. This is the softmax. $p$ is the vector $(p_1,\dots,p_N)$.
$q_k$ The sampler’s probability of token $k$: $q_k = e^{\tilde z_k} / \sum_{j=1}^N e^{\tilde z_j}$. $q$ is the vector.
$y$ The token that was actually sampled. It equals $k$ with probability $q_k$, because the sampler drew it.
$e_y$ The one-hot vector of $y$: its $y$-th entry is $1$, all others are $0$. $(e_y)_k$ is its $k$-th entry, so $(e_y)_k=1$ if $y=k$ and $0$ otherwise.
$\mathbb{E}_{y\sim q}[f(y)]$ The average of $f(y)$ when $y$ is drawn from $q$: $\sum_{y=1}^N q_y\, f(y)$. With $p$ in place of $q$ it is $\sum_y p_y\, f(y)$.
$A$ The advantage: one number saying how much better this response did than a reference level (reward minus a baseline).

Two running examples, both with a two-token vocabulary:

Why it is enough to look at the logits

The weights of the model, call them $\theta$, affect $\log p_y$ only through the logits $z$. The chain rule says

$$ \frac{\partial \log p_y}{\partial \theta_i}=\sum_{k=1}^N \frac{\partial \log p_y}{\partial z_k}\cdot\frac{\partial z_k}{\partial \theta_i}. $$

In words: to get the gradient with respect to the weights, take the vector of derivatives with respect to the logits and backpropagate it through the trainer’s network. SC and IS differ only in which vector they place on the logits. The backpropagation step is identical. So we compare vectors on the logits and nothing else.

3. The score of a softmax policy is $e_y - p$

The score is the vector of derivatives of $\log p_y$ with respect to the logits. It answers: how should the logits move to make token $y$ more likely?

Claim. $\dfrac{\partial \log p_y}{\partial z_k}=(e_y)_k-p_k$.

Proof. Write out $\log p_y$:

$$ \log p_y=\log\frac{e^{z_y}}{\sum_j e^{z_j}}=z_y-\log\sum_j e^{z_j}. $$