From 69d13540166f8d5dbc89fb69670b9cdce391a461 Mon Sep 17 00:00:00 2001 From: Eric Liang Date: Tue, 28 Aug 2018 18:13:36 -0700 Subject: [PATCH] [rllib] Document ARS & rainbow (#2744) * wip * rainbow doc too * e not used * fix ppo doc * clean list * use same title --- doc/source/rllib-algorithms.rst | 104 ++++++++++++++------------ doc/source/rllib-training.rst | 3 + doc/source/rllib.rst | 34 ++++++--- python/ray/tune/ray_trial_executor.py | 2 +- 4 files changed, 86 insertions(+), 57 deletions(-) diff --git a/doc/source/rllib-algorithms.rst b/doc/source/rllib-algorithms.rst index 8329be6e7..2cbcef178 100644 --- a/doc/source/rllib-algorithms.rst +++ b/doc/source/rllib-algorithms.rst @@ -1,8 +1,11 @@ RLlib Algorithms ================ -Ape-X Distributed Prioritized Experience Replay ------------------------------------------------ +High-throughput architectures +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Distributed Prioritized Experience Replay (Ape-X) +------------------------------------------------- `[paper] `__ `[implementation] `__ Ape-X variations of DQN and DDPG (`APEX_DQN `__, `APEX_DDPG `__ in RLlib) use a single GPU learner and many CPU workers for experience collection. Experience collection can scale to hundreds of CPU workers due to the distributed prioritization of experience prior to storage in replay buffers. @@ -13,17 +16,32 @@ Tuned examples: `PongNoFrameskip-v4 `__ +`[implementation] `__ +In IMPALA, a central learner runs SGD in a tight loop while asynchronously pulling sample batches from many actor processes. RLlib's IMPALA implementation uses DeepMind's reference `V-trace code `__. Note that we do not provide a deep residual network out of the box, but one can be plugged in as a `custom model `__. + +Tuned examples: `PongNoFrameskip-v4 `__, `vectorized configuration `__, `{BeamRider,Breakout,Qbert,SpaceInvaders}NoFrameskip-v4 `__, `Atari results `__. + +.. figure:: impala.png + :align: center + + IMPALA solves Atari several times faster than A2C / A3C, with similar sample efficiency. Here IMPALA scales from 16 to 128 workers to solve PongNoFrameskip-v4 in ~8 minutes. + +Gradient-based +~~~~~~~~~~~~~~ + Advantage Actor-Critic (A2C, A3C) --------------------------------- `[paper] `__ `[implementation] `__ RLlib implements A2C and A3C using SyncSamplesOptimizer and AsyncGradientsOptimizer respectively for policy optimization. These algorithms scale to up to 16-32 worker processes depending on the environment. Both a TensorFlow (LSTM), and PyTorch version are available. .. note:: - In most cases, `IMPALA <#importance-weighted-actor-learner-architecture-impala>`__ will outperform A2C / A3C. In our `benchmarks `__, IMPALA is almost 10x faster than A2C in wallclock time, with similar sample efficiency. + In most cases, `IMPALA <#importance-weighted-actor-learner-architecture-impala>`__ will outperform A2C / A3C. In `benchmarks `__, IMPALA is almost 10x faster than A2C in wallclock time, with similar sample efficiency. -Tuned examples: `PongDeterministic-v4 `__, `PyTorch version `__, `{BeamRider,Breakout,Qbert,SpaceInvaders}NoFrameskip-v4 `__ - -See also our `Atari results `__. +Tuned examples: `PongDeterministic-v4 `__, `PyTorch version `__, `{BeamRider,Breakout,Qbert,SpaceInvaders}NoFrameskip-v4 `__, `Atari results `__. Deep Deterministic Policy Gradients (DDPG) ------------------------------------------ @@ -32,12 +50,41 @@ DDPG is implemented similarly to DQN (below). The algorithm can be scaled by inc Tuned examples: `Pendulum-v0 `__, `MountainCarContinuous-v0 `__, `HalfCheetah-v2 `__ -Deep Q Networks (DQN) ---------------------- +Deep Q Networks (DQN, Rainbow) +------------------------------ `[paper] `__ `[implementation] `__ -RLlib DQN is implemented using the SyncReplayOptimizer. The algorithm can be scaled by increasing the number of workers, using the AsyncGradientsOptimizer for async DQN, or using Ape-X. Memory usage is reduced by compressing samples in the replay buffer with LZ4. +RLlib DQN is implemented using the SyncReplayOptimizer. The algorithm can be scaled by increasing the number of workers, using the AsyncGradientsOptimizer for async DQN, or using Ape-X. Memory usage is reduced by compressing samples in the replay buffer with LZ4. All of the DQN improvements evaluated in `Rainbow `__ are available, though not all are enabled by default. For more details, see these `DQN ablation experiments `__. -Tuned examples: `PongDeterministic-v4 `__ +Tuned examples: `PongDeterministic-v4 `__, `Rainbow configuration `__ + +Policy Gradients +---------------- +`[paper] `__ `[implementation] `__ We include a vanilla policy gradients implementation as an example algorithm. This is usually outperformed by PPO. + +Tuned examples: `CartPole-v0 `__ + +Proximal Policy Optimization (PPO) +---------------------------------- +`[paper] `__ `[implementation] `__ +PPO's clipped objective supports multiple SGD passes over the same batch of experiences. RLlib's multi-GPU optimizer pins that data in GPU memory to avoid unnecessary transfers from host memory, substantially improving performance over a naive implementation. RLlib's PPO scales out using multiple workers for experience collection, and also with multiple GPUs for SGD. + +Tuned examples: `Humanoid-v1 `__, `Hopper-v1 `__, `Pendulum-v0 `__, `PongDeterministic-v4 `__, `Walker2d-v1 `__, `{BeamRider,Breakout,Qbert,SpaceInvaders}NoFrameskip-v4 `__, `Atari results `__. + +.. figure:: ppo.png + :width: 500px + :align: center + + RLlib's multi-GPU PPO scales to multiple GPUs and hundreds of CPUs. Here we compare against a reference MPI-based implementation. + +Derivative-free +~~~~~~~~~~~~~~~ + +Augmented Random Search (ARS) +----------------------------- +`[paper] `__ `[implementation] `__ +ARS is a random search method for training linear policies for continuous control problems. Code here is adapted from https://github.com/modestyachts/ARS to integrate with RLlib APIs. + +Tuned examples: `CartPole-v0 `__, `Swimmer-v2 `__ Evolution Strategies -------------------- @@ -51,40 +98,3 @@ Tuned examples: `Humanoid-v1 `__ -`[implementation] `__ -In IMPALA, a central learner runs SGD in a tight loop while asynchronously pulling sample batches from many actor processes. RLlib's IMPALA implementation uses DeepMind's reference `V-trace code `__. Note that we do not provide a deep residual network out of the box, but one can be plugged in as a `custom model `__. - -Tuned examples: `PongNoFrameskip-v4 `__, `vectorized configuration `__, `{BeamRider,Breakout,Qbert,SpaceInvaders}NoFrameskip-v4 `__ - -See also our `Atari results `__. - -.. figure:: impala.png - :align: center - - IMPALA solves Atari about 10x faster than A2C / A3C, with similar sample efficiency. Here IMPALA scales from 16 to 128 workers on PongNoFrameskip-v4. - -Policy Gradients ----------------- -`[paper] `__ `[implementation] `__ We include a vanilla policy gradients implementation as an example algorithm. This is usually outperformed by PPO. - -Tuned examples: `CartPole-v0 `__ - -Proximal Policy Optimization (PPO) ----------------------------------- -`[paper] `__ `[implementation] `__ -PPO's clipped objective supports multiple SGD passes over the same batch of experiences. RLlib's multi-GPU optimizer pins that data in GPU memory to avoid unnecessary transfers from host memory, substantially improving performance over a naive implementation. RLlib's PPO scales out using multiple workers for experience collection, and also with multiple GPUs for SGD. - -Tuned examples: `Humanoid-v1 `__, `Hopper-v1 `__, `Pendulum-v0 `__, `PongDeterministic-v4 `__, `Walker2d-v1 `__, `{BeamRider,Breakout,Qbert,SpaceInvaders}NoFrameskip-v4 `__ - -See also our `Atari results `__. - -.. figure:: ppo.png - :width: 500px - :align: center - - RLlib's multi-GPU PPO scales to multiple GPUs and hundreds of CPUs. Here we compare against a reference MPI-based implementation. diff --git a/doc/source/rllib-training.rst b/doc/source/rllib-training.rst index 3cf3cb30b..104909abf 100644 --- a/doc/source/rllib-training.rst +++ b/doc/source/rllib-training.rst @@ -99,6 +99,8 @@ Here is an example of the basic usage: ray.init() config = ppo.DEFAULT_CONFIG.copy() + config["num_gpus"] = 0 + config["num_workers"] = 1 agent = ppo.PPOAgent(config=config, env="CartPole-v0") # Can optionally call agent.restore(path) to load a checkpoint. @@ -131,6 +133,7 @@ All RLlib agents are compatible with the `Tune API `__. This en "env": "CartPole-v0", "stop": {"episode_reward_mean": 200}, "config": { + "num_gpus": 0, "num_workers": 1, "sgd_stepsize": tune.grid_search([0.01, 0.001, 0.0001]), }, diff --git a/doc/source/rllib.rst b/doc/source/rllib.rst index ba0b2dd38..ea5bbbf58 100644 --- a/doc/source/rllib.rst +++ b/doc/source/rllib.rst @@ -36,20 +36,36 @@ Environments * `OpenAI Gym `__ * `Vectorized `__ * `Multi-Agent `__ -* `Serving (Agent driven) `__ +* `Agent-Driven `__ * `Offline Data Ingest `__ * `Batch Asynchronous `__ Algorithms ---------- -* `Ape-X Distributed Prioritized Experience Replay `__ -* `Advantage Actor-Critic (A2C, A3C) `__ -* `Deep Deterministic Policy Gradients (DDPG) `__ -* `Deep Q Networks (DQN) `__ -* `Evolution Strategies `__ -* `Importance Weighted Actor-Learner Architecture (IMPALA) `__ -* `Policy Gradients `__ -* `Proximal Policy Optimization (PPO) `__ + +* High-throughput architectures + + - `Distributed Prioritized Experience Replay (Ape-X) `__ + + - `Importance Weighted Actor-Learner Architecture (IMPALA) `__ + +* Gradient-based + + - `Advantage Actor-Critic (A2C, A3C) `__ + + - `Deep Deterministic Policy Gradients (DDPG) `__ + + - `Deep Q Networks (DQN, Rainbow) `__ + + - `Policy Gradients `__ + + - `Proximal Policy Optimization (PPO) `__ + +* Derivative-free + + - `Augmented Random Search (ARS) `__ + + - `Evolution Strategies `__ Models and Preprocessors ------------------------ diff --git a/python/ray/tune/ray_trial_executor.py b/python/ray/tune/ray_trial_executor.py index b364cd2f4..d53d928c5 100644 --- a/python/ray/tune/ray_trial_executor.py +++ b/python/ray/tune/ray_trial_executor.py @@ -163,7 +163,7 @@ class RayTrialExecutor(TrialExecutor): result = None try: result = ray.get(result_id) - except Exception as e: + except Exception: print("fetch_one_result failed:", traceback.format_exc()) return trial, result