Activation functions: ReLU, GELU and SiLU
An activation transforms a neuron's pre-activation into its output. Its shape controls both the forward signal and the local multiplier used during backpropagation. ReLU clips negative inputs; GELU and SiLU use smooth input-dependent gates. Smoothness is a design choice, not a guarantee of higher accuracy or faster training.
Read the curves
svg
The upper plot compares outputs on identical axes. The lower plot compares derivatives: GELU and SiLU have a small negative-slope region, cross zero at their minima, and approach zero slope far to the left. ReLU has a kink at zero. The dashed vertical line marks zero input, not a learned threshold.
1. ReLU: simple, sparse, piecewise linear
The derivative does not exist at zero; automatic differentiation chooses a convention there. A negative input gives zero local gradient. A unit that stays negative over all training examples can stop learning through that path, although upstream changes can sometimes revive it. The proportion of zero outputs depends on the input distribution: 50% follows for a continuous distribution symmetric about zero, not for every trained layer. One zero output is not evidence of a dead neuron.
2. GELU: a Gaussian gate
For the standard normal cumulative distribution function and density:
GELU scales the input by a Gaussian CDF. Its probabilistic motivation does not mean that a deployed GELU layer samples a random gate. The exact expression and the common tanh approximation are different computations:
The derivative above belongs to exact GELU. Differentiate the approximation when that is what the forward pass uses. Record the approximation mode when reproducing a model or comparing kernels. GELU is smooth but not monotone: its derivative is zero near $x=-0.7518$, and its minimum output is approximately $-0.1700$.
3. SiLU: a sigmoid gate
SiLU is also called Swish with gate parameter one. A general Swish gate can have a different parameter. SiLU has a zero derivative near $x=-1.2785$ and a minimum output near $-0.2785$. Both smooth activations have derivative $1/2$ at zero; both can have very small gradients at strongly negative inputs. Neither guarantees the absence of vanishing gradients. For large positive inputs both approach the identity, so their outputs are not bounded above.
Worked comparison
At input $x=-1$, ReLU returns zero; exact GELU returns approximately $-0.15866$ with derivative $-0.08332$; SiLU returns approximately $-0.26894$ with derivative $0.07233$. Negative output does not imply negative derivative. The lab below independently checks analytic derivatives against finite differences and locates each smooth activation's minimum.
Related choices: leaky ReLU, ELU, SELU and gated blocks
Leaky ReLU uses a chosen positive negative-side slope:
ELU has an exponential negative branch:
ELU's derivative is continuous at zero only when $\alpha=1$. SELU scales an ELU with particular constants; its self-normalization result concerns convergence toward zero mean and unit variance under architectural, initialization and distributional conditions. It does not promise unit mean or replace normalization in arbitrary networks.
SwiGLU is a gated block, not merely another name for elementwise SiLU. For compatible projected vectors, a common bias-free form is:
Here the product is elementwise. A comparison against an ordinary feed-forward block must account for the extra projection and any adjusted hidden width.
Choose with a controlled experiment
Start with the activation specified by the architecture or checkpoint. Changing a pretrained model's activation without retraining is not a controlled ablation. For a new model, compare under a fixed data split and training budget, with several seeds. Record validation quality, convergence, activation distributions and gradient statistics. Retune initialization or optimization only under a declared equal tuning budget.
ReLU's comparison is inexpensive; exponentials, error functions and tanh cannot be assigned a universal two- or three-FLOP cost. Runtime depends on precision, vectorization, kernel fusion, memory traffic, tensor shape and device. Measure warm steady-state latency and end-to-end throughput on the deployment hardware. Sparse zeros do not automatically produce sparse-kernel speedups. A fused smooth activation may cost little in one workload and matter in another.
ReLU remains useful; smooth functions are not universally more expressive, better regularized, or free of optimization difficulties. Depth alone does not select an activation. Claims about accuracy, perplexity, dead-unit rate or speed need a named model, dataset, training recipe and hardware measurement. There is no universal percentage advantage in this survey.
Reproducible numerical lab — Python standard library
import math
def sigmoid(x):
if x >= 0:
return 1 / (1 + math.exp(-x))
e = math.exp(x)
return e / (1 + e)
def gelu(x):
return x * 0.5 * math.erfc(-x / math.sqrt(2))
def dgelu(x):
return 0.5 * math.erfc(-x / math.sqrt(2)) + x * math.exp(-x*x/2) / math.sqrt(2*math.pi)
def silu(x):
return x * sigmoid(x)
def dsilu(x):
s = sigmoid(x)
return s + x*s*(1-s)
def minimum(df):
lo, hi = -2.0, 0.0
assert df(lo) < 0 < df(hi)
for _ in range(70):
mid = (lo+hi)/2
if df(mid) < 0:
lo = mid
else:
hi = mid
return (lo+hi)/2
for name, f, df in [('GELU', gelu, dgelu), ('SiLU', silu, dsilu)]:
for x in [-3, -1, -0.2, 0, 0.4, 1, 3]:
h = 1e-5
assert abs((f(x+h)-f(x-h))/(2*h)-df(x)) < 1e-8
assert f(0) == 0 and df(0) == 0.5
root = minimum(df)
assert abs(df(root)) < 1e-12
assert f(root) < f(root-0.01) and f(root) < f(root+0.01)
print(name, 'minimum input/output:', round(root, 6), round(f(root), 6))
print('at -1:', round(f(-1), 6), 'slope:', round(df(-1), 6))
assert abs(gelu(-1) + 0.15865525393145707) < 1e-14
assert abs(silu(-1) + 1/(1+math.e)) < 1e-14
assert math.isfinite(silu(-1000))
print('All derivative and value checks passed.')This is a scalar correctness check, not a hardware benchmark. The SVG curves are sampled from these same exact functions. Finite differences avoid the ReLU kink; the derivative at that kink is intentionally omitted from the plot.
Sources and implementation references
Hendrycks and Gimpel, Gaussian Error Linear Units (2016): https://arxiv.org/abs/1606.08415
PyTorch activation definitions and GELU approximation modes: https://docs.pytorch.org/docs/stable/nn.functional.html
Klambauer et al., Self-Normalizing Neural Networks (2017): https://arxiv.org/abs/1706.02515
Shazeer, GLU Variants Improve Transformer (2020): https://arxiv.org/abs/2002.05202