Model Distillation Verification Example #
This file demonstrates verified model distillation using LeanCert's interval arithmetic infrastructure.
The Scenario #
In AI deployment, we often need to:
- Train a large "Teacher" model for accuracy
- Compress it into a smaller "Student" model for efficiency
- Verify that the Student behaves similarly to the Teacher
LeanCert can formally prove that |Teacher(x) - Student(x)| ≤ ε for ALL inputs in a domain - not just sampled points, but a mathematical guarantee.
Example Networks #
We define two simple 2→2→1 networks and verify their outputs differ by at most ε = 3 on the input domain [0, 1]².
Main Results #
distillationCheck_passes- The computable check returns truedistillation_certificate- Formal proof of bounded difference
Network Definitions #
The Teacher network
Equations
Instances For
The Student network
Equations
Instances For
Well-formedness Proofs #
Input Domain #
Create an interval from rational bounds
Equations
- LeanCert.Examples.ML.Distillation.mkInterval lo hi h prec = LeanCert.Core.IntervalDyadic.ofIntervalRat { lo := lo, hi := hi, le := h } prec
Instances For
Input domain: [0, 1]²
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equivalence Check #
Tolerance for distillation verification
Equations
Instances For
The computable certificate
Equations
- One or more equations did not get rendered due to their size.
Instances For
The check passes! This is verified by computation.
Helper Lemmas #
The Distillation Certificate #
For ANY inputs (x, y) in [0, 1]², Teacher and Student outputs differ by at most ε = 3.
Interpretation #
The theorem distillation_certificate proves that for ANY (x, y) ∈ [0, 1]²:
|Teacher(x,y) - Student(x,y)| ≤ 3
This bound arises from interval arithmetic conservatism: the analysis computes bounds on Teacher and Student outputs independently, then subtracts them.
Applications #
- Deployment Safety: Verify compressed models before deployment
- Regulatory Compliance: Provide machine-checked certificates
- CI/CD Integration: Automatically verify model equivalence in pipelines