← All posts
Deep Learning · Activation Functions · Vanishing & Exploding Gradients · Part 1 of 1

Plugging Minimum and Maximum Derivative Bounds Across Activation Functions

In the recurrence derivation, unrolling $\delta^{(l)} = \Bigl(\bigl(W^{(l+1)}\bigr)^{\top} \delta^{(l+1)}\Bigr) \odot \phi'\!\bigl(z^{(l)}\bigr)$ across $L$ layers with unit-scale weights ($\bigl|W^{(l+1)}\bigr|=1$) showed that if an activation function’s derivative satisfies $m \le \bigl|\phi'(z)\bigr| \le M$, then the backward gradient $\bigl|\delta^{(0)}\bigr|$ at layer $0$ is sandwiched between $m^L\bigl|\delta^{(L)}\bigr|$ and $M^L\bigl|\delta^{(L)}\bigr|$:

$$m^L \bigl|\delta^{(L)}\bigr| \;\le\; \bigl|\delta^{(0)}\bigr| = \left(\prod_{l=0}^{L-1} \bigl|\phi'\!\bigl(z^{(l)}\bigr)\bigr|\right) \bigl|\delta^{(L)}\bigr| \;\le\; M^L \bigl|\delta^{(L)}\bigr|.$$

1. Why you need both bounds: the story of $m^L$ and $M^L$

2. Plugging $m$ and $M$ in for every activation function

1. Sigmoid: $\phi(z) = \sigma(z) = \frac{1}{1+e^{-z}}$

With derivative $\phi'(z) = \sigma(z)\bigl(1-\sigma(z)\bigr) = \frac{1}{4} - \bigl(\sigma(z)-\frac{1}{2}\bigr)^2$:

$$\bigl(e^{-|z|}\bigr)^{L} \bigl|\delta^{(L)}\bigr| \;\lesssim\; \bigl|\delta^{(0)}\bigr| \;\le\; \left(\frac{1}{4}\right)^{L} \bigl|\delta^{(L)}\bigr|.$$

Cause & effect: Because $M = \frac{1}{4} < 1$, even the upper bound vanishes exponentially ($(1/4)^{10} \approx 9.5 \times 10^{-7}$). Worse, because $\sigma(z) \in (0,1)$ is strictly positive, its non-zero mean pushes next-layer pre-activations into the $|z| \gg 1$ tail where the lower bound $e^{-L|z|} \to 0$ takes over. Trying to compensate by scaling weights to $|w| > 4$ (so $|w|M > 1$) causes active paths near $z=0$ to explode as $(|w|/4)^L \to \infty$ while saturated neurons stay frozen.

2. Tanh: $\phi(z) = \tanh(z)$

With derivative $\phi'(z) = 1 - \tanh^2(z)$:

$$\bigl(4e^{-2|z|}\bigr)^{L} \bigl|\delta^{(L)}\bigr| \;\lesssim\; \bigl|\delta^{(0)}\bigr| \;\le\; 1^{L} \bigl|\delta^{(L)}\bigr| = \bigl|\delta^{(L)}\bigr|.$$

Cause & effect: Raising the ceiling from $\frac{1}{4}$ to $M = 1$ stops vanishing at the origin ($1^L = 1$). However, whenever pre-activations drift past $|z| > 2$, the derivative falls onto the exponential tail floor $\bigl(4e^{-2|z|}\bigr)^L \to 0$ (vanishing gradients); conversely, if weight spectral norms exceed $|w| > 1$ near $z \approx 0$, the upper bound scales as $(|w|\cdot 1)^L = |w|^L \to \infty$ (exploding gradients).

3. ReLU: $\phi(z) = \max(0, z)$

With piecewise-constant derivative $\phi'(z) = 0$ for $z < 0$ and $\phi'(z) = 1$ for $z > 0$:

$$0^{L} \bigl|\delta^{(L)}\bigr| = 0 \;\le\; \bigl|\delta^{(0)}\bigr| \;\le\; 1^{L} \bigl|\delta^{(L)}\bigr| = \bigl|\delta^{(L)}\bigr|.$$

Cause & effect: Active positive paths sit at the upper bound $M^L = 1^L = 1$ without any tail saturation, which solves Sigmoid/Tanh vanishing—but also removes any saturation brake, so weights exceeding He scaling explode along the positive ray as $(|w|\cdot 1)^L \to \infty$. Meanwhile, any neuron pushed into $z < 0$ hits the exact lower bound $m = 0$, zeroing out its gradient forever (Dying ReLU).

4. Leaky ReLU and PReLU: $\phi(z) = \max(\alpha z, z)$

With derivative $\phi'(z) = \alpha$ for $z < 0$ and $\phi'(z) = 1$ for $z > 0$ (for $0 < \alpha < 1$):

$$\alpha^{L} \bigl|\delta^{(L)}\bigr| \;\le\; \bigl|\delta^{(0)}\bigr| \;\le\; 1^{L} \bigl|\delta^{(L)}\bigr| = \bigl|\delta^{(L)}\bigr|.$$

Cause & effect: Lifting the minimum bound from $m = 0$ to $m = \alpha > 0$ prevents dead neurons because $\alpha^L > 0$ never hits hard zero. However, if $\alpha$ is very small (e.g. $\alpha = 0.01$), a path of $L$ negative neurons still vanishes at rate $0.01^L$; in PReLU, if learned $\alpha > 1$, the upper bound becomes $\alpha^L \to \infty$ and explodes.

5. ELU and SELU: $\phi(z) = \lambda z$ ($z \ge 0$), $\lambda\alpha(e^z - 1)$ ($z < 0$)

With derivative $\phi'(z) = \lambda$ for $z \ge 0$ and $\phi'(z) = \lambda\alpha e^z$ for $z < 0$ (where ELU has $\lambda = 1$, and SELU has $\lambda \approx 1.0507, \alpha \approx 1.6733$):

$$\bigl(\lambda\alpha e^{-|z|}\bigr)^{L} \bigl|\delta^{(L)}\bigr| \;\le\; \bigl|\delta^{(0)}\bigr| \;\le\; \lambda^{L} \bigl|\delta^{(L)}\bigr| \approx (1.0507)^{L} \bigl|\delta^{(L)}\bigr| \quad (\text{for } z > 0\text{ in SELU}).$$

Cause & effect: Deep negative inputs ($z \ll -2$) decay along the lower bound $e^{-L|z|} \to 0$. Conversely, SELU deliberately sets its positive slope to $\lambda \approx 1.0507 > 1$ so positive units expand variance to offset negative-tail contraction under LeCun initialization ($s_W^2 = 1/n_{\rm in}$); if paired with He initialization ($s_W^2 = 2/n_{\rm in}$), the upper bound explodes by $(2\lambda^2)^L \approx 2.21^L$.

6. GELU ($\phi(z) = z\Phi(z)$) and SiLU / Swish ($\phi(z) = z\sigma(\beta z)$)

By the product rule, $\phi'(z) = \Phi(z) + z\Phi'(z)$ for GELU and $\phi'(z) = \sigma(\beta z) + \beta z\sigma(\beta z)\bigl(1-\sigma(\beta z)\bigr)$ for SiLU/Swish:

$$0 \;\le\; \bigl|\delta^{(0)}\bigr| \;\le\; M^{L} \bigl|\delta^{(L)}\bigr| \qquad \Bigl(M_{\rm GELU}^L \approx 1.1289^L,\;\; M_{\rm SiLU}^L \approx 1.0998^L,\;\;\text{and at } z=0:\; (1/2)^L\Bigr).$$

Cause & effect: Both functions exhibit three distinct regimes: (1) exact zero-gradient death ($m = 0$) at the trough $z^*$ and in the deep negative tail, (2) $(1/2)^L$ vanishing if pre-activations collapse around $z = 0$, and (3) $M^L > 1$ amplification (up to $1.1289^L$ or $1.0998^L$) when activations cluster in the positive overshoot zone $z \in [1, 2.5]$.

7. SwiGLU: $\phi(u, v) = \operatorname{SiLU}(u) \odot v$

Because SwiGLU multiplies two learned projections $u = W_{\rm gate}x$ and $v = W_{\rm up}x$, its partial derivatives with respect to the two branches are $\frac{\partial \phi}{\partial u} = v \odot \operatorname{SiLU}'(u)$ and $\frac{\partial \phi}{\partial v} = \operatorname{SiLU}(u)$:

$$0 \;\le\; \bigl|\delta^{(0)}\bigr| \;\le\; \left(\prod_{l=0}^{L-1} M_{\rm SiLU}\max\!\bigl(|u^{(l)}|, |v^{(l)}|\bigr)\right) \bigl|\delta^{(L)}\bigr|.$$

Cause & effect: Small initial weights trigger a double-zero vanishing bottleneck (near $u, v \approx 0$, both branches suppress each other’s gradients), whereas large outlier features ($|u|, |v| \gg 1$) grow quadratically in the forward pass ($\phi(u,v) \approx u \odot v \propto \|x\|^2$) and push the backward upper bound $M^L \to \infty$ without Pre-RMSNorm and down-projection scaling.

8. Softmax: $p_i = \frac{e^{z_i/T}}{\sum_k e^{z_k/T}}$

Replacing the scalar derivative $\phi'(z)$ with the $K \times K$ Jacobian $J = \frac{1}{T}\bigl(\operatorname{diag}(p) - pp^{\top}\bigr)$ whose entries are $J_{ij} = \frac{1}{T}p_i(\delta_{ij} - p_j)$:

$$0 \;\le\; \left\lVert\delta^{(0)}\right\rVert \;\le\; \left(\frac{1}{2T}\right)^{L} \left\lVert\delta^{(L)}\right\rVert.$$

Cause & effect: Large logit gaps—such as unscaled attention dot products $q^{\top}k$ without $\frac{1}{\sqrt{d_k}}$—push $p_c \to 1$ onto the lower bound $m = 0$, freezing attention weights. Conversely, small temperatures $T \to 0$ blow up the upper bound $M = \frac{1}{2T} \to \infty$, exploding gradients whenever two logits are nearly tied.

3. Summary table: $m$, $M$, and $[m^L, M^L]$ across all activations

Minimum and maximum derivative bounds plugged into the $L$-layer recurrence.
ActivationMin bound $m$Max bound $M$$L$-layer bound $[m^L,\, M^L]$Vanishing vs. exploding effect
Sigmoid$0$ ($e^{-|z|}$ tail)$\frac{1}{4} = 0.25$$\bigl[0,\, (1/4)^L\bigr]$Guaranteed vanishing even at $z=0$; explodes if $|w| > 4$.
Tanh$0$ ($4e^{-2|z|}$ tail)$1$$[0,\, 1^L]$Preserves scale at $z=0$; vanishes in $|z|>2$ tails; explodes if $|w|>1$.
ReLU$0$ ($z < 0$)$1$ ($z > 0$)$[0,\, 1^L]$Hard $0$ kills negative neurons (Dying ReLU); unbounded $z>0$ explodes if $|w|>1$.
Leaky ReLU / PReLU$\alpha$ ($z < 0$)$1$ (or $\max(1,\alpha)$)$[\alpha^L,\, 1^L]$Non-zero floor $\alpha^L > 0$ prevents dead neurons; explodes if learned $\alpha > 1$.
ELU / SELU$0$ ($\lambda\alpha e^z$ tail)$1$ (ELU), $\lambda \approx 1.0507$ (SELU)$[0,\, 1.0507^L]$Negative tail vanishes as $e^{-L|z|}$; SELU’s $M > 1$ explodes under He init.
GELU$0$ ($z \approx -0.7518$ & tail)$\approx 1.1289$ ($z = \sqrt{2}$)$[0,\, 1.1289^L]$Zero slope at trough, $(1/2)^L$ at $z=0$, and $1.1289^L$ overshoot amplification.
SiLU / Swish$0$ ($\beta z \approx -1.2785$ & tail)$\approx 1.0998$ ($\beta z \approx 2.40$)$[0,\, 1.0998^L]$Zero slope at trough, $(1/2)^L$ at $z=0$, and $1.0998^L$ overshoot amplification.
SwiGLU$0$ ($u=0$ or $v=0$)$\propto \max(|u|,|v|) \to \infty$$\bigl[0,\, (\max|u|)^L\bigr]$Double-zero vanishing when small; quadratic forward & unbounded $M^L$ explosion on outliers.
Softmax$0$ ($p_c \to 1$ or $\mathbf{1}$)$\frac{1}{2T}$$\bigl[0,\, (1/2T)^L\bigr]$Logit-gap saturation drives $J \to 0$; small temperature $T \to 0$ explodes as $(1/2T)^L$.