TorchLean API

NN.Proofs.RuntimeApprox.Scale.BackwardScale

BackwardScale #

Backward (reverse-mode) scale propagation.

This optional module mirrors NN.Proofs.RuntimeApprox.Graph.BackwardApprox, but for scale bounds (nonnegative bounds on linf_norm) rather than eps error bounds.

Use it alongside the backward approximation graph when you want to derive abs+rel tolerances for gradients/cotangents from both an eps error bound and a propagated magnitude bound.

def Proofs.RuntimeApprox.AddScaleSound {α : Type} (toSpec : αSpec.SpecScalar) [Add α] (addBound : {Δ : List Spec.Shape} → BList ΔBList ΔTList α ΔTList α ΔBList Δ) :

Soundness condition for accumulating scale bounds under addition in a context.

Instances For
    structure Proofs.RuntimeApprox.RevNodeScale {α : Type} (toSpec : αSpec.SpecScalar) (Γ : List Spec.Shape) (τ : Spec.Shape) extends Proofs.RuntimeApprox.RevNode toSpec Γ τ :

    A reverse node augmented with forward+VJP scale bounds.

    Instances For

      Reverse-mode graph with scale-aware nodes.

      Instances For
        def Proofs.RuntimeApprox.RevGraphScale.toRevGraph {α : Type} {toSpec : αSpec.SpecScalar} {Γ ss : List Spec.Shape} :
        RevGraphScale toSpec Γ ssRevGraph toSpec Γ ss

        Forget the scale annotations on nodes, producing an ordinary RevGraph.

        Instances For
          def Proofs.RuntimeApprox.RevGraphScale.toFwdGraphScale {α : Type} {toSpec : αSpec.SpecScalar} {Γ ss : List Spec.Shape} :
          RevGraphScale toSpec Γ ssFwdGraphScale toSpec Γ ss

          Convert a RevGraphScale into a FwdGraphScale by dropping the reverse-mode payload.

          Instances For

            Evaluate the forward pass on spec values, returning the extended context Γ ++ ss.

            Instances For
              def Proofs.RuntimeApprox.RevGraphScale.evalRuntime {α : Type} {toSpec : αSpec.SpecScalar} {Γ ss : List Spec.Shape} (g : RevGraphScale toSpec Γ ss) (x : TList α Γ) :
              TList α (Γ ++ ss)

              Evaluate the forward pass on runtime values, returning the extended context Γ ++ ss.

              Instances For
                @[simp]
                theorem Proofs.RuntimeApprox.RevGraphScale.evalRuntime_eq_rev {α : Type} {toSpec : αSpec.SpecScalar} {Γ ss : List Spec.Shape} (g : RevGraphScale toSpec Γ ss) (x : TList α Γ) :
                def Proofs.RuntimeApprox.RevGraphScale.evalBounds {α : Type} {toSpec : αSpec.SpecScalar} {Γ ss : List Spec.Shape} (g : RevGraphScale toSpec Γ ss) (epsIn : EList Γ) (xR : TList α Γ) :
                EList (Γ ++ ss)

                Forward-pass error bounds for all intermediate nodes, computed from input bounds epsIn.

                Instances For
                  def Proofs.RuntimeApprox.RevGraphScale.evalScales {α : Type} {toSpec : αSpec.SpecScalar} {Γ ss : List Spec.Shape} (g : RevGraphScale toSpec Γ ss) (bIn : BList Γ) (xR : TList α Γ) :
                  BList (Γ ++ ss)

                  Forward-pass scale bounds for all intermediate nodes, computed from input bounds bIn.

                  Instances For
                    theorem Proofs.RuntimeApprox.RevGraphScale.eval_scale {α : Type} {toSpec : αSpec.SpecScalar} {Γ ss : List Spec.Shape} (g : RevGraphScale toSpec Γ ss) (xS : TList Spec.SpecScalar Γ) (xR : TList α Γ) (epsIn : EList Γ) (bIn : BList Γ) :
                    approxCtx toSpec xS xR epsInscaleCtx toSpec xS xR bInscaleCtx toSpec (g.evalSpec xS) (g.evalRuntime xR) (g.evalScales bIn xR)
                    def Proofs.RuntimeApprox.RevGraphScale.backpropScales {α : Type} {toSpec : αSpec.SpecScalar} {Γ ss : List Spec.Shape} (g : RevGraphScale toSpec Γ ss) [Add α] (bIn : BList Γ) (xR : TList α Γ) (bSeed : BList (Γ ++ ss)) (seedR : TList α (Γ ++ ss)) (addBound : {Δ : List Spec.Shape} → BList ΔBList ΔTList α ΔTList α ΔBList Δ) :

                    Backpropagate scale bounds through a RevGraphScale, analogous to RevGraph.backpropRuntime.

                    Instances For
                      theorem Proofs.RuntimeApprox.RevGraphScale.backprop_scale {α : Type} {toSpec : αSpec.SpecScalar} {Γ ss : List Spec.Shape} (g : RevGraphScale toSpec Γ ss) [Add α] (addBound : {Δ : List Spec.Shape} → BList ΔBList ΔTList α ΔTList α ΔBList Δ) (addSound : AddScaleSound toSpec fun {Δ : List Spec.Shape} => addBound) (xS : TList Spec.SpecScalar Γ) (xR : TList α Γ) (epsIn : EList Γ) (bIn : BList Γ) (seedS : TList Spec.SpecScalar (Γ ++ ss)) (seedR : TList α (Γ ++ ss)) (bSeed : BList (Γ ++ ss)) :
                      approxCtx toSpec xS xR epsInscaleCtx toSpec xS xR bInscaleCtx toSpec seedS seedR bSeedscaleCtx toSpec (g.toRevGraph.backpropSpec xS seedS) (g.toRevGraph.backpropRuntime xR seedR) (g.backpropScales bIn xR bSeed seedR fun {Δ : List Spec.Shape} => addBound)