Forward pass: compute activations layer by layer and the final loss, caching intermediate values.
Backward pass: apply the chain rule from the loss back through each layer to get the gradient of the loss with respect to every weight and bias.
For a linear layer Y = XW + b with upstream gradient dY: dW = X transposed times dY, db = sum of dY over the batch, dX = dY times W transposed. Matching tensor shapes is a good sanity check.
The optimizer then updates the parameters using those gradients. Autograd frameworks (PyTorch, JAX) build and traverse this computation graph automatically.
Loading…