Availit World How AI really works, in your language

Lesson 11 of 4614 minFacts checked October 20, 2026

Backpropagation: how billions of weights learn at once

Gradient descent needs the slope of the loss for every single weight. Backpropagation finds all of them in one backward sweep, using a rule from school calculus. It is the engine under all of deep learning, and you can run it by hand.

In this lesson you will

  • Explain the chain rule as multiplying effects along a path
  • Follow a forward pass and a backward pass through a tiny network, by hand
  • Say why training costs about 6 operations per weight per token, and needs far more memory than running a model
  • Recognise vanishing gradients, residual connections and normalisation in model diagrams
On this page
  1. The problem: billions of slopes
  2. The chain rule: effects multiply
  3. A worked example
  4. What training really costs
  5. Keeping the slopes alive
  6. You never write it yourself
  7. Remember
  8. Check yourself

The problem: billions of slopes

In the gradient descent lesson, each step needed the slope of the loss for every weight. The obvious way to find a weight’s slope is to nudge it a little, run the model again, and see how the loss changes. For a model with 8 billion weights, that is 8 billion runs of the model for one single step. Training would never finish.

Backpropagation (backprop for short) gets every slope from just two passes. The forward pass runs the model normally and remembers the numbers it computed along the way. The backward pass then goes through the layers in reverse, from the loss back to the inputs, handing slopes from each layer to the one before. It was made popular by a four-page Nature paper in 1986, and every model in this course was trained with it.

The chain rule: effects multiply

A network is a chain of simple steps: multiply by a weight, add, bend, multiply again, compute the loss. The chain rule from calculus says that the effect of an early number on the final loss is the product of the effects of each step along the way.

∂loss/∂w = ∂loss/∂y × ∂y/∂w

Read “∂loss/∂w” as “how much the loss changes when w is nudged”. Papers use the curly ∂ for slopes when there are many variables.

A worked example

Here is a network with two weights, small enough to do on paper. One input x goes into a neuron with weight w₁ and a ReLU, then into an output with weight w₂. We want the output to be 10.

Forward pass: run it and remember everything
StepFormulaValue
Inputx1
Hidden neuronh = ReLU(w₁ × x) = ReLU(2 × 1)2
Outputy = w₂ × h = 3 × 26
Loss(y − 10)² = (6 − 10)²16
Backward pass: hand the slope back, step by step
SlopeChain ruleValue
Loss by output∂L/∂y = 2 × (y − 10)−8
Loss by w₂∂L/∂w₂ = ∂L/∂y × h = −8 × 2−16
Loss by hidden value∂L/∂h = ∂L/∂y × w₂ = −8 × 3−24
Loss by w₁∂L/∂w₁ = ∂L/∂h × x = −24 × 1−24

ReLU passes the slope through unchanged here, because its input (2) is positive. For a negative input it would pass back zero.

Both slopes are negative, so gradient descent raises both weights. With a learning rate of 0.01: w₂ becomes 3 + 0.16 = 3.16 and w₁ becomes 2 + 0.24 = 2.24. Run the forward pass again: h = 2.24, y = 7.08, and the loss falls from 16 to 8.5 in a single step.

Look at the third row. The slope for h was computed once and then reused for everything below it. In a real network each layer receives one such slope from the layer above, uses it for its own weights, and passes a new slope down. No work is repeated. That is why the backward pass is cheap.

Quick check

If w₂ had been 0 instead of 3, what would the slope for w₁ be?

Show the answer

Answer: 0, because the slope passing back through w₂ becomes 0 ∂L/∂h = ∂L/∂y × w₂. With w₂ = 0, nothing flows back to h, so w₁ gets no slope at all: changing it would not change the output.

What training really costs

The backward pass does about twice the work of the forward pass, because for each matrix it needs two slopes: one for the weights, and one to pass on to the layer below. That gives a famous rule of thumb.

Training compute
running a model ≈ 2 × parameters operations per token

The forward pass: a multiply and an add for each weight.

training ≈ 6 × parameters × tokens operations

Forward (2) plus backward (4), for every training token.

6 × 37 billion × 14.8 trillion ≈ 3.3 × 10²⁴

DeepSeek-V3: 37 billion parameters used per token, 14.8 trillion training tokens.

Training also needs far more memory than running. For the backward pass, the forward pass has to keep its in-between values (called activations). And besides the weights, training stores a slope for every weight and the optimizer’s own numbers: AdamW keeps two extra values per weight. With the usual mix of precisions, this comes to about 16 bytes per parameter before any activations.

Memory for an 8-billion-parameter model
TaskRoughly
Running it, BF16 weights16 GB
Running it, squeezed to about 4.5 bits4.5 GB
Fully training it with AdamW (16 bytes per parameter)128 GB, plus activations: several data-centre GPUs

This gap is why most people do not fully retrain models, but use cheaper methods such as LoRA, which updates a small number of extra weights. That has its own lesson in part 5.

Keeping the slopes alive

The chain rule multiplies slopes along the path. Over many layers, multiplying many numbers smaller than 1 drives the result towards zero, and the early layers stop learning. This is the vanishing gradient problem. Numbers larger than 1 cause the opposite, exploding gradients. For decades this made deep networks very hard to train.

Two simple fixes made depth possible, and both are in every transformer:

  • Residual connections (from ResNet, 2015). Instead of replacing its input, each block adds its result to it: output = x + block(x). The slope then always has a direct path back through the “+ x”, with nothing to shrink it. This is the residual stream from the vectors lesson. ResNet trained image networks 152 layers deep this way.
  • Normalisation. Before each block, the vector is rescaled to a standard size, so numbers neither shrink nor blow up from layer to layer. Most open models use RMSNorm, a simpler version of the older LayerNorm.

You never write it yourself

Nobody works out these slopes by hand for real models. Frameworks such as PyTorch record every operation in the forward pass and run the backward pass automatically. This is called autograd (automatic gradients). Here is the one-weight version of the example above:

Backprop in four lines of PyTorchpython
import torch
w = torch.tensor(3.0, requires_grad=True)
loss = (w * 2.0 - 10.0) ** 2
loss.backward()
print(w.grad)   # tensor(-16.)
  • requires_grad=True tells PyTorch to track this number.
  • loss.backward() runs the backward pass through every recorded step.
  • w.grad now holds the slope: (6 − 10) × 2 × 2 = −16, the same as the second row of the table.

Forward pass or backward pass?

0 of 6 sorted
  • Computing the model’s output from the input

    Answer: Forward pass

  • Working out ∂loss/∂w for every weight

    Answer: Backward pass

  • Computing the loss

    Answer: Forward pass

  • Handing a slope from layer 32 to layer 31

    Answer: Backward pass

  • Saving activations to use later

    Answer: Forward pass

  • The only pass needed when you chat with a model

    Answer: Forward pass

Remember

  • Backpropagation finds the slope of the loss for every weight with one forward pass and one backward pass.
  • It is the chain rule: effects multiply along the path, and each layer passes one slope to the layer before, so nothing is repeated.
  • Running costs about 2 operations per weight per token; training about 6 × parameters × tokens.
  • Training needs about 16 bytes per parameter plus activations, far more than running a model.
  • Residual connections and normalisation stop gradients vanishing or exploding. PyTorch’s autograd does it all for you.

Words to know

Backpropagation
The method that computes every weight’s slope by going backwards through the network once.
Forward pass
Running the network from input to output (and to the loss).
Backward pass
Going from the loss back through the layers, computing slopes with the chain rule.
Chain rule
The effect of a change through several steps is the product of each step’s effect.
Activations
The in-between values a network computes, kept from the forward pass for the backward pass.
Vanishing gradient
Slopes shrinking to almost nothing on their way back through many layers, so early layers stop learning.
Residual connection
Adding a block’s output to its input (x + block(x)), giving slopes a direct path back.
Normalisation
Rescaling each vector to a standard size between blocks (LayerNorm, RMSNorm).
Autograd
Software that records the forward pass and computes all slopes automatically.

Go to the source

This lesson is built on these papers and documents. Paper links open arxiv.org, a separate site.

Check yourself

5 questions. Tap the answer you think is right.

0 of 5 answered

Why not find each weight’s slope by nudging it and re-running the model?

Show the answer

Answer: It would take one run per weight, billions of runs per step That works for one weight, but a big model has billions. Backprop gets them all from one forward and one backward pass.

In the chain rule, how are the effects along a path combined?

Show the answer

Answer: Multiplied Like the gears: if each step scales the change by some amount, the total effect is the product.

A 10-billion-parameter model is trained on 1 trillion tokens. Roughly how many operations is that?

Show the answer

Answer: 6 × 10²² 6 × parameters × tokens = 6 × 10¹⁰ × 10¹² = 6 × 10²².

What does a residual connection do?

Show the answer

Answer: Adds a block’s output to its input, so slopes have a direct path back output = x + block(x). The “+ x” keeps the gradient flowing even through very deep networks.

Why does training need much more memory than running a model?

Show the answer

Answer: It stores slopes, optimizer values and activations as well as the weights Running needs only the weights (plus a cache). Training needs about 16 bytes per parameter for weights, slopes and AdamW’s values, plus the saved activations.

Lesson complete

Answer every question above to complete this lesson.

Your progress is saved on this device only.

Next lessonBefore transformers: the networks that led here
Previous lesson All lessons

Choose your language