mr2.nn.PermutedBlock

class mr2.nn.PermutedBlock[source]

Bases: CondMixin, Module

Apply a submodule along selected spatial dimensions.

__init__(apply_along_dim: Sequence[int], module: Module, features_last: bool = False)[source]

Initialize the PermutedBlock.

Parameters:
  • apply_along_dim (Sequence[int]) – Spatial dimension indices to use when applying the module. These will be moved to the last dimensions.

  • module (Module) – Module to apply on the selected dims.

  • features_last (bool, default: False) – If True, the features dimension is assumed to be the last dimension, as common in transformer models.

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

Apply the module along the selected dimensions.

Parameters:
  • x (Tensor) – Input tensor

  • cond (Tensor | None, default: None) – Conditioning tensor, passed to the module if it supports conditioning (that is, if it is a subclass of CondMixin)

Returns:

Output tensor.

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

Apply the module along the selected dimensions.