class returnn.frontend.types.Tensor(name: str, dims: ~typing.Sequence[~returnn.tensor.dim.Dim] | None = None, dtype: str | None = None, *, sparse_dim: ~returnn.tensor.dim.Dim | None = None, feature_dim: ~returnn.tensor.dim.Dim | None = None, feature_dim_axis: int | ~returnn.util.basic.NotSpecified | None = <class 'returnn.util.basic.NotSpecified'>, raw_tensor: ~returnn.tensor.tensor.RawTensorType | None = None, version: int | None = None, **kwargs)[source]

Represents a tensor, in a frame-agnostic way. See the module docstring.

  • name

  • dims – the shape, where each dimension is described by a Dim.

  • dtype – e.g. “float32” or “int64”

  • sparse_dim – when the values are indices into some dimension, this is the dimension. You can also interpret the whole tensor as a sparse representation of a dense one-hot tensor, where this sparse_dim becomes the additional dense dimension.

  • raw_tensor – the raw tensor, e.g. numpy array, TF tensor, or PyTorch tensor

  • version

    behavior version just for Tensor. If not specified, and dims is None (old code), it uses version 1. - v1: the old behavior of Data. Specifically, time_dim_axis and feature_dim_axis are used

    and automatically inferred when not specified.

    • v2: time_dim_axis, feature_dim_axis are None by default.

  • kwargs – see _handle_extra_kwargs(), infer_dim_tags()

size_dtype = 'int32'[source]
name: str[source]
dtype: str[source]
sparse_dim: Dim | None[source]
version: int[source]
property dims: Tuple[Dim, ...][source]

dim tags

property dims_set: Set[Dim][source]

set of dim tags. in all high-level code, the order of dims is irrelevant. The order must not play a role (RETURNN principles: Note that we do not include any implicit dims here. Also see verify_out_shape() and

property raw_tensor: RawTensorType | None[source]

raw tensor

property feature_dim: Dim | None[source]

self.dims[self.feature_dim_axis] or None. See for some discussion.

property device: str | None[source]


class returnn.frontend.types.Dim(dimension: int | Tensor | None, *, name: str | None = None, capacity: int | None = None, dyn_size_ext: Tensor | None = None, description: str | None = None, **kwargs)[source]

Represents a dimension of a tensor. This potentially comes with further information such as individual sequence lengths. See the module docstring.


alias of DimTypes

capacity: int | None[source]
size: int | None[source]
dyn_size_ext: Tensor | None[source]
name: str | None[source]
returnn.frontend.types.get_raw_tensor_type() Type[source]

the raw tensor type of the current selected backend, e.g. torch.Tensor or tf.Tensor

class returnn.frontend.types.GetModelFunc(*args, **kwargs)[source]

get model func

class returnn.frontend.types.StepFunc(*args, **kwargs)[source]

step func