Automatic Differentiation #
This module contains gradient, VJP, Jacobian, JVP, and HVP operations for models and pure one-argument tensor functions.
Autograd operations (grad/vjp/jacobian) over TorchLean programs.
This namespace is conceptually similar to PyTorch autograd + functorch/torch.func:
- gradients of losses w.r.t. parameters and inputs
- VJPs and Jacobians for analysis and verification tooling
PyTorch references:
- Autograd:
https://pytorch.org/docs/stable/autograd.html torch.func(jacfwd/jacrev, etc.):https://pytorch.org/docs/stable/func.html
Parameter tensors for model, indexed by its statically known parameter shapes.
Instances For
A scalar loss computed from a model output and its target.
Instances For
Cast a model's initial Float parameters into another scalar representation.
Instances For
Initialize model parameters in a scalar representation that accepts host Float values.
Instances For
Mean-squared error between a model output and its target.
Instances For
Cross-entropy between logits and one-hot targets.
Instances For
Stop gradients through the model output before evaluating loss.
Instances For
Compile loss (model params input) target as a scalar TorchLean program.
Instances For
Gradient of a model-loss w.r.t. the model parameters.
Common training use case. PyTorch analogue: loss.backward() followed by parameter updates.
Instances For
Gradient of the loss w.r.t. the inputs (x and target).
Instances For
Convenience: gradient of the loss w.r.t. x.
Instances For
Convenience: gradient of the loss w.r.t. the target argument.
Instances For
Forward+backward result for a scalar loss built from a model output.
PyTorch comparison: this is the "compute loss + backward" payload, but with shapes tracked.
- value : Spec.Tensor α Spec.Shape.scalar
Value at the current point.
- dparams : Params model α
Gradients w.r.t. parameters.
- dx : Spec.Tensor α σ
Gradient w.r.t. input.
- dtarget : Spec.Tensor α υ
Gradient w.r.t. target.
Instances For
Run loss(model(params, x), target) and compute gradients w.r.t:
- model parameters,
x,target.
This hides the CompiledScalar/argument-pack boilerplate for the common "one sample" case.
Instances For
Return the scalar loss tensor together with gradients for the model parameters.
Instances For
valueAndGradParams, but convert the 0-dim loss tensor to a scalar α.
Instances For
Return (loss_value, grad_x).
Instances For
Return (loss_value, grad_target).
Instances For
Vector-Jacobian product (VJP) w.r.t. model parameters.
Primitive for sending output cotangents back into parameters. Use it for custom losses or analysis
tooling when you already have a seed tensor seedOut : τ.
Instances For
VJP w.r.t. the model input.
Returns a one-element _root_.TorchLean.TensorPack to match the general "inputs list" API shape. For the common
case, use vjpInput to get the tensor directly.
Instances For
Vector-Jacobian product with respect to the single model input tensor.
Instances For
Reverse-mode Jacobian (jacrev) of the model output w.r.t. parameters.
Returns an array of parameter-structured gradients: one entry per output coordinate. This mirrors the usual "jacrev returns a stack of per-output gradients" shape.
Instances For
Jacobian-vector product (JVP) of a scalar loss w.r.t. parameters.
Directional derivative in the direction vparams. Conceptually:
$$ \left.\frac{d}{dt} \operatorname{loss}(\mathrm{params}+t\,\mathrm{vparams},x,\mathrm{target}) \right|_{t=0}. $$
Instances For
Hessian-vector product (HVP) of a scalar loss w.r.t. parameters.
Returns a parameter-structured tensor list of the same shape as params.
Instances For
In PyTorch terms, this is the "functorch" style: differentiate plain functions, not modules.
A scalar-polymorphic tensor function written against TorchLean's differentiable operations.
Instances For
Adapt a tensor function to the single-input program representation used by autograd.
Instances For
Forward-mode Jacobian (jacfwd) for a pure tensor function.
Instances For
Hessian for a scalar-valued function.
Instances For
Vector-Jacobian product (VJP) for a pure function.
Instances For
Reverse-mode Jacobian (jacrev) of a pure tensor function.
Returns the Jacobian rows as an array of doutput/dinput tensors.
Instances For
Gradient of a scalar-valued function w.r.t. its input.
Instances For
Return (value, grad) for a scalar-valued function at x.
Instances For
valueAndGrad, but convert the 0-dim value tensor to a scalar α.