DPO Concept › The Key Insight: Reparameterizing the Reward

Michael BrenndoerferDecember 31, 20259 min read
Language AI HandbookAll chapters
Part 37 of 67Alignment and RLHF
Chapter 282DPO Concept › The Key Insight: Reparameterizing the Reward
Reading section 3 of 14 · The Key Insight: Reparameterizing the Reward · 9 minSection 3 of 14 · 9 min

Book contents

Section 3 of 14 · 9 min read

DPO Concept › The Key Insight: Reparameterizing the RewardOne section · Sections in this chapter3 / 14 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

The key insight behind DPO comes from recognizing a mathematical relationship within the RLHF objective. To understand this insight, we need to look carefully at the RLHF objective and ask whether we can express the same goal in a different, more tractable way.

The insight, stated plainly before we get into the math: any reward function uniquely determines the optimal aligned policy, and conversely, any policy uniquely determines the reward function that would make it optimal. Reward functions and optimal policies are two descriptions of the same thing. Once you realize this, the reward model becomes unnecessary. You can work directly in policy space, using the policy itself as an implicit reward model.

Consider the RLHF objective we have been working with throughout this book:

max⁡πθEx∼D,y∼πθ(y∣x)[rϕ(x,y)−βlog⁡πθ(y∣x)πref(y∣x)]\max_{\pi_\theta} \mathbb{E}_{x \sim \mathcal{D}, y \sim \pi_\theta(y|x)} \left[ r_\phi(x, y) - \beta \log \frac{\pi_\theta(y|x)}{\pi_{\text{ref}}(y|x)} \right]

Let's carefully examine each component of this expression to build understanding:

  • πθ\pi_\theta: the policy model being trained, parameterized by weights θ\theta
  • D\mathcal{D}: the dataset of prompts xx that we want the model to respond to well
  • rϕ(x,y)r_\phi(x, y): the reward model score for completion yy given prompt xx, representing how much humans would prefer this response
  • β\beta: the KL penalty coefficient that controls how much the policy can deviate from the reference, balancing preference optimization against stability
  • πref\pi_{\text{ref}}: the reference model (usually the initial SFT model) used as an anchor to prevent the policy from changing too drastically

This objective captures a basic tradeoff. We want a policy that generates high-reward outputs, meaning outputs that humans would prefer according to our reward model. At the same time, we want to stay close to the reference model. This keeps we don't lose the useful capabilities the model learned during pretraining and supervised fine-tuning. The term log⁡πθ(y∣x)πref(y∣x)\log \frac{\pi_\theta(y|x)}{\pi_{\text{ref}}(y|x)} measures how much the policy has diverged from the reference, and β\beta controls how heavily we penalize this divergence. Small β\beta allows large deviations; large β\beta keeps the policy anchored near its starting point.

Now here is where the key insight emerges. This constrained optimization problem, despite its apparent complexity, has a closed-form solution. Given any reward function r(x,y)r(x, y), we can write down exactly what the optimal policy looks like without doing any iterative optimization:

π∗(y∣x)=1Z(x)πref(y∣x)exp⁡(1βr(x,y))\pi^*(y|x) = \frac{1}{Z(x)} \pi_{\text{ref}}(y|x) \exp\left(\frac{1}{\beta} r(x, y)\right)

where:

  • π∗(y∣x)\pi^*(y|x): the optimal policy for the given reward function, meaning the policy that maximizes our objective
  • yy: a completion sequence, any possible output the model could generate
  • xx: a prompt sequence, the input the model is responding to
  • Z(x)Z(x): the partition function (normalizing constant) that ensures probabilities sum to 1 over all possible completions for prompt xx
  • πref(y∣x)\pi_{\text{ref}}(y|x): the reference model distribution, our starting point before reward-based shaping
  • r(x,y)r(x, y): the reward function defining what outputs we prefer
  • β\beta: the temperature parameter controlling the sharpness of the distribution

The formula has a beautiful interpretation. The optimal policy takes the reference model and reweights each possible output according to its reward. Outputs with high reward get amplified by the exponential term, while outputs with low reward get suppressed. The partition function Z(x)Z(x) then normalizes everything so probabilities sum to one. The parameter β\beta controls how aggressive this reweighting is: small β\beta creates sharp distributions concentrated on high-reward outputs, while large β\beta keeps the distribution closer to the original reference. Think of β\beta as controlling how strongly you "listen" to the reward signal versus how strongly you "remember" where you started.

Out[3]:
Visualization
Gaussian reference distribution centered at zero response quality showing the starting probability density.
Reference distribution of the language model centered on average-quality responses, before any reward-based reweighting. This Gaussian represents the base model's probability mass across the response quality axis.
Linear reward function plot with green shading for high-reward region and red shading for low-reward region.
Linear reward function assigning positive scores to high-quality responses (green shading) and negative scores to low-quality responses (red shading). The reward linearly increases with response quality.
Comparison of reference and optimal policy distributions showing rightward shift toward higher quality responses.
The optimal policy (red) reweights the reference distribution (blue dashed) according to rewards, shifting substantial probability mass toward preferred outputs. The degree of shift is controlled by β.

This relationship works in both directions. We can go from reward to optimal policy using the formula above. But we can also go in the other direction, from policy to reward. If we take the expression for the optimal policy and solve for the reward, we get:

r(x,y)=βlog⁡π∗(y∣x)πref(y∣x)+βlog⁡Z(x)r(x, y) = \beta \log \frac{\pi^*(y|x)}{\pi_{\text{ref}}(y|x)} + \beta \log Z(x)

where:

  • r(x,y)r(x, y): the reward function value we are trying to recover
  • β\beta: the scaling parameter derived from the KL coefficient
  • π∗(y∣x)\pi^*(y|x): the optimal policy probability for generating yy given xx
  • πref(y∣x)\pi_{\text{ref}}(y|x): the reference model probability
  • Z(x)Z(x): the partition function, a constant that depends only on the prompt xx and not on the completion yy

The key observation is that Z(x)Z(x) does not depend on yy. It is a normalizing constant that ensures the optimal policy integrates to one over all completions, but it is the same constant for every completion given a fixed prompt. This means that when we compare two completions ywy_w and yly_l for the same prompt, Z(x)Z(x) cancels out.

This reparameterization is the engine of DPO. It says that any reward function corresponds to some optimal policy, and conversely, any policy implicitly defines a reward function. The reward a policy assigns to an output is simply, up to a constant, the log-probability ratio between that policy and the reference model, scaled by β\beta. When the policy assigns much higher probability to a response than the reference model does, that response has high implicit reward. When the policy assigns lower probability than the reference, the response has low implicit reward.

Implicit Reward

The reward function implicitly defined by a policy πθ\pi_\theta relative to reference model πref\pi_{\text{ref}} is:

r(x,y)=βlog⁡πθ(y∣x)πref(y∣x)r(x, y) = \beta \log \frac{\pi_\theta(y|x)}{\pi_{\text{ref}}(y|x)}

Higher probability under πθ\pi_\theta relative to πref\pi_{\text{ref}} means higher implicit reward. This is not an approximation; it is an exact mathematical relationship that holds for any policy. The log-ratio measures exactly how much the policy has boosted or suppressed the probability of a given completion relative to where it started.

This duality between rewards and policies suggests a different approach to preference learning. Instead of learning a reward function and then finding the optimal policy for that reward, we might be able to learn the optimal policy directly. The reward function would then be implicitly defined by whatever policy we learn. We never need to write down the reward explicitly.

Why the Partition Function Matters

The partition function Z(x)=∑yπref(y∣x)exp⁡(r(x,y)/β)Z(x) = \sum_y \pi_{\text{ref}}(y|x) \exp(r(x,y) / \beta) is a sum over all possible completions for the prompt xx. For a language model with a vocabulary of even 32,000 tokens and sequences of even 100 tokens, this sum has 3200010032000^{100} terms. It is completely intractable to compute directly.

This is why the traditional RLHF approach never tries to compute it. When you train a reward model with the Bradley-Terry loss, you compare two specific completions, and the partition function drops out of the comparison. When you optimize with PPO, you generate samples from the current policy, and again you never need to enumerate all possible completions.

DPO inherits this tractability advantage. As we will see in the next section, the partition function cancels when we compute preference probabilities, because it appears identically in both terms of the comparison. The fact that Z(x)Z(x) cancels is not a coincidence or a lucky accident; it is a direct consequence of the mathematical structure of the reward-policy duality. Understanding why it cancels is central to understanding why DPO works at all.