PPO best checkpoint vs last policy: our walking robot test
Last week, domain randomization made our CMA-ES walking gaits tip far less often, but PPO kept tipping in about 24 of 60 test runs. This week we tried a fix that costs no extra training: save a checkpoint every 96 trials and keep the one that scores best from 20 random starts. With randomization, the tips fell from 24 to 4 of 60, on test starts the selection never saw. That matches CMA-ES (5 of 60). The catch: the best policies came early, after 2,000 to 3,000 of the 12,000 training trials.
PPO with domain randomization, seed 1, the same random start pose (every joint nudged by up to 3°), default floor. Left: the policy at the end of training tips at 1.96 s. Right: the checkpoint we kept, saved after 2,112 trials, covers 10.55 m in 5 s. One example; the totals are in the table below. Physics simulation (MuJoCo), not video footage.
What we did
Robot, score and test are unchanged from our last two guides: a 36 cm box on four two-joint legs in MuJoCo [1], 5-second trials, and a trial that tilts past 30° scores −1 m. PPO [2] runs with Stable-Baselines3 defaults [3] for 12,000 trials (15 million physics steps), on one world ("fixed") or on random floor friction 0.5–1.5 and random start poses ("random"), seeds 1–3. We re-ran all six from scratch; the last policies reproduce last week's results exactly (23 and 24 tips out of 60).
The only new part is a callback that saves the policy every 96 trials, together with its VecNormalize statistics. PPO's input is normalized with running averages, and a policy loaded with the wrong statistics is a different policy. Stable-Baselines3's own CheckpointCallback can do the same with save_vecnormalize=True [4].
k = len(self.rows) + 1
self.model.save(f"{self.ckdir}/ck{k:03d}") # checkpoint: policy ...
self.training_env.save(f"{self.ckdir}/ck{k:03d}_norm.pkl") # ... and its running observation stats
After training, select_best.py runs every checkpoint (125 per run) from the same 20 random start poses and keeps the one with the best mean strict score. The test afterwards uses different random starts: last week's 20 starts per seed and the friction sweep. If you pick and grade on the same trials, the winner looks better than it is (more on that below).
def trial(pol, vn, rng):
"""One 5-second trial, forfeit rule. Stops early once the robot tips (the score is then -1 m anyway)."""
env = W.WalkerEnv('forfeit'); env.reset()
d = env.data; W.randomize_start(env.model, d, rng); obs = env._obs()
for _ in range(W.STEPS // env.FRAME_SKIP):
a, _ = pol.predict(vn.normalize_obs(obs), deterministic=True)
obs, r, term, trunc, _ = env.step(a)
if term:
return -1.0, True
return float(d.qpos[0]), False
def score_checkpoint(path):
pol = PPO.load(path + '.zip', device='cpu'); vn = pickle.load(open(path + '_norm.pkl', 'rb'))
rng = np.random.default_rng(5000 + SEED)
res = [trial(pol, vn, rng) for _ in range(N_SELECT)]
return dict(mean=float(np.mean([s for s, _ in res])), tipped=sum(t for _, t in res))
We compared three ways of choosing which policy to keep:
- Last policy: what you get from
model.learn(), and what our earlier pages used. - Best single trial: the checkpoint with the best number in the training log, one trial on the default robot. That is what you'd pick by looking at the log.
- Best of 20 starts: the checkpoint with the best mean over 20 random starts.
Results
| PPO, policy kept | Strict score, 20 test starts (mean of 3 seeds) | Test runs that tipped | Tipped in the friction sweep, 0.5–1.5 | Tipped on the 20 selection starts | Saved after (trials, seeds 1–3) |
|---|---|---|---|---|---|
| One world: last policy | 4.02 m | 23 / 60 | 77 / 150 | – | 12,000 (end) |
| One world: best single trial | 5.54 m | 18 / 60 | 54 / 150 | 25 / 60 | 4,224, 7,776, 5,568 |
| One world: best of 20 starts | 6.33 m | 12 / 60 | 45 / 150 | 3 / 60 | 6,528, 3,072, 5,088 |
| Random worlds: last policy | 3.63 m | 24 / 60 | 72 / 150 | – | 12,000 (end) |
| Random worlds: best single trial | 5.67 m | 17 / 60 | 50 / 150 | 22 / 60 | 5,664, 4,128, 8,448 |
| Random worlds: best of 20 starts | 7.42 m | 4 / 60 | 21 / 150 | 0 / 60 | 2,112, 2,976, 2,784 |
| CMA-ES, random worlds (last week) | 6.85 m | 5 / 60 | 54 / 150 | – | 12,000 (end) |
Test: each kept policy replayed for the full 5 s from 20 random start poses per seed on the default floor, and from 10 random start poses at each friction value. A tipped run scores −1. Training took 29 CPU minutes per run on one core of a cloud Linux machine. Selection is extra: up to 2,500 five-second trials per run, fewer when a trial tips early and stops.


Runs that tipped, out of 30 (3 seeds × 10 start poses), by floor friction. * = outside the randomized training range.
| Friction | 0.3* | 0.5 | 0.75 | 1 | 1.25 | 1.5 | 2* |
|---|---|---|---|---|---|---|---|
| PPO one world, last | 24 | 15 | 14 | 11 | 17 | 20 | 19 |
| PPO one world, best of 20 | 24 | 9 | 3 | 7 | 11 | 15 | 15 |
| PPO random worlds, last | 25 | 12 | 11 | 14 | 20 | 15 | 14 |
| PPO random worlds, best of 20 | 20 | 5 | 2 | 2 | 8 | 4 | 14 |
| CMA-ES, random worlds (last week) | 19 | 20 | 10 | 1 | 5 | 18 | 26 |
What we learned
- PPO's best policy came early, and later training made it worse. In all six runs the score on 20 random starts climbed fast, peaked, then sagged and swung up and down. With randomization the mean was 5.5 m over the first half of the checkpoints and 4.1 m over the second. The kept checkpoints were saved after 2,112, 2,976, 2,784 trials (random worlds) and 6,528, 3,072, 5,088 (one world), out of 12,000. Training longer with these settings did not help.
- Keeping the best checkpoint fixed what randomization couldn't. Last week randomization alone took PPO from 23 to 24 tips. With the best checkpoint it went from 12 (one world) to 4 (random worlds). So randomization did help PPO; the gain was hidden by the drift in its last policy.
- Pick with many trials, not one. The best single logged trial cut tips only to 18 and 17 of 60. A single trial is one lucky or unlucky start: one checkpoint walked 9.81 m in its logged trial and tipped in 17 of the 20 selection starts.
- The selection score is optimistic. On the starts used to pick them, our kept checkpoints tipped 3 and 0 times out of 60; on new starts, 12 and 4. With 125 candidates, some look good partly by luck. Report the number from a separate test.
- PPO now matches CMA-ES, and beats it inside the training range. 4 vs 5 tips from 60 random starts, and 21 vs 54 of 150 in the friction sweep from 0.5 to 1.5. Outside it, both still struggle: at friction 0.3, 20 and 19 of 30 tipped.
- Not every pick is safe. One of the three kept randomized checkpoints (seed 2) tipped from the plain level start, which was not among its selection starts. Test the cases you care about directly.
Ways to choose which PPO policy to keep, compared
| Method | How | Cost | Our result (tips / 60, random worlds) |
|---|---|---|---|
| Last policy | model.learn(), then save | None | 24 |
| Best single logged trial | Highest number in a one-episode training log | Checkpoints only | 17 |
| EvalCallback (default 5 episodes) | SB3 saves best_model during training [4] | 5 episodes per evaluation; the eval env must be wrapped like the training env | Not tested |
| Best of 20 random starts | Save checkpoints, score each afterwards (select_best.py) | Up to 20 trials per checkpoint | 4 |
| Early stopping | Stop training when the eval score stops improving | Saves training time; can stop at a dip | Not tested |
Run it yourself
The download has the exact code we ran, plus the analysis, figure and video scripts. From a fresh virtual environment (Python 3.13.18, mujoco 3.16.0, stable-baselines3 2.9.0, torch 2.14.1):
$ python -m venv venv && source venv/bin/activate $ pip install -r requirements.txt $ python ppo_walker.py ck 1 physics steps 120000 trials 96 policy 0.04 m cpu 12.8 s ck 2 physics steps 240000 trials 192 policy 0.08 m cpu 26.4 s ck 3 physics steps 360000 trials 288 policy 0.09 m cpu 39.9 s ... ck 23 physics steps 2760000 trials 2208 policy 9.80 m cpu 313.4 s ck 24 physics steps 2880000 trials 2304 policy -1.00 m cpu 327.8 s ck 25 physics steps 3000000 trials 2400 policy 8.56 m cpu 342.2 s
$ python select_best.py . random 1 ck 1 trials 96 20 starts: mean 0.03 m tipped 0/20 ck 2 trials 192 20 starts: mean 0.08 m tipped 0/20 ... ck 21 trials 2016 20 starts: mean 8.82 m tipped 0/20 ck 22 trials 2112 20 starts: mean 9.30 m tipped 0/20 ck 23 trials 2208 20 starts: mean 8.58 m tipped 1/20 ... best checkpoint 22 at 2112 trials: 9.3 m, 0 / 20 tipped
That is real output (shortened where marked "..."). The defaults are random worlds, seed 1, 2,400 trials. These lines match the first 2,400 trials of our full seed-1 run exactly, and the pick is the same checkpoint we kept from the full run (after 2,112 trials), because the physics and the random draws are seeded. For the page's runs: python ppo_walker.py 1 3000000 random (or fixed), then select_best.py and python analyze.py .. CPU seconds depend on your machine. No GPU needed.
Download ppo-checkpoint-walker.zip or the single files: ppo_walker.py, select_best.py, walker_env.py, requirements.txt
Limits
- Three seeds per setup, and seeds differ a lot, as is common in deep RL [5]. Treat the totals as a rough picture.
- We kept Stable-Baselines3's default PPO settings. A smaller learning rate or other tuning might stop the late drift, and then the last policy could be fine.
- Selection used the default floor only. Selecting on random frictions too might do better at the edges of the range.
- Simulation only; friction 1.0 is MuJoCo's default, not a measured value.
Evolve your own walkers
Robot Evolution Lab is the full CMA-ES code behind our videos: 2 to 8 legs, stairs and ice, body-shape evolution and a video recorder.
See Robot Evolution LabGet the next robot experiment
One email when we publish a new experiment, about once a week. Unsubscribe anytime.
FAQ
Should I keep the last PPO policy or the best checkpoint?
In our test, the best checkpoint by a wide margin. With domain randomization, the last policies tipped in 24 of 60 test runs; the checkpoints that scored best on 20 random starts tipped in 4 of 60 and walked about twice as far (7.4 m vs 3.6 m on the strict score).
Why does PPO get worse with more training?
Here its score on 20 random starts peaked after 2,000 to 7,000 trials and then sagged and swung up and down until 12,000 (mean 5.5 m in the first half of training, 4.1 m in the second, with randomization). We didn't dig into the cause. Every PPO update changes the whole policy, and with default settings nothing stops a later update from making it worse.
Is one evaluation episode enough to pick a checkpoint?
No. Picking the checkpoint with the best single trial from the training log cut tips only to 18 and 17 of 60. One of those picks walked 9.81 m in its logged trial and then tipped in 17 of 20 random starts. Stable-Baselines3's EvalCallback defaults to 5 episodes; we used 20.
Is the best checkpoint's selection score a fair estimate?
No, it is too optimistic. Our chosen checkpoints tipped 3 and 0 times out of 60 on the starts used to pick them, but 12 and 4 times on new starts. Always test the winner on starts it was not chosen on.
Does keeping the best checkpoint beat domain randomization?
They work together. Without randomization, the best checkpoint still tipped 12 of 60 times; with randomization 4 of 60, about the same as last week's CMA-ES gaits (5 of 60).
Sources
- E. Todorov, T. Erez, Y. Tassa, MuJoCo: A physics engine for model-based control, IROS 2012.
- J. Schulman, F. Wolski, P. Dhariwal, A. Radford, O. Klimov, Proximal Policy Optimization Algorithms, arXiv:1707.06347, 2017.
- A. Raffin et al., Stable-Baselines3: Reliable Reinforcement Learning Implementations, JMLR 22(268), 2021.
- Stable-Baselines3 documentation, Callbacks (CheckpointCallback with save_vecnormalize; EvalCallback with best_model_save_path, n_eval_episodes=5 by default).
- P. Henderson, R. Islam, P. Bachman, J. Pineau, D. Precup, D. Meger, Deep Reinforcement Learning that Matters, AAAI 2018 (arXiv:1709.06560).
- Experiment, code and measurements: TinyBot Forge, November 2026. Every number on this page comes from the code in the download; the CMA-ES row is from our domain-randomization guide.
More: Domain randomization · Reward hacking: fixing the score · CMA-ES vs PPO, the first test · all guides