TorchLean API

NN.Proofs.RuntimeApprox.NF.BackwardOps.Backend

NF Backward Approximation Backend #

Core approximation lemmas for the rounded NF backend: constants, sparse context writes, and the context-addition bound used when reverse-mode contributions have to be accumulated.

theorem Proofs.RuntimeApprox.NFBackend.approxT_fill_const {β : TorchLean.Floats.NeuralRadix} {fexp : } {rnd : } {cS : } {cR : TorchLean.Floats.NF β fexp rnd} {eps : } (h : |toSpec cR - cS| eps) {s : Spec.Shape} :
approxT toSpec (Spec.fill cS s) (Spec.fill cR s) eps
theorem Proofs.RuntimeApprox.NFBackend.idx_shape_eq_of_i_eq {Γ : List Spec.Shape} {s₁ s₂ : Spec.Shape} (a : Idx Γ s₁) (b : Idx Γ s₂) (h : a.i = b.i) :
s₁ = s₂
def Proofs.RuntimeApprox.NFBackend.tensorCastOfIdxEq {α : Type} {Γ : List Spec.Shape} {s₁ s₂ : Spec.Shape} (a : Idx Γ s₁) (b : Idx Γ s₂) (h : a.i = b.i) :
Spec.Tensor α s₂Spec.Tensor α s₁

Cast a tensor across a shape equality induced by equal Idx positions.

Given a : Idx Γ s₁, b : Idx Γ s₂, and h : a.i = b.i, this produces a function Tensor α s₂ → Tensor α s₁ that casts along the implied equality s₁ = s₂.

Instances For
    theorem Proofs.RuntimeApprox.NFBackend.approxT_tensor_cast {β : TorchLean.Floats.NeuralRadix} {fexp : } {rnd : } {s t : Spec.Shape} (h : s = t) {xS : Spec.SpecTensor s} {xR : Spec.Tensor (TorchLean.Floats.NF β fexp rnd) s} {eps : } (hx : approxT toSpec xS xR eps) :
    theorem Proofs.RuntimeApprox.NFBackend.approxCtx_set2Idx_ne {β : TorchLean.Floats.NeuralRadix} {fexp : } [TorchLean.Floats.NeuralValidExp fexp] {rnd : } [TorchLean.Floats.NeuralValidRndToNearest rnd] {Γ : List Spec.Shape} {s₁ s₂ : Spec.Shape} (a : Idx Γ s₁) (b : Idx Γ s₂) {t₁S : Spec.SpecTensor s₁} {t₁R : Spec.Tensor (TorchLean.Floats.NF β fexp rnd) s₁} {eps₁ : } {t₂S : Spec.SpecTensor s₂} {t₂R : Spec.Tensor (TorchLean.Floats.NF β fexp rnd) s₂} {eps₂ : } (h₁ : approxT toSpec t₁S t₁R eps₁) (h₂ : approxT toSpec t₂S t₂R eps₂) (hne : a.i b.i) :
    approxCtx toSpec (TList.set2Idx a t₁S b t₂S) (TList.set2Idx a t₁R b t₂R) (EList.set2Idx a eps₁ b eps₂ 0)
    theorem Proofs.RuntimeApprox.NFBackend.approxCtx_set3Idx_ne {β : TorchLean.Floats.NeuralRadix} {fexp : } [TorchLean.Floats.NeuralValidExp fexp] {rnd : } [TorchLean.Floats.NeuralValidRndToNearest rnd] {Γ : List Spec.Shape} {s₁ s₂ s₃ : Spec.Shape} (a : Idx Γ s₁) (b : Idx Γ s₂) (c : Idx Γ s₃) {t₁S : Spec.SpecTensor s₁} {t₁R : Spec.Tensor (TorchLean.Floats.NF β fexp rnd) s₁} {eps₁ : } {t₂S : Spec.SpecTensor s₂} {t₂R : Spec.Tensor (TorchLean.Floats.NF β fexp rnd) s₂} {eps₂ : } {t₃S : Spec.SpecTensor s₃} {t₃R : Spec.Tensor (TorchLean.Floats.NF β fexp rnd) s₃} {eps₃ : } (h₁ : approxT toSpec t₁S t₁R eps₁) (h₂ : approxT toSpec t₂S t₂R eps₂) (h₃ : approxT toSpec t₃S t₃R eps₃) (hab : a.i b.i) (hac : a.i c.i) (hbc : b.i c.i) :
    approxCtx toSpec (TList.set3IdxNe a t₁S b t₂S c t₃S hab hac hbc) (TList.set3IdxNe a t₁R b t₂R c t₃R hab hac hbc) (EList.set3IdxNe a eps₁ b eps₂ c eps₃ hab hac hbc)

    Context-wise addition bound (NF runtime vs spec).

    This produces an EList of linf_norm bounds for adding two contexts elementwise, and is used when reverse-mode accumulation must combine contributions from multiple consumers.

    Instances For
      theorem Proofs.RuntimeApprox.NFBackend.approxCtx_add {β : TorchLean.Floats.NeuralRadix} {fexp : } [TorchLean.Floats.NeuralValidExp fexp] {rnd : } [TorchLean.Floats.NeuralValidRndToNearest rnd] {Δ : List Spec.Shape} (xS yS : TList Spec.SpecScalar Δ) (xR yR : TList (TorchLean.Floats.NF β fexp rnd) Δ) (epsx epsy : EList Δ) :
      approxCtx toSpec xS xR epsxapproxCtx toSpec yS yR epsyapproxCtx toSpec (TList.add xS yS) (TList.add xR yR) (ctxAddBound epsx epsy xR yR)

      Soundness of context-wise addition under approxCtx.

      If xS ~ xR ± epsx and yS ~ yR ± epsy, then (xS + yS) ~ (xR + yR) with error bounded by ctxAddBound epsx epsy xR yR.