Automatic differentiation

Level AdvancedDifficulty ★★★★★Application⌖ Open in the map

What is it?

Computing exact derivatives of programs by applying the chain rule to each elementary operation. Neither symbolic (no expression swell) nor numerical (no truncation error). Reverse mode gives the gradient of a scalar for a small constant times the cost of the program.

Formulas

(a+bε)(c+dε)=ac+(ad+bc)ε,ε2=0(a + b\varepsilon)(c + d\varepsilon) = ac + (ad + bc)\varepsilon, \quad \varepsilon^2 = 0
forward mode with dual numbers
vˉi=∑j: i→jvˉj ∂vj∂vi\bar v_i = \sum_{j:\ i \to j} \bar v_j\,\frac{\partial v_j}{\partial v_i}
reverse mode: adjoints propagate backwards

Why does it matter?

Every deep learning framework is, at its core, an AD engine (PyTorch autograd, JAX, TensorFlow). AD also powers differentiable rendering, differentiable physics and sensitivity analysis in science.

The mathematics behind it

  • Derivative★★★★★fundamental

    AD computes exact derivatives of programs by propagating them through each operation.

  • Differentiation rules★★★★★fundamental

    AD applies exactly these rules, one elementary operation at a time, to numbers instead of formulas.

  • Chain rule★★★★★fundamental

    Forward and reverse mode are two orders of multiplying the same chain of local derivatives.

  • Multivariable chain rule★★★★★fundamental

    Forward and reverse mode are the two natural orders of multiplying the Jacobian chain.

  • Composition★★★★★fundamental

    AD sees a program as a composition of primitive operations and differentiates each one.

  • Derivatives of elementary functions★★★★★fundamental

    Every AD system ships a table of derivatives of its primitive operations.

  • Directional derivative★★★★★frequent

    Forward-mode AD with dual numbers computes DufD_u f (a JVP) in one pass.

  • Jacobian matrix★★★★★fundamental

    AD computes JVPs (forward mode) and VJPs (reverse mode) without materializing JJ.

  • Numerical differentiation★★★★★frequent

    "Gradient checking" compares autodiff gradients against finite differences to catch bugs.

Where is it used?

Computing topics reachable from here, through the chain of ideas that leads to them:

What depends on it

This page has the essentials. A fuller treatment (intuition, formal definition, worked example) is on the way.

↑ ↓ to navigate · ↵ · Esc