Analytic upgrade of the runtime link: reverse mode computes (fderiv eval)† #
Two independent developments meet in this file.
- The runtime link (
NN.Proofs.Autograd.Runtime.Link.BackwardGraph) proves that the tape engine's dense reverse pass (Tape.backwardDenseFrom) agrees with the algebraic model's full backpropagationbackpropAllCtx, over any commutative semiring carrier and an arbitrary non-differentiable environmentΔ. - The analytic tape model (
NN.Proofs.Autograd.Tape.Core.FDeriv) proves that reverse-mode accumulation computes the adjoint of the Fréchet derivative of the forward evaluation, overℝ.
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:
- The real, environment-free slice.
Algebra.Node.toReal/Algebra.Graph.toRealspecialize an algebraic graph atα := ℝand a fixed environmentd : Δto an analytic graph;Node.toAlgebra/Graph.toAlgebra(fromNN.Proofs.Autograd.Tape.Core.Soundness) embed an analytic graph back as theΔ := Unitslice, and both round trips are identities on that slice (toAlgebra_toRealandtoReal_toAlgebra). The analytic model is therefore exactly the environment-freeℝslice of the algebraic model. The commutation lemmastoReal_eval,toReal_jvpCtx,toReal_backpropCtxshow the specialization preserves all three semantics. - Input-prefix extraction.
TensorPack.takeLeftreads the input (Γ-prefix) block out of a full context (it is the left half ofTorchLean.TensorPack.split), andtakeLeft_backpropAllCtx(forGraphData, and forGraphthroughtoData) identifies the input block of the full backpropagation with the inputs-onlybackpropCtx. - Vectorization transport. The
flattenCtx_*lemmas ofNN.Proofs.Autograd.Tape.Core.FDerivcommute context vectorization withcast/snoc/unsnoc/add, so theTensorPack-level graph semantics coincide with the EuclideanCtxVecsemantics:evalVec_flattenCtx,jvpVec_flattenCtx,backpropVec_flattenCtx. - The composed endpoints.
backpropCtx_eq_adjoint_fderivupgrades the algebraic backpropagation atℝto the Fréchet-adjoint characterization, andbackwardDenseFrom_lowerGraphToTape_adjoint_fderivcombines it with the runtime link: the tape model's dense reverse pass on a lowered graph, instantiated atα := ℝ, succeeds with the full backpropagation context, whose input prefix is exactly(fderiv ℝ eval x)† seed. The_atvariants assume differentiability only at the actual execution point (GraphFDerivCorrectAt), covering graphs with non-smooth primitives (relu,abs,min/max,log,sqrt, …).
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.
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
Specialize an algebraic graph at carrier ℝ and a fixed environment to an analytic graph.
Instances For
The round trip through the algebraic model is the identity on analytic nodes.
Specializing an algebraic node with a trivial environment and embedding it back is the identity.
The round trip through the algebraic model is the identity on analytic graphs.
Specialization preserves evaluation.
Specialization preserves the JVP.
Specialization preserves the reverse pass.
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).
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.
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.
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.
Pointwise variant of backwardDenseFrom_lowerGraphToTape_adjoint_fderiv.