In this article
Linearity applies to tangent inputs at a fixed primal point, not to the original nonlinear model function.
Identify which part must be linear
A developer writes a custom directional derivative and squares the incoming tangent to damp large sensitivities. The primal model is nonlinear, but that does not justify a nonlinear tangent mapping. The custom derivative guide requires the output tangent to be linear in the input tangents. At a fixed primal point, a derivative is a linear map of perturbations. Altering this property changes the mathematical object rather than merely choosing a different implementation of the same derivative.
Separate primal coefficients from tangent arguments
A derivative coefficient can depend nonlinearly on the primal inputs. Multiplying that coefficient by the incoming tangent is compatible with linearity in the tangent. Squaring, clipping or branching on the tangent magnitude is a different operation. Write the rule with named primal-dependent coefficients and tangent contributions so a reviewer can inspect the distinction. An expression that looks similar to the model’s original nonlinear formula may be inappropriate when applied to perturbations instead of values.
Implement the declared pair interface
The defjvp reference specifies primal and tangent argument tuples and a returned pair of primal and tangent outputs. Preserve the nested structures and ensure the primal output still represents the original function. A rule that returns a correct-looking tangent but changes the forward value is not an equivalent derivative customization. Include contributions from every differentiable argument rather than silently treating a convenient secondary input as fixed.
Check reverse differentiation as a separate consumer
The custom_jvp reference defines the decorated transformable function. JAX can derive reverse differentiation by transposing the tangent computation when the rule satisfies the required contract. Test that intended transformation explicitly. A manually invoked forward rule producing finite numbers does not establish that transposition is valid, nor that the resulting parameter sensitivities match the mathematical derivative the application expects.
Use superposition and numerical reference checks
At a fixed primal point, compare the tangent result for a sum of directions with the sum of separate tangent results, and check scaling within suitable tolerance. Then compare against an independent derivative reference on smooth inputs. The guides on autograd chain rules and mixed-precision accumulation provide related context. These checks answer different questions: superposition examines a required structural property, while the derivative reference examines whether the chosen linear map is the correct one for the primal function.
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.