TorchLean API

NN.Verification.Builtin.Lowering.API

Verification IR Lowering #

Public entry points for lowering TorchLean programs to the shared verifier IR and querying IBP and CROWN bounds. Graph construction lives in Lowering.Builder; this module contains the stable result type and the operations available on a lowered graph.

The broad lowerForwardToIR entry point runs a TorchLean.Runtime.Program with the IR-building interpreter, then checks the graph's structure and shapes. A successful result is executable and ready for verifier passes, but does not by itself prove equality with the source program. The theorem-backed source fragment lives under NN.Verification.Builtin.Proved.

GELU and stable log-softmax are rejected rather than replaced by numerically different expansions. The one-hot matrix encoding of slicing performs arithmetic instead of direct indexing; structural validation does not establish numerical equivalence for that encoding. Clamp preserves the source operand order, but rejects scalar contexts whose stopGradient? requires conditional differentiation-metadata clearing at the bounds.

Public lowering entry points #

Result of lowering a TorchLean forward model to verifier IR.

This bundles:

  • the produced IR graph (NN.IR.Graph),
  • a CROWN/LiRPA-style ParamStore containing constants and layer parameters, and
  • the distinguished input/output node ids (used by bound propagation and certificate checkers).
  • graph : IR.Graph

    Lowered IR graph.

  • Parameters/constants for verifier algorithms (IBP, CROWN, etc.).

  • inputId : ℕ

    Distinguished input node id (kept stable as 0).

  • outputId : ℕ

    Output node id.

Instances For

    Seed the distinguished verifier input with an explicit flat input box.

    Instances For

      Uniform $\ell^\infty$ box around a shaped TorchLean input tensor.

      Instances For
        @[simp]
        theorem NN.Verification.Builtin.lInfBall_dim {α : Type} [TorchLean.Storage α] [Context α] [MLTheory.CROWN.BoundOps α] {s : Spec.Shape} (center : TorchLean.Tensor α s) (eps : α) :
        (lInfBall center eps).dim = s.size

        Flattening an $\ell^\infty$ ball preserves the number of tensor entries as its dimension.

        Seed the distinguished verifier input with a uniform $\ell^\infty$ ball.

        Instances For

          Shape of the distinguished verifier input node.

          Instances For

            Flattened dimension of the distinguished verifier input node.

            Instances For

              Affine/CROWN context for the distinguished verifier input.

              Instances For

                Read the verifier output box from an IBP result array.

                Instances For

                  Compute CROWN output bounds on a selected input box. Exact-reassociation backends use a forward affine sweep; rounded backends request directed backward bounds for the output coordinates.

                  Instances For

                    Run objective-dependent backward CROWN and evaluate the scalar objective on the input box.

                    Instances For
                      @[noinline]
                      def NN.Verification.Builtin.lowerForwardToIR {α : Type} [TorchLean.Storage α] [Context α] {paramShapes : List Spec.Shape} {inShape outShape : Spec.Shape} (model : Runtime.Autograd.Model.Program α (paramShapes ++ [inShape]) outShape) (params : TorchLean.TensorPack α paramShapes) :

                      Lower a TorchLean forward model with one distinguished input, supplied as its last argument.

                      Success means that every encountered operation was supported and that the produced IR passed structural and shape validation. It does not attach a source-to-IR semantic theorem.

                      Instances For