TorchLean API

NN.Verification.Robustness.Digits

Digits certified robustness #

Certified accuracy for a linear classifier on sklearn's digits dataset.

Workflow:

Run: lake exe verify -- digits lake exe verify -- digits --eps=0.02 --max=360 lake exe verify -- digits --float32-mode ieee754exec --eps=0.02

Regenerate assets: python3 scripts/verification/robustness/train_digits_linear.py

Flattened input dimension for sklearn digits (8×8).

Instances For

    Number of classes (digits 0..9).

    Instances For

      Weight shape for a linear classifier y = Wx + b (10×64).

      Instances For

        Bias shape for a linear classifier (10).

        Instances For

          Input shape (64).

          Instances For

            Output/logit shape (10).

            Instances For

              Parameter shapes list used by the compiled TorchLean program ([W, b]).

              Instances For

                CLI options for the digits certified-accuracy workflow.

                • weights : String

                  Weights JSON path (PyTorch export).

                • dataset : String

                  Dataset JSON path (PyTorch export).

                • eps : Float

                  L∞ perturbation radius around each input example.

                • max :

                  Max number of examples to evaluate (for quick local checks).

                Instances For

                  Usage string printed on --help / -h.

                  Instances For

                    Parse a float literal written as JSON (e.g. 0.02).

                    Instances For

                      Parse CLI args into DigitsOpts (returns usage as the error message on --help).

                      Instances For

                        TorchLean program for the linear classifier y = Wx + b.

                        Instances For

                          Clamp a tensor elementwise into [0,1] (used for input normalization).

                          Instances For

                            Argmax for a Float vector tensor (returns 0 if n = 0).

                            Instances For

                              Certify top-1 correctness from output bounds.

                              Given elementwise bounds lo <= y <= hi, this returns true if the lower bound on the true class logit exceeds the upper bounds of all other logits.

                              Instances For

                                Load linear classifier weights exported from PyTorch into a typed LinearSpec.

                                Instances For

                                  Load the digits test dataset exported from Python (JSON).

                                  Instances For

                                    Running counters for the digits certified-accuracy workflow.

                                    • total :

                                      Number of examples checked.

                                    • nominalOk :

                                      Number of clean examples classified correctly by the exported model.

                                    • ibpOk :

                                      Number of examples certified by interval bound propagation.

                                    • crownOk :

                                      Number of examples certified by the affine CROWN pass.

                                    Instances For

                                      Run the certified-accuracy evaluation once, under a chosen scalar backend α.

                                      This compiles the linear classifier to the verifier IR, then checks each example's L∞ box using IBP and a simple affine pass.

                                      Instances For

                                        CLI entry point for the digits certified-robustness workflow.

                                        This is wired into lake exe verify -- digits.

                                        Instances For