| 186 | """ |
| 187 | |
| 188 | def __init__( |
| 189 | self, |
| 190 | hidden_size: int, |
| 191 | intermediate_size: int, |
| 192 | num_experts: int, |
| 193 | activation=None, |
| 194 | bias: bool = False, |
| 195 | fuse_gate_up: bool = False, |
| 196 | ): |
| 197 | super().__init__() |
| 198 | if activation is None: |
| 199 | activation = nn.functional.silu |
| 200 | self.activation = activation |
| 201 | self.num_experts = num_experts |
| 202 | self.intermediate_size = intermediate_size |
| 203 | self.fuse_gate_up = fuse_gate_up |
| 204 | |
| 205 | if fuse_gate_up: |
| 206 | self.gate_up_proj = SwitchLinear( |
| 207 | hidden_size, 2 * intermediate_size, num_experts, bias=bias |
| 208 | ) |
| 209 | else: |
| 210 | self.gate_proj = SwitchLinear( |
| 211 | hidden_size, intermediate_size, num_experts, bias=bias |
| 212 | ) |
| 213 | self.up_proj = SwitchLinear( |
| 214 | hidden_size, intermediate_size, num_experts, bias=bias |
| 215 | ) |
| 216 | self.down_proj = SwitchLinear( |
| 217 | intermediate_size, hidden_size, num_experts, bias=bias |
| 218 | ) |
| 219 | |
| 220 | def forward( |
| 221 | self, |