-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add Api Examples #2204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Api Examples #2204
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds API examples for various policies and learning algorithms to support an upcoming tutorial release. The changes include refactoring common utility functions into reusable components and creating comprehensive example scripts demonstrating how to use different models (ACT, Diffusion, SmolVLA, PI0), reinforcement learning approaches (HIL-SERL), and asynchronous inference patterns.
Key changes:
- Extracted common observation preparation and action processing utilities to
src/lerobot/policies/utils.py
- Added configurable observation dimensions to environment configurations
- Created 12 new tutorial example scripts covering model usage, training, and RL workflows
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 4 comments.
Show a summary per file
File | Description |
---|---|
src/lerobot/policies/utils.py |
New utility functions for observation preprocessing and action conversion |
src/lerobot/utils/control_utils.py |
Refactored to use new utility functions from policies/utils.py |
src/lerobot/scripts/lerobot_record.py |
Updated to use new make_robot_action utility function |
src/lerobot/envs/configs.py |
Added configurable observation height/width parameters |
tests/mocks/mock_robot.py |
Enhanced mock robot with proper motor bus integration |
examples/tutorial/**/*.py |
12 new example scripts demonstrating various use cases |
actor_learner_example.py |
Comprehensive HIL-SERL implementation example |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
for _ in range(MAX_EPISODES): | ||
for _ in range(MAX_STEPS_PER_EPISODE): | ||
obs = robot.get_observation() | ||
obs_frame = build_inference_frame(obs, dataset_features, device, task=task, robot_type=robot_type) |
Copilot
AI
Oct 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function call has incorrect parameter order. According to the function signature in utils.py, the correct order should be build_inference_frame(obs, device, dataset_features, task=task, robot_type=robot_type)
.
obs_frame = build_inference_frame(obs, dataset_features, device, task=task, robot_type=robot_type) | |
obs_frame = build_inference_frame(obs, device, dataset_features, task=task, robot_type=robot_type) |
Copilot uses AI. Check for mistakes.
for _ in range(MAX_EPISODES): | ||
for _ in range(MAX_STEPS_PER_EPISODE): | ||
obs = robot.get_observation() | ||
obs_frame = build_inference_frame(obs, dataset_features, device, task=task, robot_type=robot_type) |
Copilot
AI
Oct 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function call has incorrect parameter order. According to the function signature in utils.py, the correct order should be build_inference_frame(obs, device, dataset_features, task=task, robot_type=robot_type)
.
obs_frame = build_inference_frame(obs, dataset_features, device, task=task, robot_type=robot_type) | |
obs_frame = build_inference_frame(obs, device, dataset_features, task=task, robot_type=robot_type) |
Copilot uses AI. Check for mistakes.
for _ in range(MAX_EPISODES): | ||
for _ in range(MAX_STEPS_PER_EPISODE): | ||
obs = robot.get_observation() | ||
obs_frame = build_inference_frame(obs, dataset_metadata.features, device) |
Copilot
AI
Oct 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function call has incorrect parameter order. According to the function signature in utils.py, the correct order should be build_inference_frame(obs, device, dataset_metadata.features)
.
obs_frame = build_inference_frame(obs, dataset_metadata.features, device) | |
obs_frame = build_inference_frame(obs, device, dataset_metadata.features) |
Copilot uses AI. Check for mistakes.
for _ in range(MAX_EPISODES): | ||
for _ in range(MAX_STEPS_PER_EPISODE): | ||
obs = robot.get_observation() | ||
obs_frame = build_inference_frame(obs, dataset_metadata.features, device) |
Copilot
AI
Oct 14, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function call has incorrect parameter order. According to the function signature in utils.py, the correct order should be build_inference_frame(obs, device, dataset_metadata.features)
.
obs_frame = build_inference_frame(obs, dataset_metadata.features, device) | |
obs_frame = build_inference_frame(obs, device, dataset_metadata.features) |
Copilot uses AI. Check for mistakes.
model.config, | ||
model_id, | ||
# This overrides allows to run on MPS, otherwise defaults to CUDA (if available) | ||
preprocessor_overrides={"device_processor": {"device": "mps"}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you should use device
here (but cast as string)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure I understand. You mean {"device": torch.device("mps")}
? Kinda obscure without full documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, you have a variable device
device = torch.device("mps") # or "cuda" or "cpu" |
Why not reuse this variable such as:
preprocessor_overrides={"device_processor": {"device": "mps"}}, | |
preprocessor_overrides={"device_processor": {"device": str(device)}}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The user just has to change the device variable that’s it. In your case, the user needs to update it both in the variable itself and in the overrides.
This is a minor detail.
8dc86aa
to
306429a
Compare
Part of PR stack (the lower, the closer to main)
build_inference_frame
/make_robot_action
util to easily allow API-based Inference #2143What this does
The tutorial will be released very shortly (~tomorrow), and this PR adds the examples I have added in it to the library. Happy to tweak them, although they have all been tested end-to-end for functionality! Together with the behavior conversion and tutorial, I hope this is a good step towards making the library more hackable (and researcher friendly, 😉!)
FYI, I won't be able to change these examples in the tutorial but for second edition. That can be released soon (TBD), and I'd be happy to add there whatever ends up landing on
main