---
title: "Proximal Policy Optimization (PPO)"
description: "Proximal Policy Optimization stabilizes policy-gradient training by limiting how far each update moves the policy."
url: "https://swe.quest/articles/proximal-policy-optimization-ppo-c85a21363ebb9f11"
canonical: "https://huggingface.co/blog/deep-rl-ppo"
source: "Hugging Face"
published: "2022-08-05"
difficulty: "hard"
kind: "Deep dive"
reading_minutes: 10
tags: ["model-training","machine-learning","algorithms"]
---

# Proximal Policy Optimization (PPO)

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2022-08-05, 10 min read, Deep dive. Original: [https://huggingface.co/blog/deep-rl-ppo](https://huggingface.co/blog/deep-rl-ppo)

## Summary

Proximal Policy Optimization stabilizes policy-gradient training by limiting how far each update moves the policy. It computes the probability ratio between the current and old policy and clips it to \[1−ε, 1+ε\] (ε=0.2 in the paper). It then takes the minimum of the clipped and unclipped advantage-weighted objectives, so the gradient goes to zero when an update would push the ratio further outside the range. Six ratio/advantage cases show when updates happen, and the method is contrasted with TRPO's KL constraint. The final actor-critic loss combines the clipped objective, a value loss and an entropy bonus, followed by a pointer to a from-scratch PyTorch implementation trained on CartPole-v1 and LunarLander-v2.

Written by swe.quest, not by the author.

**Difficulty:** Hard: written for specialists in the field

## Topics

- [Model training](https://swe.quest/tags/model-training.md) (AI & ML)
- [Machine learning](https://swe.quest/tags/machine-learning.md) (AI & ML)
- [Algorithms](https://swe.quest/tags/algorithms.md) (Architecture & design)

## Prerequisites

- policy gradient methods
- Advantage Actor Critic (A2C)
- advantage functions
- gradient ascent

## Keywords

Proximal Policy Optimization, PPO, TRPO, A2C, CleanRL, PyTorch, CartPole-v1, LunarLander-v2

## Related posts

- [Policy Gradient with PyTorch](https://swe.quest/articles/policy-gradient-with-pytorch-8cc397d15e17e5f8.md): Hugging Face · 2022-06-30 · Easy · 7 min read · Machine learning, Model training, Python
  Policy-gradient methods optimize a stochastic policy directly via gradient ascent on expected return, instead of deriving a policy from learned Q-values as in Deep Q-Learning.
- [Engineering and algorithmic interventions for multimodal post-training at Microsoft scale](https://swe.quest/articles/engineering-and-algorithmic-interventions-for-multimodal-post-training-at-fe8208ec9b40ef0c.md): Engineering@Microsoft · 2026-02-27 · Hard · 10 min read · Model training, AI agents, LLMs, Machine learning
  Production-scale RL post-training of multimodal Copilot agents fails silently because policy gradient advantage estimates lose informativeness even as aggregate reward climbs.
- [Diagnosing instability in production-scale agent reinforcement learning](https://swe.quest/articles/diagnosing-instability-in-production-scale-agent-reinforcement-learning-d64c85292b24dcc4.md): Engineering@Microsoft · 2026-01-28 · Hard · 6 min read · Model training, AI agents, Observability, LLMs
  Late-phase instability in on-policy RL for tool-using agents can come from variance amplification in tool-conditioned contexts.
- [Putting RL back in RLHF](https://swe.quest/articles/putting-rl-back-in-rlhf-dbdbc5d62840e65d.md): Hugging Face · 2024-06-12 · Hard · 11 min read · Model training, LLMs, Python
  RLOO (REINFORCE Leave-One-Out) is now available as a trainer in Hugging Face TRL.
- [Toward RL on mixed-precision, mixed-accelerator samplers](https://swe.quest/articles/toward-rl-on-mixed-precision-mixed-accelerator-samplers-1c0dc5519077aec1.md): Modal · 2026-10-13 · Hard · 17 min read · Model training, Inference & serving, LLMs, Hardware, Cost optimization
  RL training of Qwen3.6-35B-A3B on agentic coding stays stable when samplers run on six accelerator types (A100 through B300, RTX PRO 6000) in NVFP4, FP8 and BF16 with their own kernels, feeding a BF16 trainer on B200.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
