Collection of reinforcement learning algorithms
Python
2,939
184 commits
updated Jun 17, 2024
Reinforcement learning framework and algorithms implemented in PyTorch.
Implemented algorithms:
To get started, checkout the example scripts, linked above.
multiworld code that requires explicit environment registration.setup.py and using default conf.py.env_info and agent_info.The initial release for 0.2 has the following major changes:
Serializable class and use default pickle scheme.PyTorchModule class and use native torch.nn.Module directly.RLAlgorithm.RLAlgorithm.TwinSAC to just SAC.Overall, the refactors are intended to make the code more modular and readable than the previous versions.
$ conda env create -f environment/[linux-cpu|linux-gpu|mac]-env.yml
$ source activate rlkit
(rlkit) $ python examples/ddpg.py
Choose the appropriate .yml file for your system.
These Anaconda environments use MuJoCo 1.5 and gym 0.10.5.
You'll need to get your own MuJoCo key if you want to use MuJoCo.
PYTHONPATH environment variable or simply
run:pip install -e .
conf.py to conf_private.py and edit to override defaults:cp rlkit/launchers/conf.py rlkit/launchers/conf_private.py
DISCLAIMER: the mac environment has only been tested without a GPU.
For an even more portable solution, try using the docker image provided in environment/docker.
The Anaconda env should be enough, but this docker image addresses some of the rendering issues that may arise when using MuJoCo 1.5 and GPUs.
The docker image supports GPU, but it should work without a GPU.
To use a GPU with the image, you need to have nvidia-docker installed.
You can use a GPU by calling
import rlkit.torch.pytorch_util as ptu
ptu.set_gpu_mode(True)
before launching the scripts.
If you are using doodad (see below), simply use the use_gpu flag:
run_experiment(..., use_gpu=True)
During training, the results will be saved to a file called under
LOCAL_LOG_DIR/<exp_prefix>/<foldername>
LOCAL_LOG_DIR is the directory set by rlkit.launchers.config.LOCAL_LOG_DIR. Default name is 'output'.<exp_prefix> is given either to setup_logger.<foldername> is auto-generated and based off of exp_prefix.params.pkl. To visualize a policy, run(rlkit) $ python scripts/run_policy.py LOCAL_LOG_DIR/<exp_prefix>/<foldername>/params.pkl
or
(rlkit) $ python scripts/run_goal_conditioned_policy.py LOCAL_LOG_DIR/<exp_prefix>/<foldername>/params.pkl
depending on whether or not the policy is goal-conditioned.
If you have rllab installed, you can also visualize the results
using rllab's viskit, described at
the bottom of this page
tl;dr run
python rllab/viskit/frontend.py LOCAL_LOG_DIR/<exp_prefix>/
to visualize all experiments with a prefix of exp_prefix. To only visualize a single run, you can do
python rllab/viskit/frontend.py LOCAL_LOG_DIR/<exp_prefix>/<folder name>
Alternatively, if you don't want to clone all of rllab, a repository containing only viskit can be found here. You can similarly visualize results with.
python viskit/viskit/frontend.py LOCAL_LOG_DIR/<exp_prefix>/
This viskit repo also has a few extra nice features, like plotting multiple Y-axis values at once, figure-splitting on multiple keys, and being able to filter hyperparametrs out.
To visualize a goal-conditioned policy, run
(rlkit) $ python scripts/run_goal_conditioned_policy.py
LOCAL_LOG_DIR/<exp_prefix>/<foldername>/params.pkl
doodadThe run_experiment function makes it easy to run Python code on Amazon Web
Services (AWS) or Google Cloud Platform (GCP) by using
this fork of doodad.
It's as easy as:
from rlkit.launchers.launcher_util import run_experiment
def function_to_run(variant):
learning_rate = variant['learning_rate']
...
run_experiment(
function_to_run,
exp_prefix="my-experiment-name",
mode='ec2', # or 'gcp'
variant={'learning_rate': 1e-3},
)
You will need to set up parameters in config.py (see step one of Installation).
This requires some knowledge of AWS and/or GCP, which is beyond the scope of
this README.
To learn more, more about doodad, go to the repository, which is based on this original repository.
For Temporal Difference Models (TDMs) and the original implementation of
Reinforcement Learning with Imagined Goals (RIG), run
git checkout tags/v0.1.2.
The algorithms are based on the following papers
Offline Meta-Reinforcement Learning with Online Self-Supervision Vitchyr H. Pong, Ashvin Nair, Laura Smith, Catherine Huang, Sergey Levine. arXiv preprint, 2021.
Skew-Fit: State-Covering Self-Supervised Reinforcement Learning. Vitchyr H. Pong*, Murtaza Dalal*, Steven Lin*, Ashvin Nair, Shikhar Bahl, Sergey Levine. ICML, 2020.
Visual Reinforcement Learning with Imagined Goals. Ashvin Nair*, Vitchyr Pong*, Murtaza Dalal, Shikhar Bahl, Steven Lin, Sergey Levine. NeurIPS 2018.
Temporal Difference Models: Model-Free Deep RL for Model-Based Control. Vitchyr Pong*, Shixiang Gu*, Murtaza Dalal, Sergey Levine. ICLR 2018.
Hindsight Experience Replay. Marcin Andrychowicz, Filip Wolski, Alex Ray, Jonas Schneider, Rachel Fong, Peter Welinder, Bob McGrew, Josh Tobin, Pieter Abbeel, Wojciech Zaremba. NeurIPS 2017.
Deep Reinforcement Learning with Double Q-learning. Hado van Hasselt, Arthur Guez, David Silver. AAAI 2016.
Human-level control through deep reinforcement learning. Volodymyr Mnih, Koray Kavukcuoglu, David Silver, Andrei A. Rusu, Joel Veness, Marc G. Bellemare, Alex Graves, Martin Riedmiller, Andreas K. Fidjeland, Georg Ostrovski, Stig Petersen, Charles Beattie, Amir Sadik, Ioannis Antonoglou, Helen King, Dharshan Kumaran, Daan Wierstra, Shane Legg, Demis Hassabis. Nature 2015.
Soft Actor-Critic Algorithms and Applications. Tuomas Haarnoja, Aurick Zhou, Kristian Hartikainen, George Tucker, Sehoon Ha, Jie Tan, Vikash Kumar, Henry Zhu, Abhishek Gupta, Pieter Abbeel, Sergey Levine. arXiv preprint, 2018.
Soft Actor-Critic: Off-Policy Maximum Entropy Deep Reinforcement Learning with a Stochastic Actor. Tuomas Haarnoja, Aurick Zhou, Pieter Abbeel, and Sergey Levine. ICML, 2018.
Addressing Function Approximation Error in Actor-Critic Methods Scott Fujimoto, Herke van Hoof, David Meger. ICML, 2018.
This repository was initially developed primarily by Vitchyr Pong, until July 2021, at which point it was transferred to the RAIL Berkeley organization and is primarily maintained by Ashvin Nair. Other major collaborators and contributions:
A lot of the coding infrastructure is based on rllab. The serialization and logger code are basically a carbon copy of the rllab versions.
The Dockerfile is based on the OpenAI mujoco-py Dockerfile.
The SMAC code builds off of the PEARL code, which built off of an older RLKit version.
1,255 followers · starred Mar 2020
40 followers · starred May 2022
53 followers · starred Mar 2020
1 followers · starred Feb 2021
Collection of reinforcement learning algorithms
Python
2,939
184 commits
updated Jun 17, 2024
Reinforcement learning framework and algorithms implemented in PyTorch.
Implemented algorithms:
To get started, checkout the example scripts, linked above.
multiworld code that requires explicit environment registration.setup.py and using default conf.py.env_info and agent_info.The initial release for 0.2 has the following major changes:
Serializable class and use default pickle scheme.PyTorchModule class and use native torch.nn.Module directly.RLAlgorithm.RLAlgorithm.TwinSAC to just SAC.Overall, the refactors are intended to make the code more modular and readable than the previous versions.
$ conda env create -f environment/[linux-cpu|linux-gpu|mac]-env.yml
$ source activate rlkit
(rlkit) $ python examples/ddpg.py
Choose the appropriate .yml file for your system.
These Anaconda environments use MuJoCo 1.5 and gym 0.10.5.
You'll need to get your own MuJoCo key if you want to use MuJoCo.
PYTHONPATH environment variable or simply
run:pip install -e .
conf.py to conf_private.py and edit to override defaults:cp rlkit/launchers/conf.py rlkit/launchers/conf_private.py
DISCLAIMER: the mac environment has only been tested without a GPU.
For an even more portable solution, try using the docker image provided in environment/docker.
The Anaconda env should be enough, but this docker image addresses some of the rendering issues that may arise when using MuJoCo 1.5 and GPUs.
The docker image supports GPU, but it should work without a GPU.
To use a GPU with the image, you need to have nvidia-docker installed.
You can use a GPU by calling
import rlkit.torch.pytorch_util as ptu
ptu.set_gpu_mode(True)
before launching the scripts.
If you are using doodad (see below), simply use the use_gpu flag:
run_experiment(..., use_gpu=True)
During training, the results will be saved to a file called under
LOCAL_LOG_DIR/<exp_prefix>/<foldername>
LOCAL_LOG_DIR is the directory set by rlkit.launchers.config.LOCAL_LOG_DIR. Default name is 'output'.<exp_prefix> is given either to setup_logger.<foldername> is auto-generated and based off of exp_prefix.params.pkl. To visualize a policy, run(rlkit) $ python scripts/run_policy.py LOCAL_LOG_DIR/<exp_prefix>/<foldername>/params.pkl
or
(rlkit) $ python scripts/run_goal_conditioned_policy.py LOCAL_LOG_DIR/<exp_prefix>/<foldername>/params.pkl
depending on whether or not the policy is goal-conditioned.
If you have rllab installed, you can also visualize the results
using rllab's viskit, described at
the bottom of this page
tl;dr run
python rllab/viskit/frontend.py LOCAL_LOG_DIR/<exp_prefix>/
to visualize all experiments with a prefix of exp_prefix. To only visualize a single run, you can do
python rllab/viskit/frontend.py LOCAL_LOG_DIR/<exp_prefix>/<folder name>
Alternatively, if you don't want to clone all of rllab, a repository containing only viskit can be found here. You can similarly visualize results with.
python viskit/viskit/frontend.py LOCAL_LOG_DIR/<exp_prefix>/
This viskit repo also has a few extra nice features, like plotting multiple Y-axis values at once, figure-splitting on multiple keys, and being able to filter hyperparametrs out.
To visualize a goal-conditioned policy, run
(rlkit) $ python scripts/run_goal_conditioned_policy.py
LOCAL_LOG_DIR/<exp_prefix>/<foldername>/params.pkl
doodadThe run_experiment function makes it easy to run Python code on Amazon Web
Services (AWS) or Google Cloud Platform (GCP) by using
this fork of doodad.
It's as easy as:
from rlkit.launchers.launcher_util import run_experiment
def function_to_run(variant):
learning_rate = variant['learning_rate']
...
run_experiment(
function_to_run,
exp_prefix="my-experiment-name",
mode='ec2', # or 'gcp'
variant={'learning_rate': 1e-3},
)
You will need to set up parameters in config.py (see step one of Installation).
This requires some knowledge of AWS and/or GCP, which is beyond the scope of
this README.
To learn more, more about doodad, go to the repository, which is based on this original repository.
For Temporal Difference Models (TDMs) and the original implementation of
Reinforcement Learning with Imagined Goals (RIG), run
git checkout tags/v0.1.2.
The algorithms are based on the following papers
Offline Meta-Reinforcement Learning with Online Self-Supervision Vitchyr H. Pong, Ashvin Nair, Laura Smith, Catherine Huang, Sergey Levine. arXiv preprint, 2021.
Skew-Fit: State-Covering Self-Supervised Reinforcement Learning. Vitchyr H. Pong*, Murtaza Dalal*, Steven Lin*, Ashvin Nair, Shikhar Bahl, Sergey Levine. ICML, 2020.
Visual Reinforcement Learning with Imagined Goals. Ashvin Nair*, Vitchyr Pong*, Murtaza Dalal, Shikhar Bahl, Steven Lin, Sergey Levine. NeurIPS 2018.
Temporal Difference Models: Model-Free Deep RL for Model-Based Control. Vitchyr Pong*, Shixiang Gu*, Murtaza Dalal, Sergey Levine. ICLR 2018.
Hindsight Experience Replay. Marcin Andrychowicz, Filip Wolski, Alex Ray, Jonas Schneider, Rachel Fong, Peter Welinder, Bob McGrew, Josh Tobin, Pieter Abbeel, Wojciech Zaremba. NeurIPS 2017.
Deep Reinforcement Learning with Double Q-learning. Hado van Hasselt, Arthur Guez, David Silver. AAAI 2016.
Human-level control through deep reinforcement learning. Volodymyr Mnih, Koray Kavukcuoglu, David Silver, Andrei A. Rusu, Joel Veness, Marc G. Bellemare, Alex Graves, Martin Riedmiller, Andreas K. Fidjeland, Georg Ostrovski, Stig Petersen, Charles Beattie, Amir Sadik, Ioannis Antonoglou, Helen King, Dharshan Kumaran, Daan Wierstra, Shane Legg, Demis Hassabis. Nature 2015.
Soft Actor-Critic Algorithms and Applications. Tuomas Haarnoja, Aurick Zhou, Kristian Hartikainen, George Tucker, Sehoon Ha, Jie Tan, Vikash Kumar, Henry Zhu, Abhishek Gupta, Pieter Abbeel, Sergey Levine. arXiv preprint, 2018.
Soft Actor-Critic: Off-Policy Maximum Entropy Deep Reinforcement Learning with a Stochastic Actor. Tuomas Haarnoja, Aurick Zhou, Pieter Abbeel, and Sergey Levine. ICML, 2018.
Addressing Function Approximation Error in Actor-Critic Methods Scott Fujimoto, Herke van Hoof, David Meger. ICML, 2018.
This repository was initially developed primarily by Vitchyr Pong, until July 2021, at which point it was transferred to the RAIL Berkeley organization and is primarily maintained by Ashvin Nair. Other major collaborators and contributions:
A lot of the coding infrastructure is based on rllab. The serialization and logger code are basically a carbon copy of the rllab versions.
The Dockerfile is based on the OpenAI mujoco-py Dockerfile.
The SMAC code builds off of the PEARL code, which built off of an older RLKit version.
1,255 followers · starred Mar 2020
40 followers · starred May 2022
53 followers · starred Mar 2020
1 followers · starred Feb 2021