Home

Awesome

Training & Speed Evaluation Tools for gymnax

<a href="https://github.com/RobertTLange/gymnax-blines/blob/main/docs/logo.png?raw=true"><img src="https://github.com/RobertTLange/gymnax-blines/blob/main/docs/logo.png?raw=true" width="215" align="right" /></a>

In this repository we provide training pipelines for gymnax agents in JAX. Furthermore, you can use the utilities to speed benchmark step transitions and to visualize trained agent checkpoints. Install all required dependencies via:

pip install -r requirements.txt

Accelerated Training of Agents with gymnax

We provide training routines and the corresponding checkpoints for both Evolution Strategies (mostly OpenES using evosax and PPO (using an adaptation of @bmazoure's implementation). You can train the agents as follows:

python train.py -config agents/<env_name>/ppo.yaml
python train.py -config agents/<env_name>/es.yaml

This will store checkpoints and training logs as pkl in agents/<env_name>/ppo.pkl. Collect all training runs sequentially via:

bash exec.sh train

Visualization of gymnax Environment Rollouts

You can also generate GIF visualizations of the trained agent's behaviour as follows:

python visualize.py -env <env_name> -train <{es/ppo}>

Collect all visualizations sequentially via:

bash exec.sh visualize

Note that we do not support visualizations for most behavior suite environments, since they do not lend themselves to visual display (e.g. markov reward process, etc.).

Speed Up Evaluation for gymnax Environments

Finally, we provide simple tools for benchmarking the speed of step transitions on different hardware (CPU, GPU, TPU). For a specific environment the speed estimates can be obtained as follows:

python speed.py -env <env_name> --use_gpu --use_network --num_envs 10

Collect all speed estimates sequentially via:

bash exec.sh speed

For each environment we estimate the seconds required to execute 1 Mio steps on various hardware and for both random (R)/neural network (N) policies. We report the mean over 10 independent runs:

Environment Namenp <br /> CPU <br /> 10 Envsjax <br /> CPU <br /> 10 Envsnp <br /> CPU <br /> 40 Envsjax <br /> CPU <br /> 40 Envsjax <br /> 2080Ti <br /> 2k Envsjax <br /> A100 <br /> 2k Envs
Acrobot-v1R: 72 <br /> N: 118R: 1.16 <br /> N: 2.90R: 66 <br /> N: 77.2R: 1.03 <br /> N: 2.3R: 0.06 <br /> N: 0.08R: 0.07 <br /> N: 0.09
Pendulum-v1R: 139 <br /> N: 118R: 0.41 <br /> N: 1.41R: 118 <br /> N: 70R: 0.32 <br /> N: 1.07R: 0.07 <br /> N: 0.09R: 0.07 <br /> N: 0.10
CartPole-v1R: 46 <br /> N: 94R: 0.43 <br /> N: 1.42R: 45 <br /> N: 51R: 0.49 <br /> N: 0.98R: 0.06 <br /> N: 0.08R: 0.05 <br /> N: 0.08
MountainCar-v0R: 48 <br /> N: 105R: 0.53 <br /> N: 1.49R: 54 <br /> N: 57R: 0.39 <br /> N: 1.03R: 0.06 <br /> N: 0.09R: 0.07 <br /> N: 0.09
MountainCarContinuous-v0R: 117 <br /> N: 99R: 0.34 <br /> N: 1.11R: 98 <br /> N: 53R: 0.28 <br /> N: 0.85R: 0.09 <br /> N: 0.12R: 0.09 <br /> N: 0.12
Asterix-MinAtarR: 62.95 <br /> N: 142.21R: 5.49 <br /> N: 20.15R: 55.08 <br /> N: 73.16R: 5.86 <br /> N: 22.46R: 0.89 <br /> N: 0.96R: 0.92 <br /> N: 0.98
Breakout-MinAtarR: 49.35 <br /> N: 125.65R: 2.41 <br /> N: 13.70R: 48.30 <br /> N: 67.20R: 2.33 <br /> N: 13.93R: 0.20 <br /> N: 0.30R: 0.19 <br /> N: 0.26
Freeway-MinAtarR: 49.91 <br /> N: 141.63R: 26.35 <br /> N: 74.02R: 50.04 <br /> N: 72.59R: 26.25 <br /> N: 53.66R: 1.17 <br /> N: 1.30R: 0.87 <br /> N: 0.95
SpaceInvaders-MinAtarR: 65.58 <br /> N: 170.29R: 12.73 <br /> N: 33.51R: 69.24 <br /> N: 105.27R: 14.37 <br /> N: 30.09R: 0.35 <br /> N: 0.46R: 0.33 <br /> N: 0.39
Catch-bsuite-R: 0.99 <br /> N: 2.37-R: 0.87 <br /> N: 1.82R: 0.17 <br /> N: 0.21R: 0.15 <br /> N: 0.21
DeepSea-bsuite-R: 0.84 <br /> N: 1.97-R: 1.04 <br /> N: 1.61R: 0.27 <br /> N: 0.33R: 0.22 <br /> N: 0.36
MemoryChain-bsuite-R: 0.43 <br /> N: 1.46-R: 0.37 <br /> N: 1.11R: 0.14 <br /> N: 0.21R: 0.13 <br /> N: 0.19
UmbrellaChain-bsuite-R: 0.64 <br /> N: 1.82-R: 0.48 <br /> N: 1.28R: 0.08 <br /> N: 0.11R: 0.08 <br /> N: 0.12
DiscountingChain-bsuite-R: 0.33 <br /> N: 1.32-R: 0.21 <br /> N: 0.88R: 0.06 <br /> N: 0.07R: 0.06 <br /> N: 0.08
FourRooms-misc-R: 3.12 <br /> N: 5.43-R: 2.81 <br /> N: 4.6R: 0.09 <br /> N: 0.10R: 0.07 <br /> N: 0.10
MetaMaze-misc-R: 0.80 <br /> N: 2.24-R: 0.76 <br /> N: 1.69R: 0.09 <br /> N: 0.11R: 0.09 <br /> N: 0.12
PointRobot-misc-R: 0.84 <br /> N: 2.04-R: 0.65 <br /> N: 1.31R: 0.08 <br /> N: 0.09R: 0.08 <br /> N: 0.10
BernoulliBandit-misc-R: 0.54 <br /> N: 1.61-R: 0.42 <br /> N: 0.97R: 0.07 <br /> N: 0.10R: 0.08 <br /> N: 0.11
GaussianBandit-misc-R: 0.56 <br /> N: 1.49-R: 0.58 <br /> N: 0.89R: 0.05 <br /> N: 0.08R: 0.07 <br /> N: 0.09

TPU v3-8 comparisons will follow once I (or you?) find the time and resources 🤗