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 : 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 , where 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 with the logistic sigmoid in place of — 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:
followed by the down projection 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 at coordinate while the content projection produces there. The gate value is , so the output at that coordinate is about : 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 instead. The gate becomes , and the same content value of leaves as roughly . Identical content, opposite fate, decided by the other branch. A fixed curve cannot do that — feed ReLU the value and it returns 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 and a GELU. You swap in SwiGLU, keep 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 , 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.
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
Complete the teach-back and answer the quiz correctly to finish this lesson.
◎ · Evidence marker
Sources
- Dan Hendrycks and Kevin Gimpel (2016). Gaussian Error Linear Units (GELUs).
- Noam Shazeer (2020). GLU Variants Improve Transformer.
- Qwen Team (2026). Qwen3.8-27B Model Card.