TorchLean API

NN.API.Verification

Verification #

Convenience names for compiling TorchLean models into IBP/CROWN checks.

Compile a sequential TorchLean model into verifier IR with one distinguished input.

Usual "train a model, then run IBP/CROWN on its forward pass" path.

Instances For
    def TorchLean.Verification.compileProgram {α : Type} [Context α] [DecidableEq Shape] {paramShapes : List Shape} {σ τ : Shape} (forwardProgram : Runtime.Autograd.TorchLean.Program α (paramShapes ++ [σ]) τ) (params : TensorPack α paramShapes) :

    Compile a custom TorchLean forward program into verifier IR with one distinguished input.

    Use this when the target is not a plain TorchLean.nn.Sequential, for example a hand-written loss program or an attention fragment built directly from TorchLean.Ops.

    Instances For
      def TorchLean.Verification.seedInputBox {α : Type} [Context α] (compiled : CompiledIR α) (xB : FlatBox α) :

      Seed the verifier input with an explicit input box.

      Call this after compileForward, then hand the returned store to IBP/CROWN passes.

      Instances For
        def TorchLean.Verification.lInfBox {α : Type} [Context α] {s : Shape} (center radius : Spec.Tensor α s) :

        Flatten a center tensor and radius tensor into the FlatBox expected by IBP/CROWN.

        Use this for a shaped TorchLean input with a shaped perturbation radius.

        Instances For
          def TorchLean.Verification.lInfBall {α : Type} [Context α] {s : Shape} (center : Spec.Tensor α s) (eps : α) :

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

          This fills the input shape with the scalar radius eps, then flattens it into a verifier box.

          Instances For
            def TorchLean.Verification.seedLInfBall {α : Type} [Context α] {s : Shape} (compiled : CompiledIR α) (center : Spec.Tensor α s) (eps : α) :

            Seed the compiled verifier input with a uniform $\ell^\infty$ box around a shaped TorchLean input tensor.

            Instances For

              Shape of the distinguished verifier input node.

              Instances For

                Flattened dimension of the distinguished verifier input node.

                Instances For

                  Affine context for the distinguished verifier input.

                  Instances For

                    Run IBP on a compiled verifier graph.

                    Instances For
                      def TorchLean.Verification.outputBox? {α : Type} [Context α] (compiled : CompiledIR α) (boxes : Array (Option (FlatBox α))) :

                      Read the verifier output box from an IBP result array.

                      Instances For
                        def TorchLean.Verification.outputBoxOrThrow {α : Type} [Context α] (compiled : CompiledIR α) (boxes : Array (Option (FlatBox α))) :
                        IO (FlatBox α)

                        Read the verifier output box, throwing an IO.userError if it is missing.

                        Instances For

                          Run the forward affine pass after validating the compiled verifier input.

                          Instances For

                            Read the verifier output affine form from a forward affine result array.

                            Instances For

                              Run CROWN after validating the compiled verifier input.

                              Instances For

                                Read the verifier output CROWN bounds from a CROWN result array.

                                Instances For

                                  Run forward CROWN and evaluate the verifier output bounds on the compiled input box.

                                  Instances For

                                    Run forward CROWN and return the evaluated verifier output box, throwing on failure.

                                    Instances For

                                      Run backward CROWN for a scalar objective and evaluate it on the compiled input box.

                                      Instances For
                                        def TorchLean.Verification.twoClassMarginLowerBound {α : Type} [Context α] {n : } (lo hi : Spec.Tensor α (Spec.Shape.dim n Shape.scalar)) (class0 class1 : Fin n) :
                                        α

                                        Compute the conservative two-class margin lower bound $\mathrm{lo}[\mathrm{class0}]-\mathrm{hi}[\mathrm{class1}]$.

                                        If this is positive, class class0 is certified against class1 over the input box.

                                        Instances For

                                          Decide whether the two-class margin lower bound is strictly positive.

                                          Instances For