LeRobot
LeRobot is a state-of-the-art open-source Python library for real-world robotics using PyTorch, developed by Hugging Face. It provides tools for creating robot environments, loading pre-trained policies, and managing robotics datasets. It is currently at version 0.5.1 and is under active development, with new releases often including significant updates and breaking changes.
Common errors
-
TypeError: DatasetFactory missing 1 required positional argument: 'root_dir'
cause Attempting to instantiate `DatasetFactory` without providing the required `root_dir` argument, which became mandatory in v0.5.0.fixPass a `root_dir` argument: `DatasetFactory('hf_dataset_id', root_dir='./local_data')`. -
ValueError: The 'hf_hub_id' argument has been removed, please use 'repo_id' instead.
cause Using the old argument name `hf_hub_id` instead of `repo_id` for Hugging Face Hub identifiers.fixRename the argument: `load_policy(repo_id='your/model')`. -
AttributeError: 'Policy' object has no attribute 'sample'
cause Using the deprecated `policy.sample()` method instead of the updated `policy.sample_actions(obs)`.fixChange the method call to `action = policy.sample_actions(obs)` and ensure `obs` is the current observation. -
ModuleNotFoundError: No module named 'lerobot'
cause The `lerobot` library is not installed in the current Python environment, or the environment is not activated.fixInstall the library using `pip install lerobot` or activate the correct virtual environment.
Warnings
- breaking The `DatasetFactory` now requires the `root_dir` argument to be explicitly provided during instantiation. It was previously optional.
- breaking The `hf_hub_id` argument in functions like `load_policy` has been renamed to `repo_id` for consistency with Hugging Face Hub terminology.
- breaking The signature and name of the policy sampling method have changed. `policy.sample()` is now `policy.sample_actions(obs)` and requires the current observation as input.
- gotcha LeRobot requires Python 3.12+ and PyTorch >= 2.1. Incompatibilities can lead to installation issues or runtime errors.
Install
-
pip install lerobot -
pip install 'lerobot[all]'
Imports
- load_policy
from lerobot.common.policies.load import load_policy
from lerobot.common.policies.hf_hub.load import load_policy
- RobotEnvFactory
from lerobot.common.robot_env_factory import RobotEnvFactory
- PolicyFactory
from lerobot.common.policies.factory import PolicyFactory
- DatasetFactory
from lerobot.common.datasets.factory import DatasetFactory
Quickstart
from lerobot.common.policies.hf_hub.load import load_policy
from lerobot.common.robot_env_factory import RobotEnvFactory
import torch
# Load a pre-trained policy from the Hugging Face Hub
# This example uses a public model, so no explicit token is needed unless fine-tuning.
policy = load_policy("lerobot/diffusion_policy_v2_pen_push_multi_view_taco_play_sok_fixed_camera_v0")
# Create a dummy robot environment for demonstration
# Real environments require specific configurations like 'robomimic', 'taco_play', etc.
# e.g., env = RobotEnvFactory("taco_play", record_dir="./recordings")()
env = RobotEnvFactory("dummy")()
# Reset the environment to get initial observation
obs = env.reset()
# Sample actions from the policy
with torch.no_grad():
action = policy.sample_actions(obs)
print(f"Initial observation keys: {obs.keys()}")
print(f"Sampled action shape: {action.shape}")
env.close()