Deep Networks with Stochastic Depth
- Publication
- ECCV 2016Conference
- First submitted to arXiv
- arXiv:1603.09382
Cite this paper · BibTeX
The citation identifies the linked source version. It cites the original paper and its authors.
@misc{classiccnnsstochasticdepth2016,
title = {{Deep Networks with Stochastic Depth}},
author = {Gao Huang and Yu Sun and Zhuang Liu and Daniel Sedra and Kilian Weinberger},
year = {2016},
eprint = {1603.09382},
archivePrefix = {arXiv},
url = {https://arxiv.org/abs/1603.09382}
}
Training very deep networks comes with a dilemma.
In a shallow network, signals flow smoothly forward and backward and training is fast, but its expressive power is limited. A deep network is more expressive, but gradients vanish, features computed early on get washed out by layer after layer of weights, and training time grows along with depth, so a 152-layer ResNet takes weeks to train on ImageNet even with several GPUs.
What if you trained a shallow network and tested a deep one?
That sounds self-contradictory. In March 2016, Gao Huang, Yu Sun, Daniel Sedra, and Kilian Q. Weinberger of Cornell University, together with Zhuang Liu of Tsinghua University, released this paper. They build the network just as deep, but for every mini-batch during training, they randomly remove some of the residual blocks, leaving only their shortcuts.
Defining the Problem
The authors list three problems that very deep networks run into:
- Vanishing gradients: as gradients propagate backward, they're multiplied by small weights again and again, so by the time they reach the early layers they've become tiny.
- Diminishing forward features: input features, or features computed by early layers, are multiplied again and again by randomly initialized weights until they're “washed out” further on, which makes it hard for later layers to find meaningful gradient directions.
- Training takes too long: forward and backward propagation time both grow linearly with depth.
ResNet and Highway Networks tackle the first two problems with shortcuts that let features and gradients bypass weight layers. The third problem remains. However deep the network is, every step has to compute that many layers.
Is there a way to make a network shallower “on average” during training while keeping its full depth at test time?
Solving the Problem
Letting Blocks Randomly Sit Out
The authors use ResNet's original residual block. The output of block is:
is “convolution, BN, ReLU, convolution, BN,” and is the identity shortcut.
Stochastic depth adds just one Bernoulli random variable, :
When , this is the original residual block. When , the residual branch disappears entirely, leaving .
is the output of the previous block's final ReLU, so it's never negative (the input to the first block is also the output of a “convolution, BN, ReLU” stack), which means . An absent block is therefore exactly an identity mapping, and the signal passes to the next block untouched.
The probability that is written , which the authors call the survival probability. It's redrawn for every mini-batch, and a block drawn to sit out costs nothing at that step, with no forward pass, no backward pass, and no weight update.
Early Layers Show Up More Often
How should each block's survival probability be set? The simplest choice is to make them all the same. The authors recommend a linear decay, with at the input, for the last block, and a proportional decrease in between:

Early layers extract low-level features that every later layer uses, so the authors argue that they should show up more reliably. The experiments also show linear decay beating a uniform probability; and since results aren't very sensitive to , they use throughout the paper.
Take the 110-layer ResNet commonly used in CIFAR experiments. It has residual blocks, with survival probabilities falling linearly from 0.991 for the first block to 0.5 for the last. During training, each pass uses only about 40 blocks on average, while testing uses all 54. The expected depth is , about ; the quarter left uncomputed is what training time saves. The depth of each sampled network also varies a lot, so some updates go through especially short networks, and the gradient's path to the early layers is more direct.
Multiply by the Survival Probability at Test Time
At test time, every block has to be present so the full capacity of the network gets used. But during training, appears in only a fraction of the updates, and the next layer's weights are calibrated to that fraction. So at test time, each block's output is multiplied by its survival probability:
Let's write a block and compare its outputs during training and testing. To keep things easy to see, the residual function here is a single linear layer, and we leave out the final ReLU for now:
import torch
import torch.nn as nn
class StochasticDepthBlock(nn.Module):
def __init__(self, f, p):
super().__init__()
self.f, self.p = f, p # p: this block's survival probability
def forward(self, x):
if self.training:
if torch.rand(()) < self.p: # survives: compute the residual as usual
return x + self.f(x)
return x # doesn't survive: the whole block becomes an identity mapping
return x + self.p * self.f(x) # testing: multiply by the survival probability
torch.manual_seed(0)
block = StochasticDepthBlock(nn.Linear(4, 4), p=0.6)
x = torch.randn(1, 4)
block.train()
with torch.no_grad():
outs = torch.stack([block(x) for _ in range(20000)])
block.eval()
with torch.no_grad():
test = block(x)
print("During training, the block produces", torch.unique(outs.round(decimals=4), dim=0).shape[0], "distinct outputs")
print("Mean of training outputs:", [f"{v:.3f}" for v in outs.mean(0).squeeze()])
print("Output at test time: ", [f"{v:.3f}" for v in test.squeeze()])
During training, the block produces 2 distinct outputs
Mean of training outputs: ['-0.479', '0.711', '-1.017', '1.223']
Output at test time: ['-0.479', '0.713', '-1.017', '1.223']
During training, this block's output either includes the residual or doesn't. Averaged over twenty thousand runs, it is almost identical to the test-time output, which multiplies by .
Why Does It Work?
The authors give three reasons.
- Faster training: skipped blocks aren't computed, so forward and backward propagation time follows the expected depth rather than the full depth.
- Stronger gradients: the network is shorter during training, so gradients pass through fewer layers, and the early layers receive larger gradients.
- An implicit ensemble: with 54 blocks, each either present or absent, there are combinations in all. Each mini-batch samples one weight-sharing sub-network to update, and at test time the formula above merges them into a single network. The record-breaking results in the ResNet paper came precisely from an ensemble of ResNets of different depths.
This ensemble view resembles dropout. The difference is that dropout makes the network narrower, while stochastic depth makes it shallower. The authors also note that dropout often becomes less effective when combined with batch normalization. They tried various dropout rates on a 110-layer ResNet with BN and saw almost no improvement, while stochastic depth still worked on the same network.
Discussion
Error Rates and Training Time
| Method | CIFAR-10+ | CIFAR-100+ | SVHN | ImageNet |
|---|---|---|---|---|
| Highway Network | 7.60 | 32.24 | – | – |
| Gen. Pool | 6.05 | 28.02 | 1.69 | – |
| ResNet, constant depth | 6.41 | 27.76 | 1.80 | 21.78 |
| ResNet, stochastic depth | 5.25 | 24.98 | 1.75 | 21.98 |
CIFAR-10 uses a 110-layer ResNet trained for 500 epochs. With constant depth, the error is 6.41%; adding stochastic depth brings it down to 5.25%, an 18% relative improvement. The training and network settings are exactly the same; the only difference is randomly skipping blocks during training. CIFAR-100 uses the same network and goes from 27.76% to 24.98%.

After the first learning-rate drop, the constant-depth test error more or less stalls, while stochastic depth keeps going down. The authors also notice that the stochastic-depth test error fluctuates more, presumably because the depth keeps changing during training.
Without data augmentation, stochastic depth also gives about a 15% relative improvement on both CIFAR-10 and CIFAR-100, from 13.63% to 11.66% and from 44.74% to 37.8%, respectively. SVHN uses a 152-layer network; with constant depth it starts to overfit as soon as the second phase begins, ending at 1.80% error, while stochastic depth gets 1.75%.
Training time compared:
| CIFAR-10+ | CIFAR-100+ | SVHN | |
|---|---|---|---|
| Constant depth | 20 h 42 min | 20 h 51 min | 33 h 43 min |
| Stochastic depth | 15 h 7 min | 15 h 20 min | 25 h 33 min |
Every setting saves about a quarter of the time, consistent with the expected depth computed earlier.
Twelve Hundred Layers
The ResNet paper tried a 1202-layer network, which overfit, ending with 7.93% test error, worse than 110 layers. The authors redo this experiment with the same 1202-layer network, training for 300 epochs with a warm-up learning rate of 0.01 for the first 10 epochs.
The constant-depth 1202-layer network gets 6.67% error, again worse than the 110-layer network's 6.41%. With stochastic depth, the error is 4.91%, a 27% relative improvement over the constant-depth 1202-layer network and better than the stochastic-depth 110-layer network (5.25%) as well, with no sign of overfitting. The authors say this is the first time a network with more than a thousand layers has reduced test error further than a shallower network.
No Win on ImageNet
ImageNet uses the 152-layer ResNet. Trained for 90 epochs with constant depth, it gets 23.06% error; with stochastic depth, it's at 23.38% at epoch 90, slightly worse. The authors observed that the stochastic-depth validation error was still clearly falling, and since stochastic depth saves 25% of the computation, training it for 30 more epochs takes about the same total time as 90 epochs at constant depth. With the extra training, stochastic depth reaches 21.98%; but constant depth was also run for 30 more epochs, and it reached 21.78%.
So in this setting, stochastic depth brings no accuracy benefit. The authors cite an anonymous reviewer's view that models for ImageNet are still in a different regime from those for CIFAR. The model complexity ImageNet calls for may far exceed a 152-layer ResNet, and stochastic depth may only show its effect with larger models.
Are the Gradients Really Stronger?

The two sharp drops come from the learning-rate schedule. Stochastic depth's gradients are larger throughout, and the gap widens after the learning-rate drops, which supports the authors' claim that it alleviates vanishing gradients.
What Should the Survival Probability Be?

is the method's only hyperparameter, and the left plot shows how it affects the error rate.
- As long as is set reasonably, both rules beat constant depth.
- For most values of , linear decay beats a uniform probability.
- Linear decay isn't very sensitive to , giving good results for between 0.4 and 0.8.
- Even at , linear decay's error is on par with constant depth, while training time drops by 40%.
The heat map on the right adds depth. For a 20-layer network, skipping a little ( between 0.9 and 0.7) beats constant depth, but skipping more makes it worse, with the error rising from 8.31% to 9.39% at . For a 110-layer network, is best. The best-performing cells lie roughly along the diagonal, meaning the deeper the network, the more aggressive the skipping it can handle. The network has to be deep enough for stochastic depth to clearly beat constant depth; for shallower networks, more conservative skipping still helps.
Conclusion
Stochastic depth is a training method that leaves the test-time network unchanged. It randomly skips residual blocks during training, bringing the expected depth down to about three quarters, then combines all the blocks at test time using the survival probabilities. Experimentally, error rates fall on CIFAR and SVHN, training time drops by about a quarter, and the 1202-layer network no longer overfits. The 152-layer ResNet on ImageNet, however, shows no accuracy benefit.
In some libraries, it goes by the name DropPath. A few months later, Gao Huang, Zhuang Liu, and Kilian Q. Weinberger from this paper proposed DenseNet, whose introduction cites stochastic depth right at the start, arguing that if training still works when layers are randomly skipped, then many layers in a residual network actually contribute very little.
Using stochastic depth just means multiplying each residual branch by a random 0 or 1 during training and by the survival probability at test time. Most libraries today divide by the survival probability during training instead, like torchvision's stochastic_depth, so nothing needs to change at test time.
Back then, the authors guessed that stochastic depth might only pay off on ImageNet with larger models. Later, the training recipes of large models such as ConvNeXt and DINOv2 did indeed include it.