class-verification

CS695/SWE699: AI Safety and Assurance

10/17/2023

8/22/2023 (first day of class)

Syllabus

Graded components

Lecture 1

Motivation

DNN Everywhere

image image image image

DNN Problems

Bias

image image image

Safety

image

image

Robustness

image

image

What Can We Do?

Testing

Verifying

Testing shows the existence of bug, not its absence (Dijkstra).

We mainly focus on verification in this class.

SAT Solving using Z3

DNN Verification

DNNs introduction

DNN Representation

DNN = And(n0_0 == If(i0 + -1*i1 <= 0, 0, i0 + -1*i1),
     n0_1 == If(i0 + i1 <= 0, 0, i0 + i1),
     n1_0 ==
     If(1/2*n0_0 + -1/5*n0_1 <= 0, 0, 1/2*n0_0 + -1/5*n0_1),
     n1_1 ==
     If(-1/2*n0_0 + 1/10*n0_1 <= 0, 0, -1/2*n0_0 + 1/10*n0_1),
     o0 == n1_0 + -1*n1_1,
     o1 == -1*n1_0 + n1_1)

Property Representation

Verification as a SAT problem

We can use a constraint solver such as Z3 to query various things about this DNN from the obtained symbolic states:

  1. Generating random inputs and obtain outputs
     z3.solve(symbolic_states)
    [n0_1 = 15/2,
     o1 = 1/2,
     o0 = -1/2,
     i1 = 7/2,
     n1_1 = 1/2,
     n1_0 = 0,
     i0 = 4,
     n0_0 = 1/2]
    
  2. Simultating a concrete execution
    i0, i1, n0_0, n0_1, o0, o1 = z3.Reals("i0 i1 n0_0 n0_1 o0 o1")

    # finding outputs when inputs are fixed [i0 == 1, i1 == -1]
    g = z3.And([i0 == 1.0, i1 == -1.0])
    z3.solve(z3.And(symbolic_states, g))  # we get o0, o1 = 1, -1
    [n0_1 = 0,
    o1 = -1,
    o0 = 1,
    i1 = -1,
    n1_1 = 0,
    n1_0 = 1,
    i0 = 1,
    n0_0 = 2]
  1. Checking assertions

     print("Prove that if (n0_0 > 0.0 and n0_1 <= 0.0) then o0 > o1")
     g = z3.Implies(z3.And([n0_0 > 0.0, n0_1 <= 0.0]), o0 > o1)
     print(g)  # Implies(And(i0 - i1 > 0, i0 + i1 <= 0), o0 > o1)
     z3.prove(z3.Implies(symbolic_states, g))  # proved
    
     print("Prove that when (i0 - i1 > 0 and i0 + i1 <= 0), then o0 > o1")
     g = z3.Implies(z3.And([i0 - i1 > 0.0, i0 + i1 <= 0.0]), o0 > o1)
     print(g)  # Implies(And(i0 - i1 > 0, i0 + i1 <= 0), o0 > o1)
     z3.prove(z3.Implies(symbolic_states, g))
     # proved
    
     print("Disprove that when i0 - i1 >0, then o0 > o1")
     g = z3.Implies(i0 - i1 > 0.0, o0 > o1)
     print(g)  # Implies(And(i0 - i1 > 0, i0 + i1 <= 0), o0 > o1)
     z3.prove(z3.Implies(symbolic_states, g))
     # counterexample
     # [n0_1 = 15/2,
     # i1 = 7/2,
     # o0 = -1/2,
     # o1 = 1/2,
     # n1_0 = 0,
     # i0 = 4,
     # n1_1 = 1/2,
     # n0_0 = 1/2]
    

Property

Verification

SAT Solving

Symbolic Reasoning

SAT Solving

Basic Defs

Desired Properties to Verify

Connection to Software

Techniques

Testing
Verification

Encoding

Logical Formula and SAT solving

Encoding DNN Verification as Logical Formula

Z3 SMT solving demonstration

Challenges