Foundation Lab

Backpropagation & Automatic Differentiation

Every modern neural network is trained via backprop—it is the fundamental algorithm enabling gradient-based learning

Concept 35 of 100OptimizationPhase 3
#35BackpropOptimization
key equation
δℓ=δℓ+1⋅∂hℓ+1∂hℓ\delta_\ell = \delta_{\ell+1} \cdot \frac{\partial h_{\ell+1}}{\partial h_\ell}
Reading map and next steps

Selected Foundation Object

Keep the equation fixed; move through the evidence.

Concept 35 of 100BackpropOptimization / Phase 3: Optimization & generalization
Current question

Reverse-mode is optimal when outputs << parameters (typical in ML); forward-mode would require one pass per parameter

δℓ=δℓ+1⋅∂hℓ+1∂hℓ\delta_\ell = \delta_{\ell+1} \cdot \frac{\partial h_{\ell+1}}{\partial h_\ell}
PredictionCommit before tracing the equation.

Ask what should change under a concrete input, then trace that expectation through the equation.

EvidenceCompare the equation and source.

Use the key equation and canonical papers as the available witnesses, without implying that a runnable panel exists.

InvariantName what survives notation changes.

The useful learning product is the reusable mechanism you can carry into another model, paper, or engineering tradeoff.

Next moveContinue through the atlas.

Use prerequisites, dependents, and semantic links to repair the next gap without leaving the object behind.

Why It Matters for Modern Models

  • Every modern neural network is trained via backprop—it is the fundamental algorithm enabling gradient-based learning
  • Memory cost of storing activations explains why activation checkpointing exists and why large models need gradient accumulation
  • Understanding forward/backward asymmetry explains why inference is cheap but training is expensive

What Tutorials Skip

What is still poorly explained in textbooks and papers:

  • Reverse-mode is optimal when outputs << parameters (typical in ML); forward-mode would require one pass per parameter
  • The computation graph is built dynamically in PyTorch—this is why torch.no_grad() saves memory, not just compute
  • Vanishing/exploding gradients arise from repeated multiplication of Jacobians—residual connections fix this by adding identity

Visualization Status

Core Math (Optional Deep Dive)

If you want intuition first, start with the key equation and cited sources. Come back here for the full walkthrough.

Key Equation
δℓ=δℓ+1⋅∂hℓ+1∂hℓ\delta_\ell = \delta_{\ell+1} \cdot \frac{\partial h_{\ell+1}}{\partial h_\ell}

The chain rule computes gradients efficiently via reverse-mode autodiff:

For composite function f=fL∘fL−1∘⋯∘f1f = f_L \circ f_{L-1} \circ \cdots \circ f_1:

∂L∂θℓ=∂L∂hL⋅∂hL∂hL−1⋯∂hℓ+1∂hℓ⋅∂hℓ∂θℓ\frac{\partial L}{\partial \theta_\ell} = \frac{\partial L}{\partial h_L} \cdot \frac{\partial h_L}{\partial h_{L-1}} \cdots \frac{\partial h_{\ell+1}}{\partial h_\ell} \cdot \frac{\partial h_\ell}{\partial \theta_\ell}

The backward pass propagates sensitivities:

δℓ=∂L∂hℓ=δℓ+1⋅∂hℓ+1∂hℓ\delta_\ell = \frac{\partial L}{\partial h_\ell} = \delta_{\ell+1} \cdot \frac{\partial h_{\ell+1}}{\partial h_\ell}

Computational cost: one forward pass + one backward pass = O(2 × forward).
Memory cost: must store all intermediate activations
h1,…,hLh_1, \ldots, h_L.

Canonical Papers

Learning representations by back-propagating errors

Rumelhart, Hinton, Williams1986Nature
Read paper →

Automatic Differentiation in Machine Learning: a Survey

Baydin et al.2018JMLR
Read paper →

Connections

Next Moves

Choose the next question to carry this object forward.