Releases: pytorch/tensordict
TensorDict 0.10.0: MDS, type annotation and typed `MetaData`
TensorDict 0.10.0 Release Notes
We are excited to announce the release of TensorDict 0.10.0! This release includes significant improvements to type annotations, new features for metadata handling, enhanced tensor operations, and numerous bug fixes that improve the overall stability and usability of the library.
🎉 Highlights
- Typed MetaData: Complete rewrite of metadata handling with full type support (#1428)
- TensorCollection Parent Class: New parent class providing better type annotations and enhanced functionality (#1388)
- Enhanced String Support:
to_struct_arraynow supports string data types (#1410) - Improved Type Safety: Comprehensive type annotation improvements across the entire codebase
- Better TensorClass Support: Enhanced ClassVar support and super() functionality
- MDS data interface: the
to_mdsmethod creates an MDS dataset on your favourite location -- no more painful columns definition etc (#1426). - Support for autograd's
gradfunction (#1417)
✨ New Features
Core Functionality
- [Feature] Typed MetaData (#1428): Complete rewrite of metadata handling system with full type support, enabling better static analysis and runtime type checking
- [Feature] TensorCollection parent class and better type annotation (#1388): New parent class that provides enhanced type annotations and improved inheritance hierarchy
- [Feature] to_struct_array with strings (#1410): Extended
to_struct_arrayfunctionality to handle string data types - [Feature] MDS dataset helper functions (#1426): New helper functions for working with MDS (Multi-Dimensional Scaling) datasets
- [Feature] implement tensor_split (#1386): Added support for
tensor_splitoperation to match PyTorch tensor API - [Feature] accept cap-str as input to set_interaction_type (#1387): Enhanced flexibility in interaction type setting by accepting capitalized strings
- [Feature] Allow in-place modification of lazy stacks (#1384): Enabled in-place modifications for lazy stacked tensors, improving memory efficiency
- [Feature] Ensure super() works with TensorClass (#1381): Fixed super() functionality in TensorClass inheritance chains
- [Feature] Add all everywhere (#1389): Added comprehensive
__all__declarations across all modules for better IDE support and import control
Type System Improvements
- [Typing]
@overloadfor methods that have a reduce arg (#1427): Added proper type overloads for methods with reduce parameters - [BE] A bunch of type annotation improvements (#1409): Comprehensive type annotation improvements across the codebase
- [BE] Better CompatibleType definition (#1404): Enhanced type definitions for better compatibility checking
- [BE] Add _from_tensordict to TensorClass (#1403): Added internal method for TensorClass construction from TensorDict
- [BE] Better type annotation for
__getitem__(#1402): Improved type annotations for indexing operations
🐛 Bug Fixes
Critical Fixes
- [BugFix] Fix stacking typed MetaData (#1429): Fixed issues with stacking operations on typed metadata
- [BugFix] Call synchronization when using the td.to("cpu") operation on third-party devices (#1425): Fixed potential precision issues when transferring tensors from third-party devices to CPU
- [BugFix] Fix missing _maybe_broadcast_other in base.py (#1422): Fixed missing broadcast functionality in base operations
- [BugFix] lock_() consolidated tds to avoid overriding values (#1408): Fixed value override issues in locked TensorDicts during consolidation
TensorClass Fixes
- [BugFix] Args for TC with ClassVar (#1401): Fixed argument handling for TensorClass with ClassVar annotations
- [BugFix] Fix ClassVar support in tensorclass (#1398): Enhanced ClassVar support in tensorclass decorator
- [BugFix] Fix MetaData assignment in tensorclasses (#1394): Fixed metadata assignment issues in TensorClass instances
Type and API Fixes
- [BugFix,TypeHint] Fix type annotations in tensorclass stub file (#1421): Fixed type hints in stub files for better IDE support
- [Bugfix] Fix type annotation for tensordict.keys().iter() (#1413): Fixed iterator type annotations for TensorDict keys
- [Bugfix] Fix
TensorDictModuleWrapperforward (#1415): Fixed forward pass in TensorDictModuleWrapper - [Bugfix] Improve various typing issues (#1424): General improvements to typing across the codebase
Tensor Operations
- [BugFix] repeat_interleave supports tensors (#1391): Fixed
repeat_interleaveto properly support tensor arguments - [BugFix] Fix chunk following split fix (#1377): Fixed chunking operations after split functionality improvements
- [BugFix] Uneven splits (#1376): Fixed handling of uneven tensor splits
- [BugFix] JSON/orjson compatibility (#1373): Improved compatibility between JSON and orjson serialization
🔄 Deprecations and Breaking Changes
- [Deprecation] Upgrade set_list_to_stack behavior (#1382): Updated behavior of
set_list_to_stackwith proper deprecation warnings for the old API
🛠️ Development and Infrastructure
CI and Testing
- [CI] Better versioning (#1433): Improved versioning system for better release management
- [CI] Fix benchmark CI upload with conditional PR testing (#1397): Enhanced CI pipeline for benchmark uploads
- [CI,Tests] Fix tests (#1396): General test fixes and improvements
- [CI] Update OSX target (#1378): Updated macOS build targets
- [CI] Downgrade OSX version in builds (#1375): Adjusted macOS version requirements for broader compatibility
Documentation
- [Doc,CI] Fix installation of the lib for releases in doc CI (#1432): Fixed library installation in documentation CI
- [Doc] Fix doc errors (#1431): General documentation error fixes
- [Doc, CI] Fix Doc CI (#1430): Fixed documentation CI pipeline
- Fix typos in export tutorial (#1405): Corrected typos in export tutorial documentation
👥 Contributors
Special thanks to all the contributors who made this release possible:
- Vincent Moens (@vmoens) - Lead maintainer, major features and bug fixes
- Yichao Zhou (@Yichao-Zhou) - Type system improvements and bug fixes
- Huazhong (@huazhongyang) - Device synchronization fixes
- Yoann Poupart (@Xmaster6y) - TensorDictModuleWrapper fixes
- Chi Zhang (@chz8494) - tensor_split implementation
- Heon Song (@heonsong) - Documentation improvements
📚 Documentation
For comprehensive documentation, tutorials, and examples, visit:
For a complete list of changes, see the full changelog.
If you encounter any issues, please report them on our GitHub Issues page.
v0.9.1: Orjson/Json Interoperability
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
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.stacknow preserves names when stacking TensorDict instances (#1348) (2053031) update_batch_sizeinwhere(): Enhancedwhere()operation now supportsupdate_batch_sizeparameter (#1365) (847a86c)tolist_first(): New method for converting TensorDict to list with first-level flattening (#1334) (73fe89b)
Torch Function Integration
torch.maximumsupport: Added support fortorch.maximumoperation in TensorDict (#1362) (85f26e4)- Enhanced loss functions: Added support for
torch.sum,torch.mean,torch.varand 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
NonTensorDataBaseandMetaData: 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_initwith subclasses: Enhanced remote initialization support for TensorDict subclasses (#1308) (5859a2c)return_earlyforisend: New parameter for early return in send operations (#1306) (4012767)
🐛 Bug Fixes
TensorDict Operations
- Fixed "none"/"None" environment variable handling (#1372) (cb104a1)
- Fixed
split_sizevalidation inTensorDict.split()(#1370) (0bb94c0) - Fixed
update_batch_sizewhen 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_onlyconstruction (#1364) (75e2c26) - Fixed missing
update_batch_sizein 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.stackforcing all names toNonewhen 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
CudaGraphModuleon devices that are not 0 (#1315) (89d05a1) - Fixed lazy stack
isendearly 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_compositedefaults to True only when >1 distribution (#1328) (2c73924)
Distribution and Probabilistic Modules
- Fixed
TDParamscompatibility with export (#1285) (ecdde0b) - Fixed better list assignment in tensorclasses (#1284) (6d8119c)
- Fixed method
_is_list_tensor_compatiblemissing 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_onlyfor 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:
_Cextension 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 oftensordict.nn.NormalParamExtractor- Functional modules:
is_functional,make_functional, andget_functionalhave been removed from tensordict
Future Changes
- List-to-stack behavior: In version 0.10.0, lists will be automatically stacked by default. A
FutureWarningwill 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
- Update functional module usage: If using
is_functional,make_functional, orget_functional, these have been removed - NormalParamWrapper replacement: Use
tensordict.nn.NormalParamExtractorinstead ofNormalParamWrapper - List handling: Consider using the new
set_list_to_stackcontext 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
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
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
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
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
v0.7.2
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
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
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)!
- @egaznep made their first contribution in #1056
- @priba made their first contribution in #1065
- @SamAdamDay made their first contribution in #1075
- @emmanuel-ferdman made their first contribution in #1105
- @bachdj-px made their first contribution in #1101
- @jgrhab made their first contribution in #1130
- @amdfaa made their first contribution in #1191
BC-breaking changes
- In #1180, we use the same object for
minandmaxoperations as we do with torch.Tensor.min. Previously, tensorclasses
were used, but that lead to some undefined behaviors when indexing (in PyTorch,minreturns 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 randomsamplebut 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
TensorClassclass 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)orclass T(TensorClass["shadow"]): ...
and you will be able to use dedicated names likegetorvaluesas 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)andTensorClass["nocast"]will deactivate the auto-casting in tensorclasses.
The behavior is now:- No value: tensorclass will cast things like TensorDict (ie,
intornp.arrayswill be cast totorch.Tensor
instances for example). autocast=Truewill cause@tensorclassto go one step further and attempt to cast values to the type indicated
in the dataclass definition.nocast=Truekeeps values as they are. All non-tensor (or non-tensordict/tensorclass) values will be wrapped in
aNonTensorData.
- No value: tensorclass will cast things like TensorDict (ie,
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...