TorchLean API

NN.Proofs.Autograd.Runtime.Link.Checked

Correctness of checked differentiation #

The public autograd transforms run domain validation, lower a graph to a tape, sweep its stored reverse rules, and recover the typed input gradients from a heterogeneous array. The theorems here connect that complete checked path to the graph semantics and, for analytically correct real graphs, to mathlib's Fréchet derivative. Validation remains a separate hypothesis: passing a runtime domain check alone is not a derivative-correctness certificate.

theorem Runtime.Autograd.Torch.TypedGraphWithData.vjpChecked_eq {α Δ : Type} [TorchLean.Storage α] [Add α] [Zero α] {Γ : List Spec.Shape} {τ : Spec.Shape} (graph : TypedGraphWithData α Δ Γ τ) (inputs : TorchLean.TensorPack α Γ) (data : Δ) (seed : TorchLean.Tensor α τ) (result : Tape α × TorchLean.TensorPack α (Γ ++ graph.nodeShapes)) (checked : TypedGraph.lowerToTapeChecked graph.data inputs data = Except.ok result) :
graph.vjpChecked inputs data seed = Except.ok (graph.vjpWithSeed inputs data seed, graph.forward inputs data)

Successful validation makes the checked VJP agree with the stored graph reverse rules. This preserves the order of additions and requires no algebraic laws on the scalar backend.

The selected output has the derivative obtained by projecting the graph derivative.

theorem Runtime.Autograd.Torch.TypedGraphWithData.jvpChecked_fderiv {Δ : Type} {Γ : List Spec.Shape} {τ : Spec.Shape} (graph : TypedGraphWithData Δ Γ τ) (proofGraph : Proofs.Autograd.Algebra.Graph Δ Γ graph.nodeShapes) (same : proofGraph.toData = graph.data) (inputs tangents : TorchLean.TensorPack Γ) (data : Δ) (correct : Proofs.Autograd.GraphFDerivCorrectAt (proofGraph.toReal data) (Proofs.Autograd.flattenCtx inputs)) (result : TorchLean.TensorPack (Γ ++ graph.nodeShapes) × TorchLean.TensorPack (Γ ++ graph.nodeShapes)) (checked : TypedGraph.jvpChecked graph.data inputs tangents data = Except.ok result) :

The checked forward-mode tangent is mathlib's derivative applied to the input direction.

The pure graph pullback is the adjoint derivative of its selected output.

The checked API returns the adjoint of mathlib's derivative of its selected forward output.

The proof graph must describe the exact operation data that execution uses. Differentiability is required only at this input and the corresponding intermediate values. The carrier is ; floating-point error and native kernels are not identified with exact real arithmetic.