TensorCollection#
- class tensordict.TensorCollection(*args, **kwargs)#
Bases:
objectThe abstract base class of tensordicts and tensorclasses.
TensorDictBaseandTensorClassinherit from it. It cannot be instantiated.Use it in type hints and
isinstancechecks for “a tensordict or a tensorclass”. Classes decorated with@tensorclassdo not inherit from it, only subclasses ofTensorClassdo; to check both, useis_tensor_collection().Examples
>>> import torch >>> from tensordict import TensorClass, TensorCollection, TensorDict >>> class Data(TensorClass): ... x: torch.Tensor >>> td = TensorDict(x=torch.zeros(3), batch_size=[3]) >>> isinstance(td, TensorCollection) True >>> isinstance(Data(x=torch.zeros(3), batch_size=[3]), TensorCollection) True >>> isinstance(torch.zeros(3), TensorCollection) False