Policy gradient and PPO: how to improve a policy without breaking it
In lesson 5.1, Ada looked for the way to the kitchen on a grid of the apartment, where every cell has its own value and there are only four moves. But Ada's steering can take any value from full left to full right, and her rangefinder never sees exactly the same picture twice: you can't keep a table for that. So instead you train the policy itself, a network that outputs a distribution over steering, and adjust it so that it more often does what turned out better than usual. The difficulty is that the policy collects its own training data: take one step that is too large, and the next drives are made by already broken behavior. TRPO (2015) limited how much the policy can change in one update, and PPO (2017) achieved the same with a simple change to the objective. In 2021, PPO was used to teach the four-legged robot ANYmal to walk over steps and slopes in under 20 minutes on a single GPU: 4096 copies of it ran in the simulator at once, and training took 1500 updates.
Steering is a continuous action, and no table can describe it
In lesson 5.1, Ada looked for the way to the kitchen on a grid of the apartment: there is a finite number of cells and four moves, and value iteration stores one number per cell. In this lesson's labs, Ada drives through the apartment from lessons 1.1 and 1.2, from the hallway through the living room to the kitchen; the scenes show the apartment from above. Her speed is constant, 60 cm/s, and the only thing she chooses is the steering, that is, the turn rate from −2.2 to 2.2 radians per second, any number in between. Ada sees 9 rangefinder beams, the direction to the kitchen given by the cosine and sine of the angle, and the distance to it. That makes 12 numbers in all, and each of them also changes continuously.
Ada is a home humanoid on a wheeled base; the course labs are built around her. More about her in lesson 0.1.
The table of action values Q(s, a) from lesson 5.1 doesn't work here. There are infinitely many states, and none of them will repeat exactly. The value can be approximated with a neural network, but even then, to choose the steering you would have to search for the maximum of Q(s, a) over all steering values at every step, and that is a separate optimization problem inside the control loop. So it's done differently: you train the policy itself, with no table and no search for a maximum.
In lesson 1.1, the policy was a network that maps an observation to steering. In reinforcement learning, it is made stochastic: the network outputs not a single number but a distribution over steering. Most often this is a normal, Gaussian distribution: the network gives the mean μ(s), and the spread σ sets how far from it Ada tries to deviate. Such a policy is written : the probability density of choosing action in state with network weights . This is what Sutton and Barto's textbook (Section 13.7) suggests for continuous actions: learn not the probability of each action but the parameters of a distribution. The randomness is needed for exploration: while Ada tries steering a little to the left and a little to the right of the mean, she finds out which works better.
There is no longer a teacher who knows the correct steering, as in lesson 1.1. There's only the reward set by an engineer: +1 for every meter Ada advances toward the kitchen along the corridor, +2 when she gets there, and −1 for hitting furniture or a wall. How can a score like this tell you which way to change the network's weights?
Policy gradient: do more of what turned out well
The idea is straightforward: drive a few times with the current policy and adjust the weights so that the actions after which things went well become more likely, and those after which things went badly become less likely. How well things went is given by the return from lesson 5.1: the sum of rewards from step to the end of the episode, where each next reward is discounted by one more factor of .
The REINFORCE method (Williams, 1992) does this with a single formula. The policy gradient is the direction in weight space in which the expected return grows fastest. It is estimated from the collected drives:
Here is the expected return of the policy with weights ; the sum runs over all steps of the collected drives; and are the state and the action at step . The vector shows which way to shift the weights to make the action taken more likely. Each such vector is weighted by : the larger the return after an action, the harder it is pushed. Then the weights are moved a small step along this estimate. This is gradient ascent: the same gradient descent used to train networks, only toward a maximum.
The logarithm isn't there for looks. : the push is divided by the action's probability. Without this division, actions the policy already chooses often would win just because they show up in the data more often; this is how Sutton and Barto explain it (Section 13.3).
This rule has a weak spot, and in Ada's corridor it shows right away. The reward is given for every meter toward the kitchen, and while Ada moves forward, the return after her decisions is positive even if she crashes later: in the drive we'll examine below, the return is positive at 49 of 68 steps, although the drive ended in a crash. So almost all the actions taken get pushed up, good and bad alike, only with different strength. Which of them actually helped has to be found out by averaging over many drives. How can the signal be made cleaner?
Baseline and advantage: comparing with the usual
A gradient estimate from a few drives is noisy. In one drive Ada got a lucky start, in another a random steering command took her into a wall, and the return after the same decision jumps around. Sutton and Barto write that REINFORCE, as a Monte Carlo method, may have high variance and therefore learn slowly (Section 13.3).
What helps is a baseline: a number subtracted from the return, so that the action's weight becomes . If depends only on the state and not on the action, the direction of the gradient doesn't change on average: the subtracted part, averaged over all of the policy's actions, gives zero. But the variance of the estimate can drop a lot (Section 13.4). A natural choice of baseline is the state value from lesson 5.1, that is, the expected return from under the current policy. Then an action's weight shows how much the return after it turned out larger or smaller than is usual for this place. This is an estimate of the advantage from lesson 5.1. If the advantage is positive, the action is better than usual, and it is made more likely. If it is negative, the action is worse, and its probability is lowered.
The value is learned by a second network from the same drives: it predicts the return. The policy-and-value pair is called an actor-critic: the actor chooses the actions, and the critic estimates how well things usually go from this state.
It remains to decide how to estimate the advantage itself. You can take the full return to the end of the drive and subtract : this estimate has no systematic error, but it is noisy, because it picks up the randomness of all the following steps. Or you can look at a single step: the step's reward plus the discounted value of the next state minus the value of the current one, . There is little noise, but if the critic is wrong, so is the estimate. GAE (generalized advantage estimation, Schulman et al., 2015) mixes all the options in between: the from steps later is taken with weight . With , a single step remains; with , the full return minus the value. The authors call this a compromise between bias and variance; the best in their experiments lay between 0.92 and 0.99. From here on, we take and , as in the hyperparameter tables of the PPO paper and the Rudin et al. paper.
Below is one real drive of Ada's from Lab 1: it was driven by the policy after 10 PPO updates and is evaluated by the critic from the same moment. Ada crossed the living room and hit the edge of the doorway to the kitchen. Move the slider through the steps of the drive: the chart shows what return came after each steering decision, what the critic expected and what advantage came out of it.
Top view of the apartment, 6 × 4 m. The circle with eyes is Ada at the selected step, and the orange arc shows where the steering chosen at this step takes her. The path is colored by the weight with which the gradient pushes the decision at each step: green means the decision is pushed up, red means it is pushed down, and the paler the color, the weaker the push. The dashed circle in the kitchen marks where Ada is heading, and the red cross marks the crash.
Horizontal axis: the step of the drive, 0.1 s each. The blue line is the return after the step, and the gray dashed line is the value the critic expected. The bars show the GAE advantage: green bars point up if the decision is better than usual, red ones point down if it is worse. The vertical line marks the selected step.
Under the hood: the return, the value and GAE on this drive
For step of a drive of length , the discounted return and the one-step value error are computed as follows:
Here is the reward received after the decision at step ; after a crash or arrival in the kitchen, , because the episode is over. The GAE advantage estimate is computed with equation 16 of the GAE paper:
With , the sum of the telescopes into ; with , only remains. During training in Lab 1, the advantages of the whole rollout batch are also normalized: the mean is subtracted, and the result is divided by the standard deviation. The chart here shows the numbers before normalization. This drive is the seventh of eight in the rollout batch that the PPO Ada in Lab 1 (the one on the right) collects before the 11th update.
With a baseline, the gradient pushes the good and bad decisions of the same drive in opposite directions, and the estimate gets quieter. So training steps can be taken more boldly too. But how boldly? A gradient step changes the policy, and the next training drives will be made by that changed policy.
Why a large step ruins the policy: the trust region and clipping
In supervised learning, a bad gradient step is a small problem: the next minibatch comes from the same dataset and corrects the weights. In reinforcement learning, there is no ready-made dataset. The current policy collects the data and learns from that same data; such learning is called on-policy: it runs on fresh data from its own policy. If a training step has taken the policy too far (say, Ada now always steers at full lock), the next drives will hit the wall near the start or circle in place. Such data doesn't show how to get to the kitchen, and the policy has no data to recover on.
There is a second reason too. The gradient estimate is valid only near the policy that collected the data: the advantages were computed for its behavior. The further the new policy is from the old one, the less these numbers say about it. That is why the plain policy gradient takes one step per rollout batch (all the steps collected before an update) and then discards it. The PPO authors write that doing several optimization steps on the same rollout is not well justified, and “empirically it often leads to destructively large policy updates.”
TRPO (trust region policy optimization, Schulman et al., 2015) limits the step itself. The theory promises that the return will grow if the new policy doesn't move far from the old one in an update, but with the penalty coefficient the theory recommends, in the authors' words, “the step sizes would be very small.” Instead of a penalty, TRPO imposes a hard constraint, a trust region: the divergence between the old and the new action distributions, averaged over states, is at most . The divergence is measured with the Kullback–Leibler divergence, KL: it is zero when the distributions coincide and grows as they move apart. In all the paper's experiments, .
Here are the weights before the update, is the average over the steps of the rollout, and is the advantage estimate. The fraction under the average is the probability ratio : how many times more likely the new policy is to choose the action that the old one actually took. At the start of an update, . The product , averaged over the rollout, estimates how much the return will change, and this estimate holds as long as the new policy stays close to the old one. With this constraint, TRPO trained simulated robots to swim, hop on one leg and walk. A variant that differs from TRPO only by a fixed penalty in place of the constraint never found hopping or walking gaits. But the constrained problem is solved approximately, with the conjugate gradient method, and the PPO authors call TRPO relatively complicated: for example, it is not compatible with networks in which the policy and the value share weights.
PPO (proximal policy optimization, Schulman et al., 2017) changes the objective itself instead of adding a constraint:
is clipping: clamped to the interval from to ; the paper uses . The minimum of the two options works like this. If an action turned out better than usual (), training raises its probability until reaches 1.2; beyond that there is no gain, and this example stops pulling on the weights. If it turned out worse than usual, its probability is lowered down to 0.8 of what it was. And if the optimizer has moved the wrong way, the minimum picks the unclipped option, and the mistake is corrected at full strength. The authors call a pessimistic bound: a change in is ignored when it would make the objective better and taken into account when it makes the objective worse. That is why several epochs of minibatches can be run over one rollout batch instead of a single step.
Let's check what clipping gives in a real training run: two Adas learn with the same reward and the same step size.
Two Adas learn to drive to the kitchen: without clipping and with PPO
Both Adas start from the same random policy. It is a steering network with two hidden layers of 24 neurons; its mean steering is near zero, and its spread is about 0.6 of the maximum steering. Before every update, each Ada makes 8 drives from the hallway, from slightly different starts, and the starts and the random steering are the same for both. Then come five update epochs in minibatches of 128 steps, with Adam step size 0.003 and GAE with and . There is one difference: the Ada on the left learns with the objective without clipping, , and the Ada on the right with PPO, . There will be 50 updates and 400 drives for each Ada in total; training runs right in your browser and takes a few seconds.
Top view of the apartment, 6 × 4 m: the hallway on the left, the living room in the middle, the kitchen on the right; the furniture is hatched. The dashed circle in the kitchen marks where Ada is heading. The lines show the 8 drives before the selected update. The mark at the end of a drive shows how it ended: a green check means Ada made it, a red cross means she crashed, and a gray circle means the 20 seconds ran out before she reached the kitchen.
Horizontal axis: the update number; vertical axis: how many of the 8 drives before that update reached the kitchen. Click the chart or move the slider below it to see the drives of any update.
Under the hood: the environment, the reward, the networks and a check on ten seeds
The environment. The apartment and the motion come from lessons 1.1 and 1.2: Ada drives at 60 cm/s, the steering is limited to ±2.2 rad/s, and the simulation step is 0.05 s. A steering decision is held for 0.1 s, that is, two simulation steps. The observation includes 9 rangefinder beams over a ±120° sector out to 2.5 m, plus the direction and the distance to the kitchen. Ada starts at the hallway with a spread of 8 cm and 0.12 rad. A drive ends in the kitchen, on a crash or after 20 s.
The reward. Progress is measured along the center line of the passage: we take the point of the line nearest to Ada and the distance along the line from the start. Ada gets +1 for every meter of progress, +2 in the kitchen and −1 on a crash. If the 20 s run out, the return is continued with the value of the last state, as in Rudin et al.: a timeout is treated not as the end of the episode but as a cut in the recording.
The policy and the critic. Both networks are 13 → 24 → 24 → 1 with tanh in the hidden layers. The observation takes up 12 inputs, and the thirteenth is always zero. The mean steering is a fraction of the maximum steering, and the spread is a single trainable parameter, initially . The action is sampled as and executed as times 2.2 rad/s. The log probability and the estimate of the divergence after an update are computed as follows:
The critic learns from the target values with a mean squared error, using its own Adam with the same step size. The advantages of a rollout are normalized to a mean of 0 and a standard deviation of 1. There is no entropy bonus, as in the PPO paper's MuJoCo experiments.
The same in every browser. The exponential, the logarithm, the sine and the arctangent in the engine are built from additions, multiplications and divisions: the built-in Math.exp and Math.sin can differ in the last digit between browsers, and reinforcement learning blows such a difference up into different numbers. So everyone gets the same lab numbers.
Ten seeds. The lab uses one seed. We repeated the training on seeds 1–10, 50 updates each, and for each variant computed the share of drives that reached the kitchen over the last 10 updates. For PPO, this share was 84 to 99%. Without clipping, it is 0% on nine seeds and 1% on one, and over the whole training such an Ada made 0 to 10 drives to the kitchen out of 400. Without clipping and with step size 0.0003, the share was 5 to 50%, on every seed at least 30 points below PPO. The median KL per update was 0.0077 to 0.011 for PPO and 0.0011 to 0.003 without clipping with the small step size. The largest KL per update was 0.03 to 0.11 for PPO and 1.3 to 4.8 without clipping. For PPO with , the share came out at 0 to 57%, and on every seed it is lower than with . With step size 0.01, PPO's share was 0 to 93%: on some seeds it learns, on others it falls apart.
Without clipping, the Ada on the left never learned: in 50 updates, she did not reach the kitchen once in 400 drives. Her updates changed the policy dozens of times more than PPO's: a median KL per update of 0.29 versus 0.0095, and the largest jump was 3.6. After such a jump, the next eight drives are made by a different policy, and the advantages computed for the previous one hardly apply to it. PPO, with the same starts and the same step size, reached the kitchen in 295 of 400 drives, and in 99% of drives in the last ten updates.
A small step size also keeps updates from ruining the policy, but learning becomes slow: its median KL per update is 0.0025, almost four times less than PPO's, and in the last ten updates Ada makes it in only 48% of drives. Clipping lets the step stay large where that is safe and damps it where the policy has already moved far enough. How exactly does it decide which example to damp?
Clipping in action: where PPO stops pulling
The PPO objective is an average over all the steps of the rollout batch, and each step contributes its own term. The first plot shows one such term as a function of the probability ratio , as in Figure 1 of the PPO paper. You set the sign of the advantage and , and you can drag the point with the mouse or a finger: the arrow shows which way the gradient of this term moves at the next training step.
The second plot shows real probability ratios. After 10 updates, the PPO Ada from Lab 1 made her next 8 drives, with 772 steering decisions in them. Her policy is updated for five epochs on this rollout twice, starting from the same copy: once with clipping and once without. For each decision, we compute how many times its probability changed.
Horizontal axis: the probability ratio ; 1 means the action's probability hasn't changed, 1.5 means it grew one and a half times. Vertical axis: one example's contribution to the objective. The orange line is the PPO term, and the gray dashed line is the same term without clipping, . The gray band marks the interval from to , and the hatching marks where this example's gradient is zero. The point is the current , and the arrow shows where the gradient pulls it.
Horizontal axis: how many times the probability of a steering decision changed after five epochs, on a log scale from 0.05 to 20; vertical axis: how many of the 772 decisions fell into each bar. The top row shows the update with clipping at the current , the bottom row the update without clipping. The gray band marks the interval from to .
Under the hood: the derivative of one term, and why r still goes beyond 1 ± ε
The derivative of one term with respect to is piecewise:
Clipping zeroes out the gradient of an individual example but doesn't stop its from changing: the network's weights are shared, and a step taken for the sake of other examples shifts this example's probability too. So even with clipping, some examples go beyond . To keep from drifting far even so, Rudin et al. also adapted the Adam step size by KL: they divided the step size by 1.5 if the KL per update exceeded 0.02 and multiplied it by 1.5 if it was below 0.005 (the desired KL is 0.01).
Ten seeds. We repeated the same procedure for seeds 1–10: the PPO Ada collects one rollout batch after 10 updates, and her policy is updated for five epochs. With clipping at , 5 to 28% of decisions went outside , the KL was 0.0048 to 0.030, and the largest was 1.2 to 3.1. Without clipping, 33 to 77% of decisions went outside, the KL was 0.025 to 0.43, and the largest was 1.7 to 10.1. On every seed, more decisions ended up outside the interval without clipping than with it.
On the same rollout, without clipping, 72% of the steering decisions changed their probability by more than 20%: for one, it grew almost 8 times, and for another, it fell more than a hundredfold. With clipping, 20% did, and no decision's probability even doubled. This is the TRPO trust region, only reached without a constrained problem: PPO remains ordinary gradient ascent in minibatches, which is easy to compute in parallel on large rollout batches.
In the corridor, Ada's policy has 12 numbers as input and one as output. How does this work for a robot that has to learn to walk?
PPO and walking: thousands of robots in a simulator
A walking robot has no wheeled base like Ada's: it has dozens of joints, legs that alternately push against the ground and lift off it, and it can fall. Its policy controls all the joints at once, and it needs orders of magnitude more experience than a steering policy. Collecting that experience on a real robot is slow and dangerous for the robot, so walking is learned in a physics simulator from lesson 4.5.
Already in the GAE paper (2015), TRPO with GAE advantage estimates taught simulated two-legged and four-legged robots to run, with neural networks directly outputting joint torques. Training the biped took about two hours on a 16-core machine, and by the authors' count, it used 0.01 s per step × 50,000 steps per update × 1000 updates = 5.8 days of real time.
Hwangbo et al. (ETH Zurich and Intel, 2019) transferred a policy trained this way to the real ANYmal, a four-legged robot the size of a medium dog. They still trained with TRPO: the authors chose it because it requires almost no parameter tuning. Their simulator, together with the neural networks that model ANYmal's actuators, computed almost 500,000 steps per second, about a thousand times faster than real time, and four hours on an ordinary computer with one CPU and one GPU produced about a quarter of a billion transitions. Running on velocity commands took 9 days of simulated experience, that is, four hours of computation, and getting up after a fall took 79 days of experience and 11 hours of computation. The real ANYmal ran 25% faster than its previous record.
Rudin et al. (ETH Zurich and NVIDIA, 2021) moved both the simulation and the training onto the GPU. In the Isaac Gym simulator, thousands of copies of ANYmal learn at once, and the data never leaves the GPU. The training there is PPO: unlike TRPO, it is ordinary gradient ascent in minibatches, and in the paper, rollout batches of 98,304 steps are split into minibatches of 24,576. The policy for rough terrain (steps, slopes, obstacles) was trained for 1500 updates in under 20 minutes on a single RTX A6000 GPU, and the one for flat ground in under 4 minutes. On steps up to 0.2 m high, the trained policy succeeded in nearly 100% of attempts, and the same scheme, with adjusted rewards and actuator settings for the smaller robots, trained ANYmal C with an arm, ANYmal B, A1 and the two-legged Cassie.
Parallelism isn't free for an on-policy method. A rollout batch is the number of robots times the number of steps each makes per update. For the same rollout batch, the more robots there are, the fewer consecutive steps each one gets, and GAE needs the rewards of several consecutive steps: the authors write that the algorithm struggles with fewer than 25 consecutive steps, that is, less than 0.5 s of simulation (they themselves used 24). With fewer robots, there are more consecutive steps, and neighboring steps of one robot are similar to each other. The authors name 2048–4096 robots and rollout batches of about 100,000–200,000 steps as the best compromise for their task. Let's calculate how much experience stands behind these numbers.
How many simulation steps walking takes
There is no simulation here; we only calculate with the numbers from the Rudin et al. paper. ANYmal's policy makes a decision 50 times per second. In one update, each robot makes several consecutive steps, the rollout batch consists of all the steps of all the robots, and training lasts 1500 such updates. The sliders set the number of robots, each robot's steps per update and the number of updates; the calculator computes the rollout batch, the total number of steps and how much experience this is if converted to one robot walking without breaks. The chart below the calculator shows the same quantities for the lesson's three papers.
The policy makes 50 decisions per second, as in Rudin et al.
The bars show how many days of one robot's experience stand behind the training, on a log scale. The blue bars are the lesson's papers, and their labels say how long the training itself took. The orange bar is your setting. How long it would take on a GPU, the calculator doesn't know: that depends on the simulator and the number of robots.
Under the hood: the calculator's formulas and what they leave out
Let be the number of robots in the simulator, the number of steps each makes per update, the number of updates, and Hz the policy's decision rate. Then
Here is the rollout batch of one update, is the total number of policy steps, is how long one robot would walk, and is the segment each robot covers in one update. In Rudin et al., an episode lasts up to 20 s and is not cut off at every update: the robot keeps walking until it falls or the time runs out. How long training takes on a GPU can't be derived from these formulas: the paper shows the time falling almost linearly as the number of robots grows up to about 4000, after which the gain slows down.
For the papers, we took these numbers. In GAE, a step lasts 0.01 s, a rollout batch has 50,000 steps, there are 1000 updates, and training took about 2 hours on 16 cores. For ANYmal in 2019, 9 days of simulation took 4 hours, and 79 days took 11 hours. In Rudin et al., 4096 robots make 24 steps each per update, there are 1500 updates, and the whole training took under 20 minutes. How many times faster than real time the training ran, we calculated ourselves: 54 times for ANYmal 2019, and more than 2400 times for Rudin et al.
In 20 minutes of training, each of the 4096 copies of ANYmal walks for only 12 minutes, but together that's 147 million steps, more than a month of one robot's experience. This also makes PPO's place in the scheme clear. It uses each rollout batch for 5 epochs and throws it away, so it needs a lot of data, but it doesn't care how many robots collect it, as long as each robot gets a stretch of half a second in a row and the rollout batch is large enough. In a simulator, that is cheap.
What lives on in the systems of 2025–2026
The Rudin et al. recipe (thousands of copies of a robot in a simulator on a GPU, PPO, and physical parameters varied across the copies) has become the usual way to teach walking. In lesson 4.5, we saw how Figure described training its Figure 02 humanoid to walk (March 2025): thousands of robots learn in simulation in parallel, each with its own physical parameters, years of experience are gathered in a few hours, and then the policy is transferred to real robots without further tuning. How such training works for humanoids, we'll cover in Part 6. The Rudin et al. code is open: it's legged_gym.
PPO teaches more than walking. Dactyl from lesson 4.5, the hand that turns a cube in its palm, was also trained with PPO, in a distributed system on many machines; its authors write that “PPO scales up easily and requires little hyperparameter tuning.”
With large models, though, the policy gradient gets along less well. In lesson 3.8, π*0.6 learns from the robots' own attempts and also computes an advantage: how much better an action is than usual. But its authors write that the policy gradient is hard to apply to a flow matching model, so they train it with ordinary supervised learning, adding the text “Advantage: positive” or “Advantage: negative” to its input. The idea itself, doing more often what turned out better than usual, is the same as in this lesson.
Eight common misconceptions
Lesson takeaways
- When the action is continuous and there are infinitely many states, the value table is replaced with a stochastic policy: the network outputs the mean steering, and the spread sets how boldly Ada tries other values.
- The policy gradient (REINFORCE) pushes every action taken with the weight of the return after it. If the returns are almost always positive, almost all actions get pushed up, and the signal drowns in noise.
- The baseline turns the return into the advantage, which says whether an action is better or worse than usual. The average direction of the gradient doesn't change, and the variance drops. GAE mixes the one-step estimate and the full-return estimate with weight : in Ada's corridor, PPO with learns worse on every one of ten seeds.
- The policy collects its own data, so a step that is too large ruins both the policy and the next rollout batch. TRPO limits how far the policies diverge: a KL of at most 0.01 per update. PPO clips the probability ratio to and runs several epochs over a rollout batch. In Ada's corridor, the Ada without clipping didn't reach the kitchen once in 400 drives, while PPO made it in 99% of drives in the last 10 updates; the median KL per update was 0.29 versus 0.0095.
- A small step size also keeps updates from ruining the policy, but learning becomes slow: 48% versus 99% over the same 50 updates.
- PPO and thousands of copies of a robot on a GPU teach ANYmal to walk over rough terrain in under 20 minutes; in that time, 147 million steps pile up, about 34 days of one robot's experience. An on-policy method pays for this with data: each rollout batch lives for a few epochs and is thrown away.
Open questions
How do you choose ε and the step size without searching over them every time?
In Table 1 of the PPO paper, ε = 0.1, 0.2 and 0.3 gave average scores of 0.76, 0.82 and 0.70 on seven MuJoCo tasks, and the variant with no clipping or penalty scored −0.39, worse than a random policy. Rudin et al. kept ε = 0.2 but adapted the Adam step size by the KL per update, aiming at 0.01, which in effect brought back the TRPO constraint as a rule for the step size. There is no universal rule: a setting that works for one task doesn't guarantee success on another. In Lab 1, PPO with step size 0.01 instead of 0.003 never reaches the kitchen in the last updates, and on other seeds with the same step size, the result swings from 0 to 93%.
Can you train with PPO directly on a real robot?
After their 5.8 days of experience for the biped, the GAE authors wrote that “it is plausible that this algorithm could be run on a real robot, or multiple real robots learning in parallel, if there were a way to reset the state of the robot and ensure that it doesn't damage itself.” Learning to walk with PPO took 34 days of experience, all of it in a simulator. Methods that spend experience more economically are covered in lesson 5.3, and transferring a policy from the simulator to a real robot in lesson 5.4.
Paper guide
- Read closelySection 2: the policy gradient and TRPO in the same notation. Section 3 and Figures 1–2: clipping, the pessimistic bound and the KL after one update. Section 5 and Algorithm 1: the whole loop on one page. Table 1: what clipping gives compared with a KL penalty and with no constraint at all.
- Safe to skipSection 6.4 and Appendix B on Atari games, and Section 4 on the adaptive KL penalty if you don't plan to implement it.
- Question to keep in mindWhy does take the minimum of two terms when it could have taken just the clipped one? What changes for an example with a negative advantage whose has already reached 1.5?
Other papers in this lesson: TRPO (Schulman et al., 2015), the trust region; GAE (Schulman et al., 2015), advantage estimation and running in simulation; Learning Agile and Dynamic Motor Skills for Legged Robots (Hwangbo et al., 2019), ANYmal and TRPO; Learning to Walk in Minutes Using Massively Parallel Deep RL (Rudin et al., 2021), PPO and thousands of robots; and the textbook R. Sutton, A. Barto, “Reinforcement Learning: An Introduction”, 2nd ed., 2018, Chapter 13 on the policy gradient.
Resources
- legged_gymThe Rudin et al. code: environments for ANYmal and other robots, and PPO training in Isaac Gym
- Sutton and Barto, PDFThe free version of the textbook; the policy gradient is Chapter 13
PPO trains a policy carefully and has become the standard for walking in simulation, where thousands of copies of a robot run in parallel. But after every update it throws away the experience it collected, and even simple tasks need millions of steps: you can't collect that many on a real robot.
Lesson 5.3 · Off-policy and SAC: how to store experience and learn from it again and again