Skip to content
Tech News
← Back to articles

Why Backprop Goes Backward (2018)

read original more articles
Why This Matters

This piece is a technical explainer aimed at demystifying backpropagation, the core algorithm behind training neural networks, by addressing why gradients are computed backward rather than forward. Understanding this distinction matters to the AI/ML community because backprop's efficiency underpins the feasibility of training the deep learning models powering today's AI boom, and clarifying its mechanics helps practitioners and students build stronger intuition for optimizing and debugging neural networks.

Key Takeaways

The usual explanation of backpropagation (Rumelhart et al., 1986), the algorithm used to train neural networks, is that it is propagating errors for each node backwards. But when I first learned about the algorithm, I had a question that I could not find answered directly: why does it have to go backwards? A neural network is just a composite function, and we know how to compute the derivatives of composite functions using the chain rule. Why don’t we just compute the gradient in a forward pass? I found that answering this question strengthened my understanding of backprop.

I will assume the reader broadly understands neural networks and gradient descent and even has some familiarity with backprop. I’ll first setup backprop with some useful concepts and notation and then explain why a forward propagation algorithm is supoptimal.

Setup

Recall that the goal of backprop is to efficiently compute ∂ f / ∂ θ i \partial f / \partial \theta_i ∂f/∂θi​ for every weight θ i \theta_i θi​ in a neural network f f f. To frame the problem, let’s reason about an arbitrary weight θ 1 \theta_1 θ1​ and node v v v somewhere in f f f:

To be clear, the node v v v refers to the output value of the node after passing the weighted sum of its inputs through an activation function σ \sigma σ, i.e.:

u = θ 1 t 1 + θ 2 t 2 + ⋯ + θ n t n v = σ ( u ) \begin{aligned} u &= \theta_1 t_1 + \theta_2 t_2 + \dots + \theta_n t_n \\ v &= \sigma(u) \end{aligned} uv​=θ1​t1​+θ2​t2​+⋯+θn​tn​=σ(u)​

Note that in a typical diagram, u u u, σ \sigma σ, and v v v would all be a single node, denoted by the dashed line. In my mind, the most important observation needed to understand backprop is this: most of computing ∂ f / ∂ θ 1 \partial f / \partial \theta_1 ∂f/∂θ1​ can be done locally at every node because of the chain rule:

∂ f ∂ θ 1 = ∂ f ∂ v ∂ v ∂ u ∂ u ∂ θ 1 \frac{\partial f}{\partial \theta_1} = \frac{\partial f}{\partial v} \frac{\partial v}{\partial u} \frac{\partial u}{\partial \theta_1} ∂θ1​∂f​=∂v∂f​∂u∂v​∂θ1​∂u​

We can compute ∂ v / ∂ u \partial v / \partial u ∂v/∂u analytically; it just depends on the definition of σ \sigma σ. And we know that ∂ u / ∂ θ 1 = t 1 \partial u / \partial \theta_1 = t_1 ∂u/∂θ1​=t1​. So at every node v v v, if we knew ∂ f / ∂ v \partial f / \partial v ∂f/∂v, we could compute ∂ f / ∂ θ 1 \partial f / \partial \theta_1 ∂f/∂θ1​.

The challenge with computing ∂ f / ∂ v \partial f / \partial v ∂f/∂v is that downstream nodes depend on the value of v v v. Thankfully, the multivariable chain rule has the answer. Given a multivariable function g ( w 1 , w 2 , … , w m ) g(w_1, w_2, \dots, w_m) g(w1​,w2​,…,wm​) in which each w i w_i wi​ is a single variable function w i ( v ) w_i(v) wi​(v), the multivariable chain rule says:

... continue reading