r""" An `AdapterResnetBlock` is a helper model that implements a ResNet-like block. Parameters: channels (`int`): Number of channels of AdapterResnetBlock's input and output.
| 437 | |
| 438 | |
| 439 | class AdapterResnetBlock(nn.Module): |
| 440 | r""" |
| 441 | An `AdapterResnetBlock` is a helper model that implements a ResNet-like block. |
| 442 | |
| 443 | Parameters: |
| 444 | channels (`int`): |
| 445 | Number of channels of AdapterResnetBlock's input and output. |
| 446 | """ |
| 447 | |
| 448 | def __init__(self, channels: int): |
| 449 | super().__init__() |
| 450 | self.block1 = nn.Conv2d(channels, channels, kernel_size=3, padding=1) |
| 451 | self.act = nn.ReLU() |
| 452 | self.block2 = nn.Conv2d(channels, channels, kernel_size=1) |
| 453 | |
| 454 | def forward(self, x: torch.Tensor) -> torch.Tensor: |
| 455 | r""" |
| 456 | This method takes input tensor x and applies a convolutional layer, ReLU activation, and another convolutional |
| 457 | layer on the input tensor. It returns addition with the input tensor. |
| 458 | """ |
| 459 | |
| 460 | h = self.act(self.block1(x)) |
| 461 | h = self.block2(h) |
| 462 | |
| 463 | return h + x |
| 464 | |
| 465 | |
| 466 | # light adapter |