| 13 | |
| 14 | |
| 15 | class FFN(nn.Module): |
| 16 | |
| 17 | def __init__(self, latent_dim, ffn_dim, dropout): |
| 18 | super().__init__() |
| 19 | self.linear1 = nn.Linear(latent_dim, ffn_dim) |
| 20 | self.linear2 = zero_module(nn.Linear(ffn_dim, latent_dim)) |
| 21 | self.activation = nn.GELU() |
| 22 | self.dropout = nn.Dropout(dropout) |
| 23 | |
| 24 | def forward(self, x, **kwargs): |
| 25 | y = self.linear2(self.dropout(self.activation(self.linear1(x)))) |
| 26 | y = x + y |
| 27 | return y |
| 28 | |
| 29 | |
| 30 | class EncoderLayer(nn.Module): |