(self, dim: int, hidden_dim: int)
| 89 | """SwiGLU MLP (LLaMA-style).""" |
| 90 | |
| 91 | def __init__(self, dim: int, hidden_dim: int): |
| 92 | super().__init__() |
| 93 | self.w1 = nn.Linear(dim, hidden_dim, bias=False) # gate |
| 94 | self.w2 = nn.Linear(hidden_dim, dim, bias=False) # down |
| 95 | self.w3 = nn.Linear(dim, hidden_dim, bias=False) # up |
| 96 | |
| 97 | def forward(self, x: torch.Tensor) -> torch.Tensor: |
| 98 | return self.w2(F.silu(self.w1(x)) * self.w3(x)) |