Skip to content

Commit

Permalink
throw an error if config.do_maks_loss and action_is_pad not provided …
Browse files Browse the repository at this point in the history
…in batch (#213)

Co-authored-by: Alexander Soare <[email protected]>
  • Loading branch information
radekosmulski and alexander-soare authored May 27, 2024
1 parent 6d39b73 commit 3b86050
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lerobot/common/policies/diffusion/modeling_diffusion.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,11 @@ def compute_loss(self, batch: dict[str, Tensor]) -> Tensor:
loss = F.mse_loss(pred, target, reduction="none")

# Mask loss wherever the action is padded with copies (edges of the dataset trajectory).
if self.config.do_mask_loss_for_padding and "action_is_pad" in batch:
if self.config.do_mask_loss_for_padding:
if "action_is_pad" not in batch:
raise ValueError(
f"You need to provide 'action_is_pad' in the batch when {self.config.do_mask_loss_for_padding=}."
)
in_episode_bound = ~batch["action_is_pad"]
loss = loss * in_episode_bound.unsqueeze(-1)

Expand Down

0 comments on commit 3b86050

Please sign in to comment.