TorchLean API

NN.MLTheory.CROWN.Graph.Engine.Base

Shared definitions for the graph CROWN engine.

This file contains the flat vector representation, parameter stores, interval boxes, shape permutation helpers, and tensor casts used by the IBP, derivative, affine, CROWN, and backward objective passes.

Flat vector pack: a tensor paired with its flattened dimension.

This is used for constant payloads and objective coefficient vectors in the flat LiRPA engine.

Instances For

    Parameters for a linear layer y = W*x + b in flattened form.

    m is the output dimension and n is the input dimension.

    Instances For

      Matrix parameters for bias-free matmul: y = W x.

      Instances For
        @[reducible, inline]

        Conv2D parameters with cached spatial dimensions for graph propagation.

        Instances For
          @[reducible, inline]

          Eval-mode BatchNorm2d parameters for an N×C×H×W node.

          Instances For

            Channel index for a flattened N×C×H×W tensor in row-major order.

            Instances For

              Eval BatchNorm scale for one channel.

              Instances For

                Eval BatchNorm bias for one channel after folding running statistics into an affine map.

                Instances For

                  Build the exact diagonal affine form for eval-mode BatchNorm2d over an N×C×H×W tensor.

                  The IR stores the channel parameters in the node payload. The spatial dimensions come from the checked parent shape, so malformed shapes produce no verifier transfer rule.

                  Instances For

                    Parameters keyed by node id (weights, biases, constants, and seeded input boxes).

                    This is kept compact: it is the graph interpreter used to run IBP/CROWN on a pure Graph without pulling in a heavyweight runtime.

                    Instances For

                      Insert an input interval box for a graph node.

                      Instances For
                        def NN.MLTheory.CROWN.Graph.ParamStore.seedLInfBall {α : Type} [Context α] {s : Spec.Shape} (ps : ParamStore α) (inputId : ) (center : Spec.Tensor α s) (eps : α) :

                        Seed a graph input with a uniform ℓ∞ box around a shaped tensor.

                        Instances For
                          def NN.MLTheory.CROWN.Graph.outputBox? {α : Type} [Context α] (boxes : Array (Option (FlatBox α))) (outId : ) :

                          Read a node's interval box from an IBP-style result array.

                          Instances For
                            @[implicit_reducible]

                            Default inhabitant for FlatBox (a 0-dimensional box at 0).

                            Elementwise product of two FlatBoxes (interval product per component). Requires equal dims.

                            Instances For

                              Chain-rule multiplication for derivative intervals. Returns none on dimension mismatch.

                              Instances For

                                Convert a dependent Box of shape .dim n .scalar into a FlatBox with dim := n.

                                Instances For

                                  Convert a FlatBox to a dependent Box at shape .dim B.dim .scalar.

                                  Instances For
                                    def NN.MLTheory.CROWN.Graph.box_add {α : Type} [Context α] [BoundOps α] (B1 B2 : FlatBox α) :

                                    Add two flat interval boxes coordinatewise; dimension mismatches preserve the left box.

                                    Instances For
                                      def NN.MLTheory.CROWN.Graph.box_sub {α : Type} [Context α] [BoundOps α] (B1 B2 : FlatBox α) :

                                      Interval subtraction on FlatBox endpoints (sound enclosure).

                                      Instances For

                                        Sum all coordinates of a flat box with directed accumulation.

                                        Instances For

                                          Average all coordinates of a nonempty flat box with directed division.

                                          Instances For

                                            Apply ReLU to both endpoints of a FlatBox (monotone activation, so endpoints suffice).

                                            Instances For

                                              Componentwise absolute value bounds. Soundly encloses abs over each interval component.

                                              Instances For
                                                def NN.MLTheory.CROWN.Graph.boxUnaryEnclosure? {α : Type} [Context α] [NonlinearBoundOps α] (enclose : ααOption (α × α)) (B : FlatBox α) :

                                                Apply a scalar interval enclosure coordinatewise to a flat box.

                                                Instances For

                                                  The real value represented by each coordinate of x lies between the interpreted endpoints of B. This is the semantic relation used to connect executable endpoint arithmetic to the real graph semantics.

                                                  Instances For

                                                    Dimension-aware enclosure of a real vector by a backend box.

                                                    Instances For
                                                      theorem NN.MLTheory.CROWN.Graph.boxUnaryEnclosure?_enclosesReal {α : Type} [Context α] [BoundOps α] [LawfulBoundOps α] [NonlinearBoundOps α] (f : ) (enclose : ααOption (α × α)) (henclose : UnaryEnclosure f enclose) (B : FlatBox α) (x : Spec.Tensor (Spec.Shape.dim B.dim Spec.Shape.scalar)) (hx : EnclosesReal B x) {out : FlatBox α} (hout : boxUnaryEnclosure? enclose B = some out) :

                                                      A lawful scalar transfer remains sound when applied coordinatewise to a flat graph box.

                                                      Componentwise square-root enclosure supplied by the scalar backend.

                                                      Instances For

                                                        Componentwise reciprocal bounds, failing when an input coordinate interval crosses zero.

                                                        Instances For

                                                          Derivative range for exp; exp' = exp.

                                                          Instances For

                                                            Derivative range for log; log' x = 1/x on a strictly positive interval.

                                                            Instances For

                                                              Second-derivative range for log; log'' x = -1/x² on a positive interval.

                                                              Instances For

                                                                Negate an interval box by swapping and negating its endpoints.

                                                                Instances For
                                                                  @[reducible, inline]

                                                                  Dynamic tensor value used while reshaping and permuting flattened boxes.

                                                                  Instances For

                                                                    Shape projection for FlatDVal.

                                                                    Instances For

                                                                      Tensor projection for FlatDVal, preserving the dependent shape stored beside it.

                                                                      Instances For

                                                                        Decompose an axis permutation into adjacent swaps, rejecting invalid permutations.

                                                                        Instances For

                                                                          Apply a full axis permutation to a dynamic tensor value when the permutation is valid.

                                                                          Instances For

                                                                            Componentwise max bounds: max(x,y) over interval boxes.

                                                                            Instances For

                                                                              Componentwise min bounds: min(x,y) over interval boxes.

                                                                              Instances For

                                                                                Componentwise square of an interval box: for each component [l,u] produce [min (l^2,u^2), max (l^2,u^2)], with 0 as the minimum when the interval crosses 0.

                                                                                The body is exposed because the proof layer theorem module unfolds this executable rule when proving dimension preservation and pointwise enclosure.

                                                                                Instances For
                                                                                  def NN.MLTheory.CROWN.Graph.intervalMul {α : Type} [Context α] (aLo aHi bLo bHi : α) :
                                                                                  α × α

                                                                                  Interval multiplication for scalar endpoints: given [aLo,aHi] and [bLo,bHi], return bounds on the product.

                                                                                  Instances For

                                                                                    Length of the last axis of a shape; scalars are treated as length one.

                                                                                    Instances For

                                                                                      Runtime witness that one shape can broadcast to another.

                                                                                      Instances For

                                                                                        Reinterpret a flattened tensor as shape s when the element counts agree.

                                                                                        Instances For
                                                                                          def NN.MLTheory.CROWN.Graph.ibpBroadcastTo {α : Type} [Context α] (s₁ s₂ : Spec.Shape) (Xin : FlatBox α) :

                                                                                          IBP rule for broadcasting a flattened input box to a target shape.

                                                                                          Instances For

                                                                                            IBP rule for reducing a shaped box by summing along one axis.

                                                                                            Instances For

                                                                                              IBP rule for reducing a shaped box by averaging along one axis.

                                                                                              Instances For

                                                                                                Format-independent softmax enclosure on a flattened tensor.

                                                                                                A singleton row is exactly one. Every coordinate of a longer row lies in [0,1]. This deliberately forgoes the tighter exponential formula above so executable checking does not assume a directed transcendental implementation that its scalar backend has not supplied.

                                                                                                Instances For

                                                                                                  Hard-masked softmax IBP (last axis) #

                                                                                                  Blocked coordinates have weight zero. An allowed coordinate lies in [0,1], and it has weight one when it is the only allowed coordinate in its row. These bounds do not evaluate exp or division, so they remain valid for executable endpoint types whose BoundOps instance covers only directed arithmetic. A tighter transfer rule requires separately certified directed bounds for transcendental operations.

                                                                                                  Conservative interval bounds for hard-masked softmax along the last tensor axis.

                                                                                                  Instances For

                                                                                                    LayerNorm IBP (last axis) #

                                                                                                    Layer normalization (Ba et al.) computes, per vector, something like:

                                                                                                    y = (x - mean(x)) / sqrt(var(x) + eps).

                                                                                                    We implement a conservative enclosure by:

                                                                                                    1. Bounding mean using sums of endpoints.
                                                                                                    2. Bounding variance using a max-deviation upper bound.
                                                                                                    3. Bounding the per-component ratio by checking endpoint combinations against a positive denominator interval.

                                                                                                    This is intended as a simple checker-side transfer rule. It is conservative and is not an optimized relaxation.

                                                                                                    References:

                                                                                                    Ideal-arithmetic upper bound on the variance term used by analytic LayerNorm rules.

                                                                                                    Given endpoint bounds for a vector and bounds on its mean, each coordinate is at most max |x_i - μ| away from the bounded mean interval. Squaring and summing those coordinate radii gives a conservative variance upper bound. The implementation uses ordinary scalar arithmetic and is called only from exact-arithmetic branches; executable endpoint propagation uses ibpLayerNormRange? instead.

                                                                                                    Instances For

                                                                                                      Ideal-arithmetic mean bounds for a nonempty vector with bounded coordinates.

                                                                                                      For n = 0, the mathematical mean is undefined; this total helper returns (0,0) so callers do not accidentally divide by zero while they reject or totalize the empty case.

                                                                                                      Instances For

                                                                                                        Ideal-arithmetic bounds for x - μ when x and μ are bounded by intervals.

                                                                                                        LayerNorm transfer rules repeatedly need this centered interval for the input, first derivative, and second derivative streams. Keeping it here avoids duplicating the same endpoint arithmetic in IBP and derivative propagation.

                                                                                                        Instances For

                                                                                                          Ideal-arithmetic reciprocal-denominator bounds from an upper variance bound.

                                                                                                          Instances For

                                                                                                            Analytic real-arithmetic LayerNorm bounds on the last axis, lifted over leading dimensions.

                                                                                                            Instances For

                                                                                                              Uniform finite enclosure for last-axis layer normalization.

                                                                                                              For a row of length n, exact LayerNorm without affine scale or bias satisfies |yᵢ| ≤ sqrt n; a singleton row is identically zero. Backends provide the outward-rounded bound through NonlinearBoundOps.layerNormAbsBound. Returning none is preferable to evaluating the normalization with unqualified host division and square root.

                                                                                                              Instances For

                                                                                                                For tensors known to have shape .dim n .scalar, extract the underlying function.

                                                                                                                Instances For

                                                                                                                  Cast a 1D Box along an equality of dimensions.

                                                                                                                  Instances For

                                                                                                                    Cast a ReLU relaxation vector across a proven-equal hidden dimension.

                                                                                                                    Instances For
                                                                                                                      def NN.MLTheory.CROWN.Graph.castAffineIn {α : Type} {n n' m : } (h : n = n') (a : AffineVec α n m) :
                                                                                                                      AffineVec α n' m

                                                                                                                      Cast the input dimension of an affine map across a proven equality.

                                                                                                                      Instances For
                                                                                                                        def NN.MLTheory.CROWN.Graph.castAffineOut {α : Type} {n m m' : } (h : m = m') (a : AffineVec α n m) :
                                                                                                                        AffineVec α n m'

                                                                                                                        Cast the output dimension of an affine map across a proven equality.

                                                                                                                        Instances For
                                                                                                                          @[reducible, inline]

                                                                                                                          Cast a dim-scalar tensor across an equality of dimensions.

                                                                                                                          We keep this as an abbrev so it unfolds aggressively in simp-based soundness proofs.

                                                                                                                          Instances For

                                                                                                                            IBP propagation through explicit linear parameters.

                                                                                                                            Instances For
                                                                                                                              def NN.MLTheory.CROWN.Graph.ibp_linear {α : Type} [Context α] [BoundOps α] (id : ) (ps : ParamStore α) (Xin : FlatBox α) :

                                                                                                                              IBP propagation for a .linear node using ParamStore.linearWB.

                                                                                                                              Instances For
                                                                                                                                def NN.MLTheory.CROWN.Graph.ibp_matmul {α : Type} [Context α] [BoundOps α] (id : ) (ps : ParamStore α) (Xin : FlatBox α) :

                                                                                                                                IBP propagation for a .matmul node (bias-free) using ParamStore.matmulW.

                                                                                                                                Instances For
                                                                                                                                  def NN.MLTheory.CROWN.Graph.ibpConv2dNode {α : Type} [Context α] (id : ) (ps : ParamStore α) (Xin : FlatBox α) :

                                                                                                                                  IBP transfer for a convolution node whose parameters are stored in ParamStore.conv2dCfg.

                                                                                                                                  Instances For