Autodiff from scratch
Every framework's core is a machine that differentiates programs. Build one — forward mode with dual numbers, then a reverse-mode engine in about fifty lines — train a network with it, and check it against finite differences and PyTorch.
50 min
After this lesson you can
- Turn a program into a computational graph and compute its gradient by hand with the adjoint rule
- Explain forward mode with dual numbers () and reverse mode with a recorded graph
- Say when each mode is efficient using the shape of the Jacobian (JVP gives a column, VJP gives a row)
- Implement a scalar reverse-mode autograd engine with topological sorting and gradient accumulation
- Verify gradients with finite differences and against PyTorch
In this lesson
- Three ways to differentiate
- Programs are graphs
- Forward mode: dual numbers
- Which mode when? JVPs and VJPs
- Build a reverse-mode engine
- Train a network with it
- Check it against PyTorch
This lesson is part of Descent Pro
Descent Pro unlocks every lesson on the route, from base camp to the summit. Every plan starts with a free trial.