Backpropagation
Volume II, Chapter 6 — Part I. The chain rule on computation graphs: forward and backward passes, general layer-wise gradient formulas, vector-Jacobian products, and the theoretical foundation of deep network training.
Table of Contents
- Learning Objectives
- Prerequisites
- Notation
- Core Intuition
- Computation Graphs
- The Multivariate Chain Rule
- Forward Pass: Activations and Caching
- Backward Pass: Error Signals
- Layer-Wise Gradient Formulas
- The General Backpropagation Algorithm
- Vector-Jacobian Products
- Gradients for Common Operations
- Computational Complexity
- Worked Examples
- Connection to the Broader Curriculum
- Common Pitfalls and Misconceptions
- Research Perspective
- Summary of Takeaways
- Exercises
Learning Objectives
After reading this chapter, you should be able to:
- Represent a neural network as a directed acyclic computation graph and identify intermediate variables.
- State and apply the multivariate chain rule for composed functions .
- Derive the forward pass equations that cache activations for the backward pass.
- Derive the backward pass (error propagation) equations for a multi-layer network.
- Write the general formulas and .
- Explain backpropagation as repeated vector-Jacobian products.
- Analyze the computational cost of gradient computation via backpropagation.
Prerequisites
This chapter assumes familiarity with:
- Gradient Descent — gradients, chain rule in single-variable calculus
- Matrix Operations & Linear Transformations — matrix multiplication, transposes
- Logistic Regression — sigmoid, cross-entropy gradient
Notation
- — Activation at layer
- — Weight matrix and bias at layer
- — Error signal (adjoint variable)
- — Scalar loss
- — Element-wise (Hadamard) product
Core Intuition
Training a neural network requires computing for every parameter — potentially billions of them. Backpropagation is an efficient algorithm for this, discovered independently by Werbos (1974), Parker (1985), and popularized by Rumelhart, Hinton, and Williams (1986).
The core idea is elementary: a neural network is a composition of functions. The gradient of a composition is computed by the chain rule, applied systematically from the loss backward to the inputs. Backpropagation is not a new mathematical principle — it is the chain rule organized to reuse intermediate computations.
The efficiency comes from dynamic programming: each intermediate gradient is computed once and reused for all parameters downstream. Without this sharing, gradient computation would be exponentially expensive in network depth.
Series context. This opens Chapter 6 (Deep Learning Foundations) in Volume II. It connects Gradient Descent to all subsequent deep learning training — Batch Normalization, Self-Attention, and beyond.
Backpropagation Flow
Computation Graphs
Definition 1 (Computation Graph). A computation graph is a directed acyclic graph (DAG) where:
- Leaf nodes are inputs (data , parameters )
- Interior nodes are intermediate values computed from their parents
- Root node is the scalar loss
Each edge represents a functional dependency: if node depends on node , then is well-defined.
Definition 2 (Neural Network as Composition). An -layer network defines a composition:
where and is the loss function.
Proposition 1. Any differentiable computation — matrix multiplications, activations, normalization, attention — can be represented as a computation graph. Backpropagation applies to the entire graph.
The Multivariate Chain Rule
Theorem 1 (Multivariate Chain Rule). Let and be differentiable. Then is differentiable and
where is the Jacobian of .
Proof. For each component, . Stacking: .
Definition 3 (Error Signal / Adjoint). Define the error signal at node :
Backpropagation computes for every node by propagating from the loss backward.
Forward Pass: Activations and Caching
Definition 4 (Layer Notation). For layer :
with (input) and (output).
Algorithm (Forward Pass). For :
-
Compute pre-activation:
-
Compute activation:
-
Cache and for the backward pass
-
Compute loss:
All cached values are needed for gradient computation — memory cost is .
Backward Pass: Error Signals
We derive gradients for a two-layer network, then generalize.
Setup. Layer 2 (output): , . Layer 1 (hidden): , .
Definition 5 (Output Error). Define (error at pre-activation of layer ).
Step 1: Output layer error. For cross-entropy with sigmoid output and binary labels:
Proof. . Using :
Multiplying by gives .
Step 2: Parameter gradients at layer 2.
Proof. Since , we have and . Matrix form: .
Step 3: Propagate error to layer 1.
where denotes element-wise (Hadamard) product.
Proof. By the chain rule: . Vector form: .
Step 4: Parameter gradients at layer 1.
Layer-Wise Gradient Formulas
Theorem 2 (General Backpropagation Equations). For an -layer network with loss , the error signals satisfy:
and the parameter gradients are:
Proof. By induction on . The base case follows from the chain rule through the loss. For the inductive step, assume . Since :
This gives (11). For (12): follows from .
Important equation. Equations (11)–(12) are the workhorse of deep learning. Modern automatic differentiation systems implement these recurrences as reverse-mode adjoint passes over the computation graph.
The General Backpropagation Algorithm
Algorithm (Backpropagation).
Input: Network with parameters , input , target .
- Forward pass: Compute and cache for all .
- Output error: .
- Backward pass: For :
- Gradients: For :
- Update: (gradient descent step)
Vector-Jacobian Products
Definition 6 (VJP). The vector-Jacobian product of at with cotangent vector is:
where .
Proposition 2. Backpropagation computes VJPs in reverse topological order. Each node receives a cotangent and passes to its parents.
This abstraction generalizes backpropagation beyond feedforward networks to arbitrary DAGs (residual connections, attention, branching).
Theorem 3 (Automatic Differentiation). Reverse-mode automatic differentiation (backpropagation) computes the full gradient for parameters in operations, regardless of .
Forward-mode AD computes one directional derivative in but requires passes for the full gradient — impractical for neural networks where .
Gradients for Common Operations
Proposition 3 (Linear Layer). For with upstream gradient :
Proposition 4 (Element-wise Activation). For :
Proposition 5 (Softmax + Cross-Entropy). For -class softmax output with cross-entropy loss:
where and is the one-hot target — the same clean form as (5).
Proposition 6 (ReLU). For : .
Computational Complexity
Theorem 4 (Backprop Cost). For a network with weights and forward pass cost , backpropagation computes all gradients in — typically .
Proof sketch. Each edge in the computation graph is traversed once in the forward pass and once in the backward pass. The total work is at most twice the forward cost.
Comparison. Numerical gradient via finite differences requires forward passes for parameters — , infeasible for .
Worked Examples
Example 1: Scalar Two-Layer Network
Let , , . Forward: , , , (linear output), .
Backward: , , , .
Example 2: Batch Processing
For a mini-batch , gradients accumulate over batch dimension: .
Example 3: Depth and Vanishing Gradients
For , . Through layers: as . This motivates ReLU, residual connections, and careful initialization.
Connection to the Broader Curriculum
Backpropagation is the computational engine for:
- Batch Normalization — additional nodes in the computation graph
- Self-Attention — gradients through softmax attention weights
- Variational Autoencoders — reparameterization trick enables backprop through stochastic nodes
- LoRA — backprop through low-rank adapter matrices
- Flash Attention — IO-aware implementation of the same mathematical gradients
Gradient Descent provides the optimizer; backpropagation provides the gradients.
Common Pitfalls and Misconceptions
Pitfall 1: Thinking backpropagation is separate from the chain rule. It is the chain rule, organized efficiently. There is no additional mathematical content.
Pitfall 2: Forgetting to cache forward pass values. The backward pass requires and from the forward pass. Recomputing them doubles cost.
Pitfall 3: Confusing with . The error signal is at the pre-activation. The activation gradient requires multiplying by .
Pitfall 4: Numerical gradient checking on large networks. Finite-difference checking is — use only on tiny subnetworks for debugging.
Pitfall 5: Ignoring vanishing/exploding gradients. Deep networks require architectural mitigations (residual connections, normalization, gated activations) beyond naive backpropagation.
Research Perspective
The modern history of backpropagation begins with Werbos's 1974 PhD thesis, was independently rediscovered by Parker (1985), and was popularized by Rumelhart, Hinton, and Williams (1986), who demonstrated learning of internal representations.
Automatic differentiation was formalized by Wengert (1964) and developed into modern AD theory (Griewank & Walther, 2008). Reverse-mode AD computes the full gradient of a scalar loss in time proportional to a single forward pass — the computational foundation of deep learning optimization.
Open research directions include:
- Gradient-free optimization for non-differentiable objectives (evolution strategies, REINFORCE)
- Second-order methods using Hessian information (K-FAC, natural gradient)
- Memory-efficient backprop (gradient checkpointing, reversible networks)
- Understanding gradient dynamics in overparameterized networks (neural tangent kernel regime)
Backpropagation remains the dominant training algorithm four decades after its popularization — a testament to the chain rule's enduring power.
Summary of Takeaways
- Error signal — — Upstream gradient at layer
- Backprop recurrence — — Propagate errors backward
- Weight gradient — — Outer product of error and input
- Output layer (CE+sigmoid) — — Clean gradient form
- VJP — — General backprop abstraction
- Complexity — — Same order as one forward pass
Next article: Universal Approximation Theorem → — why depth and width give neural networks their expressive power.
Exercises
Exercise 1 (Chain rule). Derive (8) explicitly for a scalar two-layer network without matrix notation.
Exercise 2 (Softmax gradient). Prove (17) by differentiating categorical cross-entropy through softmax.
Exercise 3 (Generalization). Extend Theorem 2 to a network with skip connections: . How does the error propagate?
Exercise 4 (VJP). Express the full backpropagation algorithm for a DAG (not just a chain) using VJP notation.
Exercise 5 (Complexity). Count the number of multiply-add operations for forward and backward passes of a single fully connected layer mapping .
Exercise 6 (Vanishing gradients). For , bound and derive the worst-case gradient decay through layers.
Exercise 7 (Batch). Show that batch gradient equals the gradient of the average loss .
Exercise 8 (Conceptual). Why is reverse-mode AD preferred over forward-mode for neural network training? Give a quantitative argument using typical values of (parameters) and output dimension.