Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix padding shape in split_and_pad_trajectories to support arbitrary additional dimensions #77

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bikcrum
Copy link
Contributor

@bikcrum bikcrum commented Mar 16, 2025

Description

This PR fixes an issue in split_and_pad_trajectories(tensor, dones) where creating a full-length trajectory incorrectly assumes the input tensor is 3D ([time, number of envs, feature_dim]). This assumption fails for higher-dimensional tensors, such as images ([time, number of envs, channel, width, height]), where there are multiple additional dimensions. The previous approach, which used only the last dimension (shape[-1]), caused shape mismatches when adding a full-length zero trajectory.

Key Changes

Instead of assuming a single feature dimension (shape[-1]), the full-length trajectory is now created using all feature dimensions beyond the second dimension (number of environments), represented by *shape[2:].
This ensures compatibility with tensors of arbitrary additional dimensions while preserving the intended functionality.

For reference, the following line is changed:

trajectories = trajectories + (torch.zeros(tensor.shape[0], tensor.shape[-1], device=tensor.device),)

@ClemensSchwarke
Copy link
Contributor

Hey bikcrum, thanks a lot for opening a PR to fix this! The issue is already fixed on our internal development branch and will be resolved in the next release.
Thanks again :)

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.

2 participants