You're training a classifier to tell shirts from shoes, but its accuracy stays near chance for the first few epochs. You check the data and the learning rate, and the network's activations are still non-zero. The starting weights deserve a look too. Weight initialisation in PyTorch sets the scale of the signal that each layer passes on, and nn.Linear chooses that scale unless you tell it otherwise. Its default comes from Lua Torch, carried over to preserve existing behaviour, and differs from both Xavier and He initialisation.
We trace the starting scale through a plain ReLU network without normalisation or residual connections. After eight layers, input-dependent variation is only 0.004% of default output energy. That model stays at 10% accuracy for six to eight epochs. He initialisation reaches 78% to 83% in three epochs. The twenty-layer default remains at chance through 20 epochs across the seeds and learning rates tested.
Let's Build It
Before any code, here is the whole result in one picture. Take 600 test images, push them through two untrained 30-layer networks that differ only in their initialization, and plot each layer's representation of every image. Each frame is rescaled to the size of that layer's signal, which removes overall shrinkage from the picture, so a shrinking cloud means the images are becoming indistinguishable.

By layer 10 the default network has mapped all 600 images to what, at this scale, is a single point. The He network still tells them apart at the output. The code below measures that collapse with a single number and then shows what it does to training.
import torch
import torch.nn as nn
import torch.nn.functional as F
from torchvision import datasets
torch.set_num_threads(4)
# 10,000 FashionMNIST training images and the full test set, standardised
tr = datasets.FashionMNIST("data", train=True, download=True)
te = datasets.FashionMNIST("data", train=False, download=True)
idx = torch.randperm(60_000, generator=torch.Generator().manual_seed(0))[:10_000]
x_tr, y_tr = tr.data[idx].float().div(255).view(-1, 784), tr.targets[idx]
x_te, y_te = te.data.float().div(255).view(-1, 784), te.targets
mu, sd = x_tr.mean(), x_tr.std()
x_tr, x_te = (x_tr - mu) / sd, (x_te - mu) / sd
def mlp(depth, width=256):
layers, d = [], 784
for _ in range(depth):
layers += [nn.Linear(d, width), nn.ReLU()]
d = width
return nn.Sequential(*layers, nn.Linear(d, 10))
def he_init(model):
for m in model.modules():
if isinstance(m, nn.Linear):
nn.init.kaiming_normal_(m.weight, nonlinearity="relu")
nn.init.zeros_(m.bias)
@torch.no_grad()
def input_share(model, x):
"""Fraction of the output's energy that changes from one input to the next."""
out = model(x)
return (out.var(dim=0).mean() / out.pow(2).mean()).item()
def train(model, epochs=3, lr=0.01, seed=0):
opt = torch.optim.SGD(model.parameters(), lr=lr, momentum=0.9)
g = torch.Generator().manual_seed(seed)
for _ in range(epochs):
for b in torch.randperm(10_000, generator=g).split(128):
loss = F.cross_entropy(model(x_tr[b]), y_tr[b])
opt.zero_grad()
loss.backward()
opt.step()
with torch.no_grad():
return (model(x_te).argmax(1) == y_te).float().mean().item()
for depth in (4, 8, 20):
for name in ("default", "he"):
torch.manual_seed(0)
model = mlp(depth)
if name == "he":
he_init(model)
share = input_share(model, x_tr[:512])
print(f"depth {depth:2d} {name:7s} input share {share:.1e} "
f"test accuracy {train(model):.3f}")
It runs in about ten seconds on four CPU cores:
depth 4 default input share 2.9e-02 test accuracy 0.779
depth 4 he input share 3.5e-01 test accuracy 0.841
depth 8 default input share 3.9e-05 test accuracy 0.100
depth 8 he input share 2.8e-01 test accuracy 0.832
depth 20 default input share 2.4e-14 test accuracy 0.100
depth 20 he input share 1.4e-01 test accuracy 0.780
The runs share architecture, data, optimiser and seed and differ only in the he_init call, which after three epochs at eight layers separates a working classifier from a constant. The input share column shows why. At depth 20 the default's output varies from one image to the next by a fraction indistinguishable from floating-point rounding, which leaves the optimiser nothing to work with. Expect He's accuracies to differ in the third decimal on other hardware, while the default's 0.100 reproduces exactly.
What Just Happened?
The default, read from the source
When you write nn.Linear(256, 256), the constructor calls reset_parameters, and in PyTorch 2.x that method reads:
def reset_parameters(self) -> None:
# Setting a=sqrt(5) in kaiming_uniform is the same as initializing with
# uniform(-1/sqrt(in_features), 1/sqrt(in_features)). For details, see
# https://github.com/pytorch/pytorch/issues/57109
init.kaiming_uniform_(self.weight, a=math.sqrt(5))
if self.bias is not None:
fan_in, _ = init._calculate_fan_in_and_fan_out(self.weight)
bound = 1 / math.sqrt(fan_in) if fan_in > 0 else 0
init.uniform_(self.bias, -bound, bound)
The name kaiming_uniform_ is misleading. The argument a is the negative slope of a leaky ReLU, and setting it to drives the gain down to . The comment says what comes out: every weight is drawn uniformly from , where is the fan-in. A uniform distribution on has variance , so
He initialization sets . The default is one sixth of that. Measured on a fresh nn.Linear(256, 256), the variance times the fan-in comes out at 0.331, and nn.Conv2d(64, 64, 3) gives 0.334 with its fan-in of 576. The biases are drawn from the same box, which turns out to matter more than the weights.

Variance through one layer
The whole theory of initialization is one line of algebra. A linear unit adds up inputs, each multiplied by an independent zero-mean weight, so the variance of its output is
A ReLU then zeroes the negative half of a symmetric distribution, which halves its second moment. Put the two together and every layer multiplies the signal's second moment by the same factor:
That factor is all you need to predict what a deep stack does:
| initialization | gain per layer | after 20 layers | |
|---|---|---|---|
| PyTorch default | 1/3 | 1/6 | |
| Xavier (fan-in equals fan-out) | 1 | 1/2 | |
| He | 2 | 1 | 1 |
He initialization is the choice of that makes , so the signal neither shrinks nor grows however deep you go. Xavier was derived for units like tanh that do not halve the signal, so on a ReLU network it loses half the variance per layer. The default loses five sixths.
The bias floor
If that table were the whole story, the default's activations would vanish fastest of the three. The figure below says otherwise:

Xavier vanishes on schedule, to a standard deviation of 0.001 at layer 20, which is what the gain of one half predicts from its starting value. The default's weights with the biases zeroed vanish faster still, to by layer 30, also as predicted. But the default as PyTorch ships it falls for four layers and then stops, at a standard deviation of about 0.023, and stays there for the rest of the network.
The biases hold it up. Each layer shrinks the incoming signal by six and then adds a fresh bias whose variance is also . The pre-activation variance therefore follows
which settles at the fixed point . For that is a pre-activation standard deviation of 0.040, and after the ReLU, 0.023. The measured plateau is 0.022 to 0.024. A network that looks healthy by the standard diagnostic, activations that neither vanish nor explode, can still be broken.
Input share by layer
The floor itself causes the failure. The bias added at each layer is the same for every input. Each layer shrinks the part of the signal that came from the image by a factor of six and adds back a part that came from nowhere, so the share of the signal that depends on the input falls geometrically while the total stays constant:

From layer 5 onwards the measured share on the first seed falls by 5.3, 5.7, 6.0, 6.1 and 5.9 per layer, against the predicted 6. By the output it is , which is floating-point rounding. The zero-bias variant, the amber line, keeps the input's share near He's. The default's weights therefore shrink the signal, while its biases remove the input's contribution to it.
The right panel is the training consequence over three epochs. The default trains at two and three layers, falls six points behind He at four, drops to 51% at six, and from eight layers onwards is still at chance when He has finished. The collapse at initialization predicts the depth at which training stalls.
Going Deeper
Depth sweep
The depth sweep is three seeds per point, SGD with momentum 0.9 at a learning rate of 0.01, three epochs on 10,000 images. Averaged over seeds:
| hidden layers | 2 | 3 | 4 | 6 | 8 | 10 to 20 |
|---|---|---|---|---|---|---|
| PyTorch default | 0.813 | 0.801 | 0.766 | 0.508 | 0.100 | 0.100 |
| He | 0.831 | 0.827 | 0.826 | 0.819 | 0.810 | 0.799 to 0.815 |
Every default run from eight layers on scores exactly 0.100 after three epochs, on every seed. A score of exactly 0.100 means the network predicts one class for every image.
Eight hidden layers is modest by any current standard, and well within the range of the from-scratch exercises that teach deep learning. While the exact depths are specific to this width and data, a plain stack of nn.Linear and nn.ReLU on PyTorch's defaults loses accuracy within a few layers and stalls soon after, and from then on needs an explicit initialization or a normalisation layer.
Learning-rate sweep
The obvious objection is that SGD at 0.01 was the wrong setting for the default network. Sweeping the learning rate, three seeds per cell, three epochs:
| depth and init | 0.003 | 0.01 | 0.03 | 0.1 |
|---|---|---|---|---|
| 20, PyTorch default | 0.100 on all three | 0.100 on all three | 0.100 on all three | 0.100 on all three |
| 20, He | 0.774 to 0.798 | 0.780 to 0.813 | 0.657 to 0.721 | 0.100 on all three |
| 8, PyTorch default | 0.100 to 0.122 | 0.100 on all three | 0.178 to 0.234 | 0.320 to 0.488 |
| 8, He | 0.796 to 0.826 | 0.784 to 0.832 | 0.785 to 0.825 | 0.100 to 0.780 |
At depth 20 no learning rate moves the default off chance, and training for 20 epochs instead of 3 leaves it there too. All three seeds finish with a training loss between 2.3023 and 2.3031, against , the loss of a uniform guess over ten classes. An output that ignores the input can do no better than predict the class frequencies, and FashionMNIST's ten classes are balanced.
Depth 8 behaves differently. A larger step partly compensates for the small gradients, so at 0.1, the rate at which He starts to diverge, the default reaches 32% to 49%. Given enough epochs it also escapes at the standard rate: at 0.01 it sits at chance for six to eight epochs, then climbs, and reaches 77% to 81% by epoch 20, where He passes 78% within three. At eight layers the default delays training by most of a 20-epoch budget. At twenty layers training never starts.
The backward pass
Backpropagation runs the same multiplication in reverse. The gradient reaching layer is the gradient at layer times the transposed weights and the ReLU's on-off mask, one factor in a product of Jacobians, so its second moment shrinks by the same factor per layer. For the default that is a factor of in the gradient's norm, every layer, all the way back.

Measured between layer 8 and the output, the default's gradient norm shrinks by 2.42 to 2.51 per layer. The first layer receives a gradient 280,000 to 390,000 times smaller than the output layer's. The curve flattens over the first few layers only because those layers' inputs are still large (the activations have not yet sunk to the floor), and a weight gradient is the product of the incoming activation and the outgoing error.
This is the mirror image of the forward collapse, and Schoenholz and colleagues showed that the two are the same phenomenon, governed by the same per-layer factor in both directions. A network that cannot tell its inputs apart cannot send a useful error signal to its early layers either.
Adam and Xavier: partial rescues

Two partial escapes show up in the training curves. Adam divides each parameter's step by a running estimate of that parameter's gradient magnitude (the optimisers post builds it from scratch), so a gradient hundreds of thousands of times smaller than the output layer's still produces a step of normal size. That is why Adam moves the default network at depth 20 when SGD cannot. It does so slowly and erratically: 23%, 46% and 49% across the three seeds after three epochs, against 78% to 79% for He under the same optimiser. These marginal runs are also fragile in a way the clear-cut ones are not. Running the same code on two threads instead of four, which changes only the order of floating-point additions, left one of these seeds at chance and took the other two to 56% and 59%. Under the same change the SGD default stayed at 0.100 and He moved by at most four points.
Xavier is the more instructive case. With zero biases, a ReLU network is positively homogeneous: multiply every weight matrix by a constant and the output is multiplied by a constant too, with every direction unchanged. Xavier and He draw from the same normal distribution at different scales, so a Xavier network is the He network shrunk by per layer. Its input share is identical to He's to four decimal places. Its failure is purely one of size: at depth 20 its activations and gradients are roughly a thousand times smaller than He's, and SGD reaches 31% to 48% in three epochs where He reaches 78% to 81%. Adam, which ignores gradient scale, takes Xavier to 59% to 73%.
The default fails in a different way. While Xavier's shortfall in scale can be partly undone by an adaptive optimiser, the default's biases have replaced the information in the signal. At depth 20 they leave an input share of , below floating-point resolution, and no optimiser can recover information the forward pass no longer carries.
Architectures that absorb a bad initialization
None of this means PyTorch's default is a bug you need to fight in every model. Adding nn.BatchNorm1d after each linear layer of the depth-20 network:
default + BatchNorm 0.744 0.753 0.783
He + BatchNorm 0.750 0.750 0.744
The two initializations become indistinguishable. Batch normalisation rescales every layer's pre-activations to unit variance on each batch, which removes both the shrinkage and the floor, so the initial scale of the weights stops mattering. That is one reason batch normalisation made deep networks easier to train, and why networks with normalisation layers do not show this failure.
Residual connections protect a network by a different route: each block adds its input back to its output, so even a branch that shrinks the signal leaves the identity path intact. That arm was not measured here. Transformers usually sidestep the question in a third way, by overwriting PyTorch's default with their own scheme. Hugging Face's GPT-2, for one, draws its weights from a normal distribution with standard deviation 0.02, set by the initializer_range field of the model config, and zeroes the biases.
The default bites in the places those protections are absent: plain MLPs, custom architectures written from scratch, small networks where normalisation is left out to save time, and research code that strips a model down to isolate an effect.
Applying an initialization in practice
model.apply visits every submodule, so one function covers a whole network:
def init_weights(m):
if isinstance(m, (nn.Linear, nn.Conv2d)):
nn.init.kaiming_normal_(m.weight, mode="fan_in", nonlinearity="relu")
if m.bias is not None:
nn.init.zeros_(m.bias)
model.apply(init_weights)
Three arguments trip people up:
ais the leaky-ReLU slope. It sets the negative slope of the leaky ReLU the layer feeds into. Copyingkaiming_uniform_(w, a=math.sqrt(5))out of PyTorch's own source gives you the default, with a sixth of He's variance.nonlinearitysets the gain.kaiming_normal_defaults tononlinearity="leaky_relu"witha=0, which happens to give the same gain of as"relu", so the default call is right for ReLU networks. For tanh, usexavier_normal_(w, gain=nn.init.calculate_gain("tanh")), which applies a gain of 5/3.modechooses which pass to protect."fan_in"preserves the forward signal;"fan_out"preserves the backward gradient. torchvision's ResNet usesmode="fan_out". He and colleagues showed that either one alone keeps both passes from growing or shrinking exponentially in common network designs, so the choice matters less than making one.
Initialize biases to zero unless you have a specific reason not to. The default's random biases drain the input in the experiments above.
Choosing a scheme
The table earlier is the decision rule. Pick the variance that makes the gain per layer equal to one for the activation you use:
- ReLU and its relatives: He (
kaiming_normal_orkaiming_uniform_). Leaky ReLU: pass its slope asa. - tanh, sigmoid, or no activation: Xavier (
xavier_normal_orxavier_uniform_), withcalculate_gainfor the activation. - Uniform or normal: they are the same variance with different shapes. He's uniform bound is , its normal standard deviation . Neither shape has a consistent advantage, since signal propagation depends only on the variance.
- With batch or layer normalisation after every layer: the scheme matters much less, as the BatchNorm arm shows. Set one anyway, since it costs one line.
When you are unsure whether a model is affected, measure it. The input_share function above, run on a batch of real inputs before training, takes milliseconds. In the experiments here, an output share below about went with networks that trained poorly or not at all in three epochs of SGD, because the forward pass had already discarded most of the input.
Where This Comes From
Yann LeCun, Léon Bottou, Genevieve Orr and Klaus-Robert Müller's 1998 chapter "Efficient BackProp" set out the variance argument this whole post rests on. Its recommendation is explicit:
"Assuming that: 1. the training set has been normalized, and 2. the sigmoid from Figure 4b has been used then weights should be randomly drawn from a distribution (e.g. uniform) with mean zero and standard deviation where m is the fan-in (the number of connections feeding into the node)."
The sigmoid in that recommendation is their scaled tanh, . Under it, the right variance is , three times what PyTorch's default gives. The default comes from somewhere else. Asked on the PyTorch issue tracker why nn.Linear uses a=math.sqrt(5), Soumith Chintala explained:
"the code refactor from jramseyer changes the default pytorch initialization from manually initializing the weights by calling random number generator function
uniformto usingtorch.nn.init.kaiming-- but it wanted to have the same end-result in weights, because we wanted to preserve backward-compatibility. So the sqrt(5) is nothing more than giving the code the same end-result as before."
In a later comment on the same question he traced the uniform box back through Lush, SENNA, Torch5 and Torch7, adding that it "is not recorded in literature anywhere but has been recorded in code". The source confirms the continuity: PyTorch 0.4.1 drew uniform_(-stdv, stdv) with stdv = 1/sqrt(n) directly, and PyTorch 1.0 reached the same distribution through kaiming_uniform_.

Xavier Glorot and Yoshua Bengio's 2010 paper "Understanding the difficulty of training deep feedforward neural networks" used that same heuristic as its baseline, with the biases set to zero:
"We initialized the biases to be 0 and the weights at each layer with the following commonly used heuristic: "
They identified its variance as the problem. "The standard initialization that we have used (eq.1) gives rise to variance with the following property: ... This will cause the variance of the back-propagated gradient to be dependent on the layer (and decreasing)." Their fix, which the paper calls "normalized initialization" and which is now called Xavier or Glorot initialization, balances the forward and backward passes by averaging the two fan counts:
Their analysis assumed activations that are linear near zero, such as tanh. Kaiming He, Xiangyu Zhang, Shaoqing Ren and Jian Sun's 2015 ICCV paper, the one that also introduced the parametric ReLU, redid it for ReLU, where half of every unit's input distribution is zeroed. Their equation (10) is the gain-equals-one condition from the table above:
"This product is the key to the initialization design. A proper initialization method should avoid reducing or magnifying the magnitudes of input signals exponentially."
They tested it on a 30-layer network, and the caption of their Figure 3 reports what this post found one level down: "Our initialization (red) is able to make it converge. But 'Xavier' (blue) [7] completely stalls - we also verify that its gradients are all diminishing. It does not converge even given more epochs."
The bias floor and the drained input need one more paper. Samuel Schoenholz, Justin Gilmer, Surya Ganguli and Jascha Sohl-Dickstein's "Deep Information Propagation" (ICLR 2017), building on Poole and colleagues' 2016 work, treats a random network's weights and biases together through mean-field theory. Two inputs that start out different become more or less correlated as they pass through each layer, and a single number decides which. For a ReLU network that number is , where : the same gain as before. Their description of the regime below one:
"χ1 = 1 represents a critical line separating an ordered phase (in which c∗ = 1 and all inputs end up asymptotically correlated) and a chaotic phase (in which c∗ < 1 and all inputs end up asymptotically decorrelated)."
PyTorch's default has , deep in the ordered phase. Inputs become correlated at the rate the measurements above show, a factor of six per layer, and the paper's backward-pass analysis predicts the gradient decay from the same number: "In the ordered phase, χ1 < 1 and so . We therefore expect gradients to vanish over a depth ." The depth sweep reproduces their main practical result, that a random network can be trained only as deep as information can travel through it. He initialization with zero biases puts a ReLU network on the critical line, where the depth scale diverges. The input's share still drifts down under He, from 0.7 to 0.08 over thirty layers in the figures above, but slowly rather than by a factor of six per layer.
Further reading
For recurrent sequence models, LSTM from scratch measures how forget bias affects retention over 100 steps.
Efficient BackProp, LeCun, Bottou, Orr and Müller, 1998. Section 4.6 for the fan-in rule.
Understanding the difficulty of training deep feedforward neural networks, Glorot and Bengio, AISTATS 2010. Section 4.2 for the variance analysis and equation 16.
He, Zhang, Ren and Sun, ICCV 2015, arXiv:1502.01852. Section 2.2 for the ReLU derivation and Figure 3 for the 30-layer comparison.
Deep Information Propagation, Schoenholz, Gilmer, Ganguli and Sohl-Dickstein, ICLR 2017. Sections 3 and 4 for the depth scales and the backward pass.
PyTorch issues #15314 and #57109 for the history of the default.
Interactive Tools
- Gradient Descent Visualizer: race SGD against Adam on the same surface and compare how each scales its step.
- Distribution Explorer: compare the uniform and normal distributions, the two shapes behind
kaiming_uniform_andkaiming_normal_.
Related Posts
- SGD, Momentum, and Adam: Optimisers from First Principles: why Adam's per-parameter scaling partly rescues a badly initialized network and SGD does not.
- Batch Normalisation from Scratch: Why It Works and When It Doesn't: the layer that makes initialization matter much less, built from first principles.
- Backpropagation Demystified: Neural Nets from First Principles: the backward pass whose per-layer gain mirrors the forward one.
- Backprop, Jacobians, Hessians: Why First-Order Wins: the Jacobian products behind vanishing and exploding gradients.
- Channel Attention in PyTorch: Five Seeds, No Effect: another initialization default that costs accuracy, a sigmoid gate that starts at one half.





