| 55 | |
| 56 | |
| 57 | class FeedForward(nn.Module): |
| 58 | def __init__(self, dim, dim_out=None, mult=4, glu=False, dropout=0.): |
| 59 | super().__init__() |
| 60 | inner_dim = int(dim * mult) |
| 61 | dim_out = default(dim_out, dim) |
| 62 | project_in = nn.Sequential( |
| 63 | nn.Linear(dim, inner_dim), |
| 64 | nn.GELU() |
| 65 | ) if not glu else GEGLU(dim, inner_dim) |
| 66 | |
| 67 | self.net = nn.Sequential( |
| 68 | project_in, |
| 69 | nn.Dropout(dropout), |
| 70 | nn.Linear(inner_dim, dim_out) |
| 71 | ) |
| 72 | |
| 73 | def forward(self, x): |
| 74 | return self.net(x) |
| 75 | |
| 76 | |
| 77 | def zero_module(module): |