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 state and parameter error information computed by a numerical optimizer contract.

  • state : StateBound s

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

  • params :

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

Instances For

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

    StepData 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
      @[reducible, inline]

      Exact state and parameters threaded through an optimizer run.

      Instances For
        @[reducible, inline]

        Runtime state and parameters threaded through an optimizer run.

        Instances For
          @[reducible, inline]

          Error information threaded through an optimizer run.

          Instances For
            def Proofs.RuntimeApprox.Optimizer.NumericalStepContract.runSpec {R : Type} {toSpec : R} (contract : NumericalStepContract R toSpec) {s : Spec.Shape} :
            contract.SpecStep sList (Spec.Tensor s)contract.SpecStep s

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

            Instances For
              def Proofs.RuntimeApprox.Optimizer.NumericalStepContract.runRuntime {R : Type} {toSpec : R} (contract : NumericalStepContract R toSpec) {s : Spec.Shape} :
              contract.RuntimeStep sList (Spec.Tensor R s)contract.RuntimeStep s

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

              Instances For
                def Proofs.RuntimeApprox.Optimizer.NumericalStepContract.runBounds {R : Type} {toSpec : R} (contract : NumericalStepContract R toSpec) {s : Spec.Shape} :
                contract.RunBound scontract.RuntimeStep sList (Spec.Tensor R s)List List (contract.StepData s)Option (contract.RunBound s)

                Propagate state and parameter errors over a runtime gradient stream.

                Instances For
                  inductive Proofs.RuntimeApprox.Optimizer.NumericalStepContract.StepStreamApprox {R : Type} {toSpec : R} (contract : NumericalStepContract R toSpec) {s : Spec.Shape} :
                  contract.SpecStep scontract.RuntimeStep scontract.RunBound sList (Spec.Tensor s)List (Spec.Tensor R s)List List (contract.StepData s)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 runSpec, runRuntime, and runBounds. 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.RunSound {R : Type} {toSpec : R} (contract : NumericalStepContract R toSpec) {s : Spec.Shape} (spec : contract.SpecStep s) (runtime : contract.RuntimeStep s) (bound : contract.RunBound s) (gradsS : List (Spec.Tensor s)) (gradsR : List (Spec.Tensor R s)) (gradErrors : List ) (steps : List (contract.StepData s)) :

                    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) {s : Spec.Shape} {spec : contract.SpecStep s} {runtime : contract.RuntimeStep s} {bound : contract.RunBound s} {gradsS : List (Spec.Tensor s)} {gradsR : List (Spec.Tensor R s)} {gradErrors : List } {steps : List (contract.StepData s)} (hsteps : contract.StepStreamApprox spec runtime bound gradsS gradsR gradErrors steps) :
                      contract.stateApprox spec.1 runtime.1 bound.stateapproxT toSpec spec.2 runtime.2 bound.paramscontract.RunSound spec runtime bound gradsS gradsR gradErrors steps

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