Method
__init__
(
self,
cfg,
dim: int,
hidden_dim: int,
layer_id: int,
multiple_of: int=256,
)
Source from the content-addressed store, hash-verified
| 372 | |
| 373 | class FeedForward(nn.Module): |
| 374 | def __init__( |
| 375 | self, |
| 376 | cfg, |
| 377 | dim: int, |
| 378 | hidden_dim: int, |
| 379 | layer_id: int, |
| 380 | multiple_of: int=256, |
| 381 | ): |
| 382 | super().__init__() |
| 383 | |
| 384 | hidden_dim = multiple_of * ((hidden_dim + multiple_of - 1) // multiple_of) |
| 385 | def swiglu(x): |
| 386 | x = torch.chunk(x, 2, dim=-1) |
| 387 | return F.silu(x[0]) * x[1] |
| 388 | self.swiglu = swiglu |
| 389 | |
| 390 | self.w1 = nn.Linear( |
| 391 | dim, |
| 392 | 2 * hidden_dim, |
| 393 | bias=False, |
| 394 | ) |
| 395 | self.w2 = nn.Linear( |
| 396 | hidden_dim, |
| 397 | dim, |
| 398 | bias=False, |
| 399 | ) |
| 400 | |
| 401 | def forward(self, x): |
| 402 | x = self.swiglu(self.w1(x)) |
Callers
nothing calls this directly
Tested by
no test coverage detected