PPO agent playing LunarLander-v2

PPO implemented with PyTorch for the Hugging Face Deep RL Course, Unit 8 Part 1. Algorithm reference: CleanRL PPO.

Evaluation

Mean reward: -25.76 +/- 10.26 across 10 episodes. Actions use deterministic argmax. Standard deviation is across episode returns, not the standard error. Evaluation seeds: 10000 through 10009. Replay seed: 20000. Environment steps used for training: 1024000. Python version: 3.13.16.

Load the model

import json
import torch
from ppo import Agent
config = json.load(open('config.json'))
agent = Agent(config['obs_dim'], config['n_actions'])
agent.load_state_dict(torch.load('model.pt', map_location='cpu', weights_only=True))
agent.eval()

Training settings

{
  "env_id": "LunarLander-v2",
  "total_timesteps": 1024000,
  "output": "unit8_model",
  "seed": 1,
  "cpu": false,
  "num_envs": 4,
  "num_steps": 256,
  "num_minibatches": 4,
  "update_epochs": 4,
  "learning_rate": 0.0003,
  "gamma": 0.99,
  "gae_lambda": 0.95,
  "clip_coef": 0.2,
  "ent_coef": 0.01,
  "vf_coef": 0.5,
  "max_grad_norm": 0.5,
  "obs_dim": 8,
  "n_actions": 4,
  "completed_timesteps": 1024000
}

Reproducing the environment

These commands were verified in a Python 3.13 Colab runtime. Install the build tools before Box2D. Use the existing Colab PyTorch build.

%pip install "setuptools==80.9.0" "wheel==0.48.0" "swig==4.5.1" "jedi>=0.16"
%pip install --no-build-isolation --no-cache-dir "box2d-py==2.3.5"
%pip install "gym==0.22.0" "pygame==2.6.1" imageio imageio-ffmpeg tensorboard "huggingface_hub<2"

Pip's isolated build cannot see the installed SWIG Python launcher in this runtime. The Box2D command above uses the already-installed build tools. The setuptools version satisfies the installed PyTorch requirement.

To reproduce training and evaluation from these source files:

python ppo.py --env-id LunarLander-v2 --total-timesteps 1024000 --output unit8_model
python evaluate_unit8.py

For evaluating the exported weights directly from this repository root, set MODEL_DIR = Path(".") in evaluate_unit8.py before running it.

Downloads last month
16
Video Preview
loading

Evaluation results