TorchLean API

NN.Proofs.Autograd.Tape.Algebra.Soundness

Algebraic tape soundness #

Tape-style (SSA/DAG) reverse-mode soundness (algebraic, backend-generic).

This is a backend-generic analogue of the tensor-tape soundness layer: it proves the global reverse-mode accumulation algorithm is sound assuming only commutative semiring laws.

This file lives under NN/Proofs/Autograd/Tape/Algebra/ because it is reused by both proof-only and runtime-link developments that target exact backends (e.g. ).

PyTorch correspondence / citations #

This corresponds to the high-level structure of PyTorch’s reverse-mode engine, but stated over an arbitrary commutative semiring so we can reuse it for exact backends. https://pytorch.org/docs/stable/autograd.html

Dot product over contexts: sum of per-entry tensor dots.

This is the algebraic analogue of Spec.dotList: it uses TensorAlgebra.dot for the backend α.

Instances For

    dotList commutes with casting the left context along a shape-list equality.

    dotList is linear in its right argument with respect to TorchLean.TensorPack.add.

    Dot respects appending: dot of two snoced contexts splits into prefix + last entry.

    Dotting with the all-zero context on the right yields 0.

    Sparse context with a single nonzero entry at idx (all other tensors are 0).

    Instances For

      single is adjoint to getIdx with respect to dotList.

      Informally: ⟪dx, single idx v⟫ = ⟪getIdx dx idx, v⟫.

      Executable node payload (no correctness proof).

      Δ is an extra non-differentiable environment threaded through evaluation (e.g. parameters, auxiliary data). The VJP returns gradients only for the differentiable context Γ.

      Instances For

        Proof-carrying node: NodeData plus the local adjointness law.

        The field correct is the algebraic version of the standard JVP/VJP inner-product law.

        Instances For

          Executable-only graph: a snoc-list of NodeData.

          Instances For
            def Proofs.Autograd.Algebra.GraphData.eval {α : Type} [TorchLean.Storage α] {Δ : Type} {Γ ss : List Spec.Shape} (g : GraphData α Δ Γ ss) (x : TorchLean.TensorPack α Γ) (d : Δ) :

            Evaluate a GraphData on an input context x, producing the full context Γ ++ ss.

            Instances For
              def Proofs.Autograd.Algebra.GraphData.jvpCtx {α : Type} [TorchLean.Storage α] {Δ : Type} {Γ ss : List Spec.Shape} (g : GraphData α Δ Γ ss) (x dx : TorchLean.TensorPack α Γ) (d : Δ) :

              Compute the JVP of eval, producing a tangent context of shape Γ ++ ss.

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

                Reverse-mode accumulation on contexts (VJP), given a seed cotangent for Γ ++ ss.

                Instances For

                  Proof-carrying tape/SSA graphs.

                  Nodes are appended in topological order and may reference any previously computed value (fan-out and sharing are allowed). This mirrors the structure of PyTorch’s dynamic autograd graph, but with shape-typed contexts.

                  A proof-carrying tape/SSA graph.

                  Nodes are appended in topological order and may reference any previously computed value.

                  Instances For
                    def Proofs.Autograd.Algebra.Graph.toData {α : Type} [TorchLean.Storage α] [CommSemiring α] {Δ : Type} {Γ ss : List Spec.Shape} :
                    Graph Δ Γ ssGraphData α Δ Γ ss

                    Forget local correctness proofs, yielding an executable GraphData.

                    Instances For
                      def Proofs.Autograd.Algebra.Graph.eval {α : Type} [TorchLean.Storage α] [CommSemiring α] {Δ : Type} {Γ ss : List Spec.Shape} (g : Graph Δ Γ ss) (x : TorchLean.TensorPack α Γ) (d : Δ) :

                      Evaluate a proof-carrying graph through its executable representation.

                      Instances For
                        def Proofs.Autograd.Algebra.Graph.jvpCtx {α : Type} [TorchLean.Storage α] [CommSemiring α] {Δ : Type} {Γ ss : List Spec.Shape} (g : Graph Δ Γ ss) (x dx : TorchLean.TensorPack α Γ) (d : Δ) :

                        Propagate tangents with the same evaluator used by the executable graph.

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

                          Accumulate cotangents with the executable graph's reverse pass.

                          Instances For
                            theorem Proofs.Autograd.Algebra.Graph.backprop_correct {α : Type} [TorchLean.Storage α] [CommSemiring α] {Δ : Type} {Γ ss : List Spec.Shape} (g : Graph Δ Γ ss) (x dx : TorchLean.TensorPack α Γ) (d : Δ) (seed : TorchLean.TensorPack α (Γ ++ ss)) :
                            TensorPack.dotList (g.jvpCtx x dx d) seed = TensorPack.dotList dx (g.backpropCtx x d seed)

                            Global tape soundness (algebraic form).

                            Assuming each node satisfies its local adjointness law, backpropCtx is the adjoint of jvpCtx with respect to TensorPack.dotList.