default_is_leaf#
- tensordict.default_is_leaf(cls: Type) bool#
Returns
Trueif a type is not a tensor collection (tensordict or tensorclass), or is a pass-through type.Pass-through types (like UnbatchedTensor) have
_pass_through=Trueand are considered leaves because their shape doesn’t conform to batch dimensions.Note: NonTensorData types are NOT considered leaves here (they have
_is_non_tensor=Truebut not_pass_through=True), so they are excluded from leaves whenleaves_only=True.Examples
>>> from tensordict import TensorDict, default_is_leaf >>> import torch >>> td = TensorDict(a={}, b="a string!", c=torch.randn(())) >>> print(td.keys(leaves_only=True, is_leaf=default_is_leaf)) _TensorDictKeysView(['c'], include_nested=False, leaves_only=True)
See also