RL Baselines3 Zoo

repository·master·Indexed 25 days ago

https://github.com/dlr-rm/rl-baselines3-zoo

A training framework for Reinforcement Learning (RL) built on top of Stable Baselines3. It provides a unified interface for training, evaluating, tuning hyperparameters, and plotting results for various RL algorithms and environments. Features include support for custom environments, integration with Weights and Biases (W&B) and Huggingface Hub, and tools for recording agent performance videos.

Tokens
6.3K
Snippets
31
Records
51
Agent score
83%

What's inside rl-baselines3-zoo

  1. Overview of RL Baselines3 Zoo

    master

    RL Baselines3 Zoo is a training framework for Reinforcement Learning (RL) built on top of Stable Baselines3 (SB3). It provides a suite of scripts to automate the reinforcement learning workflow, including:

    • Training: Scripts to train RL agents.
    • Evaluation: Tools to evaluate trained agents.
    • Hyperparameter Tuning: Automated tuning of agent parameters.
    • Visualization: Scripts for plotting results and recording videos.
    • Pre-trained Agents: A collection of tuned hyperparameters and trained agents for common environments and algorithms.
  2. Enjoy a trained agent

    master

    You can run a trained agent in an environment using the enjoy.py script.

    If you are using the pre-trained agents provided in the repository, ensure you have cloned the repo recursively to include submodules: git clone --recursive https://github.com/DLR-RM/rl-baselines3-zoo.

    To enjoy an agent from the pre-trained collection, specify the algorithm, environment, folder, and number of timesteps.

    If you are enjoying an agent you trained yourself, you must specify the log folder (-f) and the experiment ID (--exp-id). Note that --exp-id 0 corresponds to the last experiment.

  3. Perform distributed hyperparameter optimization

    master

    You can perform distributed optimization by using a shared database for Optuna. Specify the --study-name and the --storage path (e.g., a file or database URL) to allow multiple processes to contribute to the same study.

    python train.py --algo ppo --env MountainCar-v0 -optimize --study-name test --storage logs/demo.log
  4. Track experiments with Weights and Biases (W&B)

    master

    RL Baselines3 Zoo supports experiment tracking (learning curves, hyperparameters, etc.) via Weights and Biases (W&B).

    To enable tracking during training, use the --track flag. You can specify the project name with --wandb-project-name and add custom tags to the run using --wandb-tags.

  5. Automated hyperparameter optimization with Optuna

    master

    The RL Baselines3 Zoo uses Optuna to optimize hyperparameters. To trigger hyperparameter tuning, use the --optimize flag with the train.py script.

    Key behaviors:

    • Hyperparameters to be tuned are defined in rl_zoo3/hyperparams_opt.py.
    • Hyperparameters not listed in rl_zoo3/hyperparams_opt.py are pulled from the agent's YAML configuration file, falling back to Stable Baselines3 defaults if not present.
    • The default budget is 500 trials.
    • By default, there is one intermediate evaluation for pruning/early stopping every 100k time steps.
    • Important: If using the SuccessiveHalvingPruner (specified via --pruner halving), you must set --n-jobs to a value greater than 1.
    # Example: Budget of 1000 trials with a maximum of 50000 steps
    python train.py --algo ppo --env MountainCar-v0 -n 50000 -optimize --n-trials 1000 --n-jobs 2 \
      --sampler tpe --pruner median
  6. Train an RL Agent

    master

    Training is configured via hyperparameter files located in hyperparameters/algo_name.yml. To train an agent, ensure the environment is defined in the corresponding algorithm's YAML file.

    Basic training command:

    python train.py --algo algo_name --env env_id

    To include evaluation during training (e.g., evaluating every 10,000 steps using 10 episodes on a single evaluation environment):

    python train.py --algo sac --env HalfCheetahBulletEnv-v0 --eval-freq 10000 --eval-episodes 10 --n-eval-envs 1
    python train.py --algo sac --env HalfCheetahBulletEnv-v0 --eval-freq 10000 --eval-episodes 10 --n-eval-envs 1