What is Backpropagation?

The training computation that propagates the error between output and target backward from output to input to obtain each weight's gradient.

Field: AI Hardware & Software Stack

Japanese name: 逆伝播

How backpropagation works

Training starts with a forward pass that computes the output and a loss measuring its error against the target. Backpropagation then applies the chain rule in reverse: starting from the loss, each layer receives the gradient with respect to its output and computes two things, the gradient with respect to its weights and the gradient with respect to its input, which it passes to the previous layer. For a fully connected layer, the weight gradient combines the incoming gradient with the input activations saved during the forward pass. An optimizer then nudges each weight against its gradient.

Computational graphs and automatic differentiation

Frameworks represent a model as a computational graph, with operations such as matrix products, additions and activations as nodes and tensors as edges. Because each node knows its own local derivative, the framework can traverse the graph backward and compute all gradients automatically, a technique called reverse-mode automatic differentiation. The graph also exposes which operations are independent. Inference runtimes such as TensorRT or ONNX Runtime drop the bookkeeping needed for backpropagation, then fuse operations, lower precision where needed and pick hardware-specific kernels, which is why they run faster than the training framework used for inference.

Compute and memory cost

The backward pass costs about twice the forward pass, because each layer computes gradients for both its inputs and its weights. A forward pass is about 2N operations per token for N parameters, so training costs about 6N per token, or 6ND for D tokens; a 7-billion-parameter model on 1 trillion tokens needs about 4.2×10224.2 × 10^22 operations. Memory grows even more: training stores intermediate activations, gradients equal in number to the weights, and optimizer state such as Adam's two moving averages. Gradient checkpointing saves only some activations and recomputes the rest, costing roughly one extra forward pass.

Numerical precision and loss scaling

Gradients are often tiny. FP16 (1 sign, 5 exponent, 10 significand bits) covers positive values from only about 6×10−86 × 10^-8, including subnormals, up to 65504, so many gradients underflow to zero and learning stalls. Loss scaling multiplies the loss by a factor such as 1024 before backpropagation, lifting gradients into range, and divides it back out before the weight update. Mixed-precision training usually also keeps a higher-precision master copy of the weights. BF16, with 8 exponent bits like FP32, has a much wider range and rarely needs loss scaling.

Try it: questions about Backpropagation

Why is it hard to train spiking neural networks (SNNs), the models run in neuromorphic computing, directly with the backpropagation used for ordinary neural networks?

  1. ASNNs have no weights
  2. BSpiking is a discontinuous operation decided by whether a threshold is crossed, so it is not differentiable
  3. CSNNs can only perform inference and have no concept of training
Show answer and explanation

Answer: B. Spiking is a discontinuous operation decided by whether a threshold is crossed, so it is not differentiable

Each SNN neuron accumulates incoming spikes as a membrane potential and emits a spike when it crosses a threshold. Because this output switches discontinuously between 0 and 1, the gradient that backpropagation needs is zero almost everywhere or undefined. Workarounds therefore include using, only during training, gradients that approximate the spike function with a smooth function, or training a conventional network and converting it into an SNN.

FAQ

What is the difference between backpropagation and gradient descent?

Backpropagation computes the gradient of the loss with respect to every weight. Gradient descent, or another optimizer such as Adam, uses those gradients to update the weights.

Why does training need more memory than inference?

Training must keep forward activations for the backward pass, plus a gradient for every weight and optimizer state, while inference needs only the weights and transient activations.

How expensive is the backward pass compared with the forward pass?

Roughly twice as expensive, so one training step costs about three forward passes, which is the origin of the 6N operations-per-token rule of thumb.

Questions that mention Backpropagation (7)

Backpropagation appears in 8 practice questions across 2 topics, including AI Hardware & Software Stack, Computer Arithmetic.

  1. When training neural networks in FP16 (half precision: 1 sign, 5 exponent, 10 significand bits), which problem tends to arise and is countered by scaling up the loss (loss scaling)?
  2. What is the difference between training and inference for a neural network?
  3. Which is NOT a reason training needs much more memory than inference for the same model?
  4. Which describes the computational graph used by AI frameworks and compilers?
  5. Why can inference runtimes such as TensorRT or ONNX Runtime run faster than using the training framework directly for inference?
  6. Which describes gradient checkpointing (activation recomputation) used in training?
  7. For a Transformer with N parameters trained on D tokens, which approximation is commonly used for the number of training operations?

Books on AI Hardware & Software Stack Ad

As an Amazon Associate I earn from qualifying purchases.

Comparisons that include this term

This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.

Back to the glossary