gated_linear_unit
gated_linear_unit
¶
Gated Linear Unit activations.
Ref: Shazeer (2020), https://arxiv.org/abs/2002.05202
GatedLinearUnit
¶
Bases: Module
Gated Linear Unit with configurable activation.
GLU(x) = act(xW_gate) ⊗ (xW_value)
SwiGLU uses SiLU, GeGLU uses GELU. The gating doubles the parameter count compared to a simple linear + activation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_dimension
|
int
|
Input feature dimension. |
required |
hidden_dimension
|
int
|
Hidden dimension (output will be this size). |
required |
bias
|
bool
|
Whether to use bias in linear layers. |
False
|
gate_activation
|
Module | None
|
Activation applied to the gate projection. |
None
|
Source code in src/versatil/models/layers/gated_linear_unit.py
forward
¶
Apply the gated projection: activation(gate(x)) * value(x).
SwiGLU
¶
Bases: GatedLinearUnit
Swish-Gated Linear Unit: GLU with SiLU (Swish) activation.
Source code in src/versatil/models/layers/gated_linear_unit.py
GeGLU
¶
Bases: GatedLinearUnit
GELU-Gated Linear Unit: GLU with GELU(approximate='tanh') activation.