.. include:: /_includes/rllib/we_are_hiring.rst .. include:: /_includes/rllib/new_api_stack.rst Examples ======== This page is an index of examples for the various use cases and features of RLlib. If any example is broken, or if you'd like to add an example to this page, feel free to raise an issue on our Github repository. Tuned Examples -------------- - `Tuned examples `__: Collection of tuned hyperparameters sorted by algorithm. Environments and Adapters ------------------------- - `Registering a custom env and model `__: Example of defining and registering a gym env and model for use with RLlib. - `Local Unity3D multi-agent environment example `__: Example of how to setup an RLlib Algorithm against a locally running Unity3D editor instance to learn any Unity3D game (including support for multi-agent). Use this example to try things out and watch the game and the learning progress live in the editor. Providing a compiled game, this example could also run in distributed fashion with `num_workers > 0`. For a more heavy-weight, distributed, cloud-based example, see ``Unity3D client/server`` below. Custom- and Complex Models -------------------------- - `Custom Keras model `__: Example of using a custom Keras model. - `Registering a custom model with supervised loss `__: Example of defining and registering a custom model with a supervised loss. - `Batch normalization `__: Example of adding batch norm layers to a custom model. - `Custom model API example `__: Shows how to define a custom Model API in RLlib, such that it can be used inside certain algorithms. - `Trajectory View API utilizing model `__: An example on how a model can use the trajectory view API to specify its own input. - `MobileNetV2 wrapping example model `__: Implementations of `tf.keras.applications.mobilenet_v2.MobileNetV2` and `torch.hub (mobilenet_v2)`-wrapping example models. - `Differentiable Neural Computer `__: Example of DeepMind's Differentiable Neural Computer for partially-observable environments. Training Workflows ------------------ - `Custom training workflows `__: Example of how to use Tune's support for custom training functions to implement custom training workflows. - `Curriculum learning with the TaskSettableEnv API `__: Example of how to advance the environment through different phases (tasks) over time. Also see the `curriculum learning how-to `__ from the documentation here. - `Custom logger `__: How to setup a custom Logger object in RLlib. - `Custom metrics `__: Example of how to output custom training metrics to TensorBoard. - `Custom Algorith.training_step() method combining on- and off-policy learning `__: Example of how to use the exec. plan of an Algorithm to trin two different policies in parallel (also using multi-agent API). - `Custom tune experiment `__: How to run a custom Ray Tune experiment with RLlib with custom training- and evaluation phases. Evaluation: ----------- - `Custom evaluation function `__: Example of how to write a custom evaluation function that is called instead of the default behavior, which is running with the evaluation worker set through n episodes. - `Parallel evaluation and training `__: Example showing how the evaluation workers and the "normal" rollout workers can run (to some extend) in parallel to speed up training. Serving and Offline ------------------- - `Offline RL with CQL `__: Example showing how to run an offline RL training job using a historic-data json file. - `Another example for using RLlib with Ray Serve `__ This script offers a simple workflow for 1) training a policy with RLlib first, 2) creating a new policy 3) restoring its weights from the trained one and serving the new policy via Ray Serve. - `Unity3D client/server `__: Example of how to setup n distributed Unity3D (compiled) games in the cloud that function as data collecting clients against a central RLlib Policy server learning how to play the game. The n distributed clients could themselves be servers for external/human players and allow for control being fully in the hands of the Unity entities instead of RLlib. Note: Uses Unity's MLAgents SDK (>=1.0) and supports all provided MLAgents example games and multi-agent setups. - `CartPole client/server `__: Example of online serving of predictions for a simple CartPole policy. - `Saving experiences `__: Example of how to externally generate experience batches in RLlib-compatible format. - `Finding a checkpoint using custom criteria `__: Example of how to find a :ref:`checkpoint ` after a `Tuner.fit()` via some custom defined criteria. Multi-Agent and Hierarchical ---------------------------- - `Simple independent multi-agent setup vs a PettingZoo env `__: Setup RLlib to run any algorithm in (independent) multi-agent mode against a multi-agent environment. - `More complex (shared-parameter) multi-agent setup vs a PettingZoo env `__: Setup RLlib to run any algorithm in (shared-parameter) multi-agent mode against a multi-agent environment. - `Rock-paper-scissors heuristic vs learned `__ and `Rock-paper-scissors learned vs learned `__: Two examples of different heuristic and learned policies competing against each other in the rock-paper-scissors environment. - `Two-step game `__: Example on how to use agent grouping in a multi-agent environment (the two-step game from the `QMIX paper `__). - `PettingZoo multi-agent example `__: Example on how to use RLlib to learn in `PettingZoo `__ multi-agent environments. - `PPO with centralized critic on two-step game `__: Example of customizing PPO to leverage a centralized value function. - `Centralized critic in the env `__: A simpler method of implementing a centralized critic by augmentating agent observations with global information. - `Hand-coded policy `__: Example of running a custom hand-coded policy alongside trainable policies. - `Weight sharing between policies `__: Example of how to define weight-sharing layers between two different policies. - `Multiple algorithms `__: Example of alternating training between DQN and PPO. - `Hierarchical training `__: Example of hierarchical training using the multi-agent API. Special Action- and Observation Spaces -------------------------------------- - `Nested action spaces `__: Learning in arbitrarily nested action spaces. - `Parametric actions `__: Example of how to handle variable-length or parametric action spaces. - `Using the "Repeated" space of RLlib for variable lengths observations `__: How to use RLlib's `Repeated` space to handle variable length observations. - `Autoregressive action distribution example `__: Learning with auto-regressive action dependencies (e.g. 2 action components; distribution for 2nd component depends on the 1st component's actually sampled value). Community Examples ------------------ - `Arena AI `__: A General Evaluation Platform and Building Toolkit for Single/Multi-Agent Intelligence with RLlib-generated baselines. - `CARLA `__: Example of training autonomous vehicles with RLlib and `CARLA `__ simulator. - `The Emergence of Adversarial Communication in Multi-Agent Reinforcement Learning `__: Using Graph Neural Networks and RLlib to train multiple cooperative and adversarial agents to solve the "cover the area"-problem, thereby learning how to best communicate (or - in the adversarial case - how to disturb communication) (`code `__). - `Flatland `__: A dense traffic simulating environment with RLlib-generated baselines. - `GFootball `__: Example of setting up a multi-agent version of `GFootball `__ with RLlib. - `mobile-env `__: An open, minimalist Gymnasium environment for autonomous coordination in wireless mobile networks. Includes an example notebook using Ray RLlib for multi-agent RL with mobile-env. - `Neural MMO `__: A multiagent AI research environment inspired by Massively Multiplayer Online (MMO) role playing games – self-contained worlds featuring thousands of agents per persistent macrocosm, diverse skilling systems, local and global economies, complex emergent social structures, and ad-hoc high-stakes single and team based conflict. - `NeuroCuts `__: Example of building packet classification trees using RLlib / multi-agent in a bandit-like setting. - `NeuroVectorizer `__: Example of learning optimal LLVM vectorization compiler pragmas for loops in C and C++ codes using RLlib. - `Roboschool / SageMaker `__: Example of training robotic control policies in SageMaker with RLlib. - `Sequential Social Dilemma Games `__: Example of using the multi-agent API to model several `social dilemma games `__. - `Simple custom environment for single RL with Ray and RLlib `__: Create a custom environment and train a single agent RL using Ray 2.0 with Tune. - `StarCraft2 `__: Example of training in StarCraft2 maps with RLlib / multi-agent. - `Traffic Flow `__: Example of optimizing mixed-autonomy traffic simulations with RLlib / multi-agent. Blog Posts ---------- - `Attention Nets and More with RLlib’s Trajectory View API `__: Blog describing RLlib's new "trajectory view API" and how it enables implementations of GTrXL (attention net) architectures. - `Reinforcement Learning with RLlib in the Unity Game Engine `__: How-To guide about connecting RLlib with the Unity3D game engine for running visual- and physics-based RL experiments. - `Lessons from Implementing 12 Deep RL Algorithms in TF and PyTorch `__: Discussion on how the Ray Team ported 12 of RLlib's algorithms from TensorFlow to PyTorch and the lessons learned. - `Scaling Multi-Agent Reinforcement Learning `__: Blog post of a brief tutorial on multi-agent RL and its design in RLlib. - `Functional RL with Keras and TensorFlow Eager `__: Exploration of a functional paradigm for implementing reinforcement learning (RL) algorithms.