Autodiff #
Autodiff utilities beyond basic .backward():
hvpParams: Hessian-vector product for scalar losses w.r.t. parameters, using forward-over-reverse viaDualscalars.
This is runtime/executable functionality intended for TorchLean ergonomics; it is separate from
the fderiv proof developments.
Unwrap a runtime Result into IO, throwing a user error on failure.
This is used throughout this module because lowering and backpropagation utilities return an
Autograd.Result with a structured error message.
Instances For
Execute the checked graph pullback, reporting domain errors through the IO API.
Instances For
Lower a scalar-valued TorchLean program to a reusable typed graph.
Instances For
Lower a TorchLean program to a reusable TypedGraph.
The graph retains a typed reference to the value returned by the program, which may be an input or
any recorded node. This is the tensor-output analogue of lowerScalarToTypedGraph; it is
used by jacrevOut* and vjpOut*.
Instances For
Reverse Jacobian, with output axes prepended to each parameter tensor.
Instances For
Reverse Jacobian, with output axes prepended to each input tensor.
Instances For
Compute the forward Jacobian for a single tensor input.
Each input basis vector runs through the checked graph JVP. This uses the same primitive rules as directional differentiation, including stopped gradients and the runtime's choices at nonsmooth points. The returned tensor has output axes followed by input axes.
Instances For
Differentiate a scalar loss with respect to parameters and inputs in one reverse pass.
Instances For
Compute a tensor-output VJP with respect to parameters and inputs in one reverse pass.
Instances For
Directional derivative of scalar loss along vparams (forward-mode JVP).
Instances For
Reverse-mode gradients over dual-valued arguments, shared by both HVP projections.
Instances For
Hessian-vector product (HVP) for a scalar loss w.r.t. parameters.
This computes d/dε (∇_params loss(params + ε*vparams)) |_{ε=0} and returns a
TorchLean.TensorPack aligned with paramShapes.
Implementation: run reverse-mode AD over dual scalars (Dual), with parameter tangents set to
vparams and input tangents set to 0. The tangent part of the resulting gradients is the HVP.
Instances For
Hessian-vector product (HVP) for a scalar loss w.r.t. inputs.
This computes d/dε (∇_xs loss(xs + ε*vxs)) |_{ε=0} and returns a TorchLean.TensorPack
aligned with inputShapes.
Implementation: the same forward-over-reverse trick as hvpParams, but we attach tangents to
inputs instead of parameters.
Instances For
Full Hessian tensor for a scalar function of a single tensor input.
Columns are evaluated as H * e_i in the flattened input basis, then arranged with one copy of
the input axes for each derivative.