Activation Functions in Depth
ReLU, GELU, SiLU and gated units: saturation, dead neurons and what smoothness buys.
Every non-polynomial activation makes a network a universal approximator, so expressivity cannot be why practice moved from sigmoids to ReLU, then to GELU and SwiGLU. The deciding properties are quieter: how an activation carries means, variances and gradients through depth, how smooth it is, how it gates, and what it costs.
What you’ll learn
- Explain why universality (Leshno et al., 1993) does not decide the choice of activation, and list the properties that do.
- Compute the Gaussian moments and that set forward and backward signal propagation at initialization, and derive why ReLU with preserves both at every scale.
- Derive SELU's constants from its fixed-point conditions, check the fixed point's stability, and state the assumptions of the self-normalizing theorem.
- Interpret GELU and SiLU as smooth self-gated ReLUs, and derive the hidden size that gives a SwiGLU feed-forward layer the parameters of a standard one.
Universality is not the criterion
Polynomials fail because sums of polynomials of degree in stay polynomials of degree ; every activation in use is non-polynomial, so all are universal (the proofs are in What Networks Can Represent). The choice is made on other grounds, and the useful vocabulary is this:
| Property | Why it matters | Who has it |
|---|---|---|
| Non-saturating on one side | stays away from for large inputs, so gradients survive depth | ReLU family, ELU, GELU, SiLU (right side); not sigmoid, tanh |
| Zero mean under | no bias shift handed to the next layer; avoids the sign-locked updates of positive inputs | tanh, SELU (exactly); ELU comes closer than ReLU ( against ) |
| Smooth ( or better) | well-defined Hessians; landscapes without kinks; better behaved second-order methods | tanh, sigmoid, softplus, GELU, SiLU; not ReLU (kink at ) |
| Monotone | each unit's output orders its inputs; simple to analyze | all but GELU and SiLU, which dip below |
| Exact zeros | sparse activations that hardware can skip | ReLU only |
| Cheap | a comparison is cheaper than or ; matters at inference scale | ReLU, leaky ReLU |
Two more differences are sharp. Lipschitz constants () bound how much a layer can amplify perturbations: for ReLU, leaky ReLU, ELU, softplus and tanh, for the sigmoid, about for GELU (at ) and for SiLU. And networks can die as a whole: a deep, narrow ReLU network with weights and biases drawn symmetrically around zero collapses to a constant function with probability tending to one as the depth grows (Lu, Shin, Su & Karniadakis, 2020), a failure mode of width and depth, not of a single unit.
Gaussian moments decide signal propagation
At initialization a wide layer with weights and no biases turns each pre-activation into a sum of many independent terms, approximately Gaussian: . Two expectations of under that Gaussian then control everything.
Forward. with :
Backward. The gradient obeys . Treating the weights in the backward pass as independent of the forward pass (the standard mean-field approximation), the mean squared gradient is multiplied per layer by
ReLU is scale-free. For , symmetry gives and for every , so both factors equal . The choice , He initialization (He et al., 2015), preserves forward variance and gradient size at every scale and depth. This is positive homogeneity at work: for .
Everything else depends on scale. Near , and , while large inputs saturate tanh. So the right gain depends on : for tanh at the variance drifts slowly toward the fixed point ; for GELU at the variance of a small signal halves at every layer. These maps, and the correlation maps behind the "edge of chaos", are developed in Initialization & Vanishing Gradients.
| Lipschitz | ||||
|---|---|---|---|---|
| ReLU | ||||
| leaky ReLU () | ||||
| ELU () | ||||
| SELU | ||||
| GELU | ||||
| SiLU | ||||
| softplus | ||||
| tanh | ||||
| sigmoid |
Self-normalizing networks
Can an activation make the moments converge to a target instead of merely preserving them? Klambauer, Unterthiner, Mayr and Hochreiter (2017) designed one, the scaled exponential linear unit:
Use the Gaussian integrals and . The mean condition does not involve :
The second moment fixes , with :
Stability. With normalized weights the next layer's pre-activations are , so the moments evolve as . Numerically, , and at : deviations shrink by about a fifth per layer. Klambauer et al. report a Jacobian spectral norm of about at .
Use , and to evaluate SELU's .
Show the answer
1.67
, so . The constant is not tuned by experiment: it is forced by asking for zero mean output from a standard normal input.
Read the assumptions before relying on it: independent inputs and wide layers (the Gaussian approximation), weights that stay close to normalized during training, and plain fully connected layers; ordinary dropout breaks the moments, so the paper introduces "alpha dropout".
Self-normalization also concerns activations, not gradients. Klambauer et al. argue that bounding the variance rules out exploding and vanishing gradients, but by the table above the backward factor at the fixed point is : in the mean-field picture the mean squared gradient still doubles about every ten layers going backward (the norm grows about ), and Philipp, Song and Carbonell (2017) measured exploding gradients in deep SELU networks. SELU did well on fully connected benchmarks but did not displace normalization layers, which enforce the moments explicitly at any depth and width (BatchNorm, LayerNorm & RMSNorm).
Smooth gates: GELU, SiLU and GLUs
GELU as an expected gate. Hendrycks and Gimpel (2016) derive GELU from a stochastic gate: multiply the input by , so that larger inputs are more likely to pass. The expected output is . ReLU is the deterministic gate ; GELU replaces it with a smooth, input-dependent probability. Implementations often use , which differs from by less than .
SiLU and Swish. The SiLU gates the input with its own sigmoid (Elfwing, Uchibe & Doya, 2018). Ramachandran, Zoph and Le (2017) found by automated search: is SiLU, gives ReLU, gives , and approximates GELU to within . Both are smooth and dip below zero, with a stationary point where the slope is exactly zero.
Gated linear units. Dauphin, Fan, Auli and Grangier (2017) gated one linear map with another: . Each unit multiplies two learned features, a multiplicative interaction that an additive unit cannot form in one layer. Shazeer (2020) swapped the sigmoid for other activations inside transformer feed-forward layers (GLU variants such as GEGLU and SwiGLU), without biases:
A standard feed-forward layer has two matrices; a gated one has three:
Equal parameter counts, and therefore equal FLOPs per token, require . With the usual :
Shazeer's baseline had and , so the gated variants used . In that comparison, at equal parameters and compute, GEGLU and SwiGLU reached the lowest pre-training perplexities of all the variants tried, ahead of ReLU, GELU and Swish layers.
A transformer has width and a standard feed-forward layer with . What hidden size gives a SwiGLU layer the same number of parameters?
Show the answer
4096
, against for the ungated layer. In practice the result is rounded to a hardware-friendly multiple.
What is known, and what is open
The evidence for gated layers is empirical but unusually robust. Narang et al. (2021) re-implemented dozens of proposed transformer modifications in one codebase and found that most did not help, while SwiGLU and GeGLU improved pre-training, fine-tuning and supervised training without slowing the model down. By the mid-2020s SwiGLU feed-forward layers were standard in large language models such as PaLM and LLaMA (Anatomy of a Modern LLM). Shazeer's own explanation is often quoted: "we attribute their success, as all else, to divine benevolence."
Key takeaways
- Any non-polynomial activation is universal (Leshno et al., 1993); activations differ in saturation, mean, smoothness, monotonicity, sparsity, Lipschitz constant and cost.
- At initialization, and set the forward variance and the backward gradient factor per layer; ReLU's homogeneity makes both at every scale, hence .
- SELU's and solve and ; the fixed point attracts (slope about ) under normalized weights, independent inputs and wide layers, but gradients still grow slowly.
- GELU () and SiLU () are smooth self-gated ReLUs; GLU variants multiply two projections, and keeps a SwiGLU layer at the cost of a one. Their advantage is well replicated but not explained.
Check yourself
In the interactive lesson these are scored with your confidence, and what you miss comes back for review.
Why does preserve both the forward variance and the backward gradient size of a deep ReLU network at any input scale, while no single gain does this for tanh?
- ReLU's derivative is exactly everywhere
- ReLU is positively homogeneous, so and for every variance
- ReLU outputs have mean zero
- ReLU networks are linear, so variances simply add
Show the answer
B. ReLU is positively homogeneous, so and for every variance
Homogeneity, for , makes both moment ratios independent of , so cancels them exactly. For tanh both ratios depend on (near-linear for small inputs, saturating for large), so any fixed gain is right for only one scale.
What do SELU's constants and achieve?
- They make the gradient factor exactly
- They make SELU's derivative continuous at
- They bound SELU's output to
- A standard normal input gives an output with mean and variance , so is a fixed point of the layer-to-layer moment map for normalized weights
Show the answer
D. A standard normal input gives an output with mean and variance , so is a fixed point of the layer-to-layer moment map for normalized weights
The two constants solve the two equations and for . Stability of the fixed point (slope about ) is then checked separately.
With one hidden layer of arbitrary width, which activation does not give a universal approximator on compact sets?
- GELU
- leaky ReLU
Show the answer
B.
By Leshno et al. (1993) universality holds exactly for non-polynomial activations. With , every network of one hidden layer is a polynomial of degree at most in , whatever its width.
Why do SwiGLU feed-forward layers typically use a hidden size of about instead of ?
- Gating halves the effective width, so less is needed
- Larger hidden sizes make SiLU saturate
- A gated layer has three weight matrices instead of two, and keeps parameters and FLOPs equal to the ungated layer
- It was found by a hyperparameter search to maximize accuracy
Show the answer
C. A gated layer has three weight matrices instead of two, and keeps parameters and FLOPs equal to the ungated layer
gives . The rule makes comparisons fair at equal cost; it is a bookkeeping choice, not a tuned optimum.
Further reading
- M. Leshno, V. Ya. Lin, A. Pinkus & S. Schocken, "Multilayer feedforward networks with a nonpolynomial activation function can approximate any function," Neural Networks 6 (1993).
- G. Klambauer, T. Unterthiner, A. Mayr & S. Hochreiter, "Self-normalizing neural networks," NeurIPS (2017).
- D. Hendrycks & K. Gimpel, "Gaussian error linear units (GELUs)," arXiv:1606.08415 (2016).
- P. Ramachandran, B. Zoph & Q. V. Le, "Searching for activation functions," arXiv:1710.05941 (2017).
- N. Shazeer, "GLU variants improve transformer," arXiv:2002.05202 (2020).
- S. Narang et al., "Do transformer modifications transfer across implementations and applications?," EMNLP (2021).