BackwardScale #
Backward (reverse-mode) scale propagation.
This optional module mirrors NN.Proofs.RuntimeApprox.Graph.BackwardApprox, but for scale bounds
(nonnegative bounds on linfNorm) 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.
Soundness condition for accumulating scale bounds under addition in a context.
Instances For
A reverse node augmented with forward+VJP scale bounds.
- forwardRuntime : TorchLean.TensorPack α Γ → TorchLean.Tensor α τ
- bound : EList Γ → TorchLean.TensorPack α Γ → Spec.SpecScalar
- sound (xS : TorchLean.TensorPack Spec.SpecScalar Γ) (xR : TorchLean.TensorPack α Γ) (eps : EList Γ) : approxCtx toSpec xS xR eps → approxTensor toSpec (self.forwardSpec xS) (self.forwardRuntime xR) (self.bound eps xR)
- vjpRuntime : TorchLean.TensorPack α Γ → TorchLean.Tensor α τ → TorchLean.TensorPack α Γ
- vjpBound : EList Γ → TorchLean.TensorPack α Γ → Spec.SpecScalar → TorchLean.Tensor α τ → EList Γ
- vjpSound (ctxS : TorchLean.TensorPack Spec.SpecScalar Γ) (ctxR : TorchLean.TensorPack α Γ) (epsCtx : EList Γ) (δS : Spec.SpecTensor τ) (δR : TorchLean.Tensor α τ) (epsδ : Spec.SpecScalar) : approxCtx toSpec ctxS ctxR epsCtx → approxTensor toSpec δS δR epsδ → approxCtx toSpec (self.vjpSpec ctxS δS) (self.vjpRuntime ctxR δR) (self.vjpBound epsCtx ctxR epsδ δR)
- fwdScaleBound : BList Γ → TorchLean.TensorPack α Γ → NNReal
- fwdScaleSound (ctxS : TorchLean.TensorPack Spec.SpecScalar Γ) (ctxR : TorchLean.TensorPack α Γ) (epsCtx : EList Γ) (bCtx : BList Γ) : approxCtx toSpec ctxS ctxR epsCtx → scaleCtx toSpec ctxS ctxR bCtx → scaleTensor toSpec (self.forwardSpec ctxS) (self.forwardRuntime ctxR) (self.fwdScaleBound bCtx ctxR)
- vjpScaleBound : BList Γ → TorchLean.TensorPack α Γ → NNReal → TorchLean.Tensor α τ → BList Γ
- vjpScaleSound (ctxS : TorchLean.TensorPack Spec.SpecScalar Γ) (ctxR : TorchLean.TensorPack α Γ) (epsCtx : EList Γ) (bCtx : BList Γ) (δS : Spec.SpecTensor τ) (δR : TorchLean.Tensor α τ) (bδ : NNReal) : approxCtx toSpec ctxS ctxR epsCtx → scaleCtx toSpec ctxS ctxR bCtx → scaleTensor toSpec δS δR bδ → scaleCtx toSpec (self.vjpSpec ctxS δS) (self.vjpRuntime ctxR δR) (self.vjpScaleBound bCtx ctxR bδ δR)
Instances For
Reverse-mode graph with scale-aware nodes.
- nil {α : Type} {toSpec : α → Spec.SpecScalar} {Γ : List Spec.Shape} : RevGraphScale toSpec Γ []
- snoc {α : Type} {toSpec : α → Spec.SpecScalar} {Γ ss : List Spec.Shape} {τ : Spec.Shape} : RevGraphScale toSpec Γ ss → RevNodeScale toSpec (Γ ++ ss) τ → RevGraphScale toSpec Γ (ss ++ [τ])
Instances For
Forget the scale annotations on nodes, producing an ordinary RevGraph.
Instances For
Convert a RevGraphScale into a FwdGraphScale by dropping the reverse-mode payload.
Instances For
Forgetting the scale annotations commutes with forgetting the reverse-mode structure.
Both directions of the square end at the same plain forward graph, which is why the scale-annotated development can reuse the unannotated evaluation lemmas instead of repeating them.
Evaluate the forward pass on spec values, returning the extended context Γ ++ ss.
Instances For
Evaluate the forward pass on runtime values, returning the extended context Γ ++ ss.
Instances For
Spec evaluation of a scale-annotated reverse graph agrees with the unannotated one.
And so does runtime evaluation. The annotations carry bounds only; they never change what is computed, which is exactly what these two lemmas record.
Forward-pass error bounds for all intermediate nodes, computed from input bounds epsIn.
Instances For
Forward-pass scale bounds for all intermediate nodes, computed from input bounds bIn.
Instances For
Forward evaluation respects the scale bounds: if the inputs are within their bounds, every
intermediate node is within the bound evalScales computes for it.
Backpropagate scale bounds through a RevGraphScale, analogous to RevGraph.backpropRuntime.
Instances For
The same statement for the backward pass: propagated cotangents stay within the backpropagated scale bounds.
The addBound combiner is a parameter rather than a fixed choice, because how two accumulated
gradients' bounds combine depends on the carrier: adding bounds is always sound, but a carrier with
a
sharper triangle inequality can do better. addSound is what pins down the requirement.