d3rlpy: An offline deep reinforcement learning library
d3rlpy is an offline deep reinforcement learning library for practitioners and researchers.
import d3rlpy
dataset, env = d3rlpy.datasets.get_dataset("hopper-medium-v0")
# prepare algorithm
sac = d3rlpy.algos.SACConfig(compile_graph=True).create(device="cuda:0")
# train offline
sac.fit(dataset, n_steps=1000000)
# train online
sac.fit_online(env, n_steps=1000000)
# ready to control
actions = sac.predict(x)
- Documentation: https://d3rlpy.readthedocs.io
- Paper: https://arxiv.org/abs/2111.03788
Key features
⚡ Most Practical RL Library Ever
- offline RL: d3rlpy supports state-of-the-art offline RL algorithms. Offline RL is extremely powerful when the online interaction is not feasible during training (e.g. robotics, medical).
- online RL: d3rlpy also supports conventional state-of-the-art online training algorithms without any compromising, which means that you can solve any kinds of RL problems only with
d3rlpy.
🔰 User-friendly API
- zero-knowledge of DL library: d3rlpy provides many state-of-the-art algorithms through intuitive APIs. You can become a RL engineer even without knowing how to use deep learning libraries.
- extensive documentation: d3rlpy is fully documented and accompanied with tutorials and reproduction scripts of the original papers.
🚀 Beyond State-of-the-art
- distributional Q function: d3rlpy is the first library that supports distributional Q functions in the all algorithms. The distributional Q function is known as the very powerful method to achieve the state-of-the-performance.
- data-prallel distributed training: d3rlpy is the first library that supports data-parallel distributed offline RL training, which allows you to scale up offline RL with multiple GPUs or nodes. See example.
Installation
d3rlpy supports Linux, macOS and Windows.
Dependencies
Installing d3rlpy package will install or upgrade the following packages to satisfy requirements:
- torch>=2.5.0
- tqdm>=4.66.3
- gym>=0.26.0
- gymnasium==1.0.0
- click
- colorama
- dataclasses-json
- h5py
- structlog
- typing-extensions
- scikit-learn
PyPI (recommended)
$ pip install d3rlpy
Anaconda
$ conda install conda-forge/noarch::d3rlpy
Docker
$ docker run -it --gpus all --name d3rlpy takuseno/d3rlpy:latest bash
Supported algorithms
| algorithm | discrete control | continuous control |
|---|---|---|
| Behavior Cloning (supervised learning) | ✅ | ✅ |
| Neural Fitted Q Iteration (NFQ) | ✅ | ⛔ |
| Deep Q-Network (DQN) | ✅ | ⛔ |
| Double DQN | ✅ | ⛔ |
| Deep Deterministic Policy Gradients (DDPG) | ⛔ | ✅ |
| Twin Delayed Deep Deterministic Policy Gradients (TD3) | ⛔ | ✅ |
| Soft Actor-Critic (SAC) | ✅ | ✅ |
| Batch Constrained Q-learning (BCQ) | ✅ | ✅ |
| Bootstrapping Error Accumulation Reduction (BEAR) | ⛔ | ✅ |
| Conservative Q-Learning (CQL) | ✅ | ✅ |
| Advantage Weighted Actor-Critic (AWAC) | ⛔ | ✅ |
| Critic Reguralized Regression (CRR) | ⛔ | ✅ |
| Policy in Latent Action Space (PLAS) | ⛔ | ✅ |
| TD3+BC | ⛔ | ✅ |
| Policy Regularization with Dataset Constraint (PRDC) | ⛔ | ✅ |
| Implicit Q-Learning (IQL) | ⛔ | ✅ |
| Calibrated Q-Learning (Cal-QL) | ⛔ | ✅ |
| ReBRAC | ⛔ | ✅ |
| Decision Transformer | ✅ | ✅ |
| Q-learning Decision Transformer (QDT) | ⛔ | ✅ |
| Transformer Actor-Critic with Regularization (TACR) | ⛔ | ✅ |
| Gato | 🚧 | 🚧 |
Supported Q functions
- standard Q function
- Quantile Regression
- Implicit Quantile Network
Benchmark results
d3rlpy is benchmarked to ensure the implementation quality. The benchmark scripts are available reproductions directory. The benchmark results are available d3rlpy-benchmarks repository.
Examples
MuJoCo
import d3rlpy
# prepare dataset
dataset, env = d3rlpy.datasets.get_d4rl('hopper-medium-v0')
# prepare algorithm
cql = d3rlpy.algos.CQLConfig(compile_graph=True).create(device='cuda:0')
# train
cql.fit(
dataset,
n_steps=100000,
evaluators={"environment": d3rlpy.metrics.EnvironmentEvaluator(env)},
)
See more datasets at d4rl.
Atari 2600
import d3rlpy
# prepare dataset (1% dataset)
dataset, env = d3rlpy.datasets.get_atari_transitions(
'breakout',
fraction=0.01,
num_stack=4,
)
# prepare algorithm
cql = d3rlpy.algos.DiscreteCQLConfig(
observation_scaler=d3rlpy.preprocessing.PixelObservationScaler(),
reward_scaler=d3rlpy.preprocessing.ClipRewardScaler(-1.0, 1.0),
compile_graph=True,
).create(device='cuda:0')
# start training
cql.fit(
dataset,
n_steps=1000000,
evaluators={"environment": d3rlpy.metrics.EnvironmentEvaluator(env, epsilon=0.001)},
)
See more Atari datasets at d4rl-atari.
Online Training
import d3rlpy
import gym
# prepare environment
env = gym.make('Hopper-v3')
eval_env = gym.make('Hopper-v3')
# prepare algorithm
sac = d3rlpy.algos.SACConfig(compile_graph=True).create(device='cuda:0')
# prepare replay buffer
buffer = d3rlpy.dataset.create_fifo_replay_buffer(limit=1000000, env=env)
# start training
sac.fit_online(env, buffer, n_steps=1000000, eval_env=eval_env)
Tutorials
Try cartpole examples on Google Colaboratory!
More tutorial documentations are available here.
Contributions
Any kind of contribution to d3rlpy would be highly appreciated! Please check the contribution guide.
Community
| Channel | Link |
|---|---|
| Issues | GitHub Issues |
Projects using d3rlpy
| Project | Description |
|---|---|
| MINERVA | An out-of-the-box GUI tool for offline RL |
| SCOPE-RL | An off-policy evaluation and selection library |
Roadmap
The roadmap to the future release is available in ROADMAP.md.
Citation
The paper is available here.
@article{d3rlpy,
author = {Takuma Seno and Michita Imai},
title = {d3rlpy: An Offline Deep Reinforcement Learning Library},
journal = {Journal of Machine Learning Research},
year = {2022},
volume = {23},
number = {315},
pages = {1--20},
url = {http://jmlr.org/papers/v23/22-0017.html}
}
Acknowledgement
This work started as a part of Takuma Seno's Ph.D project at Keio University in 2020.
This work is supported by Information-technology Promotion Agency, Japan (IPA), Exploratory IT Human Resources Project (MITOU Program) in the fiscal year 2020.
Metadata
Release files for d3rlpy 2.8.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| d3rlpy-2.8.1.tar.gz | 136.1 kB | Without provenance | Details for d3rlpy-2.8.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| d3rlpy-2.8.1-py3-none-any.whl | Python 3 | none | any | Details for d3rlpy-2.8.1-py3-none-any.whl |
Total release size: 337.2 kB
Release files / d3rlpy-2.8.1.tar.gz
| Download URL | d3rlpy-2.8.1.tar.gz |
|---|---|
| Size | 136.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2f2acec9d5973eec064dbad937979a81b3ebda2188ac751fd66492f63810be1f
|
|
BLAKE2b-256 checksum How to use checksums |
4c224d3a5b3710e41f7ede8249f1615d5e0ec50f6ae4c51bfdc02c92b2dbe82b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.5
|
Release files / d3rlpy-2.8.1-py3-none-any.whl
| Download URL | d3rlpy-2.8.1-py3-none-any.whl |
|---|---|
| Size | 201.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0603375e1f7da7a4a62fb81f6bb90c97c0ad217f2d57f58546aaaa8c45cf9abb
|
|
BLAKE2b-256 checksum How to use checksums |
66790fd89cc09af9c8b059bf25a658de646953997be7b4ef50c5dd2cf930d832
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.9.5
|
Security for d3rlpy 2.8.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.