advanced28 min studyLesson 615 in Engineering

Use variance arithmetic as a scoped initialization model

Analyze linear fan-in and residual covariance before turning an initialization rule into a claim about deep Transformer stability.

On this page

What you’ll understand

  • Derive a fan-in variance formula under explicit independence assumptions.
  • Include covariance when estimating residual-stream growth.
  • Define activation and gradient measurements that challenge the approximation.

Initialization chooses the scale of a computation before training has adapted its weights. Too much or too little signal can interact with nonlinearities, normalization, precision, and optimizer state, but there is no single variance formula that guarantees a deep language model will train. Use simple calculations to expose assumptions, then measure the actual architecture. A residual branch shares its input with the identity path, so treating their contributions as independent is an approximation that needs particular care.

State the assumptions behind a linear variance estimate

For one output z of a width-d linear map, sum d products of weights and inputs. If weights have zero mean, are independent across coordinates and independent of inputs, and cross-product terms vanish, the output variance is d times weight variance times input second moment. With zero-mean inputs, that second moment is their variance. Nonzero means, correlated weights, tied parameters, or data-dependent branches can invalidate the simple estimate. An initializer's standard deviation is not a complete description of the resulting activation distribution.

Choosing weight variance proportional to inverse fan-in can keep this idealized output variance comparable to the input variance. Glorot and Bengio's original analysis studies related signal-propagation considerations, while Transformer normalization analyses examine architecture-specific gradient behavior. Their conclusions rely on particular models and assumptions. Do not transplant a historical hyperparameter without its normalization placement, residual structure, embedding scale, and depth convention. Record which tensors receive which initializer and whether a later loading or tying step changes them.

z=∑j=1dwjxj,Var⁡(z)=d σw2qz=\sum_{j=1}^{d}w_jx_j,\qquad \operatorname{Var}(z)=d\,\sigma_w^2 q
This equality assumes zero-mean independent weight coordinates of variance σ_w², independence from inputs, and vanishing cross terms with input second moment q=E[x_j²]. If inputs are zero-mean, q is their variance. The variables are dimensionless model coordinates; the formula is not asserted for arbitrary trained tensors.↔ Scroll wide equations horizontally.

Residual growth includes a covariance term

For h_next=h+γF(h), the exact scalar-coordinate variance includes the variance of h, the scaled branch variance, and twice the scaled covariance. Even a zero-mean initialized branch is a function of h, so covariance cannot generally be discarded merely because weights were sampled independently at creation. A simplified analysis may assume negligible covariance and fixed branch variance to motivate a depth-dependent scale, but those are premises rather than results of writing a residual addition.

Under the further toy assumption that every layer adds an uncorrelated unit-variance branch, L additions with scale γ add Lγ² to the variance. Setting γ=1/√L keeps that added amount at one in this model. This does not establish gradient stability, attention-score behavior, or an optimal scale for a real decoder. Normalization placement changes which tensors are normalized and where scale can accumulate; Xiong and colleagues' analysis is an example of why those architectural details matter.

Var⁡(h+γf)=Var⁡(h)+γ2Var⁡(f)+2γCov⁡(h,f)\operatorname{Var}(h+\gamma f)=\operatorname{Var}(h)+\gamma^2\operatorname{Var}(f)+2\gamma\operatorname{Cov}(h,f)
The finite-second-moment identity is exact for scalar random variables h and f and real γ. Extending a scalar-coordinate calculation to a whole network needs the relevant coordinate and layer covariance structure. Neglecting the covariance is an additional approximation, not part of the identity.↔ Scroll wide equations horizontally.

Inspect distributions before declaring initialization healthy

Run a small forward and backward fixture before expensive training. Record per-layer residual and branch RMS, selected quantiles, attention-logit scales, finite-value counts, and gradient norms under representative serialized batches. Separate normalization inputs and outputs so a normalized tensor does not hide growth elsewhere. Test multiple initialization seeds and input domains when practical. A single finite loss is weak evidence: a model can begin with saturated submodules or strongly depth-dependent gradients while still returning a number.

The network lab illustrates saturation in one nonlinear unit, not residual-stream variance. Reset, set both x=1,w=1, predict logit 0.5 and sigmoid slope factor about 0.2350, then Play or Step. Reset and set both x=3,w=3 for logit 8.5 and a much smaller factor about 0.0002034. The second setting is control-reachable but is not a recommended initializer. There are no random weights, layers, normalization, residual additions, or training updates in this instrument; derive variance separately and use it to guide actual measurements.

Compare a toy residual depth budget

Assume an initial scalar-coordinate variance of one, sixty-four residual additions, zero covariance between each current stream and branch, and unit variance for every branch. Compare γ=1 with γ=1/8 under these deliberately idealized fixed assumptions.

  1. Each addition contributes γ²×1 to the variance because the stipulated covariance is zero. With γ=1, sixty-four additions contribute sixty-four.

  2. The resulting variance is 1+64=65. With γ=1/8, each contribution is 1/64 and the total added variance is one.

  3. The scaled model therefore ends at variance two, with RMS √2 instead of √65 for zero-mean coordinates. These are consequences of the assumed branch and covariance model, not measured properties or stability guarantees for a sixty-four-layer Transformer.

The result

Depth scaling controls the added variance in this toy model. Actual branch distributions, covariance, normalization, and gradients must be checked before using that intuition in a run.

Explore the model

Interactive lab

Interactive lab · network

Inspect one scale-sensitive nonlinear derivative

Fresh Reset → set both x=1,w=1 predicts logit 0.5 and y(1−y)≈0.2350; Reset → set both x=3,w=3 predicts logit 8.5 and factor ≈0.0002034. Play or Step displays one sigmoid, with no random initialization, residual stream, LayerNorm, or training simulation.

Inspect one scale-sensitive nonlinear derivativeOne inspectable sigmoid unit, σ(wx − 0.5). Playback traces the computation graph. There is no training, attention mechanism or hidden deep network. Current readings: Product · wx: 1.2; Logit · wx − 0.5: 0.7; Sigmoid output: 0.6682. All parameters are adjustable with the labeled controls below.One input. One weight. One sigmoid.x1.20× w1.20+ b0.70σ0.668output0.668w = 1.00b = −0.50σ(z) = 1 / (1 + exp(−z))
Computation graphSignal trace
Product · wx
1.2
Logit · wx − 0.5
0.7
Sigmoid output
0.6682
t = 0 s

One inspectable sigmoid unit, σ(wx − 0.5). Playback traces the computation graph. There is no training, attention mechanism or hidden deep network. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forScale can change nonlinear sensitivity, while deep-model initialization needs architecture-specific analysis.

Check your understanding

Which term is missing from an estimate that adds Var(h) and γ²Var(F(h)) without further assumptions?

Try it yourself

A width-256 linear output uses the idealized variance formula with input second moment q=1 and weight variance 1/256. What is output variance? If weight standard deviation doubles while the assumptions remain valid, how does output variance change?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Variance is the square of standard deviation, so doubling the latter multiplies weight variance by four.

Compare with the solution

The original output variance is 256×(1/256)×1=1. Doubling weight standard deviation changes its variance to 4/256, producing output variance four. This does not predict the exact distribution after a nonlinearity, normalization, or correlated residual addition. It gives a controlled scale hypothesis that should be compared with measured layer statistics under the actual initialized architecture.

Take it with you

  • Fan-in variance formulas need explicit mean, independence, and cross-term assumptions.
  • Residual variance includes covariance even before any weights have trained.
  • Initialization acceptance should inspect actual layerwise signals and gradients.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.