v0.8.0: Non-tensor data handling
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
- [Feature] Add init value option to AddStateIndependentNormalScale (#1259) 0dc90b2 @lin-erica
- [Feature] Allow neg dims during LazyStack 539651f @vmoens
- [Feature] Allow update to increment the number of tds in a lazy stack 3ec3be7 @vmoens
- [Feature] Deepcopy acd8f57 @vmoens
- [Feature] NotImplemented for abstractmethods in base.py to avoid empty calls 37e3454 @vmoens
- [Feature] TensorDict.tolist() (#1229) a3493de @vmoens
- [Feature] TensorDictModule method and kwargs specification bbd5ba8 @vmoens
- [Feature] Update batch-size 635d036 @vmoens
- [Feature]
strictkwarg in TDModule 06215b6 @vmoens - [Feature] as_list, as_padded_tensor and as_nested_tensor for Lazy stacks f7bc839 @vmoens
- [Feature] as_tensordict_module 9738142 @vmoens
- [Feature] capture_non_tensor_stack 7b0fd93 @vmoens
- [Feature] from_dataclass with dest_cls arg fced90d @vmoens
- [Feature] inplace arg for TensorDictSequential 55fab2a @vmoens
- [Feature] inplace kwarg for Probabilistic TD Sequential ab1b532 @vmoens
- [Feature] view, flatten and unflatten for lazy stacks 58ccbf5 @vmoens
Bug Fixes
- [BugFix] *_like functions with dtypes 947cb19 @vmoens
- [BugFix] Better check for TDModule bf9007c @vmoens
- [BugFix] Better list assignment in tensorclasses 6d8119c @vmoens
- [BugFix] Better prop of args in update c61d045 @vmoens
- [BugFix] Consolidate lazy stacks of non-tensors 0b901a7 @vmoens
- [BugFix] Consolidate lazy stacks of non-tensors f67a15c @vmoens
- [BugFix] Enforce
zip(..., strict=True)in TDModules 0a8638d @vmoens - [BugFix] Ensure that maybe_dense_stack preserves the TC type eb2fd8e @vmoens
- [BugFix] Faster and safer non-tensor stack e23ce5c @vmoens
- [BugFix] Fix .item() warning on tensors that require grad 910c953 @vmoens
- [BugFix] Fix MISSING check in tensorclass (#1275) cc0f464 @vmoens*
- [BugFix] Fix TDParams compatibility with export ecdde0b @vmoens
- [BugFix] Fix compile during _check_keys 2ad9f95 @vmoens
- [BugFix] Fix get for nestedkeys with default in tensorclass 4e1c646 @vmoens
- [BugFix] Fix non-deterministic key order in stack (#1230) c35d7aa @vmoens
- [BugFix] Fix rsub 4b77779 @vmoens
- [BugFix] Fix serialization of stacks of Tensorclasses 635c9c0 @vmoens
- [BugFix] Fix tensorclass indexing 0fccd26 @vmoens
- [BugFix] Fix tensorclass update cb81b5e @vmoens
- [BugFix] Fix tensordict.get in TDModule tensor retrieval for NonTensorData feb736f @vmoens
- [BugFix] Local cuda assessment 5b8bce8 @vmoens
- [BugFix] Method _is_list_tensor_compatible missing return value (#1277) a9cc632 @albertbou92
- [BugFix] Pass type directly during reduction ad0a8dd @vmoens
- [BugFix] Proper auto-batch size for unbatched tensors ba53d07 @vmoens
- [BugFix] _PASSTHROUGH_MEMO for passthrough tensorclass d25bd54 @vmoens
- [BugFix]
nonevalue for _CAPTURE_NONTENSOR_STACK 2f60f8d @vmoens - [BugFix] fix get for tensorclass with lazy stacks 36a49ad @vmoens
- [BugFix] fix replacing nested keys in rename_key_ 06fd756 @vmoens
- [BugFix] num_samples=None fix be88a17 @vmoens
Performance
- [Performance] Dedicated validate funcs 604b471 @vmoens
- [Performance] Faster
_get_item1e33a18 @vmoens - [Performance] tensor_only for tensorclass d4bc34c @vmoens
Miscellaneous
- [BE] Better errors for TensorDictSequential 28fbea1 @vmoens
- [CI,Setup] Fix CI and bump python3.13 (#1260) 57ca3d4 @vmoens*
- [CI] Fix 3.13t wheels 8774e73 @vmoens
- [CI] python 3.13 nightly build 0eb2ad3 @vmoens
- [Deprecation] Deprecate KJT support 63730af @vmoens
- [Deprecation] Enact deprecations 3d2e6d2 @vmoens
- [Deprecation] Softly deprecate extra-tensors wrt out_keys 7dd385b @vmoens
- [Doc,BugFix] Fix default argument in doc for
AddStateIndependentNormalScale(#1216) 309c0a3 Faury Louis* - [Doc] Better doc for TensorDictModuleBase b8d3ff9 @vmoens
- [Doc] Fix typo in pad_sequence docstring example (#1262) a121330 @codingWhale13
- [Minor] Expose is_leaf_nontensor and default_is_leaf 8bdbf01 @vmoens
- [Minor] Fix tensorclass prints 9eba0c1 @vmoens
- [Refactor] Setting lists in tensordict instances 6ad496b @vmoens
- [Setup] Fix setuptools error 4018b8b @vmoens
- [Setup] Parametrize PyTorch version with env variable for local builds (#1245) b95c382 @dvmazur
- [Test] Deactivate failing test on 2.6 2df09c9 @vmoens
- [Test] Test dataclasses.field as tensorclass default e8294da @vmoens
- [Versioning] Bump v0.8.0 37afe37 @vmoens
New Contributors
- @dvmazur made their first contribution in #1245
- @lin-erica made their first contribution in #1259
- @codingWhale13 made their first contribution in #1262
Full Changelog: v0.7.0...v0.8.0