Reinforcement learning from human feedback (RLHF) transformed autoregressive large language models from raw next-token predictors into instruction-following assistants. At the computational center of the foundational RLHF pipelines introduced in InstructGPT (Ouyang et al., 2022) is Proximal Policy Optimization (PPO), formulated by John Schulman, Filip Wolski, Prafulla Dhariwal, Alec Radford, and Oleg Klimov at OpenAI in 2017.
PPO resolved a fundamental instability in policy gradient methods: the destructive impact of large parameter updates on policy behavior. In standard supervised learning, a bad gradient step slightly degrades loss on the current batch but rarely causes permanent divergence. In reinforcement learning, where training data is generated dynamically by the model's own policy, a single destabilizing gradient step can shift policy distributions into degenerate regimes from which recovery is mathematically impossible.
While Trust Region Policy Optimization (TRPO) previously established theoretical convergence guarantees by bounding policy divergence with the Kullback-Leibler (KL) divergence, TRPO relies on second-order optimization, requiring Fisher Information Matrix approximations and conjugate gradient iterations that are computationally intractable for modern billion-parameter LLMs. PPO achieves comparable trust-region stability using a first-order, gradient-clipped surrogate objective that integrates directly with standard stochastic gradient optimizers such as AdamW.
Mathematical Foundations of Policy Gradients and Importance Sampling
In a standard Markov Decision Process (MDP) defined by states , actions , transition dynamics , and reward function , a parameterized policy generates trajectories .
The expected discounted return under policy is defined as:
The standard Policy Gradient Theorem (Sutton et al., 1999) establishes that the analytical gradient of expected return with respect to policy parameters is:
where is the state distribution and represents the advantage function, measuring whether taking action in state performs better or worse than the average action under policy .
This expectation translates into the standard policy gradient objective:
The Off-Policy Importance Sampling Formulation
Evaluating requires generating fresh rollouts from after every parameter update. To improve sample efficiency and permit multiple epochs of minibatch updates on a single rollout buffer, PPO applies importance sampling.
If samples are gathered under an older policy , the expected objective under current parameters is rewritten as:
where denotes the probability ratio:
At the start of an update iteration where , the ratio evaluates to . The gradient of at is identical to the standard policy gradient:
However, optimizing without constraints across multiple gradient steps causes rapid divergence. If an action yields a positive advantage estimate , maximizing pushes , causing large, uncontrolled shifts in policy probabilities. Conversely, when , can be driven to zero, causing policy collapse.
The Clipped Surrogate Objective ()
To eliminate excessive policy divergence without solving constrained second-order equations, PPO introduces the clipped surrogate objective:
where is a hyperparameter defining the trust region width, typically set to .

The clipping function bounds the probability ratio within the interval :
Four Operating Regimes of the Clipped Objective
The interaction between the sign of advantage and the probability ratio yields four distinct optimization behaviors:
- Positive Advantage (), Below Upper Bound ():
The action performed better than baseline expectation. The objective evaluates to . Gradients increase the probability of taking this action in state .
- Positive Advantage (), Exceeding Upper Bound ():
The policy has already substantially increased the action probability relative to . The term evaluates to . Because , the operator selects the clipped value: Because is constant with respect to , the gradient evaluates to zero (). This cuts off further parameter updates, preventing the optimizer from excessively biasing the policy toward a single advantageous sample.
- Negative Advantage (), Above Lower Bound ():
The action performed worse than expected. The objective evaluates to . Gradients decrease the probability of this action.
- Negative Advantage (), Below Lower Bound ():
When , multiplying by the scalar flips the inequality: . The operator selects the unclipped value: Gradients remain active, allowing the policy to continue driving down the probability of an undesirable action if an earlier gradient step made it more likely. Conversely, if while , the clipped term is smaller than , capping the penalty and preventing unbounded gradient spikes.
The Pessimistic Lower Bound
Taking the minimum between the unclipped surrogate objective and the clipped surrogate objective guarantees that forms a conservative, pessimistic lower bound on the true unconstrained importance-sampled objective:
By maximizing this lower bound, PPO ensures that improvements in the objective translate to true improvements in expected return, eliminating the risk of catastrophic policy drift during multi-epoch minibatch updates.
Generalized Advantage Estimation (GAE)
Accurate estimation of the advantage term is necessary for stable policy optimization. Standard Monte Carlo returns exhibit high variance, while single-step Temporal Difference (TD) targets introduce high bias when value function approximations are imperfect.
PPO pairs its clipped surrogate loss with Generalized Advantage Estimation (GAE) (Schulman et al., 2015). GAE defines an exponentially-weighted average of -step advantage estimators controlled by decay parameter and discount factor .
Let the 1-step TD residual (temporal difference error) at time be:
where is a parameterized critic (value network). The generalized advantage estimator is formulated as:
The parameter navigates the bias-variance trade-off:
- When , , reducing to a low-variance, high-bias 1-step TD advantage.
- When , , reducing to an unbiased, high-variance Monte Carlo advantage estimator.
In production LLM alignment, empirical benchmarks typically set (because sequence lengths are finite) and . Advantage values are then normalized across the batch to have zero mean and unit variance () before calculating .
Complete Actor-Critic Objective and Value Function Clipping
In actor-critic architectures where the policy network (actor) and value network (critic) are trained jointly, the complete optimization objective balances the clipped policy loss, the value function squared error loss, and an entropy regularization term:
where are hyperparameter coefficients and $S\pi_\theta$ represents the Shannon entropy of the policy distribution, encouraging exploration:
Clipped Value Loss ()
Similar to policy updates, value function optimization can suffer from instability if updates to diverge excessively from the old value predictions . To prevent large value updates from corrupting advantage calculations in subsequent iterations, PPO clips the value function:
where is the empirical return target. The operator enforces a pessimistic bound on value regression, penalizing parameter updates that over-correct toward noisy return targets.
PPO in LLM Alignment: The 4-Model RLHF Pipeline
Applying PPO to autoregressive language models requires formalizing text generation as a discrete-time Markov Decision Process:
- State : The prompt tokens concatenated with all generated tokens up to step : .
- Action : The discrete token selected from vocabulary at step : .
- Transition Dynamics: Deterministic append operation: .
- Terminal State: Occurs when the model generates the end-of-sequence token
[EOS]or reaches maximum context length .
Executing PPO on LLMs requires orchestrating four distinct neural models simultaneously:
┌───────────────────────────────┐
│ Prompt Dataset (x ~ D) │
└──────────────┬────────────────┘
│
┌───────────────┴───────────────┐
▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ Actor Model │ │ Reference Model │
│ π_θ (Trainable) │ │ π_ref (Frozen) │
└────────┬─────────┘ └────────┬─────────┘
│ Rollout y ~ π_θ │ Logits π_ref(y|x)
├───────────────────────────────┤
│ Compute Per-Token KL Penalty │
│ r_t_pen = r_t - β * KL_div │
└───────────────┬───────────────┘
│
┌──────────────┴───────────────┐
▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ Reward Model │ │ Critic Model │
│ r_ψ (Frozen) │ │ V_φ (Trainable) │
└────────┬─────────┘ └────────┬─────────┘
│ Scalar Reward R(x, y) │ Baseline Value V(s_t)
└───────────────┬──────────────┘
│
▼
┌──────────────────────────────┐
│ GAE Advantage & Return │
│ Â_t = GAE(γ, λ) │
└──────────────┬───────────────┘
│
┌──────────────┴───────────────┐
▼ ▼
┌──────────────────┐ ┌──────────────────┐
│ PPO-Clip Update │ │ Value MSE Update │
│ ∇_θ L_CLIP │ │ ∇_φ L_VF │
└──────────────────┘ └──────────────────┘- Actor Model (): The primary causal language model being aligned, initialized from the Supervised Fine-Tuning (SFT) checkpoint.
- Reference Model (): A frozen duplicate of the initial SFT model. It evaluates log-probabilities on the generated sequence to prevent the actor from drifting into gibberish or reward-hacking modes.
- Reward Model (): A frozen transformer trained on paired human preference data via the Bradley-Terry preference model (). It emits a scalar score evaluating the full completion.
- Critic Model (): A trainable value model, typically initialized from the reward model with an output linear regression head, that predicts the expected return from any token prefix .
Per-Token Reward Transformation and KL Regularization
A naive implementation of RLHF where scalar reward is applied only at the final token [EOS] suffers from extreme reward sparsity. Furthermore, unconstrained maximization of leads to severe reward model overoptimization (Goodhart's Law), where the policy exploits flaws in to generate degenerate text.
To enforce linguistic coherence, PPO penalizes the token-level reward at each step using the analytical Kullback-Leibler divergence between actor policy and reference policy :
where controls the strength of the KL penalty. The term represents the exact point-wise log-likelihood ratio. If the actor assigns a significantly higher probability to a token than the reference policy did, this ratio is positive, deducting from the reward at step .
The Generalized Advantage Estimator is computed over this penalized reward sequence using critic values , providing token-level credit assignment throughout the entire generation.
Comparative Analysis: PPO vs TRPO vs DPO vs GRPO
The evolution of post-training alignment algorithms reflects a continuous effort to balance optimization stability, mathematical rigor, and GPU memory utilization.
- TRPO (2015): Second-order constrained optimization enforcing hard trust regions () via conjugate gradient; requires 3 models (Actor, Critic, Reference); high computational overhead from Hessian-vector products.
- PPO (2017): First-order optimization with soft clipped surrogate objectives (); full 4-model architecture (Actor, Critic, Reference, Reward); high stability via normalized GAE and value clipping.
- DPO (2023): Offline closed-form likelihood loss with implicit reward KL regularization; 2-model architecture (Actor, Reference); eliminates critic and reward models; cannot perform active exploration or programmatic verification.
- GRPO (2024): First-order online RL with group relative baselines; 2-model architecture (Actor, Reference); eliminates critic network by computing baseline returns across group rollouts.
Algorithmic Trade-Offs
While Direct Preference Optimization (DPO) (Rafailov et al., 2023) analytically eliminates the reward model and critic by expressing ground-truth preference probabilities directly through policy ratios, DPO operates purely offline on static preference datasets. It cannot explore out-of-distribution trajectories or leverage automated programmatic verification (such as unit test execution or mathematical rule checks).
Group Relative Policy Optimization (GRPO) (Shao et al., 2024), utilized in models like DeepSeek-R1, maintains PPO's online exploration capabilities while eliminating the critic network . GRPO generates outputs per prompt and computes baseline returns as the group mean , slashing memory requirements by roughly 50% compared to standard 4-model PPO.
Nonetheless, PPO remains the foundational algorithm for dense, multi-step environments and continuous actor-critic reinforcement learning, providing the mathematical bedrock for modern reinforcement learning in autonomous systems and foundation model post-training.
Sources
- Schulman, J., Wolski, F., Dhariwal, P., Radford, A., & Klimov, O. (2017). Proximal Policy Optimization Algorithms. arXiv:1707.06347. https://arxiv.org/abs/1707.06347
- Schulman, J., Moritz, P., Levine, S., Jordan, M., & Abbeel, P. (2015). High-Dimensional Continuous Control Using Generalized Advantage Estimation. arXiv:1506.02438. https://arxiv.org/abs/1506.02438
- Schulman, J., Levine, S., Moritz, P., Jordan, M., & Abbeel, P. (2015). Trust Region Policy Optimization. arXiv:1502.05477. https://arxiv.org/abs/1502.05477
- Ouyang, L., Wu, J., Jiang, X., Almeida, D., Wainwright, C. L., Mishkin, P., ... & Lowe, R. (2022). Training language models to follow instructions with human feedback. arXiv:2203.02155. https://arxiv.org/abs/2203.02155
- Rafailov, R., Sharma, A., Mitchell, E., Ermon, S., Manning, C. D., & Finn, C. (2023). Direct Preference Optimization: Your Language Model is Secretly a Reward Model. arXiv:2305.18290. https://arxiv.org/abs/2305.18290
- Shao, Z., Wang, P., Zhu, Q., Xu, R., Song, J., Bi, X., ... & Guo, D. (2024). DeepSeekMath: Pushing the Limits of Mathematical Reasoning in Open Language Models. arXiv:2402.03300. https://arxiv.org/abs/2402.03300
- Sutton, R. S., McAllester, D., Singh, S., & Mansour, Y. (1999). Policy Gradient Methods for Reinforcement Learning with Function Approximation. Advances in Neural Information Processing Systems (NeurIPS 1999). https://proceedings.neurips.cc/paper_files/paper/1999/file/464d8283e3e4f0a7ab6cd076779430f8-Paper.pdf
- Bradley, R. A., & Terry, M. E. (1952). Rank Analysis of Incomplete Block Designs: I. The Method of Paired Comparisons. Biometrika, 39(3/4), 324-345. https://www.jstor.org/stable/2334029



