r""" Flax implementation of a Linear layer followed by the variant of the gated linear unit activation function from https://arxiv.org/abs/2002.05202. Parameters: dim (:obj:`int`): Input hidden states dimension dropout (:obj:`float`, *optional*, defaults to 0
| 466 | |
| 467 | |
| 468 | class FlaxGEGLU(nn.Module): |
| 469 | r""" |
| 470 | Flax implementation of a Linear layer followed by the variant of the gated linear unit activation function from |
| 471 | https://arxiv.org/abs/2002.05202. |
| 472 | |
| 473 | Parameters: |
| 474 | dim (:obj:`int`): |
| 475 | Input hidden states dimension |
| 476 | dropout (:obj:`float`, *optional*, defaults to 0.0): |
| 477 | Dropout rate |
| 478 | dtype (:obj:`jnp.dtype`, *optional*, defaults to jnp.float32): |
| 479 | Parameters `dtype` |
| 480 | """ |
| 481 | |
| 482 | dim: int |
| 483 | dropout: float = 0.0 |
| 484 | dtype: jnp.dtype = jnp.float32 |
| 485 | |
| 486 | def setup(self): |
| 487 | inner_dim = self.dim * 4 |
| 488 | self.proj = nn.Dense(inner_dim * 2, dtype=self.dtype) |
| 489 | self.dropout_layer = nn.Dropout(rate=self.dropout) |
| 490 | |
| 491 | def __call__(self, hidden_states, deterministic=True): |
| 492 | hidden_states = self.proj(hidden_states) |
| 493 | hidden_linear, hidden_gelu = jnp.split(hidden_states, 2, axis=2) |
| 494 | return self.dropout_layer(hidden_linear * nn.gelu(hidden_gelu), deterministic=deterministic) |