Level 0: Foundation
★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.Two questions you can ask a machine
Picture a machine with many knobs (inputs) and many dials (outputs). You can ask it two kinds of question:
- Forward: “If I turn the knobs a little in this combination, how do all the dials move?”
- Backward: “I care about this combination of dials. How much does each knob matter to it?”
The first question is a JVP. The second is a VJP. Training a neural network asks the backward question about a single dial, the loss. That’s backpropagation.
A robot arm’s Jacobian maps joint speeds to hand speed (forward: “move the joints like this, where does the hand go?”). Its transpose maps a force at the hand back to joint torques (backward: “push here, what does each motor feel?”). Every manipulator controller uses both products.
- 1. Asking how all outputs move for one input nudge is a…
- 2. Asking how every input affects a single loss is a…
- 3. f(x) = 3x. Nudge x by 0.1: the output moves by…
Level 1: Beginner
★★☆☆☆ Basic⏱ 15 minSecondary-school mathematics: arithmetic and elementary algebra.The two products
For with Jacobian at :
| JVP (forward / tangent) | VJP (reverse / cotangent) | |
|---|---|---|
| Input | direction | weights |
| Output | ||
| Meaning | directional derivative | gradient of |
| Picks out | a column of (when ) | a row of (when ) |
Example: for with : , so gives . And , so gives the first row .
Dual numbers: forward mode in one idea
Invent a number with . Then . The -part, 4, is exactly at 2. Running any program on returns , with exact derivatives and no step size.
- 1. For f: ℝ⁵ → ℝ², a JVP returns a vector of length…
- 2. And a VJP returns a vector of length…
- 3. (3 + ε)² with ε² = 0 has ε-part…
Level 2: Intermediate
★★★☆☆ Intermediate⏱ 45 minUndergraduate students and practising engineers.How autodiff computes them
Forward mode (JVP): carry a tangent next to every value. Each primitive updates it with its local derivative: and . Seeding inputs with yields in one pass, in the same order as the program, with no stored tape.
Reverse mode (VJP): run forward and store values, then propagate adjoints backwards (A3.3-5). Seeding outputs with yields in one backward pass.
Composition. For , :
- JVP: . Push through first, then .
- VJP: . Pull back through first, then .
Neither ever forms a matrix product. Each step is a matrix-vector product with a local Jacobian, which is usually cheap and often structured (diagonal for element-wise operations).
Which one to use
| Task | Best tool | Passes |
|---|---|---|
| gradient of a scalar loss, parameters | VJP | 1 |
| full Jacobian, (few inputs) | JVPs | |
| full Jacobian, (few outputs) | VJPs | |
| sensitivity of a trajectory to one parameter | JVP | 1 |
| Hessian–vector product | JVP of a VJP | about 1 gradient |
- 1. Full Jacobian of f: ℝ¹⁰ → ℝ⁴ with fewest passes uses…
- 2. For f = g∘h, a VJP applies…
- 3. Forward mode needs a stored tape of intermediate values?
Level 3: Advanced
★★★★☆ Advanced⏱ 40 minGraduate level, with full derivations and proofs.The adjoint identity
For any and , . Both sides equal . The VJP is the adjoint (transpose) of the JVP as linear maps. This gives the standard dot-product test for a hand-written backward pass: pick random and and check that the two sides agree to machine precision (Practice Code 4). The test is used routinely for adjoint codes in weather prediction and seismic imaging.
Why dual numbers are exact
Take a polynomial or analytic . By Taylor’s theorem, , and every term from on vanishes. The arithmetic rules for duals () are the sum and product rules, so by induction over the program, every intermediate carries its exact derivative. There’s no truncation error, unlike finite differences (A3.1-2).
Tangents and cotangents
Geometrically, pushes forward tangent vectors (velocities) from input space to output space. pulls back covectors (gradients, “measurement directions”) from output space to input space. This is why a gradient has the shape of the input, not the output. It’s also why in robotics while : velocities push forward, and forces (covectors, since power is conserved) pull back.
Hessian–vector products
The Hessian is the Jacobian of the gradient. So , a JVP of the VJP (“forward-over-reverse”). It costs a small constant times one gradient, regardless of dimension (Pearlmutter, 1994). With HVPs alone you can run conjugate gradient on and take Newton steps without ever storing (A2.4-7).
Exercise 3.1: Check the adjoint identity for J = [[1, 2], [0, 1]], u = (1, 1), v = (1, 1)
, so . , so . ✓
- 1. uᵀ(Jv) = (Jᵀu)ᵀv says the VJP is the ___ of the JVP.
- 2. Dual numbers have truncation error of order…
- 3. Joint torques from a hand force use…
Level 4: Expert
★★★★★ Expert⏱ 45 minResearchers: original papers and open problems.Matrix-free second-order methods
Second-order information is often too large to store. A model with parameters has a Hessian with entries. HVPs make it usable:
- Hessian-free optimization (Martens, 2010) runs truncated Newton-CG with HVPs or Gauss–Newton vector products.
- Hutchinson’s estimator (Hutchinson, 1989): with random vectors. It’s used for sharpness measures, for the divergence in continuous normalizing flows (Grathwohl et al., 2019), and in score matching.
- Top eigenvalues of come from Lanczos or power iteration on HVPs. This is how curvature spectra of deep networks are measured (Ghorbani et al., 2019).
More uses in research and engineering
- Lipschitz control. Power iteration with alternating JVPs and VJPs estimates . That’s the basis of spectral normalization for stable GAN and robust-controller training (Miyato et al., 2018) and of certified robustness bounds (M1) (Practice Code 5).
- Jacobian-free Newton–Krylov (Knoll and Keyes, 2004). Implicit time-stepping in plasma, combustion and re-entry flow solvers needs only products inside GMRES.
- Implicit differentiation. To differentiate through an optimizer, an equilibrium or a physics solve , solve one linear system with VJPs and never unroll the solver (Blondel et al., 2022; deep equilibrium models, Bai et al., 2019).
- Trajectory sensitivities. Forward mode suits “how does this whole trajectory change if the payload mass changes?” (one parameter, many outputs). Reverse/adjoint mode suits “how does final miss distance depend on all controls?” (many parameters, one output).
- JAX’s design.
jvpis the primitive,linearizecaches the linear map, andvjpis obtained by transposing that linear map (Frostig et al., 2021). The adjoint identity is built right into the system.
References
- B. Pearlmutter (1994). “Fast exact multiplication by the Hessian.” Neural Computation, 6(1).
- M. Hutchinson (1989). “A stochastic estimator of the trace of the influence matrix for Laplacian smoothing splines.” Communications in Statistics: Simulation and Computation, 18(3).
- J. Martens (2010). “Deep learning via Hessian-free optimization.” ICML.
- A. G. Baydin, B. Pearlmutter, A. Radul, J. Siskind (2018). “Automatic differentiation in machine learning: a survey.” JMLR, 18.
- T. Miyato, T. Kataoka, M. Koyama, Y. Yoshida (2018). “Spectral normalization for generative adversarial networks.” ICLR.
- D. Knoll, D. Keyes (2004). “Jacobian-free Newton–Krylov methods: a survey of approaches and applications.” Journal of Computational Physics, 193.
- M. Blondel et al. (2022). “Efficient and modular implicit differentiation.” NeurIPS.
- R. Frostig, M. Johnson, D. Maclaurin, A. Paszke, A. Radul (2021). “Decomposing reverse-mode automatic differentiation.” LAFI workshop, arXiv:2105.09469.
- B. Ghorbani, S. Krishnan, Y. Xiao (2019). “An investigation into neural net optimization via Hessian eigenvalue density.” ICML.
- B. Siciliano, L. Sciavicco, L. Villani, G. Oriolo (2009). Robotics: Modelling, Planning and Control. Springer. (Velocity and force Jacobians.)