Skip to content

plus_residual

PlusResidual

Bases: torch.nn.Module

Wraps a layer such that the forward pass returns x + self.layer(x)

Source code in pytorch_adapt\layers\plus_residual.py
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
class PlusResidual(torch.nn.Module):
    """
    Wraps a layer such that the forward pass returns
    ```x + self.layer(x)```
    """

    def __init__(self, layer: torch.nn.Module):
        """
        Arguments:
            layer: The layer to be wrapped.
        """
        super().__init__()
        self.layer = layer

    def forward(self, x):
        """"""
        return x + self.layer(x)

__init__(layer)

Parameters:

Name Type Description Default
layer torch.nn.Module

The layer to be wrapped.

required
Source code in pytorch_adapt\layers\plus_residual.py
10
11
12
13
14
15
16
def __init__(self, layer: torch.nn.Module):
    """
    Arguments:
        layer: The layer to be wrapped.
    """
    super().__init__()
    self.layer = layer