Braj Kishore
JourneyVaultML FoundationsAI PM GuideAgenticNewsWork With MeMentorshipPulseNow
Say hi

Hiring · Building · Investing

Have a system — or a team —that needs to scale?

info@avyxon.ai

Usually replies within a day · track record here

JourneyVaultML FoundationsAI PM GuideAgenticNewsWork With MeMentorshipPulseNow
LinkedInXYouTubeSubstackInstagramThreadsFacebookDiscordGitHubTopmate
© 2026 Braj Kishore · Bengaluru, INThink Big · Start Small · Scale Fast
ML Foundations
06Track 2 · The training loop

Backpropagation

One number of error, a million weights to blame. The chain rule on a computation graph solves credit assignment for the price of one extra forward pass.

60 min2 interactives6 sources

A network predicts £310k, the house sold for £400k, and the loss is one number. Somewhere in sixty million parameters are the ones responsible. Backpropagation works out, for every single one, exactly how much nudging it would have changed that number — and it does it in about the time of one more forward pass.

The intuition

Trace the blame backwards through the org chart. The output layer knows how wrong the final answer was. It tells the layer beneath it how much each of its outputs contributed to that error, which in turn tells the layer beneath it, and so on to the input. Every unit only needs to know its own local derivative and the blame handed down from above.

Unlearn this

That backpropagation is the learning algorithm. It isn't — it's an efficient way to compute gradients. Gradient descent is what learns. Conflating them is a common and very visible interview slip; backprop computes ∂L/∂θ, and the optimiser then decides what to do with it.

01The credit assignment problem

The naive way to get a gradient is finite differences: nudge one weight, run the whole network again, see how the loss changed, divide. Correct, and catastrophically slow — one forward pass per parameter. For a 60-million-parameter network that's 60 million forward passes for a single training step.

Backpropagation gets every partial derivative in one backward sweep whose cost is roughly the same as one forward pass. That's not an optimisation, it's the difference between possible and impossible, and it is why the 1986 Rumelhart–Hinton–Williams paper mattered so much even though the chain rule is centuries old and the technique had been derived independently several times before.

Backpropagation, intuitively (Chapter 3)3Blue1Brown

02The chain rule on a computation graph

Represent the network as a graph where each node is an elementary operation — multiply, add, ReLU, exponentiate — and each edge carries a value. The forward pass evaluates the graph left to right and, crucially, caches the intermediate values.

The backward pass starts at the loss with ∂L/∂L = 1 and walks right to left. At each node it multiplies the incoming gradient by that node's local derivative and passes the result to its inputs. That's it. No node needs to know anything about the network's global structure — only its own operation and the gradient arriving from downstream. That locality is what makes automatic differentiation possible and why you can build arbitrary architectures without deriving anything by hand.

Two routing rules cover most of the graph. An addition node passes the incoming gradient unchanged to both inputs — it's a gradient distributor. A multiplication node passes the incoming gradient times the other input — so ∂(xy)/∂x = y — which is why it's a gradient switcher. Knowing those two lets you hand-derive gradients on a whiteboard.

∂L/∂w = (∂L/∂a) · (∂a/∂z) · (∂z/∂w)

The chain rule for one weight: downstream gradient × activation derivative × input. The last term is just x.

∂L/∂b = ∂L/∂z

The bias's local derivative is 1, so it inherits the gradient at its node untouched.

Backpropagation calculus (Chapter 4)3Blue1BrownCalculus on Computational Graphs: BackpropagationChristopher Olah

Try it

One training step, node by node

Forward, then backward, then one update — with every partial derivative computed live.

03Where backprop sits in the training loop

Four beats, in order, forever. Forward: run the batch through and produce predictions, caching activations. Loss: reduce predictions and targets to one number. Backward: sweep the graph in reverse, filling in a gradient for every parameter. Update: the optimiser applies those gradients.

The cached activations are the reason training needs so much more memory than inference. Inference can discard each layer's output as soon as the next layer has consumed it; training must keep them all until the backward pass reaches them. That's the origin of gradient checkpointing — recompute some activations during the backward pass instead of storing them, trading compute for memory — which is standard practice for training large models.

Try it

The training loop as a sequence

Click any message. Note what's being held in memory between the forward and backward passes.

04Vanishing and exploding gradients

The backward pass is a long chain of multiplications. If the terms are consistently below one, their product shrinks exponentially with depth — by the time the gradient reaches layer 2 of a 30-layer network it's numerically zero and those layers never learn. If the terms are consistently above one, the product explodes, the update is enormous, and the loss goes to NaN.

Sigmoid activations make the vanishing case near-certain: the derivative peaks at 0.25, so even in the best case the gradient loses three-quarters of its magnitude per layer. Ten layers of that is a factor of about a million.

The fixes, and what each addresses. ReLU-family activations: gradient of 1 in the active region, so no attenuation. Residual (skip) connections: an additive identity path gives the gradient a route that bypasses the multiplications entirely — this is the single biggest reason networks got past twenty layers, and it's what ResNet contributed. Batch and layer normalisation: keep activations in a range where derivatives are healthy. Careful initialisation (Xavier for tanh, He for ReLU): set the initial variance so signal magnitude is preserved through depth. Gradient clipping: caps the exploding case.

In an interview

"What causes vanishing gradients and how do you fix them?" — Name the mechanism (a product of many sub-1 terms across depth), then the fixes in order of impact: residual connections, ReLU-family activations, normalisation, principled init, clipping for the exploding side.

Deep Residual Learning for Image Recognition (ResNet)He et al., CVPR · 2015

05A worked example you can do on a whiteboard

Take the smallest network that shows the mechanism: one input x = 2, one weight w₁ = 3, a ReLU, a second weight w₂ = −1, and squared-error loss against a target of 4.

Forward: z₁ = w₁x = 6. a₁ = ReLU(6) = 6. ŷ = w₂a₁ = −6. L = (ŷ − y)² = (−6 − 4)² = 100.

Backward: ∂L/∂ŷ = 2(ŷ − y) = −20. Then ∂L/∂w₂ = ∂L/∂ŷ · a₁ = −20 × 6 = −120 (multiply node: gradient times the other input). And ∂L/∂a₁ = ∂L/∂ŷ · w₂ = −20 × −1 = 20. Through the ReLU, which passes gradient unchanged because its input was positive: ∂L/∂z₁ = 20. Finally ∂L/∂w₁ = ∂L/∂z₁ · x = 20 × 2 = 40.

With η = 0.01: w₂ ← −1 − 0.01(−120) = 0.2, and w₁ ← 3 − 0.01(40) = 2.6. Re-run the forward pass: ŷ becomes 1.04 and the loss drops from 100 to about 8.8. That is the whole of learning, and being able to run it live on a whiteboard is worth more than any amount of vocabulary.

The spelled-out intro to neural networks and backpropagation: building microgradAndrej Karpathymicrogradkarpathy/micrograd
The vocabulary, defined once
Backpropagation
Reverse-mode automatic differentiation over the computation graph. Computes every gradient in ~one forward pass of extra work.
Computation graph
The network as elementary operations and values. Forward evaluates and caches; backward applies the chain rule locally.
Credit assignment
Working out how much each parameter contributed to the error. The problem backprop solves.
Vanishing gradient
A product of many sub-1 derivatives shrinking to zero across depth, so early layers stop learning.
Residual / skip connection
An additive identity path around a block. Gives gradients an unmultiplied route backwards — the reason very deep networks train.
Gradient checkpointing
Recompute activations in the backward pass instead of caching them. Trades compute for memory when training large models.

The lab

Everything above, with the dials exposed. Break it deliberately — the failure modes are where the understanding is.

Try it

One training step, node by node

Forward, then backward, then one update — with every partial derivative computed live.

Try it

The training loop as a sequence

Click any message. Note what's being held in memory between the forward and backward passes.

What they actually ask

Backpropagation — the interview questions

QExplain backpropagation in two minutes.Answer it out loud first, then open this

The network is a computation graph. The forward pass computes the output and caches intermediates. The loss gives one number. The backward pass starts with ∂L/∂L = 1 and walks the graph in reverse: each node multiplies the gradient arriving from downstream by its own local derivative and hands the result to its inputs. Because every node only needs its local derivative, one reverse sweep produces the gradient for every parameter at about the cost of one forward pass. The optimiser then applies those gradients.

What they're listening for
Say 'chain rule applied locally on a graph' and 'one reverse sweep, cost of one forward pass'. Those two phrases carry the whole answer.

QWhy do residual connections help so much?Answer it out loud first, then open this

Two reasons. Optimisation: the additive identity path lets the gradient flow backwards without being multiplied by a chain of weight matrices, so vanishing is much less severe and depth beyond twenty layers becomes trainable. Representation: each block only has to learn a residual correction to the identity, which is an easier function to learn than the full mapping — so adding depth can't make things much worse.

QYou add layers and training accuracy gets worse. What's happening?Answer it out loud first, then open this

Not overfitting — that would show as worse validation with better training. Worse training accuracy with more depth is the degradation problem: optimisation difficulty from vanishing gradients and a harder loss surface. Fixes: residual connections, normalisation layers, He initialisation, and checking the learning rate, since deeper networks often need a lower one.

Before you move on

Recall beats re-reading, every time. Answer before you flip.

Backpropagation · self-test1 / 3

Why is backprop faster than nudging each weight and re-running?

Go to the primary sources

Where each claim above comes from. Open them alongside the lesson rather than after it — the papers are shorter than you think, and the figures usually carry the whole argument.

Paper
  • Deep Residual Learning for Image Recognition (ResNet)(2015)He et al., CVPRWhere skip connections come from. Figure 1 — deeper networks with *worse* training error — is the clearest statement of the degradation problem.
Watch
  • Backpropagation, intuitively (Chapter 3)3Blue1BrownThe intuition first: which weights want to move, and by how much, and why the demands from every training example get averaged.
  • Backpropagation calculus (Chapter 4)3Blue1BrownThe same content with the chain rule made explicit. Watch chapter 3 first, then this — the pairing is deliberate.
  • The spelled-out intro to neural networks and backpropagation: building microgradAndrej KarpathyBuilds a working autograd engine from an empty file in about two hours. If you do exactly one practical exercise in this whole series, do this one.
Read
  • Calculus on Computational Graphs: BackpropagationChristopher OlahThe clearest written derivation of reverse-mode differentiation, including why it costs one forward pass rather than one per parameter.
Code
  • microgradkarpathy/micrograd≈150 lines of Python implementing backprop over a scalar computation graph, plus a small neural net library on top. Read it in one sitting.

External links open in a new tab. Every URL was reachable when this page was written; links rot, so treat the list as a map rather than a guarantee.

Got it? Tick it off — progress saves on this device.

← PreviousGradient descentNext →Fit & generalisation
One training step, node by nodeforward pass · 1/10
x2.0w₁3.00×6.00ReLUw₂-1.00×(ŷ−y)²target y = 4.0
z₁ = w₁ · x
The first multiply: 3.00 × 2.00. z₁ = 6.00. The forward pass caches this — the backward pass will need it.
Change the numbers and re-derive

Set w₁ negative so z₁ goes below zero, then walk the backward pass again. Every gradient upstream of the ReLU becomes zero — the unit is dead, and no amount of training will revive it while that input stays negative. That is the dying-ReLU problem, in four sliders.

Forward fills in values and caches them. Backward walks the same graph in reverse, multiplying by each node's local derivative. Nothing here knows about the network as a whole — that locality is what makes autograd possible.

The training loop, as a sequence
activations held heretraining's real memory costDataLoaderModelLoss fnOptimisera mini-batch (x, y)predictions ŷL — one numberzero_grad()backward sweep — fill every .gradgradients (clipped)θ ← θ − η·∇θLdecay η…and again, a few hundred thousand times
pred = model(xb)

The forward pass, layer by layer. Every intermediate activation is retained, because the backward pass will need it to compute local derivatives. This is where training's memory footprint comes from.

Click any message. The band between the forward pass and the backward sweep is the part people forget: those activations are being held in memory the whole time, which is why training needs several times the memory of inference.

One training step, node by nodeforward pass · 1/10
x2.0w₁3.00×6.00ReLUw₂-1.00×(ŷ−y)²target y = 4.0
z₁ = w₁ · x
The first multiply: 3.00 × 2.00. z₁ = 6.00. The forward pass caches this — the backward pass will need it.
Change the numbers and re-derive

Set w₁ negative so z₁ goes below zero, then walk the backward pass again. Every gradient upstream of the ReLU becomes zero — the unit is dead, and no amount of training will revive it while that input stays negative. That is the dying-ReLU problem, in four sliders.

Forward fills in values and caches them. Backward walks the same graph in reverse, multiplying by each node's local derivative. Nothing here knows about the network as a whole — that locality is what makes autograd possible.

The training loop, as a sequence
activations held heretraining's real memory costDataLoaderModelLoss fnOptimisera mini-batch (x, y)predictions ŷL — one numberzero_grad()backward sweep — fill every .gradgradients (clipped)θ ← θ − η·∇θLdecay η…and again, a few hundred thousand times
pred = model(xb)

The forward pass, layer by layer. Every intermediate activation is retained, because the backward pass will need it to compute local derivatives. This is where training's memory footprint comes from.

Click any message. The band between the forward pass and the backward sweep is the part people forget: those activations are being held in memory the whole time, which is why training needs several times the memory of inference.