Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lerobot/common/robot_devices/control_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ def predict_action(observation, policy, device, use_amp):
):
# Convert to pytorch format: channel first and float32 in [0,1] with batch dimension
for name in observation:
observation[name] = observation[name].to(device)
if "image" in name:
observation[name] = observation[name].type(torch.float32) / 255
Copy link

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] Consider using the .float() alias instead of .type(torch.float32) for readability and consistency with common PyTorch code style.

Suggested change
observation[name] = observation[name].type(torch.float32) / 255
observation[name] = observation[name].float() / 255

Copilot uses AI. Check for mistakes.
observation[name] = observation[name].permute(2, 0, 1).contiguous()
observation[name] = observation[name].unsqueeze(0)
Comment on lines +112 to 116
Copy link

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can combine device transfer, dtype conversion, and normalization into a single chained call to reduce intermediate allocations, e.g.: observation[name] = observation[name].to(device=device, dtype=torch.float32).div(255).permute(2,0,1).unsqueeze(0).

Suggested change
observation[name] = observation[name].to(device)
if "image" in name:
observation[name] = observation[name].type(torch.float32) / 255
observation[name] = observation[name].permute(2, 0, 1).contiguous()
observation[name] = observation[name].unsqueeze(0)
if "image" in name:
observation[name] = observation[name].to(device=device, dtype=torch.float32).div(255).permute(2, 0, 1).unsqueeze(0)
else:
observation[name] = observation[name].to(device).unsqueeze(0)

Copilot uses AI. Check for mistakes.
observation[name] = observation[name].to(device)

# Compute the next action with the policy
# based on the current observation
Expand Down