r""" A [variant](https://huggingface.co/papers/2002.05202) of the gated linear unit activation function. It's similar to `GEGLU` but uses SiLU / Swish instead of GeLU. Parameters: dim_in (`int`): The number of channels in the input. dim_out (`int`): The number of channel
| 124 | |
| 125 | |
| 126 | class SwiGLU(nn.Module): |
| 127 | r""" |
| 128 | A [variant](https://huggingface.co/papers/2002.05202) of the gated linear unit activation function. It's similar to |
| 129 | `GEGLU` but uses SiLU / Swish instead of GeLU. |
| 130 | |
| 131 | Parameters: |
| 132 | dim_in (`int`): The number of channels in the input. |
| 133 | dim_out (`int`): The number of channels in the output. |
| 134 | bias (`bool`, defaults to True): Whether to use a bias in the linear layer. |
| 135 | """ |
| 136 | |
| 137 | def __init__(self, dim_in: int, dim_out: int, bias: bool = True): |
| 138 | super().__init__() |
| 139 | |
| 140 | self.proj = nn.Linear(dim_in, dim_out * 2, bias=bias) |
| 141 | self.activation = nn.SiLU() |
| 142 | |
| 143 | def forward(self, hidden_states): |
| 144 | hidden_states = self.proj(hidden_states) |
| 145 | hidden_states, gate = hidden_states.chunk(2, dim=-1) |
| 146 | return hidden_states * self.activation(gate) |
| 147 | |
| 148 | |
| 149 | class ApproximateGELU(nn.Module): |
no outgoing calls
no test coverage detected
searching dependent graphs…