Registry / ai-ml / tensordict-nightly

tensordict-nightly

JSON →
library2026.6.14pypypi✓ verified 84d ago

TensorDict is a PyTorch-dedicated tensor container that provides a dictionary-like class inheriting properties from `torch.Tensor`. It streamlines the organization and manipulation of collections of tensors, enabling efficient batch operations, shape transformations, and seamless device management. As a nightly build, `tensordict-nightly` offers the latest features and bug fixes, with frequent updates that may introduce breaking changes.

pip install tensordict-nightly
INSTALL
IMPORT
SIG · TENSORDICT-NIGHTLY
T
tensordict-nightly
ai-mlpythonv2026.6.14
Install
67.9s avg
Import
11566ms
Disk
4838MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2026.6.7 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
4/8 runs
✓ 79.2s
py 3.11
4/8 runs
✓ 73.08s
py 3.12
4/8 runs
✓ 61.83s
py 3.13
4/8 runs
✓ 57.65s
py 3.9
4/8 runs
4/8 runs
4838MB installed
● package 4838MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

TensorDict
from tensordict import TensorDict
MemoryMappedTensor
from tensordict import MemoryMappedTensor
my_memmap_tensor._tensor
The `_tensor` property on `MemoryMappedTensor` was removed in v0.11.0 and now raises a RuntimeError. Access the instance directly.
TensorDictModule
from tensordict.nn import TensorDictModule
tensorclass
from tensordict import tensorclass

This quickstart demonstrates how to create a `TensorDict`, access and add elements, move it to a different device (if CUDA is available), and perform basic slicing operations.

import torch from tensordict import TensorDict # Create a TensorDict with a specified batch_size td = TensorDict( {"observations": torch.randn(128, 84), "actions": torch.randn(128, 4)}, batch_size=[128] ) print("Original TensorDict:\n", td) print("Batch size:", td.batch_size) # Accessing elements obs = td["observations"] print("\nObservations shape:", obs.shape) # Adding a new key td["rewards"] = torch.randn(128, 1) print("\nTensorDict after adding rewards:\n", td) # Moving to device if torch.cuda.is_available(): td_gpu = td.to("cuda") print(f"\nTensorDict moved to {td_gpu.device}:\n", td_gpu) # Slicing sub_td = td[:64] print("\nSliced TensorDict (first 64 elements):\n", sub_td) print("Sliced batch size:", sub_td.batch_size)
Debug
Known issues
breakingPython 3.9 support was dropped in TensorDict v0.11.0. Python 3.10 or newer is now required.
fix
Upgrade your Python environment to version 3.10 or higher.
affects: >=0.11.0
breakingDeprecated methods `lock`, `unlock`, and `rename_key` (without a trailing underscore) were removed in v0.11.0.
fix
Use `lock_`, `unlock_`, and `rename_key_` instead for in-place modifications, e.g., `td.lock_()` instead of `td.lock()`.
affects: >=0.11.0
breakingThe `MemoryMappedTensor._tensor` property now raises a `RuntimeError` since v0.11.0. Users should interact with the `MemoryMappedTensor` instance directly as it is a tensor subclass.
fix
Access the tensor content directly, e.g., `my_memmap_tensor` instead of `my_memmap_tensor._tensor`.
affects: >=0.11.0
gotchaFrom v0.10.0, lists assigned to a TensorDict will be automatically stacked by default, potentially raising a `FutureWarning`.
fix
Review code that assigns lists to TensorDicts. If list stacking is not the desired default behavior or to suppress the warning, explicitly use context managers like `td.set_` or specify the desired behavior.
affects: >=0.10.0
gotchaCalling `.to()` method on a `TensorDict` with a `dtype` argument will raise an error. The `to()` method is for device casting only.
fix
To change the dtype of tensors within a TensorDict, iterate through its items and apply `item.to(dtype=...)` or use `td.apply(lambda x: x.to(dtype=...))`.
affects: All versions
Errors
Common errors & fixes
IndexError: tuple index out of range
Passing a dictionary with non-string keys (e.g., integers, tuples) to the `TensorDict` constructor or `make_tensordict` function.
fix
Ensure all keys in the input dictionary are strings. If you need nested keys, use string keys or consider using `flatten_keys` later with a separator.
RuntimeError: Cannot modify locked TensorDict.
Attempting to modify a `TensorDict` instance that has been locked (e.g., by calling `td.lock_()` or being created with `lock=True`).
fix
Unlock the TensorDict using `td.unlock_()` before modification, or use in-place methods with a trailing underscore (e.g., `td.set_(key, value)`) if the key already exists.
Wrong values in TensorDict with device='cpu' specified
When creating or moving a `TensorDict` to CPU with `non_blocking=True` (which is often implicit or default), data transfer might not be synchronized, leading to incorrect values if accessed immediately. This is more prevalent with non-CUDA devices.
fix
Explicitly set `non_blocking=False` when moving to CPU if immediate and synchronized access is critical, or ensure a synchronization call (`torch.cuda.synchronize()` if applicable) is made before accessing the data.
_dist_sample hasattr error OR load_state_dict fails if checkpoint lacks entries for TensorDictParams
These are general issues often related to specific versions of PyTorch or `tensordict`, or complex model architectures and distributed setups where `TensorDict` or `tensorclass` objects are used in state dictionaries or sampling processes.
fix
Check the `pytorch/tensordict` GitHub issues for similar reports and potential workarounds or targeted bug fixes for your specific `tensordict` and PyTorch versions. Consider updating to the latest nightly builds for potential fixes.
Upgrade
Version history
2026.6.14latest on PyPI · released Jun 14, 2026
Audit
Dependencies
torchrequiredCore dependency, TensorDict is built for PyTorch tensors.
numpyoptionalRequired for certain operations or data handling.
cloudpickleoptionalUsed for serialization, especially in multiprocessing/distributed settings.
packagingoptionalUsed for version parsing and compatibility checks.
importlib_metadataoptionalBackward compatibility for Python versions prior to 3.8.
orjsonoptionalOptional dependency for faster JSON serialization, primarily for Python < 3.13.
Agent activity
14 hits · last 30 days
node
12
OpenAI (training)
1
Resources