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

[BUG] dtype in _split_and_pad_sequence is established using incorrect dim #2758

Open
KubaMichalczyk opened this issue Feb 5, 2025 · 1 comment

Comments

@KubaMichalczyk
Copy link

KubaMichalczyk commented Feb 5, 2025

In torchrl/objectives/value/utils.py#L287-L290, the code currently uses tensor.shape[-2] to choose between torch.int16 and torch.int32. This should use the time dimension (time_dim) instead, especially since it's used in _fast_td_lambda_return_estimate where the inputs are transposed first. As a result, the condition may be incorrect for certain input shapes (when the size of time_dim exceeds the int16 range, but F dimension of _fast_td_lambda_return_estimate inputs is within this range).

Code Reference:

    # int16 supports length up to 32767
    dtype = (
        torch.int16 if tensor.shape[-2] < torch.iinfo(torch.int16).max else torch.int32
    )

Proposed Fix:

    dtype = (
        torch.int16 if tensor.size(time_dim) < torch.iinfo(torch.int16).max else torch.int32
    )
@vmoens
Copy link
Contributor

vmoens commented Feb 7, 2025

You are correct! Do you want to push the fix or should I?

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

No branches or pull requests

2 participants