Skip to main content

No project description provided

Project description

facebookresearch

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:

A series of examples are provided with an illustrative purpose:

and many more to come!

We also provide tutorials and demos that give a sense of what the library can do.

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 cudatoolkit=11.3 -c pytorch
# For CPU-only build
conda install pytorch torchvision cpuonly -c pytorch

pip install functorch

Nightly

# For CUDA 10.2
pip3 install --pre torch torchvision --extra-index-url https://download.pytorch.org/whl/nightly/cu102
# For CUDA 11.3
pip3 install --pre torch torchvision --extra-index-url https://download.pytorch.org/whl/nightly/cu113
# For CPU-only build
pip3 install --pre torch torchvision --extra-index-url https://download.pytorch.org/whl/nightly/cpu

and functorch

pip install "git+https://github.com/pytorch/functorch.git"

If the generation of this artifact in MacOs M1 doesn't work correctly or in the execution the message (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')) appears, then try

ARCHFLAGS="-arch arm64" pip install "git+https://github.com/pytorch/functorch.git"

Torchrl

You can install the latest release by using

pip install torchrl

This should work on linux and MacOs (not M1). For Windows and M1/M2 machines, one should install the library locally (see below).

To install extra dependencies, call

pip install "torchrl[atari,dm_control,gym_continuous,rendering,tests,utils]"

or a subset of these.

Alternatively, as the library is at an early stage, it may be wise to install it in develop mode as this will make it possible to pull the latest changes and benefit from them immediately. Start by cloning the repo:

git clone https://github.com/facebookresearch/rl

Go to the directory where you have cloned the torchrl repo and install it

cd /path/to/torchrl/
python setup.py develop

If the generation of this artifact in MacOs M1 doesn't work correctly or in the execution the message (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64e')) appears, then try

ARCHFLAGS="-arch arm64" python setup.py develop

To run a quick sanity check, leave that directory (e.g. by executing cd ~/) and try to import the library.

python -c "import torchrl"

This should not return any warning or error.

Optional dependencies

The following libraries can be installed depending on the usage one wants to make of torchrl:

# diverse
pip install tqdm tensorboard "hydra-core>=1.1" hydra-submitit-launcher

# 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 pyyaml pytest-instafail

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

torchrl-0.0.1rc0-cp310-cp310-manylinux1_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.10

torchrl-0.0.1rc0-cp310-cp310-macosx_10_15_x86_64.whl (402.2 kB view details)

Uploaded CPython 3.10macOS 10.15+ x86-64

torchrl-0.0.1rc0-cp39-cp39-manylinux1_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.9

torchrl-0.0.1rc0-cp39-cp39-macosx_10_15_x86_64.whl (402.5 kB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

torchrl-0.0.1rc0-cp38-cp38-manylinux1_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.8

torchrl-0.0.1rc0-cp38-cp38-macosx_10_15_x86_64.whl (402.2 kB view details)

Uploaded CPython 3.8macOS 10.15+ x86-64

torchrl-0.0.1rc0-cp37-cp37m-manylinux1_x86_64.whl (3.3 MB view details)

Uploaded CPython 3.7m

torchrl-0.0.1rc0-cp37-cp37m-macosx_10_15_x86_64.whl (397.2 kB view details)

Uploaded CPython 3.7mmacOS 10.15+ x86-64

File details

Details for the file torchrl-0.0.1rc0-cp310-cp310-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for torchrl-0.0.1rc0-cp310-cp310-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 287ef04c8217ff73b4b136446fb2cc615c9562cddcd37e5c27022cc048537885
MD5 539dd7e4534f68d02baec2329fae4f85
BLAKE2b-256 b096396ac071be34a11256cc054a34b33ce1d44ea09fad00c1892ca992e2ce2b

See more details on using hashes here.

File details

Details for the file torchrl-0.0.1rc0-cp310-cp310-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for torchrl-0.0.1rc0-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 5fa0e24cdffec5c6f99c26e5ed2786de4474f830b344cac256d57dd4445a10c5
MD5 bb92d46dcd923079c57e10e0b4ec82d9
BLAKE2b-256 411e6fa6bd65ac9b59ff805183ace4b54205531ad0d987c09ab6cba67f18957a

See more details on using hashes here.

File details

Details for the file torchrl-0.0.1rc0-cp39-cp39-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for torchrl-0.0.1rc0-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 b33abd281bcf6f5050e5352645cf5c83e109b84fc01480e5a1deed79bffd822b
MD5 6b4719e44c5ff3c81882adcd3cde7ebc
BLAKE2b-256 b5f0b2b6ac782ea7b1bdeee3db74b60ddfdd2dbff83138f945ec03e5b81537be

See more details on using hashes here.

File details

Details for the file torchrl-0.0.1rc0-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for torchrl-0.0.1rc0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 9ddab0ada2e0949df12a59373d70d12147cdfcf6719bd6be90de162d796e0ef8
MD5 eec3a22b8594ba3912284f8ed56666a1
BLAKE2b-256 9dd2a0d75ca992edbe2b07ef2b1d42018cfabf18bab84d3cd159e1de3a639bf3

See more details on using hashes here.

File details

Details for the file torchrl-0.0.1rc0-cp38-cp38-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for torchrl-0.0.1rc0-cp38-cp38-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 bccc7317cb120712fe1d089af43713c28ea9fa75c3ae45f7f460ef7b20fe70d3
MD5 812fc955d178e2c84ba55cb7956df857
BLAKE2b-256 341939ffc8c471ad0d7b7edf93b24e9ae5ea3a836f4306dc70b23e7c04fc1dfe

See more details on using hashes here.

File details

Details for the file torchrl-0.0.1rc0-cp38-cp38-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for torchrl-0.0.1rc0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 f41c1d66019d5976db64df36d937b523556380da7ea72cac2e440710f10de320
MD5 becbb84df46c2aa0a6098f587572fe1d
BLAKE2b-256 dcd6f16257bdbc0a39a687eaa6fcfae560050c9d3088fee5d46ec3fbb4ae1213

See more details on using hashes here.

File details

Details for the file torchrl-0.0.1rc0-cp37-cp37m-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for torchrl-0.0.1rc0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 27d9f76b7c9ebd3e5ed57b05bc012c12519928ea833dc8ab485f4407ba3fe597
MD5 a3f0fe1be2f9c920f8bcc5f32b41ff89
BLAKE2b-256 d737a4bbaa34edca8ba60070cec33cb6923a91b23929de3674564b143b81f9c5

See more details on using hashes here.

File details

Details for the file torchrl-0.0.1rc0-cp37-cp37m-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for torchrl-0.0.1rc0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 baa9b3fe87e7831e1d157e23950b898fee41fadccf06618ac8e7ebe367172de0
MD5 8b90d97b604e27e632872d2449e84abb
BLAKE2b-256 3016e94bc085f4b53963c6c4d023913b00dc8e65b19b75282b9f68ce1cd8b21c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page