# adityakamath/lerobot architecture

> Architecture diagram of the GitHub repository adityakamath/lerobot, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/adityakamath/lerobot
- Repository: https://github.com/adityakamath/lerobot

## Overview

##### Main components
- Core Library (“lerobot” package): This is the heart of the project and includes several major subcomponents:
- Configurations (lerobot/configs): Manages experiment, training, evaluation, and policy settings.
- Common Utilities (lerobot/common): Contains modules for datasets, environments, various policy architectures (e.g., ACT, diffusion, tdmpc, pi0, vqbet), robot device support (motors, cameras, robots), optimizers, and utility functions.
- Scripts (lerobot/scripts): CLI entry points for training (train.py), evaluation (eval.py), visualization (visualize_dataset.py), control of both simulated and real robots, and dataset upload (push_dataset_to_hub.py).

- Datasets and Data Management:
- LeRobotDataset: Handling datasets stored locally or on the Hugging Face hub.
- Submodules for different dataset formats in lerobot/common/datasets and versioned folders (v2, v21).
- Benchmarks folder: Contains scripts and examples (like video benchmarks) to validate system performance.

- Policy Modules:
- Multiple policy approaches (e.g., ACT, diffusion, TDMPC, VQ-BeT) are housed inside lerobot/common/policies.
- Each has its own configuration and modeling scripts, plus conversion/utilities for compatibility.

- Environment and Simulation:
- Gymnasium environments are provided (aloha, pusht, xarm) which serve as simulation environments to run policies either in simulation or on real hardware.

- Robot Devices:
- Dedicated modules for cameras, motors, and robots (lerobot/common/robot_devices) which abstract real-world hardware interfacing.

- External Integrations and Deployment:
- Docker support (docker/) for CPU and GPU development images.
- Integration with external tools such as Weights and Biases (WandB) for experiment tracking.
- Support for visualization (using rerun.io as shown in the examples) and Hugging Face hub integration (for datasets and pretrained models).

##### Relationships and Data Flow
- The command-line scripts (train.py, eval.py, control_robot.py, etc.) serve as entry points that configure the environment using the configuration files and then invoke functions from the core “lerobot” modules.
- Datasets are loaded either from a local source or remotely via the Hugging Face hub, processed through a unified dataset interface (LeRobotDataset), and then passed to policy models during training/evaluation.
- Policy modules obtain data from the dataset, process it, and send output to simulated or real environments.
- Environment components (both simulation and real-world interfacing) communicate with policy modules and the underlying robot device layer.
- Logging, visualization, and experiment tracking (via WandB and rerun.io integration) are integrated throughout the training and evaluation pipelines.
- Docker components encapsulate the entire environment (with separate recipes for CPU, GPU, and development) to ensure consistency of deployments.

##### Architectural Patterns and Design Principles
- Modular design: Each major functionality (datasets, policies, environments, devices) is separated into its own component, promoting adaptability and easier maintenance.
- Plugin / factory patterns: For policies and dataset creation, the use of “factory” modules in both policies and datasets hints at an extensible design for adding new methods without changing the core.
- CLI-driven orchestration: The scripts provide a clear interface for training, evaluation, and visualization—ensuring a repeatable and reproducible workflow.
- Clear separation between simulation and real-world interfacing: Code is organized to support both simulated environments (Gymnasium based) and real device controllers, keeping concerns isolated.

##### Relevant Technologies and Frameworks
- Python 3.10 environment with PyTorch at its core for model training and inference.
- Gymnasium for simulation environments.
- Docker for containerized deployment.
- Weights and Biases for experiment tracking.
- Hugging Face Hub integration for datasets and pretrained models.
- Safetensors format for model parameter serialization.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Scripts["CLI Scripts"]:::script
    Core["Core Library"]:::core
    Config["Configurations"]:::component
    Common["Common Utilities"]:::component
    Datasets["Datasets & Data Management"]:::component
    Policies["Policy Modules"]:::component
    Envs["Environments/Simulators"]:::component
    Devices["Robot Devices"]:::component
    Ext["External Services & Deployment"]:::external
    Bench["Benchmarks"]:::external

    Scripts -->|"invokes"| Core
    Core -->|"loads"| Config
    Core -->|"manages"| Common
    Common -->|"handles"| Datasets
    Common -->|"contains"| Policies
    Common -->|"interfaces with"| Envs
    Common -->|"connects to"| Devices
    Datasets -->|"supplies data to"| Policies
    Policies -->|"sends actions to"| Envs
    Policies -->|"controls"| Devices
    Core -->|"integrates with"| Ext
    Core -->|"validates via"| Bench

    click Scripts "https://github.com/adityakamath/lerobot/tree/main/lerobot/scripts/"
    click Core "https://github.com/adityakamath/lerobot/tree/main/lerobot/"
    click Config "https://github.com/adityakamath/lerobot/tree/main/lerobot/configs/"
    click Common "https://github.com/adityakamath/lerobot/tree/main/lerobot/common/"
    click Datasets "https://github.com/adityakamath/lerobot/tree/main/lerobot/common/datasets/"
    click Policies "https://github.com/adityakamath/lerobot/tree/main/lerobot/common/policies/"
    click Envs "https://github.com/adityakamath/lerobot/tree/main/lerobot/common/envs/"
    click Devices "https://github.com/adityakamath/lerobot/tree/main/lerobot/common/robot_devices/"
    click Ext "https://github.com/adityakamath/lerobot/tree/main/docker/"
    click Bench "https://github.com/adityakamath/lerobot/tree/main/benchmarks/"

    classDef script fill:#ff9999,stroke:#333,stroke-width:2px;
    classDef core fill:#ffcc00,stroke:#333,stroke-width:2px;
    classDef component fill:#cce5ff,stroke:#333,stroke-width:2px;
    classDef external fill:#c1e1c1,stroke:#333,stroke-width:2px;
```
