LeRobot: Train Real-World Robots with Hugging Face's PyTorch Library

6月24日 Published inAI Tools

LeRobot removes the typical barriers to entry in robotics research. As a PyTorch-based library, it provides streamlined access to shared datasets, pre-trained models, and practical development tools. The objective is straightforward: to enable anyone to experiment with robot learning, even without physical hardware on hand.

The framework emphasizes methods that translate effectively to physical robots, specifically prioritizing imitation learning and reinforcement learning. Users can access pre-trained policies, human-recorded demonstration datasets, and various simulation environments—all hosted directly on the Hugging Face Hub.

Examples of pre-trained models available in simulation include:

  • The ACT policy within the ALOHA environment
  • The TDMPC policy in SimXArm
  • The Diffusion policy in PushT

Installing LeRobot

First, clone the repository:

git clone https://github.com/huggingface/lerobot.git
cd lerobot

Create and activate a virtual environment; Python 3.10 is the recommended version:

conda create -y -n lerobot python=3.10
conda activate lerobot

If you are using miniconda, you will need to install ffmpeg:

conda install ffmpeg -c conda-forge

Install LeRobot in editable mode:

pip install -e .

If you intend to run ALOHA or PushT simulations, add the necessary simulation support:

pip install -e ".[aloha, pusht]"

Visualizing Datasets

You can inspect datasets directly from the Hugging Face Hub:

python lerobot/scripts/visualize_dataset.py \
    --repo-id lerobot/pusht \
    --episode-index 0

Alternatively, you can point the script to a local directory:

python lerobot/scripts/visualize_dataset.py \
    --repo-id lerobot/pusht \
    --root ./my_local_data_dir \
    --local-files-only 1 \
    --episode-index 0

The script utilizes rerun.io to display camera feeds, robot states, and recorded actions simultaneously.

Evaluating a Pre-trained Policy

To test a model hosted on the Hub, use the following command:

python lerobot/scripts/eval.py \
    --policy.path=lerobot/diffusion_pusht \
    --env.type=pusht \
    --eval.batch_size=10 \
    --eval.n_episodes=10 \
    --policy.use_amp=false \
    --policy.device=cuda

To evaluate a specific checkpoint after a training run, point the --policy.path argument to your local output directory:

python lerobot/scripts/eval.py --policy.path={OUTPUT_DIR}/checkpoints/last/pretrained_model

Training Your Own Policy

The repository provides examples for both core library integration and standalone command-line execution. Weights & Biases (WandB) integration is available to log training and evaluation metrics. Ensure you run wandb login first, then append --wandb.enable=true to your training command.

To replicate published results, load the corresponding configuration file:

python lerobot/scripts/train.py --config_path=lerobot/diffusion_pusht

LeRobot makes robot learning accessible to a broader audience. By providing shared models, clear evaluation scripts, and an expanding collection of demonstration data, it simplifies the transition from concept to experiment—whether you are working with a physical robot or a GPU.