Skip to content
Closed
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
5 changes: 5 additions & 0 deletions src/lerobot/policies/pi0/modeling_pi0.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ def prepare_language(self, batch) -> tuple[Tensor, Tensor]:
"""Tokenize the text input"""
device = batch[OBS_STATE].device
tasks = batch["task"]
if isinstance(tasks, str):
tasks = [tasks]

if len(tasks) == 1:
Comment on lines +395 to +398
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The condition len(tasks) == 1 will always be true after the previous block that converts a string to a single-element list. This means single tasks will always be replicated to match batch size, even when the original input was already a list with one element that shouldn't be replicated.

Suggested change
if isinstance(tasks, str):
tasks = [tasks]
if len(tasks) == 1:
was_string = isinstance(tasks, str) # Track if the input was originally a string
if was_string:
tasks = [tasks]
if was_string and len(tasks) == 1: # Only replicate if the input was originally a string

Copilot uses AI. Check for mistakes.
Comment on lines +395 to +398
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

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

The logic assumes that when len(tasks) == 1, it should replicate the task across the batch dimension. However, this doesn't distinguish between a single string input (which should be replicated) and a legitimate single-element list (which may not need replication). Consider checking the original input type or batch size mismatch instead.

Suggested change
if isinstance(tasks, str):
tasks = [tasks]
if len(tasks) == 1:
was_string = isinstance(tasks, str) # Track if the input was originally a string
if was_string:
tasks = [tasks]
if was_string or len(tasks) == 1 and len(tasks) != batch[OBS_STATE].shape[0]:

Copilot uses AI. Check for mistakes.
tasks = [tasks[0] for _ in range(batch[OBS_STATE].shape[0])]

# PaliGemma prompt has to end with a new line
tasks = [task if task.endswith("\n") else f"{task}\n" for task in tasks]
Expand Down