Math toolkit
Calculus and gradients
Derivatives, partial derivatives, the chain rule and gradients. This is the math that turns a loss number into parameter updates.
Training a model means repeatedly answering one question: if I nudge this weight a little, does the loss go up or down? The answer is a derivative. With millions of weights you need a gradient, a vector of derivatives, and the chain rule computes it efficiently. Autograd libraries hide this arithmetic. This topic makes it visible, so you can read backprop code, spot exploding gradients and check your math.
Linear algebra is the language of the forward pass. Calculus is the language of the backward pass. Every optimizer step assumes you can compute the gradient of the loss. Any custom loss you design must be differentiable, at least almost everywhere.
Concepts in this topic
Read in this order. Each page builds on the one before it.
| Step | Concept | What it answers |
|---|---|---|
| 1 | Derivatives as slopes | How fast does the output change for a tiny change in input? |
| 2 | Partial derivatives and gradients | What happens when there are many inputs? |
| 3 | The chain rule | How do slopes combine through a chain of operations? |
| 4 | Jacobians and vector-Jacobian products | What is the slope of a layer that outputs a vector? |
| 5 | Derivatives of common functions | What are the slopes of sigmoid, ReLU and softmax with cross-entropy? |
| 6 | Curvature and second derivatives | Why does a safe learning rate depend on the shape of the loss? |
Backpropagation applies the chain rule to a whole network. See backpropagation from scratch.
Common mistakes across the topic
- Trusting autograd silently. A detached tensor gives a zero gradient with no error. After
backward(), printparam.gradfor a few parameters. - Blaming autograd for NaNs. NaN losses usually come from exploding gradients,
log(0)in cross-entropy, or division by zero. - Using numerical gradients in training. They need one forward pass per parameter. Use them to check code, not to train.
In practice
- Vanishing gradients through deep stacks of sigmoids or tanh pushed the field toward ReLU, residual connections and normalization.
- A residual connection
y = x + F(x)adds an identity path, so∂L/∂xincludes a+1term. Gradients have a route that avoids many weight matrices. - When writing a custom op, check its gradient against finite differences on a small input before you trust it.
Key takeaways
- A derivative is a local slope. A gradient is the vector of partial derivatives, pointing uphill.
- The chain rule, applied on a computational graph, is backpropagation.
- Frameworks compute vector-Jacobian products, not full Jacobians. That is why reverse mode scales.
- Know the derivatives of sigmoid, tanh and ReLU, and the
p − yresult for softmax with cross-entropy.
Further learning
3Blue1Brown's essence of calculus builds the idea that slopes multiply under composition:
The chain rule chapter is the direct prerequisite for backprop:
Related
Linear algebra for ML
Vectors, matrices and matrix multiplication, the language every model is written in. Learn the shapes, then batching, FLOP counts and low-rank tricks.
Backpropagation from scratch
How training computes the gradient of the loss for every weight in one backward pass. Covers computational graphs, reverse-mode autodiff and the bugs that break training.
Optimization and gradient descent
How models learn, from loss landscapes and gradient descent to learning rates, mini-batches, momentum and Adam.