Skip to main content

Activations and Gated Feed-Forward Networks

“ReLU is obsolete” is too broad; “learn only ReLU, sigmoid, and tanh” is outdated. Choices now differ by architecture, scale, precision, kernels, and hardware. Transformer FFNs also often replace a plain two-layer path with a gated one, which changes more than an elementwise function.

Elementwise Functions

NameDefinition or roleStrengthBoundary
ReLUmax(0,x)\max(0,x)cheap, exact zeros, nonsaturating positive sidezero negative gradient; kink at zero
Leaky/PReLUmax(ax,x)\max(ax,x)retains negative-side gradientadds an assumption or parameter
GELUxΦ(x)x\Phi(x)smooth magnitude-dependent scalingapproximation and kernel variants; no exact sparsity
SiLU/Swishxσ(βx)x\sigma(\beta x)smooth and permits small negative outputsnonmonotonic region; kernel and quantization costs
Sigmoidσ(x)\sigma(x)[0,1][0,1] gate or probability mapsaturates at large magnitude
Tanhtanh(x)\tanh(x)bounded, zero-centered recurrent statesaturates at both ends

GELU may use erf or tanh approximations. The Swish paper studies learnable β\beta; framework SiLU commonly fixes β=1\beta=1. Papers often use the names nearly interchangeably, so record the implementation.

Smooth Does Not Mean Universally Better

Smooth functions can help some large training regimes, but their effects interact with initialization, normalization, width, data, optimization, and fused kernels. ReLU remains a counterexample to a simple progress story: cheap kernels and exact zeros can matter in convolutional, lightweight, or quantized deployment; small-data error may be dominated by regularization; and a stable ReLU baseline reveals whether a gated model merely added parameters.

GLUs and Gated FFNs

A plain Transformer FFN is

FFN(x)=W2ϕ(W1x+b1)+b2.\operatorname{FFN}(x)=W_2\phi(W_1x+b_1)+b_2.

A simplified GLU multiplies two paths:

GLU(x)=A(x)σ(B(x)).\operatorname{GLU}(x)=A(x)\odot\sigma(B(x)).

Common Transformer variants include

GEGLU(x)=Wo(GELU(Wgx)Wvx),\operatorname{GEGLU}(x)=W_o\left(\operatorname{GELU}(W_gx)\odot W_vx\right), SwiGLU(x)=Wo(SiLU(Wgx)Wvx).\operatorname{SwiGLU}(x)=W_o\left(\operatorname{SiLU}(W_gx)\odot W_vx\right).

ReGLU substitutes ReLU in the gate branch. A gated layer has three major projections (Wg,Wv,WoW_g,W_v,W_o) rather than two. Equal-parameter comparisons therefore reduce its intermediate width; there is no universal ratio once biases, embeddings, and alignment constraints are counted.

Dated Architecture Examples

The BERT paper used GELU; PaLM reported SwiGLU; the Llama 3 architecture report combines SwiGLU with RMSNorm, RoPE, and GQA; ConvNeXt showed GELU in a modern ConvNet. These establish specific designs, not universal superiority. When several block changes move together, their aggregate result cannot be attributed to activation alone.

Output Activations Are a Separate Decision

Binary classification commonly trains one logit; exclusive multiclass uses logits with Softmax; multilabel uses independent sigmoids; regression support determines whether output is linear, positive, or bounded. Stable losses generally consume logits directly rather than manually applying sigmoid/Softmax before a logarithm.

Failure Modes

SymptomCandidate causeCheck
permanently zero unitsdead ReLU, large learning rate, shifted inputshistograms, gradients, Leaky control
near-zero gradientssaturation or bad scalingpre-activation distribution and initialization
collapsed gatesgate/value scale imbalancebranch norms and an ungated baseline
mixed-precision NaNsextremes, approximation, loss scalingfp32 control and finite-value assertions
slower “new” functionmissing fused kernel or extra projectionend-to-end throughput, not FLOPs alone
post-quantization lossrange and calibration mismatchevaluation on target hardware

Controlled Selection

Fix split, initialization family, optimizer, steps, and stopping rule. For plain ReLU/GELU/SiLU FFNs, make widths and parameter counts explicit. For GEGLU/SwiGLU, report intermediate width, total parameters, FLOPs, memory, and target-hardware throughput. Repeat seeds and predeclare quality, latency, memory, and stability thresholds.

This note is biased toward dense GPU-trained Transformers. Periodic activations, implicit neural representations, splines, spiking models, and specialized accelerators may require different criteria. Ask whether a new function changes representation, optimization, budget, or kernel before adding it to an activation zoo.