Skip to content

[BUG] DataLoader with LazyStackedTensorDict of different sizes #1296

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

Open
3 tasks done
Modexus opened this issue Apr 25, 2025 · 0 comments
Open
3 tasks done

[BUG] DataLoader with LazyStackedTensorDict of different sizes #1296

Modexus opened this issue Apr 25, 2025 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@Modexus
Copy link

Modexus commented Apr 25, 2025

Describe the bug

Not sure if I am missing something but I am trying to load a batch of lazy_stacked TensorDicts that have variable size tensors.
The DataLoader throws an error however that it cannot stack the tensors.

To Reproduce

import tensordict
import torch

tensors = [{"x": torch.rand((i,))} for i in range(10)]
tensordicts_stacked = tensordict.lazy_stack(
    [tensordict.TensorDict.from_dict(x) for x in tensors]
)

dl = DataLoader(tensordicts_stacked, batch_size=4, collate_fn=lambda x: x)
next(iter(dl))

Expected behavior

Not sure if this is supposed to work but I would have expected it to return a batch of LazyStackedTensorDicts.

Reason and Possible fixes

I think it's because __getitems__ actually points to <bound method TensorDictBase.__getitem__ of LazyStackedTensorDict.
If I add __getitems__ = __getitem__ after the __getitem__ in LazyStackedTensorDict (the same as in the Base) it returns a LazyStackedTensorDict without an error.

Checklist

  • I have checked that there is no similar issue in the repo (required)
  • I have read the documentation (required)
  • I have provided a minimal working example to reproduce the bug (required)
@Modexus Modexus added the bug Something isn't working label Apr 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants