mr2.nn.Residual

class mr2.nn.Residual[source]

Bases: CondMixin, Module

Residual connection.

__init__(module: Module, skip: Module | None = None)[source]

Initialize the residual connection.

Parameters:
  • module (Module) – The main path of the residual connection.

  • skip (Module | None, default: None) – The skip path of the residual connection. If None, the identity function is used.

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

Apply the module.

Parameters:
  • x (Tensor) – The input tensor.

  • cond (Tensor | None, default: None) – The optional conditioning tensor. If the modules are an instance of CondMixin, the conditioning is passed to the modules.

Returns:

The output tensor.

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

Apply the module.