BenchMARL

repository·main·Indexed 20 days ago

https://github.com/facebookresearch/benchmarl

A Multi-Agent Reinforcement Learning (MARL) training and benchmarking library built on TorchRL. It provides a standardized framework for comparing MARL algorithms, environments, and models with a focus on reproducibility and statistical rigor. The library supports custom algorithm and model implementation, ensemble configurations via EnsembleAlgorithmConfig and EnsembleModelConfig, and integration with Hydra for configuration and Weights & Biases for hyperparameter sweeps.

Tokens
14.3K
Snippets
48
Records
77
Agent score
70%

What's inside BenchMARL

  1. What is BenchMARL?

    main

    BenchMARL is a Multi-Agent Reinforcement Learning (MARL) training library designed for reproducibility and benchmarking. It provides a standardized interface for integrating new algorithms and environments, ensuring fair comparisons.

    Key features include:

    • Backend: Uses TorchRL for high performance.
    • Configuration: Uses Hydra for modularity.
    • Evaluation: Compatible with marl-eval for statistically strong reporting.
    • Design: Focuses on independence between algorithms, environments, and models.
  2. Overview of BenchMARL

    main

    BenchMARL is a Multi-Agent Reinforcement Learning (MARL) training library designed for reproducibility and benchmarking. It provides a standardized interface to integrate new algorithms and environments, enabling fair comparisons between different MARL solutions.

    Key Technical Stack:

    • Backend: Uses TorchRL and PyTorch for high performance and state-of-the-art implementations.
    • Configuration: Uses Hydra for flexible and modular configuration.
    • Evaluation: Data reporting is compatible with marl-eval for standardized and statistically strong evaluations.

    Core Design Tenets:

    • Reproducibility via systematic configuration grounding.
    • Standardized and statistically-strong plotting and reporting.
    • Experiments that are independent of algorithm, environment, and model choices.
    • Easy implementation of new algorithms, environments, and models.
  3. Overview of benchmarl.models abstractions

    main

    The benchmarl.models module provides the core abstractions for defining neural network architectures used in BenchMARL. It is organized into two main categories:

    1. Common Abstractions: Base classes and configuration schemas used to define models, including Model, ModelConfig, SequenceModel, and SequenceModelConfig.
    2. Specific Model Implementations: A collection of concrete model classes (e.g., various architectures for multi-agent reinforcement learning) that implement the Model interface.
  4. Extend BenchMARL with custom algorithms, tasks, or models

    main

    BenchMARL is designed to be extensible. You can implement your own solutions by inheriting from the provided base classes and implementing their abstract methods. These base classes leverage TorchRL objects.

    • Algorithms: Implement via benchmarl/algorithms/common.py
    • Tasks: Implement via benchmarl/environments/common.py
    • Models: Implement via benchmarl/models/common.py
  5. How BenchMARL components work together

    main

    BenchMARL is a unified training library that interconnects components from TorchRL to enable fair and reproducible Multi-Agent Reinforcement Learning (MARL) benchmarking. The library uses a hierarchical structure of components:

    1. Experiment: The smallest unit of a training run. An Experiment fixes an Algorithm, a Task (environment), and a Model, along with a specific seed and hyperparameters.
    2. Benchmark: A collection of experiments. A benchmark allows you to compare different components (e.g., different algorithms or different tasks) by sharing the same experiment configuration across all its constituent experiments.

    To ensure reproducibility, BenchMARL provides default configurations for each component. While experiment hyperparameters can be modified, task configurations should generally remain unchanged.

  6. How BenchMARL configuration works

    main

    BenchMARL uses a dual approach for configuration: it can be managed directly within a Python script or via hydra.

    All components (Experiments, Algorithms, Tasks, and Models) have corresponding YAML configuration files located in the benchmarl/conf directory. These YAML files are loaded into Python dataclasses which serve as schemas. This provides both separation of configuration from code and strong typing for parameter name and type validation.

    If you need to load and validate a configuration YAML file manually in a script without using Hydra, you can use the .get_from_yaml() method available on the component's configuration dataclass.

  7. Core concepts of BenchMARL: Experiments, Benchmarks, Algorithms, Tasks, and Models

    main

    BenchMARL is a unified training library for Multi-Agent Reinforcement Learning (MARL) that uses TorchRL as a backend. It is built around several key abstractions:

    • Experiment: A single training run where an algorithm, a task, and a model are fixed. Experiments are configured with a seed and specific hyperparameters (found in benchmarl/conf/experiment/base_experiment.yaml).
    • Benchmark: A collection of experiments that vary in tasks, algorithms, or models, but share the same experiment configuration. This allows for standardized comparisons.
    • Algorithms: The training strategy, composed of components like loss functions and replay buffers. Supported algorithms include MAPPO, IPPO, MADDPG, IDDPG, MASAC, ISAC, QMIX, VDN, and IQL.
    • Tasks: Specific scenarios from a MARL environment (e.g., VMAS, SMACv2, MPE, SISL, MeltingPot, MAgent2). Tasks define the cooperation type, observability, reward functions, and action spaces.
    • Models: Neural networks used as actors (policies) or critics. Supported architectures include MLP, GRU, LSTM, GNN, CNN, and Deepsets. Models can be used in decentralized, centralized with local inputs, or centralized with global input configurations.

    Note on Agent Grouping: BenchMARL uses the TorchRL MARL API for grouping agents. In competitive environments, agents in different teams belong to different groups, each having its own loss, models, and buffers. Parameter sharing applies within these groups.

  8. Extend BenchMARL with custom algorithms, tasks, and models

    main

    BenchMARL is designed to be extensible, allowing you to benchmark new solutions by implementing standard interfaces. To introduce a custom solution, you must implement the abstract methods provided by the following base classes:

    • benchmarl.algorithms.Algorithm: For implementing new learning algorithms.
    • benchmarl.environments.Task: For defining new benchmark environments or tasks.
    • benchmarl.models.Model: For implementing custom neural network architectures.

    These base classes utilize objects from the TorchRL library. Detailed implementation examples for each can be found in the repository's examples directory.

    # Example links for implementation patterns:
    # Custom Algorithm: https://github.com/facebookresearch/BenchMARL/blob/main/examples/extending/algorithm
    # Custom Task: https://github.com/facebookresearch/BenchMARL/blob/main/examples/extending/task
    # Custom Model: https://github.com/facebookresearch/BenchMARL/blob/main/examples/extending/model
  9. Use Ensemble Algorithms and Models

    main

    BenchMARL allows assigning different algorithms or models to different agent groups using EnsembleAlgorithmConfig or EnsembleModelConfig.

    Ensemble Algorithms:

    • Takes a dictionary mapping group names to algorithm configs.
    • Constraint: You cannot mix on-policy and off-policy paradigms in a single ensemble.

    Ensemble Models:

    • Takes a dictionary mapping group names to model configs.
    • Constraint: If using sequence models, the ensemble must be the outer layer (you can have an ensemble of sequences, but not a sequence of ensembles).
    from benchmarl.algorithms import EnsembleAlgorithmConfig, IsacConfig, MaddpgConfig
    from benchmarl.models import EnsembleModelConfig, GnnConfig, MlpConfig
    
    # Ensemble Algorithm Example
    algorithm_config = EnsembleAlgorithmConfig(
        {"agent": MaddpgConfig.get_from_yaml(), "adversary": IsacConfig.get_from_yaml()}
    )
    
    # Ensemble Model Example
    model_config = EnsembleModelConfig(
        {"agent": MlpConfig.get_from_yaml(), "adversary": GnnConfig.get_from_yaml()}
    )
  10. Generate benchmark plots with plot_benchmark.py

    main

    You can generate various benchmark visualizations including aggregate scores, sample efficiency curves, performance profiles, and probability of improvement plots by running the plot_benchmark.py script. This script utilizes the marl-eval library to produce these plots.

    To use this, ensure you have marl-eval installed and then execute the plotting script against your benchmark data.

    python plot_benchmark.py