mr2.nn.LayerNorm

class mr2.nn.LayerNorm[source]

Bases: CondMixin, Module

Layer normalization.

__init__(n_channels: int | None, features_last: bool = False, cond_dim: int = 0) → None[source]

Initialize the layer normalization.

Parameters:
  • n_channels (int | None) – Number of channels in the input tensor. If None, the layer normalization does not do an elementwise affine transformation.

  • features_last (bool, default: False) – If True, the channel dimension is the last dimension.

  • cond_dim (int, default: 0) – Number of channels in the conditioning tensor. If 0, no adaptive scaling is applied.

__call__(x: Tensor, *, cond: Tensor | None = None) → Tensor[source]

Apply layer normalization to the input tensor.

Parameters:
  • x (Tensor) – Input tensor

  • cond (Tensor | None, default: None) – Conditioning tensor. If None, no conditioning is applied.

Returns:

Normalized output tensor

forward(x: Tensor, *, cond: Tensor | None = None) → Tensor[source]

Apply layer normalization to the input tensor.