Data-driven Deep Reinforcement Learning Library as an Out-of-the-box Tool
Project description
d3rlpy: A data-driven deep reinforcement learning library as an out-of-the-box tool
d3rlpy is a data-driven deep reinforcement learning library as an out-of-the-box tool.
from d3rlpy.dataset import MDPDataset
from d3rlpy.algos import CQL
# MDPDataset takes arrays of state transitions
dataset = MDPDataset(observations, actions, rewards, terminals)
# train data-driven deep RL
cql = CQL()
cql.fit(dataset.episodes)
# ready to control
actions = cql.predict(x)
Documentation: https://d3rlpy.readthedocs.io
key features
:zap: 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
. - advanced engineering: d3rlpy is designed to implement the faster and efficient training algorithms. For example, you can train Atari environments with x4 less memory space and as fast as the fastest RL library.
:beginner: Easy-To-Use 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.
- scikit-learn compatibility: d3rlpy is not only easy, but also completely compatible with scikit-learn API, which means that you can maximize your productivity with the useful scikit-learn's utilities.
:rocket: 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.
- many tweek options: d3rlpy is also the first to support N-step TD backup, ensemble value functions and data augmentation in the all algorithms, which lead you to the place no one ever reached yet.
installation
d3rlpy supports Linux, macOS and Windows.
PyPI (recommended)
$ pip install d3rlpy
Anaconda
$ conda install -c conda-forge d3rlpy
Docker
$ docker run -it --gpus all --name d3rlpy takuseno/d3rlpy:latest bash
build from source (please try this if core dumped
error occurs)
$ git clone https://github.com/takuseno/d3rlpy
$ cd d3rlpy
$ pip install Cython numpy # if not installed yet
$ pip install -e .
supported algorithms
algorithm | discrete control | continuous control | data-driven RL? |
---|---|---|---|
Behavior Cloning (supervised learning) | :white_check_mark: | :white_check_mark: | |
Deep Q-Network (DQN) | :white_check_mark: | :no_entry: | |
Double DQN | :white_check_mark: | :no_entry: | |
Deep Deterministic Policy Gradients (DDPG) | :no_entry: | :white_check_mark: | |
Twin Delayed Deep Deterministic Policy Gradients (TD3) | :no_entry: | :white_check_mark: | |
Soft Actor-Critic (SAC) | :white_check_mark: | :white_check_mark: | |
Batch Constrained Q-learning (BCQ) | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Bootstrapping Error Accumulation Reduction (BEAR) | :no_entry: | :white_check_mark: | :white_check_mark: |
Advantage-Weighted Regression (AWR) | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Conservative Q-Learning (CQL) (recommended) | :white_check_mark: | :white_check_mark: | :white_check_mark: |
Advantage Weighted Actor-Critic (AWAC) | :no_entry: | :white_check_mark: | :white_check_mark: |
Policy in Latent Action Space (PLAS) | :no_entry: | :white_check_mark: | :white_check_mark: |
supported Q functions
- standard Q function
- Quantile Regression
- Implicit Quantile Network
- Fully parametrized Quantile Function (experimental)
other features
Basically, all features are available with every algorithm.
- evaluation metrics in a scikit-learn scorer function style
- export greedy-policy as TorchScript or ONNX
- parallel cross validation with multiple GPU
- model-based algorithm
examples
Atari 2600
from d3rlpy.datasets import get_atari
from d3rlpy.algos import DiscreteCQL
from d3rlpy.metrics.scorer import evaluate_on_environment
from d3rlpy.metrics.scorer import discounted_sum_of_advantage_scorer
from sklearn.model_selection import train_test_split
# get data-driven RL dataset
dataset, env = get_atari('breakout-expert-v0')
# split dataset
train_episodes, test_episodes = train_test_split(dataset, test_size=0.2)
# setup algorithm
cql = DiscreteCQL(n_frames=4, q_func_factory='qr', scaler='pixel', use_gpu=True)
# start training
cql.fit(train_episodes,
eval_episodes=test_episodes,
n_epochs=100,
scorers={
'environment': evaluate_on_environment(env),
'advantage': discounted_sum_of_advantage_scorer
})
See more Atari datasets at d4rl-atari.
PyBullet
from d3rlpy.datasets import get_pybullet
from d3rlpy.algos import CQL
from d3rlpy.metrics.scorer import evaluate_on_environment
from d3rlpy.metrics.scorer import discounted_sum_of_advantage_scorer
from sklearn.model_selection import train_test_split
# get data-driven RL dataset
dataset, env = get_pybullet('hopper-bullet-mixed-v0')
# split dataset
train_episodes, test_episodes = train_test_split(dataset, test_size=0.2)
# setup algorithm
cql = CQL(q_func_factory='qr', use_gpu=True)
# start training
cql.fit(train_episodes,
eval_episodes=test_episodes,
n_epochs=300,
scorers={
'environment': evaluate_on_environment(env),
'advantage': discounted_sum_of_advantage_scorer
})
See more PyBullet datasets at d4rl-pybullet.
Online Training
import gym
from d3rlpy.algos import SAC
from d3rlpy.online.buffers import ReplayBuffer
# setup environment
env = gym.make('HopperBulletEnv-v0')
eval_env = gym.make('HopperBulletEnv-v0')
# setup algorithm
sac = SAC(use_gpu=True)
# setup replay buffer
buffer = ReplayBuffer(maxlen=1000000, env=env)
# start training
sac.fit_online(env, buffer, n_steps=1000000, eval_env=eval_env)
tutorials
Try a cartpole example on Google Colaboratory!
scikit-learn compatibility
This library is designed as if born from scikit-learn. You can fully utilize scikit-learn's utilities to increase your productivity.
from sklearn.model_selection import train_test_split
from d3rlpy.metrics.scorer import td_error_scorer
train_episodes, test_episodes = train_test_split(dataset)
cql.fit(train_episodes,
eval_episodes=test_episodes,
scorers={'td_error': td_error_scorer})
You can naturally perform cross-validation.
from sklearn.model_selection import cross_validate
scores = cross_validate(cql, dataset, scoring={'td_error': td_error_scorer})
And more.
from sklearn.model_selection import GridSearchCV
gscv = GridSearchCV(estimator=cql,
param_grid={'actor_learning_rate': [3e-3, 3e-4, 3e-5]},
scoring={'td_error': td_error_scorer},
refit=False)
gscv.fit(train_episodes)
contributions
Any kind of contribution to d3rlpy would be highly appreciated! Please check the contribution guide.
citation
@misc{seno2020d3rlpy,
author = {Takuma Seno},
title = {d3rlpy: A data-driven deep reinforcement library as an out-of-the-box tool},
year = {2020},
publisher = {GitHub},
journal = {GitHub repository},
howpublished = {\url{https://github.com/takuseno/d3rlpy}}
}
acknowledgement
This work is supported by Information-technology Promotion Agency, Japan (IPA), Exploratory IT Human Resources Project (MITOU Program) in the fiscal year 2020.
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 Distribution
Built Distributions
Hashes for d3rlpy-0.70-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81975ceb82ecdc54d0fae49e0dde18ddfa9df48ba4bdea509776a2e2e4faf892 |
|
MD5 | 732f84aa7ae3cc414e275a509bd64258 |
|
BLAKE2b-256 | 481431820b2ad5246c2b03d08589f8f6e55805fbe19daf2f60f373e184a198b8 |
Hashes for d3rlpy-0.70-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a5064c7d0284512eed508f33664f69f5af71845e7f734647fe3476d3ab96cb7c |
|
MD5 | a8ea33d47d4e1c2767b53c83de441a4e |
|
BLAKE2b-256 | 2d623d31dcb5a7fd8ce9f875492588879a83ad018da654fcb5b805f317953b92 |
Hashes for d3rlpy-0.70-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f3eed693cebefc7a0577b2163a6d7bd5b65401d82163b4a9c8121c85c1e37eb9 |
|
MD5 | 9fe49b170f825ab01b01fea517742aca |
|
BLAKE2b-256 | f6ea83af0b15b3d6aa71dc1cca7d0a8f40c83731745bd12982d977c3ad7199d4 |
Hashes for d3rlpy-0.70-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 923527445c016091083ab75be5e5094161bf4d64b800efbf894a78e7f012614c |
|
MD5 | a0fc588cecbaf7f374c82235c64a541e |
|
BLAKE2b-256 | 07944ca86873d85b4621fbbbcd119c21c75ce81cd054c499c5a4c820d26d285b |
Hashes for d3rlpy-0.70-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e063d580aa823edda7e5376b8f652751aa4952d08a8a0b1114d5511d3b5b3d54 |
|
MD5 | 4926fb390a745f55c35fd03fa2b98dea |
|
BLAKE2b-256 | 4c4023765980089f1a313aa55955d34ca423a0ae83ce054d1ae5e7f7bad6cf79 |
Hashes for d3rlpy-0.70-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6df6d9d4cc16b39a981c0ef43c657f527cb67b3236f726bed8848332ea2b1d72 |
|
MD5 | e96e68058c07e91086be130d796e77bc |
|
BLAKE2b-256 | 2bd4eba6c09b7f70891f99726fb07fe3cd3cb154fb8e04126fdf348e3e18bf5c |
Hashes for d3rlpy-0.70-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7fe8881392bca1cdf36cf75cd22f5c7c929fa9a6fc6680b84468253b8d03b935 |
|
MD5 | f3374e62b319bf0bdfb0a3cedbe195ae |
|
BLAKE2b-256 | f9aad41bf4899fdd8c24f904ba4987cbf26635fa2b4d490839f3673969ae98d1 |
Hashes for d3rlpy-0.70-cp36-cp36m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1da5f7a13a1498c0e212215621c0a15d5584b27dcf18ae17c140b774dce368a3 |
|
MD5 | 7a806f6f485d605a0bff0eb373710c02 |
|
BLAKE2b-256 | e1c010b30ee3873c4a7386719d1e31cba0ab9599d226899400274706793df462 |
Hashes for d3rlpy-0.70-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d67d637fd20af0c1a1d2377456e3412a766b095856b63980da81f99bef9340be |
|
MD5 | ff4a409fa3c59de7e52f9d5e65a99fd5 |
|
BLAKE2b-256 | 141ae2c1fb25b3b86b50c30bc743ba8c704c633137dc768fb004606359015324 |