Rate this Page
★ ★ ★ ★ ★

TensorDictBase#

The methods of TensorDictBase are shared by every tensordict class and by tensorclasses. They are listed by task in Methods by task, with one page for each method.

class tensordict.TensorDictBase(*args, **kwargs)#

The abstract base class of every tensordict.

TensorDict, LazyStackedTensorDict, PersistentTensorDict and the other tensordict classes subclass it, and tensorclasses have the same methods. You do not create a TensorDictBase: use it in type hints and in isinstance checks. A tensorclass is not an instance of it: use is_tensor_collection() to accept both. The methods are listed by task in Methods by task.

Examples

>>> import torch
>>> from tensordict import TensorDict, TensorDictBase, lazy_stack
>>> td = TensorDict(a=torch.zeros(3), batch_size=[3])
>>> isinstance(td, TensorDictBase), isinstance(lazy_stack([td, td]), TensorDictBase)
(True, True)

Tutorials that use TensorDictBase#

Using TensorDict for datasets

Using TensorDict for datasets

Functional calls and ensembles with TensorDict

Functional calls and ensembles with TensorDict

Benchmarking TensorDict serialization speed

Benchmarking TensorDict serialization speed

Building tensordicts from streams

Building tensordicts from streams

Getting, setting, and nesting keys

Getting, setting, and nesting keys

Devices and memory-mapped tensors

Devices and memory-mapped tensors

Building models with TensorDictModule

Building models with TensorDictModule

Filling a TensorDict row by row

Filling a TensorDict row by row

Changing the shape of a TensorDict

Changing the shape of a TensorDict

Slicing, indexing, and masking

Slicing, indexing, and masking

Storing TensorDicts in zarr

Storing TensorDicts in zarr