Views
No views yet



![]() | ![]() | ![]() |
| ACT policy on ALOHA env | TDMPC policy on SimXArm env | Diffusion policy on PushT env |
1git clone https://github.com/huggingface/lerobot.git
2cd lerobotminiconda:1conda create -y -n lerobot python=3.10
2conda activate lerobotpip install -e .NOTE: Depending on your platform, If you encounter any build errors during this step you may need to installcmakeandbuild-essentialfor building some of our dependencies. On linux:sudo apt-get install cmake build-essential
pip install -e ".[aloha, pusht]"wandb login.
├── examples # contains demonstration examples, start here to learn about LeRobot
| └── advanced # contains even more examples for those who have mastered the basics
├── lerobot
| ├── configs # contains config classes with all options that you can override in the command line
| ├── common # contains classes and utilities
| | ├── datasets # various datasets of human demonstrations: aloha, pusht, xarm
| | ├── envs # various sim environments: aloha, pusht, xarm
| | ├── policies # various policies: act, diffusion, tdmpc
| | ├── robot_devices # various real devices: dynamixel motors, opencv cameras, koch robots
| | └── utils # various utilities
| └── scripts # contains functions to execute via command line
| ├── eval.py # load policy and evaluate it on an environment
| ├── train.py # train a policy via imitation learning and/or reinforcement learning
| ├── control_robot.py # teleoperate a real robot, record data, run a policy
| ├── push_dataset_to_hub.py # convert your dataset into LeRobot dataset format and upload it to the Hugging Face hub
| └── visualize_dataset.py # load a dataset and render its demonstrations
├── outputs # contains results of scripts execution: logs, videos, model checkpoints
└── tests # contains pytest utilities for continuous integration1python lerobot/scripts/visualize_dataset.py \
2 --repo-id lerobot/pusht \
3 --episode-index 0root option and the --local-files-only (in the following case the dataset will be searched for in ./my_local_data_dir/lerobot/pusht)1python lerobot/scripts/visualize_dataset.py \
2 --repo-id lerobot/pusht \
3 --root ./my_local_data_dir \
4 --local-files-only 1 \
5 --episode-index 0rerun.io and display the camera streams, robot states and actions, like this:python lerobot/scripts/visualize_dataset.py --help for more instructions.LeRobotDataset formatLeRobotDataset format is very simple to use. It can be loaded from a repository on the Hugging Face hub or a local folder simply with e.g. dataset = LeRobotDataset("lerobot/aloha_static_coffee") and can be indexed into like any Hugging Face and PyTorch dataset. For instance dataset[0] will retrieve a single temporal frame from the dataset containing observation(s) and an action as PyTorch tensors ready to be fed to a model.LeRobotDataset is that, rather than retrieving a single frame by its index, we can retrieve several frames based on their temporal relationship with the indexed frame, by setting delta_timestamps to a list of relative times with respect to the indexed frame. For example, with delta_timestamps = {"observation.image": [-1, -0.5, -0.2, 0]} one can retrieve, for a given index, 4 frames: 3 "previous" frames 1 second, 0.5 seconds, and 0.2 seconds before the indexed frame, and the indexed frame itself (corresponding to the 0 entry). See example 1_load_lerobot_dataset.py for more details on delta_timestamps.LeRobotDataset format makes use of several ways to serialize data which can be useful to understand if you plan to work more closely with this format. We tried to make a flexible yet simple dataset format that would cover most type of features and specificities present in reinforcement learning and robotics, in simulation and in real-world, with a focus on cameras and robot states but easily extended to other types of sensory inputs as long as they can be represented by a tensor.LeRobotDataset instantiated with dataset = LeRobotDataset("lerobot/aloha_static_coffee"). The exact features will change from dataset to dataset but not the main aspects:dataset attributes:
├ hf_dataset: a Hugging Face dataset (backed by Arrow/parquet). Typical features example:
│ ├ observation.images.cam_high (VideoFrame):
│ │ VideoFrame = {'path': path to a mp4 video, 'timestamp' (float32): timestamp in the video}
│ ├ observation.state (list of float32): position of an arm joints (for instance)
│ ... (more observations)
│ ├ action (list of float32): goal position of an arm joints (for instance)
│ ├ episode_index (int64): index of the episode for this sample
│ ├ frame_index (int64): index of the frame for this sample in the episode ; starts at 0 for each episode
│ ├ timestamp (float32): timestamp in the episode
│ ├ next.done (bool): indicates the end of en episode ; True for the last frame in each episode
│ └ index (int64): general index in the whole dataset
├ episode_data_index: contains 2 tensors with the start and end indices of each episode
│ ├ from (1D int64 tensor): first frame index for each episode — shape (num episodes,) starts with 0
│ └ to: (1D int64 tensor): last frame index for each episode — shape (num episodes,)
├ stats: a dictionary of statistics (max, mean, min, std) for each feature in the dataset, for instance
│ ├ observation.images.cam_high: {'max': tensor with same number of dimensions (e.g. `(c, 1, 1)` for images, `(c,)` for states), etc.}
│ ...
├ info: a dictionary of metadata on the dataset
│ ├ codebase_version (str): this is to keep track of the codebase version the dataset was created with
│ ├ fps (float): frame per second the dataset is recorded/synchronized to
│ ├ video (bool): indicates if frames are encoded in mp4 video files to save space or stored as png files
│ └ encoding (dict): if video, this documents the main options that were used with ffmpeg to encode the videos
├ videos_dir (Path): where the mp4 videos or png images are stored/accessed
└ camera_keys (list of string): the keys to access camera features in the item returned by the dataset (e.g. `["observation.images.cam_high", ...]`)LeRobotDataset is serialised using several widespread file formats for each of its parts, namely:root argument if it's not in the default ~/.cache/huggingface/lerobot location.1python lerobot/scripts/eval.py \
2 --policy.path=lerobot/diffusion_pusht \
3 --env.type=pusht \
4 --eval.batch_size=10 \
5 --eval.n_episodes=10 \
6 --policy.use_amp=false \
7 --policy.device=cudapython lerobot/scripts/eval.py --policy.path={OUTPUT_DIR}/checkpoints/last/pretrained_modelpython lerobot/scripts/eval.py --help for more instructions.wandb login as a one-time setup step. Then, when running the training command above, enable WandB in the configuration by adding --wandb.enable=true.
--eval.n_episodes=500 to evaluate on more episodes than the default. Or, after training, you may want to re-evaluate your best checkpoints on more episodes or change the evaluation settings. See python lerobot/scripts/eval.py --help for more instructions.python lerobot/scripts/train.py --config_path=lerobot/diffusion_pusht${hf_user}/${repo_name} (e.g. lerobot/diffusion_pusht).outputs/train/2024-05-05/20-21-12_aloha_act_default/checkpoints/002500). Within that there is a pretrained_model directory which should contain:config.json: A serialized version of the policy configuration (following the policy's dataclass config).model.safetensors: A set of torch.nn.Module parameters, saved in Hugging Face Safetensors format.train_config.json: A consolidated configuration containing all parameter userd for training. The policy configuration should match config.json exactly. Thisis useful for anyone who wants to evaluate your policy or for reproducibility.huggingface-cli upload ${hf_user}/${repo_name} path/to/pretrained_model1from torch.profiler import profile, record_function, ProfilerActivity
2
3def trace_handler(prof):
4 prof.export_chrome_trace(f"tmp/trace_schedule_{prof.step_num}.json")
5
6with profile(
7 activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA],
8 schedule=torch.profiler.schedule(
9 wait=2,
10 warmup=2,
11 active=3,
12 ),
13 on_trace_ready=trace_handler
14) as prof:
15 with record_function("eval_policy"):
16 for i in range(num_episodes):
17 prof.step()
18 # insert code to profile, potentially whole body of eval_policy function1@misc{cadene2024lerobot,
2 author = {Cadene, Remi and Alibert, Simon and Soare, Alexander and Gallouedec, Quentin and Zouitine, Adil and Wolf, Thomas},
3 title = {LeRobot: State-of-the-art Machine Learning for Real-World Robotics in Pytorch},
4 howpublished = "\url{https://github.com/huggingface/lerobot}",
5 year = {2024}
6}1@article{chi2024diffusionpolicy,
2 author = {Cheng Chi and Zhenjia Xu and Siyuan Feng and Eric Cousineau and Yilun Du and Benjamin Burchfiel and Russ Tedrake and Shuran Song},
3 title ={Diffusion Policy: Visuomotor Policy Learning via Action Diffusion},
4 journal = {The International Journal of Robotics Research},
5 year = {2024},
6}1@article{zhao2023learning,
2 title={Learning fine-grained bimanual manipulation with low-cost hardware},
3 author={Zhao, Tony Z and Kumar, Vikash and Levine, Sergey and Finn, Chelsea},
4 journal={arXiv preprint arXiv:2304.13705},
5 year={2023}
6}1@inproceedings{Hansen2022tdmpc,
2 title={Temporal Difference Learning for Model Predictive Control},
3 author={Nicklas Hansen and Xiaolong Wang and Hao Su},
4 booktitle={ICML},
5 year={2022}
6}1@article{lee2024behavior,
2 title={Behavior generation with latent actions},
3 author={Lee, Seungjae and Wang, Yibin and Etukuru, Haritheja and Kim, H Jin and Shafiullah, Nur Muhammad Mahi and Pinto, Lerrel},
4 journal={arXiv preprint arXiv:2403.03181},
5 year={2024}
6}