TINYBOT FORGE
EN中文
Home › Learn › PPO best checkpoint

PPO best checkpoint vs last policy: our walking robot test

Our experimentMuJoCo + stable-baselines36 training runs, 750 checkpointsUpdated November 30, 2026

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.

24 to 4 / 60PPO test runs that tipped: last policy vs best checkpoint, with domain randomization
23 to 12 / 60Same, without randomization
3.6 to 7.4 mStrict score (a tip scores −1), mean of 3 seeds

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:

Results

PPO, policy keptStrict score, 20 test starts (mean of 3 seeds)Test runs that tippedTipped in the friction sweep, 0.5–1.5Tipped on the 20 selection startsSaved after (trials, seeds 1–3)
One world: last policy4.02 m23 / 6077 / 150–12,000 (end)
One world: best single trial5.54 m18 / 6054 / 15025 / 604,224, 7,776, 5,568
One world: best of 20 starts6.33 m12 / 6045 / 1503 / 606,528, 3,072, 5,088
Random worlds: last policy3.63 m24 / 6072 / 150–12,000 (end)
Random worlds: best single trial5.67 m17 / 6050 / 15022 / 605,664, 4,128, 8,448
Random worlds: best of 20 starts7.42 m4 / 6021 / 1500 / 602,112, 2,976, 2,784
CMA-ES, random worlds (last week)6.85 m5 / 6054 / 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.

Bar chart of test runs that tipped out of 60. PPO on one world: last policy 23, best single trial 18, best of 20 starts 12. PPO on random worlds: 24, 17 and 4. CMA-ES on random worlds last week: 5.
Test runs that tipped, out of 60 (3 seeds × 20 start poses the selection never saw).
Six panels, one per PPO run. The mean score over 20 random starts rises to 6 to 9 m within about 2,000 to 6,000 trials, then drops and swings between about 1 and 7 m until the end. Grey dots for single logged trials jump between -1 and 10 m. A star marks the kept checkpoint in each panel, between 2,000 and 6,600 trials.
Every checkpoint of every run. Line: mean strict score over the 20 selection starts. Grey dots: the single trial in the training log. Star: the checkpoint we kept.

Runs that tipped, out of 30 (3 seeds × 10 start poses), by floor friction. * = outside the randomized training range.

Friction0.3*0.50.7511.251.52*
PPO one world, last24151411172019
PPO one world, best of 2024937111515
PPO random worlds, last25121114201514
PPO random worlds, best of 20205228414
CMA-ES, random worlds (last week)192010151826

What we learned

Ways to choose which PPO policy to keep, compared

MethodHowCostOur result (tips / 60, random worlds)
Last policymodel.learn(), then saveNone24
Best single logged trialHighest number in a one-episode training logCheckpoints only17
EvalCallback (default 5 episodes)SB3 saves best_model during training [4]5 episodes per evaluation; the eval env must be wrapped like the training envNot tested
Best of 20 random startsSave checkpoints, score each afterwards (select_best.py)Up to 20 trials per checkpoint4
Early stoppingStop training when the eval score stops improvingSaves training time; can stop at a dipNot 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

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 Lab

Get the next robot experiment

One email when we publish a new experiment, about once a week. Unsubscribe anytime.

Free. No spam, one email per experiment.

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

  1. E. Todorov, T. Erez, Y. Tassa, MuJoCo: A physics engine for model-based control, IROS 2012.
  2. J. Schulman, F. Wolski, P. Dhariwal, A. Radford, O. Klimov, Proximal Policy Optimization Algorithms, arXiv:1707.06347, 2017.
  3. A. Raffin et al., Stable-Baselines3: Reliable Reinforcement Learning Implementations, JMLR 22(268), 2021.
  4. Stable-Baselines3 documentation, Callbacks (CheckpointCallback with save_vecnormalize; EvalCallback with best_model_save_path, n_eval_episodes=5 by default).
  5. P. Henderson, R. Islam, P. Bachman, J. Pineau, D. Precup, D. Meger, Deep Reinforcement Learning that Matters, AAAI 2018 (arXiv:1709.06560).
  6. 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