TorchLean API

NN.Verification.Robustness.Digits

Digits certified robustness #

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

Workflow:

Run: scripts/lake.sh exe verify -- digits scripts/lake.sh exe verify -- digits --eps=0.02 --max=360 scripts/lake.sh exe verify -- digits --arithmetic ieee --eps=0.02 scripts/lake.sh exe verify -- digits-train-certify --epochs=50 --eps=0.02 --max=100

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

Bundled sklearn-digits linear classifier weights.

Instances For

    Bundled sklearn-digits test set.

    Instances For

      Python exporter used by the train-then-certify command.

      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^\infty$ perturbation radius around each input example.

        • max : ℕ

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

        Instances For

          Options for the train → lower → certify report command.

          • certify : Digits.Options

            Lean side certification options after Python exports the model and dataset.

          • script : String

            Python trainer script path.

          • seed : ℕ

            Reproducibility seed forwarded to the trainer.

          • epochs : ℕ

            Number of Python training epochs.

          • batch : ℕ

            Python trainer batch size.

          • lr : Float

            Python trainer learning rate.

          • testSize : Float

            Test split fraction used by the trainer.

          • maxTest : ℕ

            Number of test examples exported by the trainer.

          Instances For

            Usage string printed on --help / -h.

            Instances For

              Consume the certification flags shared by both digits commands (after -- stripping and the --help check), returning the remaining arguments. Flags are extracted by key, so the caller may consume its own flags from the remainder in any order.

              Instances For

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

                Instances For

                  Parse the combined trainer/certifier CLI for digits-train-certify.

                  Instances For

                    Python trainer arguments, including the artifact destinations checked by Lean afterward.

                    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

                            The certified input box: the binary64 ℓ∞ ball around x, rounded outward by FlatBox.lInfBall, clipped to the pixel range [0, 1], and converted to α with the directed rounding of TorchLean.Runtime.ofFloatDirected. It contains every real input within eps of the binary64 center that lies in [0, 1].

                            Instances For

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

                              This lowers the linear classifier to the verifier IR, then checks each example's $L^\infty$ box using IBP and two-sided CROWN output bounds.

                              Instances For

                                CLI entry point for the digits certified-robustness workflow.

                                This is wired into scripts/lake.sh exe verify -- digits.

                                Instances For

                                  Train a fresh digits classifier, lower it through the TorchLean verifier path, and certify it.

                                  The Python trainer is an artifact producer only. Lean still parses the exported JSON, lowers the TorchLean program to verifier IR, runs IBP and affine CROWN bounds, and prints the certification report from the checked artifacts.

                                  Instances For