TorchLean API

NN.Proofs.RuntimeApprox.Optimizer

Numerical Contracts for Optimizer Steps #

An optimizer proof has two kinds of state: the mathematical recurrence and the rounded runtime state. NumericalStepContract records their relation once. A concrete optimizer supplies its exact and runtime update equations, a transformer for state/parameter error bounds, and a proof that one step preserves the relation. run_approx then composes that local proof over any finite gradient stream.

This interface is deliberately independent of SGD, Adam, or a particular scalar backend. It avoids duplicating an induction theorem for every optimizer and, unlike an equality theorem obtained by unfolding two identical definitions, states the numerical refinement claim needed by training.

For the distinction between local rounding errors and their propagation through an iterative algorithm, see N. J. Higham, Accuracy and Stability of Numerical Algorithms, 2nd ed., 2002.

Per-step optimizer-state and parameter errors computed by a numerical optimizer contract.

  • optimizerStateError : StateError shape

    Bound object for the optimizer's private state after the step.

  • parameterError :

    Infinity-norm error budget for the parameter tensor after the step.

Instances For

    A numerical refinement contract for one shape-polymorphic optimizer update.

    StepAssumptions carries numerical information required only for the current update. It is Unit for unconditional rules such as SGD, while adaptive optimizers use it for denominator margins and rounded scalar-expression bounds. This lets one finite-run theorem cover both cases.

    Instances For
      structure Proofs.RuntimeApprox.Optimizer.NumericalStepContract.StepInput {R : Type} {toSpec : R} (contract : NumericalStepContract R toSpec) (shape : Spec.Shape) :

      Exact, rounded, and error information for one optimizer update.

      • exactGradient : TorchLean.Tensor shape

        Exact-real gradient.

      • runtimeGradient : TorchLean.Tensor R shape

        Rounded runtime gradient.

      • gradientError :

        Infinity-norm error relating the exact and runtime gradients.

      • assumptions : contract.StepAssumptions shape

        Optimizer-specific side data and domain margins.

      Instances For
        def Proofs.RuntimeApprox.Optimizer.NumericalStepContract.runExact {R : Type} {toSpec : R} (contract : NumericalStepContract R toSpec) {shape : Spec.Shape} (initial : Optim.Step shape (contract.ExactState shape)) (steps : Array (contract.StepInput shape)) :
        Optim.Step shape (contract.ExactState shape)

        Execute a finite step stream using the exact-real recurrence.

        Instances For
          def Proofs.RuntimeApprox.Optimizer.NumericalStepContract.runRuntime {R : Type} {toSpec : R} (contract : NumericalStepContract R toSpec) {shape : Spec.Shape} (initial : Optim.Step R shape (contract.RuntimeState shape)) (steps : Array (contract.StepInput shape)) :
          Optim.Step R shape (contract.RuntimeState shape)

          Execute the same finite step stream using the rounded runtime recurrence.

          Instances For
            def Proofs.RuntimeApprox.Optimizer.NumericalStepContract.runErrors {R : Type} {toSpec : R} (contract : NumericalStepContract R toSpec) {shape : Spec.Shape} (initialError : StepError contract.StateError shape) (initialRuntime : Optim.Step R shape (contract.RuntimeState shape)) (steps : Array (contract.StepInput shape)) :
            StepError contract.StateError shape

            Propagate state and parameter errors over a bundled optimizer step stream.

            Instances For
              inductive Proofs.RuntimeApprox.Optimizer.NumericalStepContract.StepStreamApprox {R : Type} {toSpec : R} (contract : NumericalStepContract R toSpec) {shape : Spec.Shape} :
              Optim.Step shape (contract.ExactState shape)Optim.Step R shape (contract.RuntimeState shape)StepError contract.StateError shapeArray (contract.StepInput shape)Prop

              Approximation and side-condition evidence for a complete optimizer run.

              The indices thread exact state, runtime state, and error bounds through the same recurrence used by runExact, runRuntime, and runErrors. Adaptive-domain conditions are therefore checked at the step where they are needed rather than asserted once for an entire run.

              Instances For
                def Proofs.RuntimeApprox.Optimizer.NumericalStepContract.RunApprox {R : Type} {toSpec : R} (contract : NumericalStepContract R toSpec) {shape : Spec.Shape} (exact : Optim.Step shape (contract.ExactState shape)) (runtime : Optim.Step R shape (contract.RuntimeState shape)) (error : StepError contract.StateError shape) (steps : Array (contract.StepInput shape)) :

                Final soundness statement associated with one finite optimizer run.

                Instances For
                  theorem Proofs.RuntimeApprox.Optimizer.NumericalStepContract.run_approx {R : Type} {toSpec : R} (contract : NumericalStepContract R toSpec) {shape : Spec.Shape} {exact : Optim.Step shape (contract.ExactState shape)} {runtime : Optim.Step R shape (contract.RuntimeState shape)} {error : StepError contract.StateError shape} {steps : Array (contract.StepInput shape)} (stepsApprox : contract.StepStreamApprox exact runtime error steps) :
                  contract.stateApprox exact.optimizerState runtime.optimizerState error.optimizerStateErrorapproxTensor toSpec exact.parameters runtime.parameters error.parameterErrorcontract.RunApprox exact runtime error steps

                  A local optimizer contract composes over any finite validated gradient stream.