No project description provided
Project description
TorchRL
Disclaimer
This library is not officially released yet and is subject to change.
The features are available before an official release so that users and collaborators can get early access and provide feedback. No guarantee of stability, robustness or backward compatibility is provided.
TorchRL is an open-source Reinforcement Learning (RL) library for PyTorch.
It provides pytorch and python-first, low and high level abstractions for RL that are intended to be efficient, documented and properly tested. The code is aimed at supporting research in RL. Most of it is written in python in a highly modular way, such that researchers can easily swap components, transform them or write new ones with little effort.
This repo attempts to align with the existing pytorch ecosystem libraries in that it has a dataset pillar (torchrl/envs), transforms, models, data utilities (e.g. collectors and containers), etc. TorchRL aims at having as few dependencies as possible (python standard library, numpy and pytorch). Common environment libraries (e.g. OpenAI gym) are only optional.
On the low-level end, torchrl comes with a set of highly re-usable functionals for cost functions, returns and data processing.
On the high-level end, torchrl provides:
- multiprocess data collectors;
- efficient and generic replay buffers;
- TensorDict, a convenient data structure to pass data from one object to another without friction;
- An associated
TensorDictModule
class which is functorch-compatible! - interfaces for environments from common libraries (OpenAI gym, deepmind control lab, etc.) and wrappers for parallel execution, as well as a new pytorch-first class of tensor-specification class;
- environment transforms, which process and prepare the data coming out of the environments to be used by the agent;
- various tools for distributed learning (e.g. memory mapped tensors);
- various architectures and models (e.g. actor-critic);
- exploration wrappers and modules;
- various recipes to build models that correspond to the environment being deployed;
- a generic trainer class.
A series of examples are provided with an illustrative purpose:
and many more to come!
Installation
Create a conda environment where the packages will be installed.
Before installing anything, make sure you have the latest version of the ninja
library:
conda create --name torch_rl python=3.9
conda activate torch_rl
pip install ninja
Depending on the use of functorch that you want to make, you may want to install the latest (nightly) pytorch release or the latest stable version of pytorch:
Stable
# For CUDA 10.2
conda install pytorch torchvision cudatoolkit=10.2 -c pytorch
# For CUDA 11.3
conda install pytorch torchvision torchaudio cudatoolkit=11.3 -c pytorch
# For CPU-only build
conda install pytorch torchvision torchaudio cpuonly -c pytorch
pip install functorch
Nightly
# For CUDA 10.2
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cu102
# For CUDA 11.3
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cu113
# For CPU-only build
pip3 install --pre torch torchvision torchaudio --extra-index-url https://download.pytorch.org/whl/nightly/cpu
and functorch
pip install "git+https://github.com/pytorch/functorch.git"
Torchrl
Go to the directory where you have cloned the torchrl repo and install it
cd /path/to/torchrl/
python setup.py develop
As the library is at an early stage, it may be wise to install it in develop mode (python setup.py develop
instead of install
) as this will make it possible to pull the latest changes and benefit from them immediately.
To run a quick sanity check, leave that directory (e.g. by executing cd ~/
) and try to import the library.
python -c "import torchrl"
Optional dependencies
The following libraries can be installed depending on the usage one wants to make of torchrl:
# diverse
pip install tqdm pyyaml configargparse
# rendering
pip install moviepy
# deepmind control suite
pip install dm_control
# gym, atari games
pip install gym gym[accept-rom-license] pygame gym_retro
# tests
pip install pytest
Alternatively, extra dependencies can be installed using
pip install -e ".[atari,dm_control,gym_continuous,rendering,tests,utils]"
or a selection of these.
Troubleshooting
If a ModuleNotFoundError: No module named ‘torchrl._torchrl
errors occurs, it means that the C++ extensions were not installed or not found.
One common reason might be that you are trying to import torchrl from within the git repo location. Indeed the following code snippet should return an error if torchrl has not been installed in develop
mode:
cd ~/path/to/rl/repo
python -c 'from torchrl.envs import GymEnv'
If this is the case, consider executing torchrl from another location.
On MacOs, we recommend installing XCode first. With Apple Silicon M1 chips, make sure you are using the arm64-built python (e.g. here). Running the following lines of code
wget https://raw.githubusercontent.com/pytorch/pytorch/master/torch/utils/collect_env.py
python collect_env.py
should display
OS: macOS *** (arm64)
and not
OS: macOS **** (x86_64)
Running examples
Examples are coded in a very similar way but the configuration may change from one algorithm to another (e.g. async/sync data collection, hyperparameters, ratio of model updates / frame etc.)
To train an algorithm it is therefore advised to use the predefined configurations that are found in the configs
sub-folder in each algorithm directory:
python examples/ppo/ppo.py --config=examples/ppo/configs/humanoid.txt
Note that using the config files requires the configargparse library.
One can also overwrite the config parameters using flags, e.g.
python examples/ppo/ppo.py --config=examples/ppo/configs/humanoid.txt --frame_skip=2 --collection_devices=cuda:1
Each example will write a tensorboard log in a dedicated folder, e.g. ppo_logging/...
.
Contributing
Internal collaborations to torchrl are welcome! Feel free to fork, submit issues and PRs. You can checkout the detailed contribution guide here.
Contributors are recommended to install pre-commit hooks (using pre-commit install
). pre-commit will check for linting related issues when the code is commited locally. You can disable th check by appending -n
to your commit command: git commit -m <commit message> -n
Upcoming features
In the near future, we plan to:
- provide tutorials on how to design new actors or environment wrappers;
- implement IMPALA (as a distributed RL example) and Meta-RL algorithms;
- improve the tests, documentation and nomenclature.
License
TorchRL is licensed under the MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for torchrl-0.0.1a0-cp310-cp310-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59a6953ab4fa646b658586fe896cd7e849ec89d4269fce27f033ea518c9d0842 |
|
MD5 | 99bf1812a3aab039b9e17f97f34a5bd0 |
|
BLAKE2b-256 | b63434b9ae100ebaada296a4b51bdb053666155ebc9809d191a3c0617df51133 |
Hashes for torchrl-0.0.1a0-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 19217e2012f2b26b14a77a29246e192bb7c106366ac0c4a84e8945706789998b |
|
MD5 | 9c4d713bbfe057884b50ccda1a1ea823 |
|
BLAKE2b-256 | 6167bc06600e2b37758911e7ea461cc2d87ffd578bac660cad345c333f848e90 |
Hashes for torchrl-0.0.1a0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6afede2f83aa332b834f09c3b07b8b1db86eebd4f0986d8a089be5a07bac9e3a |
|
MD5 | 4c57f1f6692724d0b5f25f5528cf3c9b |
|
BLAKE2b-256 | 24c44d8092702d110dd5458ce1b6cf8ae68b517b9d1611224aabefdb003fad50 |
Hashes for torchrl-0.0.1a0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e8a162de316d6790fb7c7edb02e8d5dd639f06081db5d41371f12c203c2111f2 |
|
MD5 | 7c7659667d24cbd13f81974b96c6bb47 |
|
BLAKE2b-256 | 4699e8dab72ad6aa973e136d1536406ddff022e3be2df536896b28f9349d3d55 |
Hashes for torchrl-0.0.1a0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e6acc27b73c290af214ac0c1061b5bf79399420976519bf6a519a3532905d7a3 |
|
MD5 | 695bf90e88999d1e48ae5d3b2e4462be |
|
BLAKE2b-256 | b49c76dbfedac963f5b1335db9a2a0bd64971c9de4d030379e709089fa428292 |
Hashes for torchrl-0.0.1a0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bde753b44490873c2d84c8b962b02d7cdbac7d4cff0b5c53ca9c5e4693bcd638 |
|
MD5 | 0473d7eeb9338849af422ac1cb899223 |
|
BLAKE2b-256 | 93ed5d446b945f8ea8c95c78de395ef33594e8367de4e8ad6c1b0525c8a628f9 |
Hashes for torchrl-0.0.1a0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 306bb432ababfe10c25564bf91e6f2687804b9fd7f42554b5a1f8dcc1945589e |
|
MD5 | 1de779e8b46347f1fb282bdfe5e519a4 |
|
BLAKE2b-256 | 73cd6b78f15445619c4ca5ea787827f4fe87b43d26a8273b37414b545f85f354 |
Hashes for torchrl-0.0.1a0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | abf1508aa81bb2d460b8b068e5fcf0ed97a75cce163315194f403dfca19e422b |
|
MD5 | 00c0011ca23088f369b91474654b3ca8 |
|
BLAKE2b-256 | b100b310becf049ba5293fd828e9dd290e9258fda48ffd9d2366149a14e372ef |