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 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.
- 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
Average all coordinates of a nonempty flat box with directed division.
Instances For
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
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
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 layer 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 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
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:
- 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
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
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.