Verifier IR Lowering #
This interpreter records the forward operations of a TorchLean Program in NN.IR.Graph.
Tensor constants and layer weights go into a separate ParamStore, keyed by node identifier.
The resulting graph can be passed to the interval and CROWN checkers, which first check whether
their transfer rules support its operations and parameter payloads.
The builder handles arithmetic, shape operations, common activations, pooling, linear layers, and arbitrary-rank convolution. Composite operations such as multi-head attention produce several IR nodes. Training BatchNorm, tensor-valued gather/scatter indices, and selection on an inner axis return lowering errors.
Softplus and safeLog have dedicated operations that retain the scalar specification's stable
branch. SafeLog stores epsilon as a scalar constant parent, so its value, including any dual
components, reaches the evaluator unchanged. Its outer logarithm follows the source backend's
semantics; certificate transfers separately check the domain needed for a sound enclosure.
LayerNorm stores the supplied epsilon, scale, and bias together in its parameter payload. We keep
epsilon even when its scalar equality test reports the default value: for example, Dual equality
compares the primal part, while its tangent may still differ. The IR evaluator uses the complete
payload. Last-axis IBP and CROWN value bounds use directed arithmetic for the normalization and
affine transform. The derivative passes leave these payloads unresolved until their rules account
for the supplied parameters and the specification's variance calculation.
Leading-axis select receives a Fin index while constructing the graph. Reading coordinate zero
of a state vector therefore becomes a constant one-hot projection followed by a reshape.
indexSelect and scatterAdd receive their indices as tensor data and need separate lowering and
transfer rules.
PyTorch weight and graph import is implemented under NN.Runtime.PyTorch.Import.
References (informal):
- IBP: Gowal et al. (2018).
- CROWN / DeepPoly-style linear relaxations: Zhang et al. (2018).
- LiRPA unification viewpoint: Xu et al. (2020).
IR builder #
Reference produced while lowering a TorchLean program.
A value is either already materialized as an IR node, or it is still a compile-time tensor constant
that can be inserted into the verifier ParamStore if a later operation needs a node parent.
- node {α : Type} [TorchLean.Storage α] {s : Spec.Shape} (id : ℕ) : Ref α s
- const {α : Type} [TorchLean.Storage α] {s : Spec.Shape} (t : TorchLean.Tensor α s) : Ref α s
Instances For
Mutable builder state for translating a TorchLean program into verifier IR.
IR nodes emitted so far, in construction/topological order.
Parameter payload accumulated for constant tensors and layer weights.
Instances For
Builder monad used by TorchLean-to-IR lowering.
Instances For
Raise a lowering error inside BuildM.
Instances For
Run a shared IR shape contract and surface its error from lowering.
Instances For
Append a freshly constructed IR node to the builder state.
Instances For
Return the next node identifier, which is the current node-array size.
Instances For
Ensure a Ref is represented by an IR node.
Compile-time constants are materialized as .const nodes and recorded in the verifier
ParamStore; existing graph nodes are returned unchanged.
Instances For
Emit a unary IR operation with one parent node.
Instances For
Emit a binary IR operation whose operands have the same shape.
Instances For
Emit a matrix-multiplication IR node.
Instances For
Emit the designated verifier input node. We keep this at id 0 for bound seeding.
Instances For
Read a compile-time constant tensor, failing if the value already depends on graph input.
Instances For
Lower one sample of multi-head attention into the verifier IR.
Instances For
Exact leading-axis slice expressed through the verifier's affine matrix fragment.
Instances For
Emit a verifier-IR concatenation along the leading axis.
Instances For
Lower batched attention as the leading-axis map of the single-sample verifier graph.
This is intentionally a semantic lowering rather than a claim that the verifier understands a new opaque fused kernel.