add action mask in loss computation#871
Open
HomerIsAFool wants to merge 1 commit intoPhysical-Intelligence:mainfrom
Open
add action mask in loss computation#871HomerIsAFool wants to merge 1 commit intoPhysical-Intelligence:mainfrom
HomerIsAFool wants to merge 1 commit intoPhysical-Intelligence:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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