TorchLean API

NN.Proofs.Autograd.Runtime.Link.Invariants

Tape invariants of lowered graphs #

Lowering a graph marks every runtime node as a gradient accumulation slot and only emits backward contributions to earlier node ids (BackwardPidsLt). The dense reverse sweep proofs in BackwardGraph consume both invariants.

addLeaves keeps every tape node eligible for gradient accumulation.

All nodes produced by lowerGraphDataToTape have requiresGrad = true.

This is a simplifying invariant: the lowered tape is meant for correctness proofs, so we mark every node as eligible for gradient accumulation (including leaves for inputs).

theorem Proofs.Autograd.Algebra.Graph.lowerGraphDataToTape_requires_grad_true {α Δ : Type} [TorchLean.Storage α] {Γ ss : List Spec.Shape} (g : GraphData α Δ Γ ss) (x : TorchLean.TensorPack α Γ) (d : Δ) :
have t := (lowerGraphDataToTape g x d).1; ∀ (i : ℕ) (hi : i < t.nodes.size), t.nodes[i].requiresGrad = true

Pointwise form of lowerGraphDataToTape_all_requires_grad_true, convenient for array indexing: every node of the lowered tape has requiresGrad = true.

Backward closure safety for lowerGraphDataToTape: parent ids produced by any node are strictly smaller than the node id.

This is the “edges point backwards” invariant required by the runtime reverse loop: when processing node id, every contribution targets an earlier node (pid < id), so accumulation is well-founded.