imitation: Clean Imitation Learning Implementations

Adam Gleave, Mohammad Taufeeque, Juan Rocamonde, Erik Jenner, Steven H. Wang, Sam Toyer, Maximilian Ernestus, Nora Belrose, Scott Emmons, Stuart RussellarXiv 2022

Abstract

imitation provides open-source implementations of imitation and reward learning algorithms in PyTorch. We include three inverse reinforcement learning (IRL) algorithms, three imitation learning algorithms and a preference comparison algorithm. The implementations have been benchmarked against previous results, and automated tests cover 98% of the code. Moreover, the algorithms are implemented in a modular fashion, making it simple to develop novel algorithms in the framework. Our source code, including documentation and examples, is available at https://github.com/HumanCompatibleAI/imitation.

Introduction

Reinforcement Learning (RL) is a powerful paradigm for training agents, but its success often hinges on the availability of well-defined reward functions. In complex, real-world tasks, hand-crafting these functions is notoriously difficult. Imitation Learning (IL) and Inverse Reinforcement Learning (IRL) offer a solution by allowing agents to learn directly from human demonstrations or preferences.

Despite the promise of these fields, research has been hindered by a "reproducibility crisis." Reference implementations frequently suffer from software decay, being tied to deprecated frameworks like TensorFlow 1 or Theano. Furthermore, performance is often sensitive to undocumented implementation "tricks." Without standardized, high-quality baselines, researchers may inadvertently compare new methods against weak or buggy implementations. The imitation library aims to provide a robust, modular, and reliable foundation for the community.

Methods and Modularity

The imitation library is built using modern backends, specifically PyTorch and Stable Baselines3 (SB3). A core design principle is modularity. Unlike many previous implementations where an imitation algorithm is tightly coupled to a specific RL solver, imitation allows users to independently swap out reward networks, policy architectures, and RL optimizers (such as PPO or SAC).

The library currently implements seven key algorithms:

  • Inverse Reinforcement Learning (IRL): Maximum Causal Entropy (MCE) IRL, a density estimation baseline, and Adversarial IRL (AIRL).
  • Imitation Learning (IL): Behavioral Cloning (BC), DAgger (Dataset Aggregation), and Generative Adversarial Imitation Learning (GAIL).
  • Preference Learning: Deep RL from Human Preferences (DRLHP), which learns reward functions from binary comparisons of trajectory fragments.

Software Quality and Benchmarking

A distinguishing feature of imitation is its commitment to production-grade software engineering standards. The library maintains 98% test coverage and utilizes static type checking (via mypy and pytype). This ensures that the implementations remain "clean" and reliable as the project evolves.

Comparison of imitation learning libraries across software quality and maintenance metrics.

As shown in the comparison above, imitation stands out against other popular libraries like OpenAI Baselines or Intel COACH by offering superior documentation, active maintenance, and support for custom RL components.

Evaluation Framework

To ensure fair comparisons, the authors evaluate the library using standard MuJoCo continuous control tasks (Ant, HalfCheetah, Hopper, Swimmer, and Walker2d). Crucially, they utilize the seals (Suite of Environments for Algorithms that Learn Specifications) package. These environments are modified versions of standard Gym tasks designed to be "fixed-horizon." This prevents algorithms from "cheating" by terminating episodes early to avoid negative rewards—a common pitfall in prior IL research.

Performance Results

The implementations were benchmarked against expert policies (normalized to 1.0) and random policies (normalized to 0.0).

Normalized performance of implemented algorithms across MuJoCo environments (1.0 = expert, 0.0 = random).

GAIL and Behavioral Cloning (BC) consistently reached or exceeded expert performance across most environments. For instance, GAIL achieved a normalized return of ~0.98 on Walker and ~1.01 on Hopper.

However, the benchmarking also revealed important limitations. AIRL performed poorly on the "Ant" environment (0.089) and "Walker" (0.276). Investigation revealed that the original AIRL paper likely used a custom version of the Ant environment, highlighting the danger of non-standardized benchmarks. Similarly, DAgger struggled on the Hopper environment (0.187). These results suggest that some algorithms may be less general-purpose than previously reported in the literature.

Conclusion

The imitation library provides a high-quality, modular suite of algorithms that addresses the reproducibility crisis in imitation learning. By offering consistent interfaces and rigorous testing, it provides a reliable platform for researchers to develop and benchmark new reward learning methods. The project remains open for community contributions as the field continues to evolve.

Summary updated

BibTeX
@misc{gleave2022imitation,
  author = {Adam Gleave and Mohammad Taufeeque and Juan Rocamonde and Erik Jenner and Steven H. Wang and Sam Toyer and Maximilian Ernestus and Nora Belrose and Scott Emmons and Stuart Russell},
  title = {{imitation: Clean Imitation Learning Implementations}},
  year = {2022},
  eprint = {2211.11972},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2211.11972},
}
Figure