returnn.tf.frontend_layers._utils#

Some utilities for internal use

returnn.tf.frontend_layers._utils.unique_tensor_list(tensors: Iterable[Tensor]) List[Tensor][source]#
Parameters:

tensors (list[Tensor]) –

Returns:

list with unique tensors

Return type:

list[Tensor]

returnn.tf.frontend_layers._utils.copy(tensor: Tensor[Layer], *, name: Layer | str) Tensor[Layer][source]#
returnn.tf.frontend_layers._utils.identity_with_control_deps(tensor: Tensor[Layer], control_deps: Sequence[Tensor[Layer]], *, name: str | Layer | None = None) Tensor[Layer][source]#
Parameters:
  • tensor

  • control_deps

  • name

Returns:

tensor with control deps

returnn.tf.frontend_layers._utils.constant(value: int | float, *, name: str | Layer)[source]#
returnn.tf.frontend_layers._utils.constant_value(x: Tensor[Layer]) int | float | complex | bool | str | None[source]#

If the tensor is a constant, return its value.

returnn.tf.frontend_layers._utils.zeros_like_as_output_in_scope(tensor: Tensor, *, name: Layer)[source]#
Parameters:
  • tensor

  • name

Returns:

returnn.tf.frontend_layers._utils.mark_as_output_in_scope(tensor: Tensor, scope: Layer) Tensor[source]#

Mark this as an output.

returnn.tf.frontend_layers._utils.get_last_hidden_state(source: ~returnn.tensor.tensor.Tensor, *, out_dim: ~returnn.tensor.dim.Dim | None = <class 'returnn.util.basic.NotSpecified'>, combine: str = <class 'returnn.util.basic.NotSpecified'>, key: str | int | None = <class 'returnn.util.basic.NotSpecified'>) Tensor[source]#

Will combine (concat or add or so) all the last hidden states from all sources.

Parameters:
  • source (nn.Tensor) –

  • out_dim (nn.Dim|None) –

  • combine (str) – “concat” or “add”

  • key (str|int|None) – for the state, which could be a namedtuple. see RnnCellLayer.get_state_by_key()

Returns:

layer