autograd
20 memberslucid.autogradlucid.autograd — reverse-mode differentiation and the grad-mode controls.
backward and grad walk the tape the engine records as ops execute.
Function together with FunctionCtx lets Python define a new
differentiable op by writing its forward and backward explicitly, for cases
the composed ops cannot express.
Grad modes: no_grad, enable_grad, inference_mode, and the
set_grad_enabled / is_grad_enabled pair. Note that
set_grad_enabled(flag) is a plain function returning None, not a
context manager — using it in a with statement turns grad off globally
and never restores it, which then affects every later computation.
Higher-order and verification: jacobian, hessian, vjp and jvp
for derivatives of derivatives, and gradcheck / gradgradcheck to
verify a hand-written backward against finite differences — worth running on
any new Function, since a wrong backward produces plausible numbers
rather than an error. checkpoint trades recomputation for activation
memory, and detect_anomaly traces the op that first produced a NaN.
Classes
no_grad3 methodsContext manager / decorator that disables gradient tracking.
enable_grad3 methodsContext manager / decorator that (re-)enables gradient tracking.
Function3 methodsBase class for custom differentiable operations.
FunctionCtx4 methodsPer-call context shared between Function.forward and
Function.backward.
detect_anomaly4 methodsContext manager / decorator that enables autograd anomaly detection.
RemovableHandle4 methodsHandle returned by lucid.Tensor.register_hook.
Functions
set_grad_enabled→ NoneGlobally set the autograd gradient-tracking flag.
is_grad_enabled→ boolReturn whether autograd gradient tracking is currently enabled.
inference_mode→ Iterator[None]Context manager for inference-time autograd suppression.
backward→ NoneCompute gradients of tensors w.r.t. the leaf variables in their graph.
grad→ tuple[Tensor or None, ...]Compute gradients of outputs w.r.t. inputs, returning them as a tuple.
gradcheck→ bool True if all gradients agree within tolerance.Compare analytical gradients from backward() against finite-difference Jacobians.
gradgradcheck→ boolVerify second-order gradients via finite differences.
is_anomaly_enabled→ boolReturn whether autograd anomaly detection is currently enabled.
set_detect_anomaly→ NoneProgrammatic global toggle for autograd anomaly detection.
jacobian→ Tensor or tuple of TensorCompute the Jacobian matrix of func with respect to each input.
hessian→ Tensor or tuple of tuple of TensorCompute the Hessian matrix of a scalar-valued func.
vjp→ tuple of (Tensor, tuple of (Tensor or None))Vector-Jacobian product (reverse-mode AD).
jvp→ tuple of (Tensor or tuple of Tensor, Tensor or tuple of Tensor)Jacobian-vector product (forward-mode directional derivative).
checkpoint→ TensorRun function under gradient checkpointing.