TorchLean API

NN.Examples.DeepDives.OneSemanticUniverse

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:

  1. evaluate it under multiple scalar semantics (, FP32, ExecFloat.Binary 8 23);
  2. run IBP under multiple interval semantics (endpoints in , FP32, ExecFloat.Binary 8 23 with directed rounding);
  3. empirically check that evalIEEE(G,x) lies in the IBP output box for random $x\in B$;
  4. point to the Lean theorem that the Boolean checker is sound (Box.containsDecBool_sound).

Notes:

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
      @[reducible, inline]

      Shape of one input vector.

      Instances For
        @[reducible, inline]

        Shape of the hidden activation.

        Instances For
          @[reducible, inline]

          Shape of the second layer's output, before the reduction.

          Instances For
            @[reducible, inline]

            First weight matrix, [out, in] as in PyTorch.

            Instances For
              @[reducible, inline]

              First bias.

              Instances For
                @[reducible, inline]

                Second weight matrix.

                Instances For
                  @[reducible, inline]

                  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.

                    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

                                        Present an input box in the flat form the propagator consumes.

                                        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.

                                          Instances For

                                            Entry point; --samples controls how many random points are checked against the bounds.

                                            Instances For