TorchLean API

NN.MLTheory.CROWN.Cert.PhasedCROWN

α-CROWN with ReLU phases (graph dialect) #

This extends AlphaCROWN.alphaCrownStepNode? with optional ReLU phases. For a ReLU node, a certificate may provide one phase per neuron:

The step checks each phase against the IBP pre-activation bounds: active requires 0 ≤ lo, and inactive requires hi ≤ 0. When every phase is consistent, active and inactive neurons use the exact ReLU (slope 1 or 0) and unstable neurons use the usual α-CROWN relaxation.

Because a phase is accepted only when the IBP interval already proves it, phases add no information beyond IBP. α-CROWN already uses the identity when 0 < lo and zero when hi ≤ 0, so there the two passes agree. They differ only for an active phase with lo = 0: the phase uses the identity, while α-CROWN uses the lower slope α when 0 < hi and zero when hi = 0. Both lines agree at zero, so either choice is sound. Without phases the pass is exactly alphaCrownStepNode?. There are no Lagrangian β multipliers and no branch splits.

Phases have the form of the ReLU split constraints of β-CROWN (Wang et al., Beta-CROWN: Efficient Bound Propagation with Provable Guarantees, NeurIPS 2021), where branch-and-bound chooses the splits and β multipliers enforce them; neither is formalized here. CROWN itself is Zhang et al., Efficient Neural Network Robustness Certification with General Activation Functions, NeurIPS 2018.

ReLU phase encoding #

A phase has three values:

At runtime, a certificate provides an Array Int with entries in $\{-1,0,1\}$, which we decode using ReLUPhase.ofInt?.

Which side of the origin a certificate claims a pre-activation stays on.

unstable is the honest "do not know", and it is the only phase that forces the relaxation to spend an α parameter.

  • inactive : ReLUPhase

    The pre-activation is claimed nonpositive, so the ReLU output is zero.

  • unstable : ReLUPhase

    No claim: the pre-activation may cross zero.

  • active : ReLUPhase

    The pre-activation is claimed nonnegative, so the ReLU acts as the identity.

Instances For

    Encode a ReLUPhase as the certificate integer convention {-1, 0, 1}.

    Instances For

      Decode a phase integer (-1/0/1) into a ReLUPhase, returning none on invalid input.

      Instances For

        The phases of node id, if the certificate gives any.

        Instances For

          Executable phase-consistency check for a scalar pre-activation interval $[l,u]$.

          This is written for a generic Context α (so it can run over floats or other semirings). For proof-level soundness over ℝ, see theorems in NN/MLTheory/CROWN/Proofs/PhasedReLUScalarSoundness.lean.

          Instances For

            Phase-aware upper (over-approx) linear relaxation for ReLU.

            Instances For

              Phase-aware lower (under-approx) linear relaxation for ReLU.

              Instances For

                Read the phase of neuron i, with 0 (unconstrained) past the end of the array.

                phaseRelaxVec? checks the array length before reading, so the default is never used there. The total read keeps the executable code free of bounds proofs, and the definition reduces in the kernel.

                Instances For

                  Vectorized construction of ReLU relaxations under phase constraints.

                  Returns (relaxLo, relaxHi) if:

                  • the phase array has the correct length, and
                  • every scalar entry is decodable and phase-consistent with the IBP interval bounds.

                  Implementation notes:

                  • We first compute a boolean ok over all indices (so the function remains executable in a generic Context α).
                  • Phases are read with phaseAt (a total Array.getD read) after checking the length, so no bounds proofs are carried and the definition reduces in the kernel.
                  Instances For

                    One-node α-CROWN step with ReLU phases:

                    • delegates to alphaCrownStepNode? for all non-ReLU ops;
                    • for ReLU, uses the node's phases if phases[id] provides them.

                    If the node has no phases, this is exactly alphaCrownStepNode?.

                    Instances For

                      Automatic graph execution #

                      The certificate step above accepts explicit α vectors and phases. The helpers below provide the ordinary executable path used by TorchLean's high-level verifier: α uses the checker's default relaxation, and the phases record every ReLU already proved stable by IBP. Crossing intervals remain unconstrained. This is a fixed-relaxation pass, not the branch-and-bound search of the external alpha-beta-CROWN verifier.

                      The output-box API uses this affine pass only for backends that certify exact reassociation. Rounded backends use directed CROWN instead; rounded affine coefficients alone are not sound enclosures of the real-valued model. The requested input box seeds both paths.

                      Infer the strongest phase justified directly by one pre-activation interval.

                      Instances For

                        The IBP-justified phases of one ReLU node.

                        Instances For

                          The phases of every ReLU node that the IBP pass already justifies.

                          Instances For

                            Run the fixed-relaxation α-CROWN graph pass with IBP phase annotations.

                            Stable ReLU phases come from IBP and are checked again by phasedCrownStepNode?. Unstable neurons use the default α-CROWN lower relaxation. No β multipliers are optimized and no neuron is split.

                            Instances For
                              def NN.MLTheory.CROWN.Cert.outputBoxPhasedCROWN? {α : Type} [TorchLean.Storage α] [Context α] [BoundOps α] [NonlinearBoundOps α] (g : Graph) (ps : Graph.ParamStore α) (xB : FlatBox α) (inputId outputId inputDim : ℕ) :

                              Evaluate the automatic phased α-CROWN pass at the graph output.

                              Rounded scalars use directed CROWN: composing nearest-rounded affine coefficients is not a sound enclosure calculation. Both routes seed IBP with the caller's requested input box.

                              Instances For