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. ℚ).
In particular, it can be instantiated for exact backends such as ℚ.
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
A heterogeneous list of tensors indexed by a list of shapes.
TList α Γ is the algebraic (backend-generic) version of the typed tape context:
it stores one tensor of each shape in Γ.
PyTorch analogue: the engine carries a runtime list of saved tensors for backward; here Γ
tracks the shapes statically.
- nil {α : Type} : TList α []
- cons {α : Type} {s : Spec.Shape} {ss : List Spec.Shape} : Spec.Tensor α s → TList α ss → TList α (s :: ss)
Instances For
Get the ith tensor from a context, with its shape tracked by List.get.
Instances For
All-zero context (fills each tensor entry with zeros).
Instances For
Pointwise addition of two contexts of the same shape list.
Instances For
Scale every tensor in a context by the same scalar.
This is the context-level analogue of scaleSpec. It lives beside zero and add because several
proof layers need scalar multiplication on heterogeneous parameter/gradient packs, not just the
training-step file.
Instances For
Pointwise subtraction of two contexts with the same shape list.
This is the context-level analogue of subSpec; it is used to state pure optimizer updates over an
entire typed parameter context.
Instances For
Append a tensor to the end of a context.
Instances For
Split a context of shape list ss ++ [τ] into its prefix and last tensor.
Instances For
Cast a context along an equality of shape lists.
Instances For
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 TList.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.
Idx Γ s is a “typed index” into a heterogeneous context: it stores a Fin Γ.length together
with a proof that the shape at that position is s.
A typed index into a heterogeneous context Γ, carrying a proof of the expected shape s.
i.
h.
Instances For
Read a tensor from a context at a typed index, casting along the stored shape equality.
Instances For
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 Γ.
- forward : TList α Γ → Δ → Spec.Tensor α τ
forward.
- jvp : TList α Γ → TList α Γ → Δ → Spec.Tensor α τ
jvp.
- vjp : TList α Γ → Δ → Spec.Tensor α τ → TList α Γ
vjp.
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.
- forward : TList α Γ → Δ → Spec.Tensor α τ
- jvp : TList α Γ → TList α Γ → Δ → Spec.Tensor α τ
- vjp : TList α Γ → Δ → Spec.Tensor α τ → TList α Γ
- correct (x dx : TList α Γ) (d : Δ) (δ : Spec.Tensor α τ) : TensorAlgebra.dot (self.jvp x dx d) δ = dx.dotList (self.vjp x d δ)
Instances For
Executable-only graph: a snoc-list of NodeData.
- nil {α Δ : Type} {Γ : List Spec.Shape} : GraphData α Δ Γ []
- snoc {α Δ : Type} {Γ ss : List Spec.Shape} {τ : Spec.Shape} : GraphData α Δ Γ ss → NodeData α Δ (Γ ++ ss) τ → GraphData α Δ Γ (ss ++ [τ])
Instances For
Evaluate a GraphData on an input context x, producing the full context Γ ++ ss.
Instances For
Compute the JVP of eval, producing a tangent context of shape Γ ++ ss.
Instances For
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.
- nil {α : Type} [CommSemiring α] {Δ : Type} {Γ : List Spec.Shape} : Graph Δ Γ []
- snoc {α : Type} [CommSemiring α] {Δ : Type} {Γ ss : List Spec.Shape} {τ : Spec.Shape} : Graph Δ Γ ss → Node Δ (Γ ++ ss) τ → Graph Δ Γ (ss ++ [τ])
Instances For
Forget local correctness proofs, yielding an executable GraphData.
Instances For
Evaluate a proof-carrying Graph on an input context x.
Instances For
Compute the JVP of eval, producing a tangent context of shape Γ ++ ss.
Instances For
Reverse-mode accumulation on contexts (VJP) for a proof-carrying Graph.
Instances For
Global tape soundness (algebraic form).
Assuming each node satisfies its local adjointness law, backpropCtx is the adjoint of jvpCtx
with respect to TList.dotList.