TorchLean API

NN.MLTheory.CROWN.Operators.Batchnorm

BatchNorm operator bounds (IBP + affine) #

This file bounds inference-time BatchNorm. Since inference-time BatchNorm is an affine transformation (with frozen statistics), both IBP and affine propagation are exact (componentwise).

At inference time, TorchLean uses y = γ * (x - μ) / sqrt(max(σ², 0) + ε) + β, so the layer reduces to y = scale * x + offset, where scale = γ / sqrt(max(σ², 0) + ε) and offset = β - γ * μ / sqrt(max(σ², 0) + ε).

The max is the same totalization used by Spec.batchNormInference and the IR evaluator. It has no effect on valid nonnegative running variances, while keeping every TorchLean layer aligned on malformed approximate-runtime inputs.

References:

Parameters for BatchNorm layer (frozen at inference).

Instances For

    Compute the equivalent affine scale: γ / sqrt(max(σ², 0) + ε).

    Instances For

      Compute the equivalent affine offset: β - γ * μ / sqrt(max(σ², 0) + ε).

      Instances For

        IBP for BatchNorm. Since BatchNorm is affine, its bounds are exact.

        For $y=sx+o$:

        • if $s>0$, then $y_{\mathrm{lo}}=s x_{\mathrm{lo}}+o$ and $y_{\mathrm{hi}}=s x_{\mathrm{hi}}+o$;
        • if $s<0$, then $y_{\mathrm{lo}}=s x_{\mathrm{hi}}+o$ and $y_{\mathrm{hi}}=s x_{\mathrm{lo}}+o$.
        Instances For
          def NN.MLTheory.CROWN.Operators.Batchnorm.affBatchnorm {α : Type} [Context α] {inDim : } (params : BatchNormParams α) (aff : AffineVec α inDim params.dim) :
          AffineVec α inDim params.dim

          Affine bounds for BatchNorm propagation.

          Since BatchNorm is affine, compose the two affine forms:

          $$ \begin{aligned} y_{\mathrm{prev}} &= A_{\mathrm{prev}}x_{\mathrm{in}}+c_{\mathrm{prev}},\\ \operatorname{BN}(y) &= sy+o,\\ \operatorname{BN}(y_{\mathrm{prev}}) &= \operatorname{diag}(s)A_{\mathrm{prev}}x_{\mathrm{in}} +(s c_{\mathrm{prev}}+o). \end{aligned} $$

          Instances For

            Derivative bounds for BatchNorm. Since BatchNorm is affine, $\frac{d}{dx}\operatorname{BN}(x)=s$ is constant. Input bounds $[d_{\mathrm{lo}},d_{\mathrm{hi}}]$ therefore become $s[d_{\mathrm{lo}},d_{\mathrm{hi}}]$.

            Instances For

              Propagate second-derivative bounds through inference-time BatchNorm.

              Although the second derivative of the affine map x ↦ scale * x + offset with respect to x is zero, composition with a curve x(t) gives d²/dt² BN(x(t)) = scale * x''(t). Consequently this uses the same signed scaling rule as first-derivative propagation.

              Instances For