TorchLean API

NN.Proofs.RuntimeApprox.NF.EndToEnd

NF End-To-End GraphData Bridge #

End-to-end runtime→spec bridge for NF graphs executed as GraphData.

NN.Proofs.RuntimeApprox.NF provides per-op NF approximation lemmas and composes them over RevGraph via RevGraph.eval_approx and NFBackend.backprop_approx.

This file links those results to the executable SSA/DAG form used by typed graph execution: Proofs.Autograd.Algebra.GraphData. A GraphData stores forward, JVP, and VJP functions; it does not carry the derivative laws required by the proof-carrying Graph type.

In other words, this is where the abstract approximation graph model meets the executable graph interpreter used elsewhere in TorchLean.

Executable forward-pass soundness for an NF RevGraph erased to GraphData.

The theorem says that evaluating the executable GraphData forward interpreter gives the same runtime context covered by RevGraph.eval_approx, so the abstract graph approximation theorem applies to the executable representation.

Executable backward-pass soundness for an NF RevGraph erased to GraphData.

Given approximate inputs and approximate seed cotangents, executable GraphData.backpropCtx approximates the real-spec reverse-mode result with the bound computed by the NF backend.

Extract one typed gradient and its numerical error from executable reverse mode.

This is the common bridge used by every optimizer theorem below. Keeping the projection here avoids repeating a proof that the ith entry of an approximated heterogeneous context is itself approximated.

A typed backward-and-update step #

The seed context represents the cotangent supplied by a loss. The theorem below takes one gradient from the executable reverse pass and applies an arbitrary proved numerical optimizer contract to the corresponding parameter tensor. It is deliberately indexed by i: models with many parameter tensors apply the same theorem to each entry of the typed parameter context.

theorem Proofs.RuntimeApprox.NFBackend.backprop_optimizer_update_approx_graphData {β : FloatLib.Numerics.Radix} {fexp : } [FloatLib.Floats.Formats.Flocq.ValidExp fexp] {rnd : } [FloatLib.Floats.Formats.Flocq.ValidRndToNearest rnd] {Γ ss : List Spec.Shape} (g : RevGraph toSpec Γ ss) (i : Fin Γ.length) (contract : Optimizer.NumericalStepContract (FloatLib.Floats.Formats.Flocq.NF β fexp rnd) toSpec) (xS : TorchLean.TensorPack Spec.SpecScalar Γ) (xR : TorchLean.TensorPack (FloatLib.Floats.Formats.Flocq.NF β fexp rnd) Γ) (epsIn : EList Γ) (seedS : TorchLean.TensorPack Spec.SpecScalar (Γ ++ ss)) (seedR : TorchLean.TensorPack (FloatLib.Floats.Formats.Flocq.NF β fexp rnd) (Γ ++ ss)) (epsSeed : EList (Γ ++ ss)) (paramsS : TorchLean.Tensor (Γ.get i)) (paramsR : TorchLean.Tensor (FloatLib.Floats.Formats.Flocq.NF β fexp rnd) (Γ.get i)) (paramsError : ) (stateS : contract.ExactState (Γ.get i)) (stateR : contract.RuntimeState (Γ.get i)) (stateError : contract.StateError (Γ.get i)) (assumptions : contract.StepAssumptions (Γ.get i)) (hx : approxCtx toSpec xS xR epsIn) (hseed : approxCtx toSpec seedS seedR epsSeed) (hparams : approxTensor toSpec paramsS paramsR paramsError) (hstate : contract.stateApprox stateS stateR stateError) (hAssumptions : have exactGradients := g.backpropSpec xS seedS; have runtimeGradients := (LinkAutogradAlgebra.RevGraph.toGraphData g).backpropCtx xR () seedR; have gradientError := (g.backpropBounds epsIn xR epsSeed seedR fun {Δ : List Spec.Shape} => ctxAddBound).get i; contract.assumptionsHold stateS stateR stateError paramsS paramsR paramsError (exactGradients.get i) (runtimeGradients.get i) gradientError assumptions) :
have exactGradients := g.backpropSpec xS seedS; have runtimeGradients := (LinkAutogradAlgebra.RevGraph.toGraphData g).backpropCtx xR () seedR; have gradientError := (g.backpropBounds epsIn xR epsSeed seedR fun {Δ : List Spec.Shape} => ctxAddBound).get i; have nextError := contract.nextError stateError paramsError gradientError stateR paramsR (runtimeGradients.get i) assumptions; contract.stateApprox (contract.updateExact stateS paramsS (exactGradients.get i)).optimizerState (contract.updateRuntime stateR paramsR (runtimeGradients.get i)).optimizerState nextError.optimizerStateError approxTensor toSpec (contract.updateExact stateS paramsS (exactGradients.get i)).parameters (contract.updateRuntime stateR paramsR (runtimeGradients.get i)).parameters nextError.parameterError

Executable reverse mode followed by any valid numerical optimizer contract is sound.

The theorem is shape-polymorphic and optimizer-polymorphic. assumptionsHold is trivial for globally sound updates such as SGD and records domain conditions for updates such as AdamW whose square root and division must stay away from singularities. No optimizer needs a separate graph theorem. Models with several parameter tensors instantiate this theorem at each typed index.

Architecture-independent reporting #

Proof-free numerical summary of one forward/backward/update step.

The arrays retain typed-context order. A UI may attach architecture-specific display names after lowering, but propagation itself does not inspect whether the graph came from an MLP, CNN, transformer, or another model family.

Instances For
    noncomputable def Proofs.RuntimeApprox.NFBackend.trainingStepTrace {β : FloatLib.Numerics.Radix} {fexp : } [FloatLib.Floats.Formats.Flocq.ValidExp fexp] {rnd : } {Γ ss : List Spec.Shape} (g : RevGraph toSpec Γ ss) (i : Fin Γ.length) (contract : Optimizer.NumericalStepContract (FloatLib.Floats.Formats.Flocq.NF β fexp rnd) toSpec) (xR : TorchLean.TensorPack (FloatLib.Floats.Formats.Flocq.NF β fexp rnd) Γ) (epsIn : EList Γ) (seedR : TorchLean.TensorPack (FloatLib.Floats.Formats.Flocq.NF β fexp rnd) (Γ ++ ss)) (epsSeed : EList (Γ ++ ss)) (paramsR : TorchLean.Tensor (FloatLib.Floats.Formats.Flocq.NF β fexp rnd) (Γ.get i)) (paramsError : ) (stateR : contract.RuntimeState (Γ.get i)) (stateError : contract.StateError (Γ.get i)) (assumptions : contract.StepAssumptions (Γ.get i)) :

    Compute the report consumed by CLI, file, or InfoView front ends.

    This function is intentionally proof-free: backprop_optimizer_update_approx_graphData is the theorem establishing its interpretation when the input, seed, parameter, optimizer-state, and step assumptions hold.

    Instances For