Backpropagation › Vectorized Backpropagation

Michael BrenndoerferMay 6, 20252 min read
Language AI HandbookAll chapters
Part 10 of 67Neural Network Foundations
Chapter 65Backpropagation › Vectorized Backpropagation
Reading section 11 of 20 · Vectorized Backpropagation · 2 minSection 11 of 20 · 2 min

Book contents

Section 11 of 20 · 2 min read

Backpropagation › Vectorized BackpropagationOne section · Sections in this chapter11 / 20 ↓
Reading tools Definitions & inline links

Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.

Article links

Make inline references clickable

Real implementations work with mini-batches rather than single examples. With a batch of BB examples, the input is X∈RB×n\mathbf{X} \in \mathbb{R}^{B \times n}, and all forward and backward computations generalize naturally.

For a linear layer Z=XWT+b\mathbf{Z} = \mathbf{X} \mathbf{W}^T + \mathbf{b}:

  • Forward: Z=XWT\mathbf{Z} = \mathbf{X} \mathbf{W}^T (matrix multiplication, Z∈RB×m\mathbf{Z} \in \mathbb{R}^{B \times m})
  • Backward gradient w.r.t. weights: ∂L∂W=(∂L∂Z)TX\frac{\partial \mathcal{L}}{\partial \mathbf{W}} = \left(\frac{\partial \mathcal{L}}{\partial \mathbf{Z}}\right)^T \mathbf{X} (result shape m×nm \times n)
  • Backward gradient w.r.t. input: ∂L∂X=∂L∂ZW\frac{\partial \mathcal{L}}{\partial \mathbf{X}} = \frac{\partial \mathcal{L}}{\partial \mathbf{Z}} \mathbf{W} (result shape B×nB \times n)
  • Backward gradient w.r.t. bias: ∂L∂b=∑i=1B∂L∂zi\frac{\partial \mathcal{L}}{\partial \mathbf{b}} = \sum_{i=1}^{B} \frac{\partial \mathcal{L}}{\partial \mathbf{z}_i} (sum over batch dimension)

The bias gradient requires summing over the batch dimension because the same bias vector is added to all examples. This is another example of gradient accumulation: the bias participates in BB computations (one per example), so its gradient is the sum over all BB paths.

Vectorized backpropagation improves performance and naturally averaged (or summed, depending on how the loss is normalized) over the batch. A batch gradient descent step moves the parameters in a direction that reduces the average loss across all examples in the batch. With large batches, this average is a better approximation of the true gradient over the full dataset, leading to more stable optimization. With small batches (stochastic gradient descent), the noisier gradient estimate can help escape sharp local minima, which is why SGD with a small batch size often generalizes better than full-batch gradient descent.