mr2.nn.Sequential

class mr2.nn.Sequential[source]

Bases: CondMixin, Sequential

Sequential container with support for conditioning and Operators.

Allows multiple input tensors and a single output tensor of the sequential block.

__init__(*args: Module) → None
__init__(arg: OrderedDict[str, Module]) → None

Initialize internal Module state, shared by both nn.Module and ScriptModule.

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

Apply all modules in series to the input.

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

  • cond (Tensor | None, default: None) – The (optional) conditioning tensor.

Returns:

The output tensor.

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

Apply all modules in series to the input.

append(module: Module) → Self

Append a given module to the end.

Parameters:

module (nn.Module) – module to append

Example:

>>> import torch.nn as nn
>>> n = nn.Sequential(nn.Linear(1, 2), nn.Linear(2, 3))
>>> n.append(nn.Linear(3, 4))
Sequential(
    (0): Linear(in_features=1, out_features=2, bias=True)
    (1): Linear(in_features=2, out_features=3, bias=True)
    (2): Linear(in_features=3, out_features=4, bias=True)
)
extend(sequential: Iterable[Module]) → Self

Extends the current Sequential container with layers from another Sequential container.

Parameters:

sequential (Sequential) – A Sequential container whose layers will be added to the current container.

Example:

>>> import torch.nn as nn
>>> n = nn.Sequential(nn.Linear(1, 2), nn.Linear(2, 3))
>>> other = nn.Sequential(nn.Linear(3, 4), nn.Linear(4, 5))
>>> n.extend(other) # or `n + other`
Sequential(
    (0): Linear(in_features=1, out_features=2, bias=True)
    (1): Linear(in_features=2, out_features=3, bias=True)
    (2): Linear(in_features=3, out_features=4, bias=True)
    (3): Linear(in_features=4, out_features=5, bias=True)
)
insert(index: int, module: Module) → Self

Inserts a module into the Sequential container at the specified index.

Parameters:
  • index (int) – The index to insert the module.

  • module (Module) – The module to be inserted.

Example:

>>> import torch.nn as nn
>>> n = nn.Sequential(nn.Linear(1, 2), nn.Linear(2, 3))
>>> n.insert(0, nn.Linear(3, 4))
Sequential(
    (0): Linear(in_features=3, out_features=4, bias=True)
    (1): Linear(in_features=1, out_features=2, bias=True)
    (2): Linear(in_features=2, out_features=3, bias=True)
)
pop(key: int | slice) → Module

Pop key from self.