7 routes42 sections324 units

Unit 3.1 · about 5 h

185 / 324

Initialization and signal scale across depth

Every later unit assumes signals survive the forward and backward pass. Wrong scale fails silently as flat or exploding loss, and no optimizer setting repairs it.

  • derive
  • measure

You can now

  • Derive the He variance \(2/\text{fan-in}\) for ReLU layers from variance propagation, and state the Xavier form for symmetric activations.
  • Predict whether activations and gradients shrink or grow across depth for a stated initialization scale.
  • Measure per-layer activation and gradient norms in a deep MLP and name the failing regime.

Covers

  • Xavier and Kaiming initialization
  • Activation and gradient scale across depth

Study, in this order

3 steps

  1. Parameter initialization (derivation)
    Understanding Deep Learning - fitting, gradients and regularization

    Chapter 7, Section 7.5 through 7.5.3 (pp. 107 to 111): forward variance, backward variance and the \(4/(\text{fan-in} + \text{fan-out})\) compromise

  2. Numerical stability, symmetry breaking and Xavier
    D2L - optimization and regularization slice

    Vanishing and Exploding Gradients, Breaking the Symmetry, Parameter Initialization and Xavier Initialization; Summary

  3. HOML: Glorot and He initialization in PyTorch
    Hands-On Machine Learning with Scikit-Learn and PyTorch

    Chapter 11, Glorot Initialization and He Initialization (printed pp. 365-368): Equation 11-1, Table 11-1 and the nn.init calls with model.apply

    Depth · Read it for the PyTorch default: nn.Linear draws Kaiming-uniform weights with bound \(1/\sqrt{\text{fan\_in}}\), a factor \(\sqrt{6}\) below the He bound \(\sqrt{6/\text{fan\_in}}\), so a ReLU stack needs nn.init.kaiming_uniform_ or kaiming_normal_ to reach the He scale.

Focus on

  • ReLU keeps about half of symmetric inputs, so \(\mathbb{E}[h^2]\) is half the pre-activation variance. That half is where the factor 2 in He comes from.
  • Xavier balances fan-in against fan-out for the near-linear regime. UDL's compromise averages the two He conditions; it is not the classic tanh Xavier formula.
  • Constant initialization never breaks symmetry: identical weights give identical gradients, so units update identically forever. Randomness must differ across units, not just across layers.
  • Variance preservation is an expectation over random draws. One unlucky draw still skews a narrow layer, so width matters alongside scale.

Reproduce closed-book

Closed-book, derive \(\sigma^2 = 2/\text{fan-in}\) for a ReLU layer from mean-zero pre-activations and \(\mathbb{E}[h^2] = \operatorname{Var}(f)/2\). Then push a batch through a 50-layer, width-100 ReLU MLP at weight variances 0.001, 0.02 and 1.0 and log the mean squared pre-activation per layer. Expect 0.001 to collapse toward zero, 1.0 to overflow, and 0.02 (the He value) to stay within about an order of magnitude of its start; single draws drift, so try a few seeds.

Traps

  • Using Xavier variance for ReLU layers. Without the factor 2 the forward variance halves each layer; use He for ReLU and Xavier-style \(1/\text{fan}\) forms for tanh or sigmoid.
  • Reading UDL equation 7.34 as classic Xavier. It averages the forward and backward He conditions for ReLU, \(4/(\text{fan-in} + \text{fan-out})\); the chapter Notes (p. 113) say Glorot or Xavier initialization ignores the ReLU and so differs by a factor of two.
  • Concluding stability from one seed. Variance statements are expectations, so rerun narrow layers with fresh draws before trusting a scale.

Practice

D2L Numerical Stability and Initialization: Exercises

Exercises: the symmetry-breaking, constant-init and eigenvalue questions

TrenTorch: Weight Initialization

Implement xavier_uniform_bound, xavier_normal_std, kaiming_uniform_bound and kaiming_normal_std from the variance targets

Derive each value before coding: Kaiming normal std with the default gain \(\sqrt{2}\) is \(\sqrt{2/\text{fan\_in}}\), and each uniform bound is \(\sqrt{3}\) times its normal std because \(U(-a, a)\) has variance \(a^2/3\).

Self-test

  1. A ReLU layer has fan-in 200. What weight variance preserves activation scale, and why 2 and not 1?

  2. Tanh layer, fan-in 256, fan-out 128. Give the D2L Xavier uniform bound.

  3. All weights in an MLP layer are initialized to the same constant. What happens?

  4. Init variance is far too large. Which two signatures do you expect forward and backward?

Completion criterion

Stop when

You derive \(2/\text{fan-in}\) without notes, and your probe shows collapse below the He value, overflow above it, and bounded drift at it across a few seeds.

Mark passed, then open 3.2 Only mark this when you can do it without notes.

Leads to

Comes after

Resources for this unit

  • Understanding Deep Learning - fitting, gradients and regularization
    Simon J. D. Princeprimarytheory
    Use Chapters 6-9 and targeted parts of Chapter 20 for optimization, initialization, measurement, regularization and why training works. Re-derive the update rules you keep in the trainer.
  • D2L - optimization and regularization slice
    D2L authorsrequiredimplementation
    Use MLP implementation, dropout, deep generalization, numerical stability, optimization introduction, SGD, minibatch SGD, momentum, AdaGrad, RMSProp, Adam and learning-rate scheduler. Implement momentum, AdamW, initialization, dropout, one normalization, clipping and one schedule.
  • Hands-On Machine Learning with Scikit-Learn and PyTorch
    Aurelien Geron (O'Reilly, 2025)supporttheory
    Read the Chapter 11 sections named in the units for the PyTorch side of initialization, normalization, clipping and schedules.

Also in this section

Quick find

Search Michi

Type to search every route, section, unit, topic and resource.

Enter opens the first result Esc closes

Reference

Keyboard shortcuts

n
Continue to the first unit not passed
j / k
Next / previous unit
1 2 3
Toggle learned, practised, passed
/
Open search
?
Show this help
Esc
Close open panels