Foundations

Activation functions: ReLU, GELU, and SwiGLU

Modern feed-forward blocks do not merely bend the signal, they gate it: one learned branch multiplies another, which is why Qwen3.8-27B's FFN carries three matrices instead of two.

Updated

01 · Concept

Concept

Open the parameter list of any recent large language model and count the matrices in one feed-forward block. Lesson 2.2 described that block as up-project, activate, down-project — two matrices. Qwen3.8-27B has three per block, named gate, up, and down (Qwen3.8-27B Model Card, 2026). Something changed between the textbook picture and the shipped model, and the third matrix is where this lesson lives.

Begin with what the textbook version does. An activation function sits between two learned affine maps and makes their composition nonlinear. ReLU is ReLU(x)=max(0,x)\operatorname{ReLU}(x)=\max(0,x): positive inputs pass unchanged, negative inputs become zero. It is cheap, piecewise linear, has derivative one on the positive side and zero on the negative side, and it avoided the broad saturation of sigmoid and tanh that had made deep networks hard to train. Its known hazard is that flat negative side. If a unit’s pre-activation stays negative across all relevant examples, no gradient reaches it through the ReLU path and the unit is effectively dead; leaky variants keep a small negative slope to preserve a recovery route.

GELU smooths the corner. It is usually written xΦ(x)x\Phi(x), where Φ\Phi is the standard normal cumulative distribution function, so the input is scaled by how far into the distribution it sits: large positives pass almost untouched, large negatives are almost fully suppressed, and the transition near zero is gradual rather than a kink. It produces small negative outputs instead of hard zeros. SiLU, also called swish in this form, is the close cousin xσ(x)x\sigma(x) with the logistic sigmoid in place of Φ\Phi — same shape, cheaper to evaluate, and the one that ended up inside gated blocks.

Every function so far is a fixed curve applied elementwise. Feed it a number and it returns a number; the rule never depends on anything else. Here is the move that broke that pattern.

A gated linear unit projects the same input twice. One projection is the content, the other is a gate, and the two are multiplied together element by element. With SiLU on the gate branch this is SwiGLU:

SwiGLU(x)=SiLU(xWg)(xWu),\operatorname{SwiGLU}(x)=\operatorname{SiLU}(xW_{g})\odot(xW_{u}),

followed by the down projection WdW_{d} back to the model width. Three matrices, not two. The gate branch does not carry content forward; its only job is to decide, per feature and per input, how much of the content branch survives.

Work one coordinate through with numbers. Suppose for some token the gate projection produces 3.0-3.0 at coordinate jj while the content projection produces +8.0+8.0 there. The gate value is SiLU(3.0)=3.0×σ(3.0)3.0×0.0470.14\operatorname{SiLU}(-3.0)=-3.0\times\sigma(-3.0)\approx-3.0\times0.047\approx-0.14, so the output at that coordinate is about 0.14×8.01.1-0.14\times8.0\approx-1.1: a strong content signal has been almost entirely suppressed, and slightly inverted. Now take a different token where the same coordinate’s gate projection is +3.0+3.0 instead. The gate becomes 3.0×σ(3.0)3.0×0.9532.863.0\times\sigma(3.0)\approx3.0\times0.953\approx2.86, and the same content value of 8.08.0 leaves as roughly 22.922.9. Identical content, opposite fate, decided by the other branch. A fixed curve cannot do that — feed ReLU the value 8.08.0 and it returns 8.08.0 every single time, regardless of what the rest of the vector said.

Here is the classic wrong turn in evaluating this. You have a feed-forward block with intermediate width dffd_{ff} and a GELU. You swap in SwiGLU, keep dffd_{ff} the same, retrain, and measure a quality gain. It is tempting to report that gating helped. It is not a clean claim: you also added an entire extra matrix of shape dmodel×dffd_{\text{model}}\times d_{ff}, so parameters and compute rose by roughly fifty percent for that block. The gain may be gating, may be capacity, and the experiment cannot separate them. The standard correction is to shrink the intermediate width when adopting a gate, commonly to about two-thirds of the ungated value, so that the three-matrix block costs what the two-matrix block cost. Only then does the comparison isolate the mechanism.

Now put the numbers on the block. In Qwen3.8-27B each of the 64 layers holds one gated feed-forward block that takes the 5120-dimensional hidden state, projects to an intermediate width of 17408 along both the gate and the up path, multiplies, and projects back to 5120. That is roughly 267 million parameters per layer, and near 17 billion across the model (Qwen3.8-27B Model Card, 2026). Whatever else gating is, it is where the majority of this model’s parameters chose to live.

Two engineering cautions close the lesson. First, activations shape distributions across depth: large inputs amplify outputs and gradients, saturated regions suppress learning, and nonzero means shift what following layers see — which is precisely why lesson 2.8’s normalization and residual paths exist. Second, always check the exact formula and dtype the implementation uses. GELU ships in exact and approximate forms, fused kernels reassociate arithmetic, and bf16 rounding differs from the symbolic curve. Two blocks sharing an activation’s name can compute measurably different functions.

02 · Analogy

Analogy

A recording studio routes every microphone through a different kind of gate. ReLU is a hard noise gate: negative signal is shut off, positive signal passes unchanged. GELU is a soft gate that fades uncertain levels rather than cutting abruptly. SwiGLU splits the channel: one path carries content while another learned path controls how much of it passes. The choice changes both the sound moving forward and the feedback engineers receive when tuning earlier equipment.

03 · Teach it back

Teach it back

Explain why a gated activation needs three weight matrices where ReLU needs two, walk through the SwiGLU computation, and state what the gate branch buys that a fixed curve cannot.

Minimum: 80 characters and 15 words. Your writing stays only in this browser.

Waiting for your explanation.

Compare with a model answer

A plain feed-forward block is up-project, apply a fixed elementwise curve, down-project: two matrices. A gated block projects the input twice, once to a gate branch and once to a value branch, passes the gate through SiLU, multiplies the two elementwise, then projects back: three matrices, named gate, up, and down. The multiplication is the point — how strongly a feature passes is computed from the input itself rather than fixed by the curve, so suppression becomes learned and content-dependent. Qwen3.8-27B uses this gated form in every one of its 64 feed-forward blocks, expanding 5120 to 17408 and back, about 267M parameters per layer.

04 · Check your understanding

Check your understanding

01Lesson 2.2 showed that removing the nonlinearity collapses stacked affine layers into one. Which part of SwiGLU prevents that collapse?
Answer and explanation

The elementwise multiplication of the two branches, which is not an affine operation even before SiLU is applied — A product of two linear functions of the input is quadratic, not affine; the SiLU on the gate adds further curvature, but multiplication alone already breaks the collapse.

02What is ReLU's derivative for a strictly negative input, and why does it matter?
Answer and explanation

Zero — a unit that stays negative on all relevant examples receives no gradient through that path and can go dead — The flat negative side is what leaky variants and the smooth activations were designed to soften.

03Why can you not credit a quality gain to SwiGLU by swapping it into an existing block and keeping the same intermediate width?
Answer and explanation

The third matrix adds parameters and compute, so the comparison is no longer budget-matched — Architectures normally shrink the intermediate width when adopting a gate, precisely so that the comparison holds parameters roughly constant.

Complete the teach-back and answer the quiz correctly to finish this lesson.

◎ · Evidence marker

Sources

  1. Dan Hendrycks and Kevin Gimpel (2016). Gaussian Error Linear Units (GELUs).
  2. Noam Shazeer (2020). GLU Variants Improve Transformer.
  3. Qwen Team (2026). Qwen3.8-27B Model Card.