Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tensordict/_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -2696,6 +2696,8 @@ def recompose(converted_idx, stack_dim=new_stack_dim):
result.lock_()
return result

__getitems__ = __getitem__

def __eq__(self, other):
return self._dispatch_comparison(other, "__eq__", "__eq__", default=False)

Expand Down
11 changes: 11 additions & 0 deletions test/tensordict/test_lazy.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,17 @@ def test_to_mds(self, tmpdir):
test_td = LazyStackedTensorDict(*batches)
assert_allclose_td(td, test_td)

def test_dataloader_ragged_lazy_stack(self):
dataset = lazy_stack([TensorDict(x=torch.zeros(i)) for i in range(10)])
batches = list(
torch.utils.data.DataLoader( # noqa: TOR401
dataset, batch_size=4, collate_fn=lambda batch: batch
)
)
assert [len(batch) for batch in batches] == [4, 4, 2]
assert all(isinstance(batch, LazyStackedTensorDict) for batch in batches)
assert [len(td["x"]) for batch in batches for td in batch] == list(range(10))

def test_all_keys(self):
td = TensorDict({"a": torch.zeros(1)}, [])
td2 = TensorDict({"a": torch.zeros(2)}, [])
Expand Down
Loading