In this article
JVP pushes a chosen input perturbation forward; VJP pulls a chosen output weighting back to the inputs.
Name the sensitivity question precisely
A model maps a parameter collection to several measured outputs. An engineer asks for its derivative but actually needs the output change along a particular parameter perturbation. Another consumer needs parameter sensitivity for a weighted output score. These are different linear operations. The autodiff cookbook develops Jacobian products without requiring a dense Jacobian. Begin with the desired input and output spaces, including the units and interpretation of the chosen direction or weighting.
Push an input direction with JVP
The JVP API accepts primal arguments and tangents with matching tree structure and array shapes. It returns the primal output and its directional tangent. The direction is data supplied to the derivative calculation, not another model prediction or a request for all partial derivatives. Preserve its scale deliberately: changing the perturbation vector changes the directional result. Matching dimensions alone does not establish that the vector represents the sensitivity the application intended to measure.
Pull an output weighting with VJP
The VJP API returns a primal output and a pullback callable. The callable consumes an output cotangent and returns input cotangents corresponding to the original arguments. Choose the output weighting according to the scalar quantity of interest. An all-ones weighting combines outputs; it does not expose every Jacobian entry separately. If output components have different meanings or units, an unexplained aggregate can produce a mathematically valid result that answers an unhelpful question.
Retain structure instead of guessing orientation
Write down how nested parameter leaves and output leaves correspond to tangent and cotangent leaves. Flattening can help a reference calculation, but its ordering must be explicit. Do not select an API by copying a matrix multiplication from a notation convention without checking its actual interface. A small linear function with distinguishable coefficients makes orientation and structure mistakes visible before using the same wrapper around a larger nonlinear GPU calculation.
Compare the required product rather than every derivative
Validate the selected product against an analytical example or suitable finite-difference directional check, with a justified tolerance. The guides on autograd chain rules and tensor memory descriptors provide related context. Materialize a full Jacobian only when the consumer requires its entries. An explicit sensitivity direction makes the calculation easier to explain and can avoid storing derivative information that the downstream analysis will immediately discard.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.