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.
- n : ℕ
Vector dimension.
- v : Spec.Tensor α (Spec.Shape.dim self.n Spec.Shape.scalar)
Vector payload (shape
.dim n .scalar).
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.
- m : ℕ
Output dimension.
- n : ℕ
Input dimension.
- w : Spec.Tensor α (Spec.Shape.dim self.m (Spec.Shape.dim self.n Spec.Shape.scalar))
- b : Spec.Tensor α (Spec.Shape.dim self.m Spec.Shape.scalar)
Instances For
Matrix parameters for bias-free matmul: y = W x.
- m : ℕ
Output dimension.
- n : ℕ
Input dimension.
- w : Spec.Tensor α (Spec.Shape.dim self.m (Spec.Shape.dim self.n Spec.Shape.scalar))
Instances For
Conv2D parameters with cached spatial dimensions for graph propagation.
Instances For
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 simply do not produce a 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.
- inputBoxes : Std.HashMap ℕ (FlatBox α)
Seed boxes for designated input nodes (
id -> FlatBox). - constVals : Std.HashMap ℕ (FlatVec α)
- linearWB : Std.HashMap ℕ (LinParams α)
Linear layer params (
id -> (W,b)). - matmulW : Std.HashMap ℕ (MatParams α)
Matmul params (
id -> W) for bias-free multiplication. - conv2dCfg : Std.HashMap ℕ (Conv2DParams α)
Conv2d specs (
id -> conv configuration). - batchNorm2dNchwEval : Std.HashMap ℕ (BatchNorm2DNchwEvalParams α)
Eval-mode BatchNorm2d parameters (
id -> gamma/beta/running stats).
Instances For
Insert an input interval box for a graph node.
Instances For
Seed a graph input with a uniform ℓ∞ box around a shaped tensor.
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
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
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-facing theorem module unfolds this executable rule when proving dimension preservation and pointwise enclosure.
Instances For
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 an axis is valid for a shape.
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
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
Softmax IBP (last axis) #
For a 1D vector x with interval bounds l <= x <= u, a standard componentwise enclosure for
softmax is:
softmax_i(x) = exp(x_i) / sum_j exp(x_j)- Lower bound (worst-case denominator):
exp(l_i) / (exp(l_i) + sum_{j != i} exp(u_j)) - Upper bound (best-case denominator):
exp(u_i) / (exp(u_i) + sum_{j != i} exp(l_j))
This uses monotonicity of exp and the fact that all terms in the denominator are nonnegative.
The implementation below applies the 1D rule on the last tensor axis and recurses over leading batch
dimensions.
References:
- CROWN / DeepPoly context: Zhang et al., 2018 (CROWN): https://arxiv.org/abs/1811.00866
- auto_LiRPA: Xu et al., 2020: https://arxiv.org/abs/2002.12920
Interval bound propagation for softmax, applied on the last axis and lifted over leading dims.
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:
- Bounding mean using sums of endpoints.
- Bounding variance using a max-deviation upper bound.
- 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:
- Ba, Kiros, Hinton, "Layer Normalization", 2016: https://arxiv.org/abs/1607.06450
- Bound propagation context: Xu et al., 2020 (auto_LiRPA): https://arxiv.org/abs/2002.12920
Upper bound on the variance term used by the LayerNorm interval 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 the conservative variance upper bound reused by IBP, affine propagation, and derivative
interval passes.
Instances For
Mean bounds for a vector whose coordinates are bounded by endpoint tensors.
Instances For
Bounds for x - μ when x is bounded coordinatewise and μ is bounded by an interval.
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
Bounds for the reciprocal LayerNorm denominator from an upper variance bound.
Instances For
Interval bound propagation for layernorm, applied on the last axis and lifted over leading
dims.
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
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 for a .linear node using ParamStore.linearWB.
Instances For
IBP propagation for a .matmul node (bias-free) using ParamStore.matmulW.
Instances For
IBP transfer for a convolution node whose parameters are stored in ParamStore.conv2dCfg.