One graph, several scalar interpretations #
Evaluate the same graph over exact reals, rounded reals, and executable binary32 values, then propagate intervals through its operations.
This tutorial lives under NN/Examples/DeepDives because it connects execution, interval semantics,
and checker soundness in one graph.
We build one six-node IR graph:
$$ x\mapsto\tanh\!\left(\operatorname{sum} \left(\operatorname{Linear}_2(\operatorname{ReLU}(\operatorname{Linear}_1(x)))\right)\right) $$
and then:
- evaluate it under multiple scalar semantics (
ℝ,FP32,ExecFloat.Binary 8 23); - run IBP under multiple interval semantics (endpoints in
ℝ,FP32,ExecFloat.Binary 8 23with directed rounding); - empirically check that
evalIEEE(G,x)lies in the IBP output box for random $x\in B$; - point to the Lean theorem that the Boolean checker is sound (
Box.containsDecBool_sound).
Notes:
ℝandFP32instantiations are proof-oriented and noncomputable (they typecheck, but do not run as an executable).ExecFloat.Binary 8 23is executable inside Lean, so we use it for the runnable consistency check.
Run:
scripts/lake.sh exe torchlean graph_semantics --samples 50
Command-line help for the graph-semantics tutorial.
Instances For
The network's parameters, generic in the scalar type.
Being generic in α is the whole point of this tutorial: one parameter record is transported to
Float, to the bit-level IEEE model, to ℝ and to the rounded-real FP32, and the same graph is
evaluated in each.
- outputWeight : TorchLean.Tensor α [3, 5]
Weight matrix for layer 2.
- outputBias : TorchLean.Tensor α [3]
Bias for layer 2.
Instances For
Transport every parameter tensor along a scalar conversion.
Instances For
Concrete parameters, written as small decimal literals.
The executable binary32 parameters are obtained from these host Float values by Parameters.map.
Conversion may round coefficients; the graph structure and parameter layout remain fixed.
Instances For
The network as six IR nodes: input, linear, ReLU, linear, sum, tanh.
Written out node by node rather than built by a combinator, so the reader can see exactly what the evaluator and the interval propagator are given.
Instances For
Attach the weight and bias tensors to the two linear nodes.
Instances For
The same parameters in the form interval propagation wants, together with the input box.
Instances For
Evaluate the graph at scalar type α and check that the result really is a scalar.
Instances For
Proof-oriented instantiations #
The same graph evaluator and interval propagation algorithm specialize directly to ℝ and
proof-oriented FP32. These definitions are noncomputable because their scalar semantics are
intended for reasoning rather than native execution.
The centre of the input box.
Instances For
An eps-ball around center, in the scalar type α.
Instances For
Read a one-dimensional flat box back as a scalar box, failing loudly if the dimension is not one.
Instances For
Draw a deterministic sample using the box's scalar arithmetic and shape.
Rounding in lo + u * (hi - lo) can move a sample outside the endpoints. Clamp after the
interpolation; the runnable example still checks membership before evaluating the sample.
Instances For
Run the tutorial: evaluate at the centre, propagate bounds, then check that randomly drawn samples from the input box land inside the propagated output interval.