One semantic universe #
End-to-end “one semantic universe” tutorial (single graph, many semantics, one checker).
This tutorial lives under NN/Examples/DeepDives because it connects execution, interval semantics,
and checker soundness in one graph.
We build one medium 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 fully executable inside Lean, so we use it for the runnable consistency check.
Run:
lake exe torchlean one_semantic_universe --samples 50
Command-line help for the one-semantics tutorial.
Instances For
Three outputs, then summed and squashed to a scalar.
Instances For
Shape of one input vector.
Instances For
Shape of the second layer's output, before the reduction.
Instances For
Second weight matrix.
Instances For
Second bias.
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 α outputWeightShape
Weight matrix for layer 2.
- outputBias : TorchLean.Tensor α outputBiasShape
Bias for layer 2.
Instances For
Transport every parameter tensor along a scalar conversion.
Instances For
Concrete parameters, written as small decimal literals.
These are the only numbers in the file; every other instantiation is obtained from them by map, so
the four semantics are guaranteed to be looking at the same network.
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.
Evaluation over the reals: the mathematical meaning of the network, with no rounding at all.
Instances For
Evaluation over rounded reals: each operation rounds to nearest binary32, but the carrier is still
ℝ, which is what makes the error proofs possible.
Instances For
Interval bound propagation over the reals.
Instances For
The same propagation over rounded reals.
Instances For
The centre of the input box.
Instances For
An eps-ball around referenceInputFloat, in the scalar type α.
Instances For
Present an input box in the flat form the propagator consumes.
Instances For
Read a one-dimensional flat box back as a scalar box, failing loudly if the dimension is not one.
Instances For
Draw one sample from an input box under the bit-level IEEE model.
The final clamp is not cosmetic: lo + u * (hi - lo) is computed in binary32, so rounding can push
the result a fraction of an ulp outside the box. Clamping makes the sample genuinely a member of the
box, which is what the enclosure check below assumes.
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.