The GELU derivative, and the kink that is not there
gradient▲▲△4 d.p.
STATEMENT
Derive , evaluate it at seven points, and compare its behaviour at the origin with ReLU’s. Then state the optimisation consequence of the difference and find where the derivative is most negative.
GIVEN
with the standard normal CDF and , the standard normal density .
FIND
A closed form for ; its values at ; the value at against ReLU’s; and .
STRATEGY
Product rule, then evaluate. The interesting content is entirely in what the second term does for negative .
SOLUTION
Step 1 — differentiate. By the product rule on :
\mathrm{GELU}'(z) = \Phi(z) + z\,\phi(z) \tag{I.3.4}
Two terms with different characters. is a soft gate rising from to . The correction is positive for , negative for , and decays to zero in both tails because the Gaussian density does.
Step 2 — evaluate.
| GELU | |||
|---|---|---|---|
| undefined | |||
Step 3 — the origin. , and it is a genuine two-sided derivative: GELU is everywhere, being a product of smooth functions.
ReLU has no derivative at at all. Its left slope is , its right slope is , and every framework silently picks a subgradient from — usually , sometimes , sometimes . GELU’s is not a convention: it is the value.
Step 4 — the minimum. Setting gives , so (taking the negative root). There
The derivative goes negative. No activation studied so far does this. Between roughly and , increasing the pre-activation decreases the output.
Step 5 — the optimisation consequences. Three, in order of how often they are stated correctly.
No dead region. , which is about — vanishingly small but nonzero. So the dead-unit failure of I.3.B04 cannot occur exactly, though at the distinction is academic and fp16 will round it to zero regardless.
No kink, so second-order methods are well defined. Anything relying on curvature — natural gradient, K-FAC, or simply a smooth loss landscape — is better behaved when the activation is twice differentiable. ReLU’s Hessian is a sum of Dirac deltas at the kinks.
The negative lobe is a real functional difference. It lets a unit express “this input is moderately against my feature” with a small negative output rather than with silence. Whether that helps is empirical, and the honest answer is that GELU’s advantage over ReLU in transformers is consistent but small, and no convincing theoretical account of it exists.
Answer
exactly, where does not exist. The minimum is , so the derivative is negative on roughly .
Check — numeric · i-3-b06-gelu-derivative.py
def dgelu(z): return Phi(z) + z * phi(z)
lo = min(dgelu(z / 1000.0) for z in range(-3000, 1))Prints the table, most negative dGELU -0.1289, and dGELU(0) 0.5000.
Executed in CI. The digits above are the digits it printed.
Check — sanity
The tails match ReLU. At , ; at , . GELU is asymptotically ReLU in both directions, as its construction intends.
The derivative integrates back to the function. Between and the mean of is roughly , so the predicted rise is against the actual . Agreement to two digits from a two-point trapezoid, which is as much as that method deserves.
The minimum is where the second derivative says. at , and the numerical scan over points found , consistent with the closed-form evaluation at .
Where this breaks
Everything above is for the exact GELU. The tanh approximation , which most implementations actually use, has a slightly different derivative — the minimum is near rather than , and the two functions differ by up to about around . Small, but the two are not the same function, and a paper reporting “GELU” may mean either.
Variation
Derive the derivative of SiLU, , and find its minimum. Compare with GELU’s and say which activation has the deeper negative lobe.