﻿# JAX JVP or VJP: specify the sensitivity direction before constructing a Jacobian

Choose JAX JVP for input-direction sensitivities or VJP for output-weighted pullbacks, preserving tangent and cotangent structures without materializing an unnecessary Jacobian.

Author: Retrivium editorial team
Updated: 2026-11-04
Canonical URL: https://retrivium.ai/journal/fg2-jax-jvp-vjp-projection-direction/
Language: en

## 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](https://docs.jax.dev/en/latest/301/cookbook.html) 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](https://docs.jax.dev/en/latest/_autosummary/jax.jvp.html) 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](https://docs.jax.dev/en/latest/_autosummary/jax.vjp.html) 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](/journal/autograd-chain-rule-neural-graphs/) and [tensor memory descriptors](/journal/learn-tensor-memory-descriptor/) 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.
