Skip to content

v0.8.0: Non-tensor data handling

Choose a tag to compare

@vmoens vmoens released this 29 Apr 14:47
· 117 commits to main since this release

What's Changed

We're excited to announce a new tensordict release, packed with new features, packaging perks as well as bug fixes.

New features

The interaction with non-tensor data is now much easier to get by ():

set_list_to_stack(True).set() # Ask for new behaviour
td = TensorDict(batch_size=(3, 2))
td["numbers"] = [["0", "1"], ["2", "3"], ["4", "5"]]
print(td)
# TensorDict(
#     fields={
#         numbers: NonTensorStack(
#             [['0', '1'], ['2', '3'], ['4', '5']],
#             batch_size=torch.Size([3, 2]),
#             device=None)},
#     batch_size=torch.Size([3, 2]),
#     device=None,
#     is_shared=False)

Stacks of non-tensor data can also be reshaped 58ccbf5. Using the previous example:

td = td.view(-1)
td["numbers"]
# ['0', '1', '2', '3', '4', '5']

We also made it easier to get values of lazy stacks (f7bc839):

tds = [TensorDict(a=torch.zeros(3)), TensorDict(a=torch.ones(2))]
td = lazy_stack(tds)
print(td.get("a", as_list=True))
# [tensor([0., 0., 0.]), tensor([1., 1.])]
print(td.get("a", as_nested_tensor=True))
# NestedTensor(size=(2, j1), offsets=tensor([0, 3, 5]), contiguous=True)
print(td.get("a", as_padded_tensor=True, padding_value=-1))
# tensor([[ 0.,  0.,  0.],
#         [ 1.,  1., -1.]])

Packaging

You can now install tensordict with any PyTorch version. We only provide test coverage for the latest pytorch (currently 2.7.0), so for any other version you will be on your own in terms of compatibility but there should be no limitations in term of installing the library with older version of pytorch.

New features

Bug Fixes

Performance

Miscellaneous

New Contributors

Full Changelog: v0.7.0...v0.8.0