cleanrl README

The project's README from github.com/vwxyzjn/cleanrl. As one markdown file: README.md.

CleanRL (Clean Implementation of RL Algorithms)

tests docs Code style: black Imports: isort Open In Colab

CleanRL is a Deep Reinforcement Learning library that provides high-quality single-file implementation with research-friendly features. The implementation is clean and simple, yet we can scale it to run thousands of experiments using AWS Batch. The highlight features of CleanRL are:

You can read more about CleanRL in our JMLR paper and documentation.

Notable CleanRL-related projects:

ℹ️ Support for Gymnasium: Farama-Foundation/Gymnasium is the next generation of openai/gym that will continue to be maintained and introduce new features. Please see their announcement for further detail. We are migrating to gymnasium and the progress can be tracked in vwxyzjn/cleanrl#277.

⚠️ NOTE: CleanRL is not a modular library and therefore it is not meant to be imported. At the cost of duplicate code, we make all implementation details of a DRL algorithm variant easy to understand, so CleanRL comes with its own pros and cons. You should consider using CleanRL if you want to 1) understand all implementation details of an algorithm's variant or 2) prototype advanced features that other modular DRL libraries do not support (CleanRL has minimal lines of code so it gives you great debugging experience and you don't have do a lot of subclassing like sometimes in modular DRL libraries).

Get started

Prerequisites:

To run experiments locally, give the following a try:

git clone https://github.com/vwxyzjn/cleanrl.git && cd cleanrl
uv pip install .

# alternatively, you could use `uv venv` and do
# `python run cleanrl/ppo.py`
uv run python cleanrl/ppo.py \
    --seed 1 \
    --env-id CartPole-v0 \
    --total-timesteps 50000

# open another terminal and enter `cd cleanrl/cleanrl`
tensorboard --logdir runs

To use experiment tracking with wandb, run

wandb login # only required for the first time
uv run python cleanrl/ppo.py \
    --seed 1 \
    --env-id CartPole-v0 \
    --total-timesteps 50000 \
    --track \
    --wandb-project-name cleanrltest

If you are not using uv, you can install CleanRL with requirements.txt:

# core dependencies
pip install -r requirements/requirements.txt

# optional dependencies
pip install -r requirements/requirements-atari.txt
pip install -r requirements/requirements-mujoco.txt
pip install -r requirements/requirements-mujoco_py.txt
pip install -r requirements/requirements-procgen.txt
pip install -r requirements/requirements-envpool.txt
pip install -r requirements/requirements-pettingzoo.txt
pip install -r requirements/requirements-jax.txt
pip install -r requirements/requirements-docs.txt
pip install -r requirements/requirements-cloud.txt
pip install -r requirements/requirements-memory_gym.txt

To run training scripts in other games:

uv venv

# classic control
python cleanrl/dqn.py --env-id CartPole-v1
python cleanrl/ppo.py --env-id CartPole-v1
python cleanrl/c51.py --env-id CartPole-v1

# atari
uv pip install ".[atari]"
python cleanrl/dqn_atari.py --env-id BreakoutNoFrameskip-v4
python cleanrl/c51_atari.py --env-id BreakoutNoFrameskip-v4
python cleanrl/ppo_atari.py --env-id BreakoutNoFrameskip-v4
python cleanrl/sac_atari.py --env-id BreakoutNoFrameskip-v4

# NEW: 3-4x side-effects free speed up with envpool's atari (only available to linux)
uv pip install ".[envpool]"
python cleanrl/ppo_atari_envpool.py --env-id BreakoutNoFrameskip-v4
# Learn Pong-v5 in ~5-10 mins
# Side effects such as lower sample efficiency might occur
uv run python ppo_atari_envpool.py --clip-coef=0.2 --num-envs=16 --num-minibatches=8 --num-steps=128 --update-epochs=3

# procgen
uv pip install ".[procgen]"
python cleanrl/ppo_procgen.py --env-id starpilot
python cleanrl/ppg_procgen.py --env-id starpilot

# ppo + lstm
uv pip install ".[atari]"
python cleanrl/ppo_atari_lstm.py --env-id BreakoutNoFrameskip-v4

You may also use a prebuilt development environment hosted in Gitpod:

Open in Gitpod

Algorithms Implemented

Algorithm Variants Implemented
✅ Proximal Policy Optimization (PPO) ppo.py, docs
ppo_atari.py, docs
ppo_continuous_action.py, docs
ppo_atari_lstm.py, docs
ppo_atari_envpool.py, docs
ppo_atari_envpool_xla_jax.py, docs
ppo_atari_envpool_xla_jax_scan.py, docs)
ppo_procgen.py, docs
ppo_atari_multigpu.py, docs
ppo_pettingzoo_ma_atari.py, docs
ppo_continuous_action_isaacgym.py, docs
ppo_trxl.py, docs
✅ Deep Q-Learning (DQN) dqn.py, docs
dqn_atari.py, docs
dqn_jax.py, docs
dqn_atari_jax.py, docs
✅ Categorical DQN (C51) c51.py, docs
c51_atari.py, docs
c51_jax.py, docs
c51_atari_jax.py, docs
✅ Soft Actor-Critic (SAC) sac_continuous_action.py, docs
sac_atari.py, docs
✅ Deep Deterministic Policy Gradient (DDPG) ddpg_continuous_action.py, docs
ddpg_continuous_action_jax.py, docs
✅ Twin Delayed Deep Deterministic Policy Gradient (TD3) td3_continuous_action.py, docs
td3_continuous_action_jax.py, docs
✅ Phasic Policy Gradient (PPG) ppg_procgen.py, docs
✅ Random Network Distillation (RND) ppo_rnd_envpool.py, docs
✅ Qdagger qdagger_dqn_atari_impalacnn.py, docs
qdagger_dqn_atari_jax_impalacnn.py, docs

Open RL Benchmark

To make our experimental data transparent, CleanRL participates in a related project called Open RL Benchmark, which contains tracked experiments from popular DRL libraries such as ours, Stable-baselines3, openai/baselines, jaxrl, and others.

Check out https://benchmark.cleanrl.dev/ for a collection of Weights and Biases reports showcasing tracked DRL experiments. The reports are interactive, and researchers can easily query information such as GPU utilization and videos of an agent's gameplay that are normally hard to acquire in other RL benchmarks. In the future, Open RL Benchmark will likely provide an dataset API for researchers to easily access the data (see repo).

Support and get involved

We have a Discord Community for support. Feel free to ask questions. Posting in Github Issues and PRs are also welcome. Also our past video recordings are available at YouTube

Citing CleanRL

If you use CleanRL in your work, please cite our technical paper:

@article{huang2022cleanrl,
  author  = {Shengyi Huang and Rousslan Fernand Julien Dossa and Chang Ye and Jeff Braga and Dipam Chakraborty and Kinal Mehta and João G.M. Araújo},
  title   = {CleanRL: High-quality Single-file Implementations of Deep Reinforcement Learning Algorithms},
  journal = {Journal of Machine Learning Research},
  year    = {2022},
  volume  = {23},
  number  = {274},
  pages   = {1--18},
  url     = {http://jmlr.org/papers/v23/21-1342.html}
}

Acknowledgement

CleanRL is a community-powered by project and our contributors run experiments on a variety of hardware.

cleanrl (vwxyzjn/cleanrl)

Searching Database…

10.6K ·GitHub
这是什么?CleanRL 是一套高质量的单文件深度强化学习算法实现合集(包括 PPO、DQN、C51、SAC、DDPG、TD3、PPG 等),它的设计目标是让人阅读和修改,而不是当作库来导入。
它是一个可以安装并导入到我项目里的库吗?不是——作者明确说明它不是模块化的库,也不打算被导入。每个算法变体都放在一个独立完整的 Python 文件里,代码重复是为了可读性而有意付出的代价。
我怎么把一个实验跑起来?先安装 Python(>=3.7.1,<3.11)和 uv 0.7.9 以上版本,然后运行其中一个训练脚本,比如 ppo.py。如果没有 uv,也可以用 requirements.txt 安装依赖,或者直接打开预配置好的 Gitpod 开发环境。
对 Gymnasium 的支持现在是什么情况?项目正在迁移到 Gymnasium,也就是 openai/gym 之后仍在维护的继任者;进度在 issue #277 里跟踪,所以环境支持目前还处在过渡阶段。
什么人应该选 CleanRL 而不是普通的 RL 库?想弄懂某个算法变体每一处实现细节的人,或者想尝试模块化深度强化学习库不支持的高级功能的人——代码足够精简,不用写一堆子类就能轻松调试。
实现了哪些算法和变体?PPO(大约十几个变体:Atari、连续动作、LSTM、多 GPU、Isaac Gym、Procgen 等)、DQN、C51、SAC、DDPG、TD3、PPG、RND 和 Qdagger——总共大约 30 个脚本变体。
我怎么记录和对比自己的训练过程?训练集成了 Weights & Biases 来做实验记录;另外通过相关的 Open RL Benchmark,你可以浏览交互式报告,把 CleanRL 和 Stable-Baselines3、openai/baselines、jaxrl 进行对比,细到 GPU 利用率和游戏画面视频。
有没有算法提供 JAX 版本?有——算法表格在 PyTorch 版本旁边列出了 JAX 移植版,比如 dqnjax.py、c51atarijax.py、ddpgcontinuousactionjax.py 和 td3continuousactionjax.py,还有若干基于 JAX 的 PPO 和 Qdagger 变体。
如果我在研究里用到它,有论文可以引用吗?有——README 要求你在工作中使用它时引用 CleanRL 的技术论文。
Creator
vwxyzjn
Size
137.9 MB
Stars
10.6K
Age
7y
Commits · 90 Days