In this release we introduce a bunch of exciting features to TensorDict:
- We deprecate MemmapTensor in favour of MemoryMappedTensor, which is fully backed by torch.Tensor and not numpy anymore. The new API is faster and way more bug-free than it used too. See 541
- Saving tensordicts on disk can now be done via `memmap`, `memmap_` and `memmap_like` which all support multithreading. If possible, serialization is pickle free (memmap + json) and `torch.save` is only used for classes that fail to be serialized with json. Serializing models using tensordict is now 3-10x faster than using torch.save, even for SOTA LLMs such as LLAMA.
- TensorDict can now carry non tensor data through the `NonTensorData` class. Assigning non-tensor data can also be done via `__setitem__` and they can be retrieved via `__getitem__`. 601
- A bunch of new operations have appeared too such as `named_apply` (apply with key names) or `tensordict.auto_batch_size_()`, and operations like update can now be achieved for only a subset of keys.
- Almost all operations in the library are now faster!
- We are slowing deprecating lazy classes except for `LazyStackedTensorDict`. Whereas `torch.stack` used to systematically return a lazy stack, it now returns a dense stack if the `set_lazy_legacy(mode)` decorator is set to `False` (which will be the default in the next release). The old behaviour can be set with `set_lazy_legacy(True)`. Lazy stacks can still be obtained using `LazyStackedTensorDict.lazy_stack`. Appropriate warnings are raised unless you have patched your code accordingly.
What's Changed
* [Refactor] MemoryMappedTensor by vmoens in https://github.com/pytorch/tensordict/pull/541
* [Feature] Multithread memmap by vmoens in https://github.com/pytorch/tensordict/pull/592
* [Refactor] Graceful as_tensor by vmoens in https://github.com/pytorch/tensordict/pull/549
* [Test] Fix as_tensor test by vmoens in https://github.com/pytorch/tensordict/pull/551
* Fix assignment of `str`-typed value to `_device` attribute in `MemmapTensor` by kurt-stolle in https://github.com/pytorch/tensordict/pull/552
* [Refactor] Refactor split by vmoens in https://github.com/pytorch/tensordict/pull/555
* [Refactor] Refactor implement_for by vmoens in https://github.com/pytorch/tensordict/pull/556
* [Feature] Better constructors for MemoryMappedTensors by vmoens in https://github.com/pytorch/tensordict/pull/557
* [CI] Fix benchmark on gpu by vmoens in https://github.com/pytorch/tensordict/pull/560
* [CI] Add regular benchmarks to CI in PRs without upload by vmoens in https://github.com/pytorch/tensordict/pull/561
* [Refactor] Major refactoring of codebase by vmoens in https://github.com/pytorch/tensordict/pull/559
* [Benchmark] Benchmark split and chunk by vmoens in https://github.com/pytorch/tensordict/pull/564
* [Performance] Faster split, chunk and unbind by vmoens in https://github.com/pytorch/tensordict/pull/563
* [Feature] Consolidate functional calls by vmoens in https://github.com/pytorch/tensordict/pull/565
* [Refactor] Improve functional call efficiency by vmoens in https://github.com/pytorch/tensordict/pull/567
* [Refactor] Do not lock nested tensordict in tensordictparams by vmoens in https://github.com/pytorch/tensordict/pull/568
* [Performance] Faster params and buffer registration in TensorDictParams by vmoens in https://github.com/pytorch/tensordict/pull/569
* [BugFix] Graceful attribute error exit in TensorDictParams by vmoens in https://github.com/pytorch/tensordict/pull/571
* [Refactor] Upgrade pytree import by vmoens in https://github.com/pytorch/tensordict/pull/573
* [BugFix] Compatibility with missing _global_parameter_registration_hooks by vmoens in https://github.com/pytorch/tensordict/pull/574
* [Feature] Seed workers in TensorDict.map by vmoens in https://github.com/pytorch/tensordict/pull/562
* [Performance] Faster update by vmoens in https://github.com/pytorch/tensordict/pull/572
* [Performance] Faster to_module by vmoens in https://github.com/pytorch/tensordict/pull/575
* [BugFix] _FileHandler for windows by vmoens in https://github.com/pytorch/tensordict/pull/577
* [Performance] Faster `__init__` by vmoens in https://github.com/pytorch/tensordict/pull/576
* [Feature, Test] Add tests for partial update by vmoens in https://github.com/pytorch/tensordict/pull/578
* [BugFix] No fallback on `TensorDictModule.__getattr__` for private attributes by vmoens in https://github.com/pytorch/tensordict/pull/579
* [BugFix] Fix deepcopy of TensorDictParams by vmoens in https://github.com/pytorch/tensordict/pull/580
* Add MANIFEST.in by vmoens in https://github.com/pytorch/tensordict/pull/581
* [BugFix] Delete parameter/buffer before setting it with regular setattr in to_module by vmoens in https://github.com/pytorch/tensordict/pull/583
* [Feature] named_apply and default value in apply by vmoens in https://github.com/pytorch/tensordict/pull/584
* [BugFix] Faster empty_like for MemoryMappedTensor by vmoens in https://github.com/pytorch/tensordict/pull/585
* [BugFix] Faster empty_like for MemoryMappedTensor (dup) by vmoens in https://github.com/pytorch/tensordict/pull/586
* [BugFix] Adapt MemoryMappedTensor for torch < 2.0 by vmoens in https://github.com/pytorch/tensordict/pull/587
* [Performance] Make copy_ a no-op if tensors are identical by vmoens in https://github.com/pytorch/tensordict/pull/588
* [BugFix] Fix non-blocking arg in copy_ by vmoens in https://github.com/pytorch/tensordict/pull/590
* [Feature] Unbind and stack tds in map with chunksize=0 by vmoens in https://github.com/pytorch/tensordict/pull/589
* [Performance] Faster dispatch by vmoens in https://github.com/pytorch/tensordict/pull/487
* [Feature] Saving metadata of tensorclass by vmoens in https://github.com/pytorch/tensordict/pull/582
* [BugFix] Fix osx tests by vmoens in https://github.com/pytorch/tensordict/pull/591
* [Feature] Weakref for unlocking tds by vmoens in https://github.com/pytorch/tensordict/pull/595
* [BugFix] Fix pickling of weakrefs by vmoens in https://github.com/pytorch/tensordict/pull/597
* [Feature] Return early a tensordict created through memmap with multiple threads by vmoens in https://github.com/pytorch/tensordict/pull/598
* [CI] Depend on torch nightly for nightly releases by vmoens in https://github.com/pytorch/tensordict/pull/599
* [Feature] Storing non-tensor data in tensordicts by vmoens in https://github.com/pytorch/tensordict/pull/601
* [Feature, Test] FSDP and DTensors by vmoens in https://github.com/pytorch/tensordict/pull/600
* [Minor] Fix type deletion in tensorclass load_memmap by vmoens in https://github.com/pytorch/tensordict/pull/602
* [BugFix] Fix ellipsis check by vmoens in https://github.com/pytorch/tensordict/pull/604
* [Feature] Best intention stack by vmoens in https://github.com/pytorch/tensordict/pull/605
* [Feature] Remove and check for prints in codebase using flake8-print by vmoens in https://github.com/pytorch/tensordict/pull/603
* [Doc] Doc revamp by vmoens in https://github.com/pytorch/tensordict/pull/593
* [BugFix, Doc] Fix tutorial by vmoens in https://github.com/pytorch/tensordict/pull/606
* [BugFix] Fix gh-pages upload by vmoens in https://github.com/pytorch/tensordict/pull/607
* [BugFix] Upload content of html directly by vmoens in https://github.com/pytorch/tensordict/pull/608
* [Feature] Improve in-place ops for TensorDictParams by vmoens in https://github.com/pytorch/tensordict/pull/609
* [BugFix, CI] Fix GPU benchmarks by vmoens in https://github.com/pytorch/tensordict/pull/611
* [Feature] inplace to_module by vmoens in https://github.com/pytorch/tensordict/pull/610
* [Versioning] Bump v0.3.0 by vmoens in https://github.com/pytorch/tensordict/pull/613
* [Feature] Support group specification by lucifer1004 in https://github.com/pytorch/tensordict/pull/616
* [Refactor] Remove remaining MemmapTensor references by vmoens in https://github.com/pytorch/tensordict/pull/617
* [Tests] Reorder and regroup tests by vmoens in https://github.com/pytorch/tensordict/pull/614
* [Performance] Faster set by vmoens in https://github.com/pytorch/tensordict/pull/619
* [Performance] Better shared/memmap inheritance and faster exclude by vmoens in https://github.com/pytorch/tensordict/pull/621
* [Benchmark] Benchmark select, exclude and empty by vmoens in https://github.com/pytorch/tensordict/pull/623
* [Feature] Improve the `empty` method by vmoens in https://github.com/pytorch/tensordict/pull/622
* [BugFix] Fix is_memmap attribute for memmap_like and memmap by vmoens in https://github.com/pytorch/tensordict/pull/625
* Bump jinja2 from 3.1.2 to 3.1.3 in /docs by dependabot in https://github.com/pytorch/tensordict/pull/626
* [BugFix] Remove shared/memmap inheritance from clone / select / exclude by vmoens in https://github.com/pytorch/tensordict/pull/624
* [BugFix] Fix `index in list` error by vmoens in https://github.com/pytorch/tensordict/pull/627
* [Refactor] Make unbind call tensor.unbind by vmoens in https://github.com/pytorch/tensordict/pull/628
* [Feature] `auto_batch_size_` by vmoens in https://github.com/pytorch/tensordict/pull/630
* [BugFix] Fix NonTensorData interaction by vmoens in https://github.com/pytorch/tensordict/pull/631
* [Doc] More doc on how to set and get non-tensor data by vmoens in https://github.com/pytorch/tensordict/pull/632
* [Feature] _auto_make_functional and _dispatch_td_nn_modules by vmoens in https://github.com/pytorch/tensordict/pull/633
* [BugFIx] Fix exclude indent by vmoens in https://github.com/pytorch/tensordict/pull/637
* [BugFix] Limit number of threads in workers for .map() by vmoens in https://github.com/pytorch/tensordict/pull/638
* [Feature] Robust to lazy_legacy set to false and context managers for reshape ops by vmoens in https://github.com/pytorch/tensordict/pull/634
* [Minor] Typo in lazy legacy warnings by vmoens in https://github.com/pytorch/tensordict/pull/639
* [Minor] NestedKey typing issues by vmoens in https://github.com/pytorch/tensordict/pull/640
* [Feature] nested_keys option in named_apply by vmoens in https://github.com/pytorch/tensordict/pull/641
* [Feature] Expose NestedKey in root by vmoens in https://github.com/pytorch/tensordict/pull/642
New Contributors
* kurt-stolle made their first contribution in https://github.com/pytorch/tensordict/pull/552
* lucifer1004 made their first contribution in https://github.com/pytorch/tensordict/pull/616
* dependabot made their first contribution in https://github.com/pytorch/tensordict/pull/626
**Full Changelog**: https://github.com/pytorch/tensordict/compare/v0.2.1...v0.3.0