Common Activation Functions
Common elementwise activation functions.
Groups the classical textbook activation functions: the sigmoid/tanh family, the smooth softplus family, and the core rectifier / gating units used in the feed-forward network. These are stateless (no learnable parameters).
Formulations follow Lederer (arXiv:2101.09957) and the survey by Dubey et al. (arXiv:2109.14545).
- class src.model.activation_function.common.Arctan(*args: Any, **kwargs: Any)[source]
Bases:
ModuleInverse tangent:
arctan(x).Range
(-pi/2, pi/2). Monotonic, smooth, bounded. Reference: Lederer §2.1.2.
- class src.model.activation_function.common.Elliott(*args: Any, **kwargs: Any)[source]
Bases:
ModuleElliott activation (fast sigmoid approximation):
x / (1 + |x|).Alias of
Softsign; the survey (arXiv:2109.14545) lists it under the name “Elliott”. Range(0, 1)for the one-sided variant, but the implemented two-sided form matches the standardelliottsig.
- class src.model.activation_function.common.GELU(*args: Any, **kwargs: Any)[source]
Bases:
ModuleGaussian Error Linear Unit (exact):
x * Phi(x) = x * 0.5 * (1 + erf(x / sqrt(2))).Range
(-0.17, inf). Smooth, probabilistic. Used in BERT, GPT-2/3. Reference: Hendrycks & Gimpel (2016), arXiv:1606.08415; survey §7.2.
- class src.model.activation_function.common.GELUTanh(*args: Any, **kwargs: Any)[source]
Bases:
ModuleGELU with the tanh approximation.
0.5 * x * (1 + tanh(sqrt(2/pi) * (x + 0.044715 * x^3))).Faster than exact GELU; the approximation used by the original GPT-2 and BERT implementations.
- class src.model.activation_function.common.Identity(*args: Any, **kwargs: Any)[source]
Bases:
ModuleIdentity / linear activation:
f(x) = x.Range
(-inf, inf). Useful as a no-op activation. Reference: Lederer §2.2.1.
- class src.model.activation_function.common.Mish(*args: Any, **kwargs: Any)[source]
Bases:
ModuleMish:
x * tanh(softplus(x)) = x * tanh(log(1 + e^x)).Non-monotonic, smooth, self-regularized. Reported to outperform Swish on several benchmarks. Reference: Misra (2019), arXiv:1908.08681; survey §7.1.
- class src.model.activation_function.common.ReLU(*args: Any, **kwargs: Any)[source]
Bases:
ModuleRectified Linear Unit:
max(0, x).Range
[0, inf). Reference: Nair & Hinton (2010); Lederer §2.2.2.
- class src.model.activation_function.common.SiLU(*args: Any, **kwargs: Any)[source]
Bases:
ModuleSigmoid Linear Unit (SiLU / Swish with beta=1):
x * sigmoid(x).Range
(-0.278, inf). Smooth, non-monotonic. Default FFN activation in Llama, PaLM, and this codebase. Reference: Elfwing et al. (2018), Ramachandran et al. (2017) arXiv:1710.05941; survey §3.
- class src.model.activation_function.common.Sigmoid(*args: Any, **kwargs: Any)[source]
Bases:
ModuleLogistic sigmoid:
1 / (1 + e^{-x}).Range
(0, 1). Monotonic, smooth, bounded. Reference: Lederer §2.1.1.
- class src.model.activation_function.common.Softplus(*args: Any, **kwargs: Any)[source]
Bases:
ModuleSoftplus:
log(1 + e^x).Smooth approximation of ReLU; an antiderivative of the logistic sigmoid. Range
[0, inf). Reference: Lederer §2.3.1, Glorot et al. (2011).
- class src.model.activation_function.common.Softsign(*args: Any, **kwargs: Any)[source]
Bases:
ModuleSoftsign (Elliott activation):
x / (1 + |x|).Range
(-1, 1). Once-differentiable at 0, smooth elsewhere. Cheaper than tanh. Reference: Lederer §2.1.4 (also calledelliottsig).
- class src.model.activation_function.common.Swish(*args: Any, **kwargs: Any)[source]
Bases:
ModuleParametric Swish:
x * sigmoid(beta * x)with fixedbeta.Range
(-c, inf)wherec ~= 0.278 / beta. Non-monotonic, smooth. Whenbeta = 1this reduces to SiLU. Largebetaapproaches ReLU. UseSwishTrainablefor a learnablebeta.- Parameters:
beta – Fixed positive slope. Default:
1.0.
- beta
The (fixed) sigmoid slope.
Reference: Ramachandran et al. (2017), arXiv:1710.05941; survey §6.