Skip to content

Stochastic depth

Stochastic depth gates residual branches during training. Compare original and inverted scaling, enumerate a two-branch chain, and see why mean matching is not exact ensemble prediction.

Stochastic depth randomly bypasses whole residual branches during training while retaining the shortcut path. It regularises a residual network by exposing its shared parameters to networks of varying effective depth. For a financial forecasting encoder, this changes the training procedure; its value must still be established on eligible later data.
A branch can contain several layers. Bypassing it is temporary, unlike permanent neural-network pruning, and differs from ordinary dropout that masks individual activations. The mechanism was introduced by Huang and coauthors (2016), Section 3.

Keep the shortcut, gate the correction

For a shape-preserving residual addition, write

xℓ+1=xℓ+bℓFℓ(xℓ),bℓ∼Bernoulli⁡(qℓ).x_{\ell+1}=x_\ell+b_\ell F_\ell(x_\ell),\qquad b_\ell\sim\operatorname{Bernoulli}(q_\ell).
Here qℓq_\ell is the survival probability, not the drop probability. When bℓ=0b_\ell=0, the branch contributes nothing and the shortcut passes the input onward. The gate belongs on the residual branch, before addition; masking the sum would also erase the shortcut.

This equation isolates the addition without a subsequent activation. The original paper includes a post-addition ReLU; its identity bypass relies on nonnegative incoming activations. Shape-changing blocks also need a compatible shortcut rather than an unqualified identity.

The paper uses unscaled surviving branches in training and multiplies each branch by its survival probability at inference:

xℓ+1test=xℓtest+qℓFℓ(xℓtest).x_{\ell+1}^{\mathrm{test}} =x_\ell^{\mathrm{test}}+q_\ell F_\ell(x_\ell^{\mathrm{test}}).

Thus all branches are available at inference. “Randomly shallower during training” does not mean permanently deploying a smaller model.

Enumerate a two-branch network

Consider an original synthetic scalar chain starting at 1010, with constant residual contributions 22 and 44. Masks are independent, with survival probabilities q1=0.8q_1=0.8 and q2=0.5q_2=0.5. All quantities are dimensionless; there is no fitted market model.

First mask b1b_1Second mask b2b_2ProbabilityTraining output 10+2b1+4b210+2b_1+4b_2
000.1010
010.1014
100.4012
110.4016

The complete probability-weighted mean is

0.1(10)+0.1(14)+0.4(12)+0.4(16)=13.6.0.1(10)+0.1(14)+0.4(12)+0.4(16)=13.6.

Scaled inference also gives 10+0.8(2)+0.5(4)=13.610+0.8(2)+0.5(4)=13.6. The expected number of active residual branches during training is 0.8+0.5=1.30.8+0.5=1.3, compared with both branches at inference. This counts branches, not individual layers or elapsed computation time.

Four possible training outputs have probabilities: 10 at 10%, 12 at 40%, 14 at 10%, and 16 at 40%. Their mean is 13.6. Both residual branches are active at inference, scaled by survival, giving 13.6.
Four possible training outputs have probabilities: 10 at 10%, 12 at 40%, 14 at 10%, and 16 at 40%. Their mean is 13.6. Both residual branches are active at inference, scaled by survival, giving 13.6.
Original exact enumeration of a synthetic constant-branch chain. The dashed line is the probability-weighted training mean; the inference value matches it in this restricted example.
Matching this mean is not exact ensemble prediction for a nonlinear network. Append the readout g(y)=max⁡(0,y−14)g(y)=\max(0,y-14). Only the outcome 1616 contributes, so the mean readout is 0.4(2)=0.80.4(2)=0.8. Deterministic inference instead gives g(13.6)=0g(13.6)=0. Input-dependent residual branches introduce further nonlinear composition. Replacing each mask by its mean cannot generally reproduce averaging all network outputs.

Check the scaling and the mask shape

Current Torchvision source uses inverted survival scaling: for qℓ>0q_\ell>0, the training branch is (bℓ/qℓ)Fℓ(x)(b_\ell/q_\ell)F_\ell(x) and inference leaves Fℓ(x)F_\ell(x) unchanged. Its argument p is the drop probability, 1−qℓ1-q_\ell. Do not apply the original inference multiplier on top of this convention.

With the same fixed constants, inverted scaling gives a training mean and ordinary inference value of 1616, rather than 13.613.6. This compares two operators on stipulated branches; it is not a claim that models trained under the two conventions learn identical parameters.

Torchvision's batch mode shares one gate across the whole mini-batch. Its row mode samples a gate per example, broadcasting it across that example's remaining dimensions. Neither mode independently drops each feature or token. Its function receives an already computed branch tensor, so zeroing that tensor alone does not skip the preceding branch computation. Actual speed savings require an execution path that avoids that work.
For residual addition and tensor-shape foundations, see Normalization, Residual Connections, and Stable Deep Architectures. The preview is public; the full lesson requires membership.

Sources

  • Huang, Sun, Liu, Sedra and Weinberger (2016), Deep Networks with Stochastic Depth, Section 3, Equations 2–5: branch gating, survival schedules, effective depth and original inference scaling. The enumeration and nonlinear readout here are original.
  • Torchvision, stochastic_depth documentation and upstream implementation, accessed 1 November 2026: drop-probability argument, batch/row broadcasting, inverted training scaling and evaluation identity.
Last updated
  • neural networks
  • regularisation
  • residual networks
  • stochastic depth
← Back to the glossaryBack to top ↑