Md. Asif Uddin
Problem I.3.B03

The depth at which a sigmoid stack stops passing gradient

limit▲▲▲

Derivatives to 6 s.f.; products in scientific notation.

STATEMENT

Find the maximum of σ\sigma'. Compute the product of ten sigmoid derivatives at z=4|z| = 4. Then find the depth at which the product underflows fp16, both at z=4|z| = 4 and in the best case.

GIVEN

σ(z)=σ(z)(1σ(z))\sigma'(z) = \sigma(z)(1-\sigma(z)) from I.3.B02. The smallest positive fp16 value is the subnormal 224=5.96×1082^{-24} = 5.96\times10^{-8} (Floating point 0.NU.01). A gradient reaching layer 11 of an LL-layer stack is multiplied by one σ\sigma' per layer.

FIND

maxzσ(z)\max_z \sigma'(z); the value of σ(4)10\sigma'(4)^{10}; and the smallest LL with σL<224\sigma'^{\,L} < 2^{-24} at z=4|z| = 4 and at z=0z = 0.

STRATEGY

Maximise the derivative by treating it as a quadratic in σ\sigma rather than in zz — the substitution turns calculus into inspection. Then take logarithms to turn the repeated product into a linear count.

SOLUTION

Step 1 — the maximum. Let s=σ(z)(0,1)s = \sigma(z) \in (0,1). Then σ=s(1s)=ss2\sigma' = s(1-s) = s - s^2, a downward parabola in ss with vertex at s=1/2s = 1/2:

maxσ=12(112)=14=0.2500\max \sigma' = \tfrac12\left(1 - \tfrac12\right) = \tfrac14 = 0.2500

and s=1/2s = 1/2 means z=0z = 0. So the best a sigmoid ever does for a gradient is divide it by four, and it does that only at one point.

Step 2 — the derivative at z=4|z| = 4. σ(4)=1/(1+e4)=0.982014\sigma(4) = 1/(1+e^{-4}) = 0.982014, so

σ(4)=(0.982014)(0.017986)=0.0176627\sigma'(4) = (0.982014)(0.017986) = 0.0176627

Fourteen times smaller than the best case, from a pre-activation that is not extreme — z=4z = 4 is entirely ordinary in an unnormalised network.

Step 3 — ten layers.

σ(4)10=(0.0176627)10=2.955×1018\sigma'(4)^{10} = (0.0176627)^{10} = 2.955\times10^{-18}

For comparison the best case gives 0.2510=9.537×1070.25^{10} = 9.537\times10^{-7}. Even at every layer’s single most favourable point, ten layers cost six orders of magnitude.

Step 4 — the fp16 depth. Solve gL<224g^{L} < 2^{-24} by taking logarithms:

L>24ln2lng=16.6355lngL > \frac{-24\ln 2}{\ln g} = \frac{-16.6355}{\ln g}

At z=4|z| = 4, ln(0.0176627)=4.0362\ln(0.0176627) = -4.0362, so L>4.12L > 4.12, giving L=5\boxed{L = 5}.

At z=0z = 0, ln(0.25)=1.3863\ln(0.25) = -1.3863, so L>11.999L > 11.999, giving L=12\boxed{L = 12}.

What the two numbers say. A sigmoid network in fp16 has a hard ceiling of about twelve layers even under conditions that never occur — every unit sitting exactly at its most favourable point on every example. In realistic conditions, with pre-activations spread over a range including z=4|z| = 4, the ceiling is five. Not “training is slow past five layers”: the gradient is exactly zero, because the product is not representable and rounds to it.

This is why deep networks were not trained before roughly 2010, and it is why three separate later chapters exist. ReLU (this chapter) removes the shrinking factor entirely for active units. Normalisation (I.8) keeps zz near the favourable region. Residual connections (II.6) provide a path with derivative exactly 11 that no activation stands on.

Answer

maxzσ(z)=14,σ(4)10=2.955×1018\max_z \sigma'(z) = \tfrac14, \qquad \sigma'(4)^{10} = 2.955\times10^{-18}

fp16 underflow at depth 5\mathbf{5} for z=4|z| = 4, and at depth 12\mathbf{12} in the impossible best case z=0z = 0 throughout.

Check — numeric · i-3-b03-saturation-depth.py
def dsigmoid(z): s = sigmoid(z); return s * (1.0 - s)
prod, L = 1.0, 0
while prod > 2.0 ** -24: prod *= g; L += 1

Prints max sigma' 0.2500, sigma'(4)^10 2.955102e-18, and both depths.

Executed in CI. The digits above are the digits it printed.

Check — sanity

The maximum is attained where the function is symmetric. σ\sigma' inherits σ(z)=1σ(z)\sigma(-z) = 1-\sigma(z), so σ(z)=σ(z)\sigma'(-z) = \sigma'(z): the derivative is even, and an even function’s extremum on R\R sits at 00 unless it is bimodal. Consistent.

The logarithmic estimate agrees with the loop. The closed form gave L>4.12L > 4.12 and the loop counted 55; L>11.999L > 11.999 and the loop counted 1212. Two methods, same answer.

The magnitudes bracket correctly. 2.955×1018<9.537×1072.955\times10^{-18} < 9.537\times10^{-7}, since 0.0177<0.250.0177 < 0.25 and both are raised to the same power. A product of smaller numbers must be smaller.

Where this breaks

The analysis assumes every layer’s derivative is the same, which it is not: real pre-activations vary per unit and per example, so the true product is a mix of factors. That makes the situation worse, not better — the product is dominated by its smallest factors, and a single saturated layer anywhere in the stack zeroes the whole path regardless of how favourable the others are.

The analysis also assumes fp16 without loss scaling. Multiplying the loss by 2152^{15} before the backward pass shifts every gradient up by that factor and buys about four more layers, which is exactly what mixed-precision training does (II.8.B04). It buys layers; it does not remove the mechanism.

Variation

Repeat for tanh, whose maximum derivative is 11 rather than 1/41/4. Find the fp16 depth at z=4|z| = 4 and state how many extra layers tanh buys over sigmoid — then say whether that is enough to matter.

Draws on