Skip to content

Releases: pytorch/tensordict

v0.9.1: Orjson/Json Interoperability

14 Jul 12:53
Compare
Choose a tag to compare

This minor releases brings the following improvements and bug fixes:

  • Fixing orjson / json interoperability #1373
  • Downgrade OSX build target to 14 #1378
  • Fixing split and chunk #1376 and #1377

Full Changelog: v0.9.0...v0.9.1

v0.9.0

09 Jul 16:09
Compare
Choose a tag to compare

TensorDict 0.9.0 Release Notes

Overview

TensorDict 0.9.0 introduces significant improvements in performance, new features for lazy operations, enhanced CUDA graph support, and various bug fixes. This release focuses on stability improvements and new functionality for distributed and lazy tensor operations.

🚀 New Features

Lazy Operations and Stacking

  • to_lazystack(): New method to convert TensorDict instances to lazy stacks (#1351) (a5aab97)
  • Stack name preservation: tensordict.stack now preserves names when stacking TensorDict instances (#1348) (2053031)
  • update_batch_size in where(): Enhanced where() operation now supports update_batch_size parameter (#1365) (847a86c)
  • tolist_first(): New method for converting TensorDict to list with first-level flattening (#1334) (73fe89b)

Torch Function Integration

  • torch.maximum support: Added support for torch.maximum operation in TensorDict (#1362) (85f26e4)
  • Enhanced loss functions: Added support for torch.sum, torch.mean, torch.var and loss functions (l1, smooth_l1, mse) (#1361) (17ca2ff)

CUDA Graph Enhancements

  • CudaGraphModule.state_dict(): New method to access state dictionary of CUDA graph modules (#1346) (909907b)
  • Improved device handling: Better support for CUDA graph operations on non-zero devices (#1315) (89d05a1)
  • Stream management: Enhanced stream handling for CUDA graph operations (#1314) (2fd4843)

Non-Tensor Data Support

  • NonTensorDataBase and MetaData: New base classes for handling non-tensor data in TensorDict (#1324) (8d0241d)
  • Enhanced metadata handling: Improved support for metadata operations

Copy Operations

  • TensorDict.__copy__(): New method for creating shallow copies of TensorDict instances (#1321) (b6feadd)

Distributed tensordicts

  • broadcast tensordicts: New functionality for broadcasting TensorDict instances across different shapes (#1307) (2959863)
  • remote_init with subclasses: Enhanced remote initialization support for TensorDict subclasses (#1308) (5859a2c)
  • return_early for isend: New parameter for early return in send operations (#1306) (4012767)

🐛 Bug Fixes

TensorDict Operations

  • Fixed "none"/"None" environment variable handling (#1372) (cb104a1)
  • Fixed split_size validation in TensorDict.split() (#1370) (0bb94c0)
  • Fixed update_batch_size when source is TD and destination is LTD (#1371) (c8bfda2)
  • Fixed device argument in TensorDict constructor to respect CUDA current device (#1369) (afcbcec)
  • Fixed new_ operations on NonTensorStack (#1366) (5e67c32)
  • Fixed tensor_only construction (#1364) (75e2c26)
  • Fixed missing update_batch_size in lazy stack updates (#1359) (c9f0e40)
  • Fixed context managers update when a key is in _non_tensordict (#1353) (c11a95b)
  • Fixed tensorclass __enter__ and __exit__ methods (#1352) (08abb06)

Stacking and Chunking

  • Fixed tensordict.stack forcing all names to None when no match (#1350) (c90df00)
  • Fixed chunk/split memmap index when dim!=0 (#1345) (297a514)
  • Fixed nested key iterations for lazy stacks within tensorclasses (#1344) (2e616f8)
  • Fixed leaf check in stack function (#1341) (e03c25e)
  • Fixed nested tensorclass maybe_dense_stacks (#1340) (9c8dd2d)
  • Fixed chunk of NJTs (Nested JAX Tensors) (#1339) (3477e96)

Compilation and Device Issues

  • Fixed compilation of TensorClass with non-tensor + batch-size + device (#1337) (5c98749)
  • Fixed new_* operations for Lazy stacks (#1317) (1c8be19)
  • Fixed improper name setting in __setitem__ (#1313) (1d642b0)
  • Fixed CudaGraphModule on devices that are not 0 (#1315) (89d05a1)
  • Fixed lazy stack isend early return (#1316) (8d3c470)

Memory and Performance

  • Fixed memory leak caused by _validate_value (#1310) (a36f7f9)
  • Fixed flatten operation with start=end dim (#1333) (d9972b4)
  • Fixed expansion of lazy stacks (#1331) (56b4493)
  • Fixed return_composite defaults to True only when >1 distribution (#1328) (2c73924)

Distribution and Probabilistic Modules

  • Fixed TDParams compatibility with export (#1285) (ecdde0b)
  • Fixed better list assignment in tensorclasses (#1284) (6d8119c)
  • Fixed method _is_list_tensor_compatible missing return value (#1277) (a9cc632)
  • Fixed .item() warning on tensors that require grad (#1283) (910c953)

⚡ Performance Improvements

  • Faster _get_item: Optimized item retrieval operations (#1288) (1e33a18)
  • Dedicated validation functions: Improved validation performance (#1281) (604b471)
  • tensor_only for tensorclass: Enhanced performance for tensor-only operations (#1280) (d4bc34c)
  • Second attempt at caching validation: Improved caching mechanisms (#1311) (5f26a8b)
  • Better property handling in TC: Optimized property operations in TensorClass

🔧 Setup and CI Improvements

  • Static linking: _C extension now statically linked against Python library (#1304) (af17524)
  • Better version checking: Improved version validation in smoke tests (#1303) (e84d44f)
  • Python 3.13 support: Added support for Python 3.13 nightly builds (#1279) (0eb2ad3)
  • Enhanced CI workflows: Improved continuous integration for various platforms
  • Simplified setup: Streamlined package setup process (#1286) (fffffe5)

🚨 Deprecations and Breaking Changes

Deprecated Features

  • NormalParamWrapper: Deprecated in favor of tensordict.nn.NormalParamExtractor
  • Functional modules: is_functional, make_functional, and get_functional have been removed from tensordict

Future Changes

  • List-to-stack behavior: In version 0.10.0, lists will be automatically stacked by default. A FutureWarning will be raised if lists are assigned to TensorDict without setting the appropriate context manager.

🛠️ Quality of Life Improvements

  • Simplified error handling: Better error messages and handling in TensorDictSequential execution (#1326) (1330b72)
  • Enhanced flatten operations: Made flatten operation idempotent (#1332) (49698e2)
  • Better list handling: Improved list assignment in TensorDict instances (#1282) (6ad496b)
  • Enhanced validation: Better validation functions for different data types

📦 Dependencies

  • Python: Support for Python 3.9, 3.10, 3.11, 3.12, and 3.13
  • PyTorch: Compatible with PyTorch 1.12 and upward
  • Additional: numpy, cloudpickle, packaging, importlib_metadata, orjson (for Python < 3.13)

🔗 Migration Guide

For Users Upgrading from 0.8.0

  1. Update functional module usage: If using is_functional, make_functional, or get_functional, these have been removed
  2. NormalParamWrapper replacement: Use tensordict.nn.NormalParamExtractor instead of NormalParamWrapper
  3. List handling: Consider using the new set_list_to_stack context manager for consistent list behavior

For Developers

  • The new lazy stacking features provide better memory efficiency for large datasets
  • CUDA graph support has been enhanced for better GPU performance
  • Non-tensor data handling has been improved with new base classes

🎯 Contributors

Special thanks to all contributors who made this release possible, including:

  • Vincent Moens
  • Nikolai Karpov
  • Jiahao Li
  • Faury Louis
  • Douglas Boubert
  • Albert Bou

📝 Full Changelog

For a complete list of all changes, please refer to the git log from version 0.8.0 to 0.9.0.

v0.8.3: Better CudaGraphModule

16 May 15:24
Compare
Choose a tag to compare

This minor release provides some fixes to CudaGraphModule, allowing the module to run on different devices than the default.

It also adds __copy__ to the TensorDict ops, such that copy(td) triggers td.copy(), resulting in a copy of the TD stucture without new memory allocation.

Full Changelog: v0.8.2...v0.8.3

v0.8.2: Fix memory leakage due to validate

05 May 20:49
Compare
Choose a tag to compare

This release fixes an apparent memory leak due to the value validation in tensordict.
The leak is apparent, as in it disappears in gc.collect() is invoked.
See #1309 for context.

Full Changelog: v0.8.1...v0.8.2

Minor fix: Statically link _C extension against the Python library

30 Apr 12:37
Compare
Choose a tag to compare

This new minor fixes the _C build pipeline, which was failing on some machines as the extension was build with dynamic linkage against libpython

v0.8.0: Non-tensor data handling

29 Apr 14:47
Compare
Choose a tag to compare

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

v0.7.2

27 Feb 11:31
3a0a8bb
Compare
Choose a tag to compare

We are pleased to announce the release of tensordict v0.7.2, which includes several bug fixes and backend improvements.

Bug Fixes:

  • Consolidated lazy stacks of non-tensors (#1222, #1224)
  • Passed type directly during reduction (#1225)
  • Fixed non-deterministic key order in stack (#1230)
  • Added _PASSTHROUGH_MEMO for passthrough tensorclass (#1231)
  • Improved performance and safety of non-tensor stack (#1232)
  • Fixed serialization of stacks of Tensorclasses (#1236)
  • Fixed compile during _check_keys (#1239)

Backend Improvements:

Improved errors for TensorDictSequential (#1227)

Documentation Updates:

Improved documentation for TensorDictModuleBase (#1226)

Full Changelog: v0.7.1...v0.7.2

0.7.1: Fixes and doc improvements

18 Feb 11:03
Compare
Choose a tag to compare

We are pleased to announce the release of tensordict v0.7.1, which includes several bug fixes and a deprecation notice.

Bug Fixes

  • Fixed get method for nested keys with default values in TensorClass (#1211)
  • Enforced zip(..., strict=True) in TDModules to prevent potential issues (#1212)
  • Properly handled auto-batch size for unbatched tensors (#1213)
  • Fixed indexing issues in TensorClass (#1217)

Deprecation Notice

Softly deprecated extra-tensors with respect to out_keys (#1215). We make sure a warning is raised when the number of output tensors and output keys do not match.

Full Changelog: v0.7.0...v0.7.1

v0.7.0: More robust composite distributions, TensorClass superclass

05 Feb 16:39
Compare
Choose a tag to compare

v0.7.0: More robust composite distributions, TensorClass superclass

v0.7.0 brings a lot of new features and bug fixes. Thanks to the vibrant community to help us keeping this project
alive!

New Contributors

A special thanks to our new contributors (+ people interacting with us on the PyTorch forum, discord or via issues and
social platforms)!

BC-breaking changes

  • In #1180, we use the same object for min and max operations as we do with torch.Tensor.min. Previously, tensorclasses
    were used, but that lead to some undefined behaviors when indexing (in PyTorch, min returns a namedtuple that can be
    indexed to get the values or argmax, whereas indexing a tensorclass indexes it along the batch dimension).
  • In #1166, we introduce broadcasting for pointwise operations between tensors and tensordicts. Now, the following two
    operations on either sides of the == sign are exactly equivalent:
    td = TensorDict(..., batch_size=[3, 5])
    t = torch.randn(5)
    td + t == td + t.expand(td.shape)

Announced API changes

CompositeDistribution

TL;DR: We're changing the way log-probs and entropies are collected and written in ProbabilisticTensorDictModule and
in CompositeDistribution. The "sample_log_prob" default key will soon be "<value>_log_prob (or
("path", "to", "<value>_log_prob") for nested keys). For CompositeDistribution, a different log-prob will be
written for each leaf tensor in the distribution. This new behavior is controlled by the
tensordict.nn.set_composite_lp_aggregate(mode: bool) function or by the COMPOSITE_LP_AGGREGATE environment variable.
We strongly encourage users to adopt the new behavior by setting tensordict.nn.set_composite_lp_aggregate(False).set()
at the beginning of their training script.

We've had multiple rounds of refactoring for CompositeDistribution which relied on some very specific assumptions and
resulted in a brittle and painful API. We now settled on the following API that will be enforced in v0.9, unless the
tensordict.nn.set_composite_lp_aggregate(mode) value is explicitly set to True (the current default).

The bulk of the problem was that log-probs were aggregated in a single tensor and registered in td["sample_log_prob"].
This had the following problems:

  • Summing the log-probs isn't a good idea, users should be entitled to user the log-probs as they please.
  • "sample_log_prob" is a generic but inappropriate name (the data may not be a random sample but anything else.)
  • Summing requires reduction (because log-probs may have different shapes), but sometimes we don't want to reduce to the
    shape of the root tensordict (see pytorch/rl#2756 for instance).

What's new

tensorclass

  • Introduction of the TensorClass class to do simple inheritance-style coding, which is accompanied by a stub file
    that encodes all the TensorDict op signatures (we ensure this in the CI). See #1067
  • @Tensorclass shadow attributes: you can now do @tensorclass(shadow=True) or class T(TensorClass["shadow"]): ...
    and you will be able to use dedicated names like get or values as attribute names. This is slightly unsafe when you
    nest the tensorclass, as we can't guarantee that the container won't be calling these methods directly on the
    tensorclass.
  • Similarly, @tensorclass(nocast=True) and TensorClass["nocast"] will deactivate the auto-casting in tensorclasses.
    The behavior is now:
    • No value: tensorclass will cast things like TensorDict (ie, int or np.arrays will be cast to torch.Tensor
      instances for example).
    • autocast=True will cause @tensorclass to go one step further and attempt to cast values to the type indicated
      in the dataclass definition.
    • nocast=True keeps values as they are. All non-tensor (or non-tensordict/tensorclass) values will be wrapped in
      a NonTensorData.

NonTensorData

  • It is not easier to build non-tensor stacks through a simple NonTensorStack(*values).

See the full list of features here:
[Feature] Add __abs__ docstrings, __neg__, __rxor__, __ror__, __invert__, __and__, __rand__, __radd__, __rtruediv__, __rmul__, __rsub__, __rpow__, bitwise_and, logical_and (#1154) (d1363eb) by @vmoens ghstack-source-id: 97ce710b5a4b552d9477182e1836cf3777c2d756
[Feature] Add expln map to NormalParamExtractor (#1204) (e900b24) by @vmoens ghstack-source-id: 9003ceafbe8ecb73c701ea1ce96c0a342d0679b0
[Feature] Add missing __torch_function__ (#1169) (bc6390c) by @vmoens ghstack-source-id: 3dbefb4f5322a944664bbc2d29af7f862cb92342
[Feature] Better list casting in TensorDict.from_any (#1108) (1ffc463) by @vmoens ghstack-source-id: 427d19d5ef7c0d2779e064e64522fc0094a885af
[Feature] Better logs of key errors in assert_close (#1082) (747c593) by @vmoens ghstack-source-id: 46cb41d0da34b17ccc248119c43ddba586d29d80
[Feature] COMPOSITE_LP_AGGREGATE env variable (#1190) (9733d6e) by @vmoens ghstack-source-id: 16b07d0eac582cfd419612f87e38e1a7acffcfc0
[Feature] CompositeDistribution.from_distributions (#1113) (a45c7e3) by @vmoens ghstack-source-id: 04a62439b0fe60422fbc901172df46306e161cc5
[Feature] Ensure all dists work with DETERMINSTIC type without warning (#1182) (8e63112) by @vmoens ghstack-source-id: 63117f9b3ac4125a2be4e3e55719cc718051fc10
[Feature] Expose WrapModule (#1118) (d849756) by @vmoens ghstack-source-id: 55caa5d7c39e0f98c1e0558af2a076fee15f7984
[Feature] Fix type assertion in Seq build (#1143) (eaafc18) by @vmoens ghstack-source-id: 83d3dcafe45568c366207395a22b22fb35f61de1
[Feature] Force log_prob to return a tensordict when kwargs are passed to ProbabilisticTensorDictSequential.log_prob (#1146) (98c57ee) by @vmoens ghstack-source-id: 326d0763c9bbb13b51daac91edca4f0e821adf62
[Feature] Make ProbabilisticTensorDictSequential account for more than one distribution (#1114) (c7bd20c) by @vmoens ghstack-source-id: b62b81b5cfd49168b5875f7ba9b4f35b51cd2423
[Feature] NonTensorData(*sequence_of_any) (#1160) (70d4ed1) by @vmoens ghstack-source-id: 537f3d87b0677a1ae4992ca581a585420a10a284
[Feature] NonTensorStack.data (#1132) (4404abe) by @vmoens ghstack-source-id: 86065377cc1cd7c7283ed0a468f5d5602d60526d
[Feature] NonTensorStack.from_list (#1107) (f924afc) by @vmoens ghstack-source-id: e8f349cb06a72dcb69a639420b14406c9c08aa99
[Feature] Optional in_keys for WrapModule (#1145) (2d37d92) by @vmoens ghstack-source-id: a18dd5dff39937b027243fcebc6ef449b547e0b0
[Feature] OrderedDict for TensorDictSequential (#1142) (7df2062) by @vmoens ghstack-source-id: a8aed1eaefe066dafaa974f5b96190860de2f8f1
[Feature] ProbabilisticTensorDictModule.num_samples (#1117) (978d96c) by @vmoens ghstack-source-id: dc6b1c98cee5fefc891f0d65b66f0d17d10174ba
[Feature] ProbabilisticTensorDictSequential.default_interaction_type (#1123) (68ce9c3) by @vmoens ghstack-source-id: 37d38df36263e8accd84d6cb895269d50354e537
[Feature] Subclass conservation in td ops (#1186) (070ca61) by @vmoens ghstack-source-id: 83e79abda6a4bb6839d99240052323380981855c
[Feature] TensorClass (#1067) (a6a0dd6) by @vmoens ghstack-source-id: c3d4e17599a3204d4ad06bceb45e4fdcd0fd1be5
[Feature] TensorClass shadow attributes (#1159) (c744bcf) by @vmoens ghstack-source-id: b5cc7c7fea2d48394e63d289ee2d6f215c2333bc
[Feature] TensorDict.(dim='feature') (#1121) (ba43159) by @vmoens ghstack-source-id: 68f21aca722895e8a240dbca66e97310c20a6b5d
[Feature] TensorDict.clamp (#1165) (646683c) by @vmoens ghstack-source-id: 44f0937c195d969055de10709402af7c4473df32
[Feature] TensorDict.logsumexp (#1162) (e564b3a) by @vmoens ghstack-source-id: 84148ad9c701029db6d02dfb84ddb0a9b26c9ab7
[Feature] TensorDict.separates (#1120) (674f356) by @vmoens ghstack-source-id: be142a150bf4378a0806347257c3cf64c78e4eda
[Feature] TensorDict.softmax (#1163) (c0c6c14) by @vmoens ghstack-source-id: a88bebc23e6aaa02ec297db72dbda68ec9628ce7
[Feature] TensorDictModule in_keys allowed as Dict[str, tuple | list] to enable multi use of a sample feature (#1101) (e871b7d) by @bachdj-px
[Feature] UnbatchedTensor (#1170) (74cae09) by @vmoens ghstack-source-id: fa25726d61e913a725a71f1579eb06b09455e7c8
[Feature] intersection for assert_close (#1078) (84d31db) by @vmoens ghstack-source-id: 3ae83c4ef90a9377405aebbf1761ace1a39417b1
[Feature] allow tensorclass to be customized (#1080) (31c7330) by @vmoens ghstack-source-id: 0b65b0a2dfb0cd7b5113e245c9444d3a0b55d085
[Feature] broadcast pointwise ops for tensor/tensordict mixed inputs (#1166) (aeff837) by @vmoens ghstack-source-id: bbefbb1a2e9841847c618bb9cf49160ff1a5c36a
[Feature] compatibility of consolidate with compile (quick version) (#1061) (3cf52a0) by @vmoens ghstack-source-id: 1bf3ca550dfe5499b58f878f72c4f1687b0f247e
[Feature] dist_params_keys and dist_sample_keys (#1179) (a728a4f) by @vmoens ghstack-source-id: d1e53e780132d04ddf37d613358b24467520230f
[Feature] flexible return type when indexing prob sequences (#1189) (790bef6) by @vmoens ghstack-source-id: 74d28ee84d965c11c527c60b20d9123ef30007f6
[Feature] from_any with UserDict (#1106) (3485c2c) by @vmoens ghstack-source-id: 420464209cff29c3a1c58ec521fbf4ed69d1355f
[Feature] inplace to method (#1066) (fbb71...

Read more

v0.6.2:

14 Nov 15:08
Compare
Choose a tag to compare

Minor bug fixes

[BugFix] Fix none ref in during reduction (#1090) 88c86f8
[Versioning] v0.6.2 fix cdd5cb3
[BugFix] smarter check in set_interaction_type 0b3c778
[Versioning] 0.6.2 b26bbe3
[Quality] Better use of StrEnum in set_interaction_type 477d85b
[Minor] print_directory_tree returns a string 05c0fe7
[Doc] Add doc on export with nested keys d64c33d
[Feature] Better logs of key errors in assert_close 1ef1188
[Refactor] Make _set_dispatch_td_nn_modules compatible with compile f24e3d8
[Doc] Better docstring for to_module 178dfd9
[Feature] intersection for assert_close 8583392
[Quality] Better error message for incongruent lists of keys 866943c
[BugFix] Better repr of lazy stacks e00965c
[BugFix] calling pad with immutable sequence (#1075) d3bcb6e
[Performance] Faster to f031bf2

Full Changelog: v0.6.1...v0.6.2