Skip to content

add action mask in loss computation#871

Open
HomerIsAFool wants to merge 1 commit intoPhysical-Intelligence:mainfrom
HomerIsAFool:main
Open

add action mask in loss computation#871
HomerIsAFool wants to merge 1 commit intoPhysical-Intelligence:mainfrom
HomerIsAFool:main

Conversation

@HomerIsAFool
Copy link

Motivation

In the implementation of π pytorch version, the loss is computed in the forward() as below:
https://github.com/Physical-Intelligence/openpi/blob/main/src/openpi/models_pytorch/pi0_pytorch.py#L373

return F.mse_loss(u_t, v_t, reduction="none")

But the dim of u_t and v_t are max_dim from the config (32 in π05). This means that the padded actions will also be included in the loss calculation. I think this may harm the model performance.

The lerobot π05 has fixed this by using action_mask when calculating the loss:
https://github.com/huggingface/lerobot/blob/main/src/lerobot/policies/pi05/modeling_pi05.py#L1257

Modification

In this PR, we create a new param actual_action_dim in src/openpi/models/pi0_config.py to represent the actual action dim.
And create a new param action_mask in class PI0Pytorch.

In the forward func, use the action_mask to eliminate the impact of padded actions on the loss.

return F.mse_loss(u_t, v_t, reduction="none") * self.action_mask

@jimmyt857 jimmyt857 removed their request for review February 5, 2026 17:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant