TorchLean API

NN.Proofs.Autograd.Runtime.Link.FDeriv

Analytic upgrade of the runtime link: reverse mode computes (fderiv eval)† #

Two independent developments meet in this file.

The two developments are stated on different graph types: the algebraic Algebra.Graph (α := α) Δ Γ ss versus the ℝ-monomorphic, environment-free Proofs.Autograd.Graph Γ ss. Both use TorchLean.TensorPack ℝ Γ for their contexts. This file connects their evaluation, JVP, and backpropagation semantics:

Throughout, "reverse pass" means the exact tape model: the Tape.backwardDenseFrom program of Runtime/Autograd instantiated at the exact carrier α := ℝ. Nothing in this file is a statement about the native Float evaluation or the CUDA execution path; relating those to the exact model is a separate (approximation) concern.

def Proofs.Autograd.Algebra.Node.toReal {Δ : Type} {Γ : List Spec.Shape} {τ : Spec.Shape} (node : Node Δ Γ τ) (d : Δ) :

Specialize an algebraic node at carrier ℝ and a fixed environment d : Δ to an analytic node. The adjointness law transports along dot_eq_tensorAlgebra_dot.

Instances For
    def Proofs.Autograd.Algebra.Graph.toReal {Δ : Type} {Γ ss : List Spec.Shape} :
    Graph Δ Γ ss → Δ → Autograd.Graph Γ ss

    Specialize an algebraic graph at carrier ℝ and a fixed environment to an analytic graph.

    Instances For
      @[simp]

      The round trip through the algebraic model is the identity on analytic nodes.

      @[simp]

      Specializing an algebraic node with a trivial environment and embedding it back is the identity.

      @[simp]

      The round trip through the algebraic model is the identity on analytic graphs.

      @[simp]

      Specializing an algebraic graph with a trivial environment and embedding it back is the identity.

      theorem Proofs.Autograd.Algebra.Graph.toReal_eval {Δ : Type} {Γ ss : List Spec.Shape} (g : Graph Δ Γ ss) (x : TorchLean.TensorPack ℝ Γ) (d : Δ) :
      (g.toReal d).eval x = g.eval x d

      Specialization preserves evaluation.

      theorem Proofs.Autograd.Algebra.Graph.toReal_jvpCtx {Δ : Type} {Γ ss : List Spec.Shape} (g : Graph Δ Γ ss) (x dx : TorchLean.TensorPack ℝ Γ) (d : Δ) :
      (g.toReal d).jvpCtx x dx = g.jvpCtx x dx d

      Specialization preserves the JVP.

      theorem Proofs.Autograd.Algebra.Graph.toReal_backpropCtx {Δ : Type} {Γ ss : List Spec.Shape} (g : Graph Δ Γ ss) (x : TorchLean.TensorPack ℝ Γ) (d : Δ) (seed : TorchLean.TensorPack ℝ (Γ ++ ss)) :
      (g.toReal d).backpropCtx x seed = g.backpropCtx x d seed

      Specialization preserves the reverse pass.

      @[reducible, inline]

      Read the input (Γ-prefix) block out of a full context over Γ ++ ss: the left half of the public TorchLean.TensorPack.split, under the name the link theorems use.

      Instances For

        The proof context's input projection is the public tensor-pack split.

        On a context with no intermediates, takeLeft is the cast along Γ ++ [] = Γ.

        takeLeft ignores a snoc-ed final block (after reassociating the context).

        theorem Proofs.Autograd.Algebra.GraphData.takeLeft_backpropAllCtx {α : Type} [TorchLean.Storage α] [Add α] {Δ : Type} {Γ ss : List Spec.Shape} (g : GraphData α Δ Γ ss) (x : TorchLean.TensorPack α Γ) (d : Δ) (seed : TorchLean.TensorPack α (Γ ++ ss)) :

        The input (Γ-prefix) block of the full backpropagation is the inputs-only backpropagation.

        This identifies the link-facing backpropAllCtx (which retains a cotangent for every value, mirroring the tape engine's dense reverse pass) with the proof-facing backpropCtx on the input block.

        theorem Proofs.Autograd.Algebra.Graph.takeLeft_backpropAllCtx {α : Type} [TorchLean.Storage α] [CommSemiring α] {Δ : Type} {Γ ss : List Spec.Shape} (g : Graph Δ Γ ss) (x : TorchLean.TensorPack α Γ) (d : Δ) (seed : TorchLean.TensorPack α (Γ ++ ss)) :

        Graph form of GraphData.takeLeft_backpropAllCtx: both backpropAllCtx and backpropCtx of a proof-carrying graph are the GraphData programs on g.toData.

        Analytic upgrade of the algebraic reverse pass. At carrier ℝ and a fixed environment, the inputs-only backpropagation computes the adjoint of the Fréchet derivative of the graph's (vectorized) forward evaluation.

        Pointwise variant of backpropCtx_eq_adjoint_fderiv: differentiability is assumed only at the values actually encountered, admitting non-smooth primitives away from their kinks.

        theorem Proofs.Autograd.Algebra.Graph.toReal_evalVec {Δ : Type} {Γ ss : List Spec.Shape} (g : Graph Δ Γ ss) (d : Δ) (x : TorchLean.TensorPack ℝ Γ) :

        The function differentiated in the endpoints is the graph's own forward evaluation.

        Tape-model reverse pass = adjoint of the Fréchet derivative. Running the tape engine's dense reverse pass (Tape.backwardDenseFrom) on a lowered graph (the exact tape model instantiated at α := ℝ, not the native Float or CUDA execution path) succeeds and returns the full backpropagation context, whose input (Γ-prefix) block is exactly the adjoint of the Fréchet derivative of the graph's forward evaluation applied to the seed.

        This composes the runtime link (backwardDenseFrom_lowerGraphToTape_eq_backpropAllCtx) with the analytic upgrade above.