Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update nnneum #1

Open
wants to merge 58 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
a1da010
bug fixes for small no-split initial sets
Sep 13, 2020
0986d21
Merge branch 'master' of https://github.com/stanleybak/nnenum
Sep 13, 2020
1a87804
Bump tensorflow from 2.2.0 to 2.2.1
dependabot[bot] Sep 25, 2020
2c255e9
Merge pull request #1 from stanleybak/dependabot/pip/tensorflow-2.2.1
stanleybak Sep 26, 2020
a909af9
updated lp star and lpi
Nov 2, 2020
79fca4d
Merge branch 'master' of https://github.com/stanleybak/nnenum
Nov 2, 2020
00d6cf0
removed delcols
Nov 9, 2020
010c1c4
minor for nfm
Dec 13, 2020
9597fb5
NFM version, added comment about one-norm name
Dec 15, 2020
f1344b3
added get_input_box_bounds to star
Dec 21, 2020
7b54456
minor
Dec 22, 2020
5e8f238
renamed to src
Dec 28, 2020
06fdebe
fixed conrete counterexample input shape when pre-overapprox sim is u…
Dec 31, 2020
16ed7b0
removed debug printing
Jan 2, 2021
b3899d6
default normalize and fixed bounds check order in lp_star
Jan 24, 2021
81178bc
removed extra printing
Feb 13, 2021
138d1e4
added underflow settings and fixed unsat counterexample
May 31, 2021
4018cc0
updated normalization logic
May 31, 2021
8e161d0
working on adding vnnlib support
Jun 10, 2021
96e446f
removing adversarial counterexmaples
Jun 10, 2021
22724e4
added examples for image networks
Jun 10, 2021
e57fbc5
changed to 'c' order flattening
Jun 10, 2021
e0971d6
removed debug settings
Jun 10, 2021
a19dfb7
added cifar spec
Jun 10, 2021
c6c3de3
added run in docker command
Jun 10, 2021
ad7e34b
typo
Jun 10, 2021
c02de5f
reverted travis ci yml
Jun 11, 2021
29e8cf8
update config
Jun 11, 2021
d789400
removed upgrade pip in docker file
Jun 11, 2021
caec1d1
minor
Jun 13, 2021
53c1b24
added tool scripts
Jun 13, 2021
01272dc
minor
Jun 13, 2021
1e51c83
updated run_instance
Jun 13, 2021
ac99dc5
updated env variables
Jun 13, 2021
6c0a5dc
fixed optimized network load bug
Jun 13, 2021
75f3fd4
updated scripts
Jun 13, 2021
c93a39c
updated readme
Jun 13, 2021
6854a6b
fixed kamenev plotting bug
Jun 15, 2021
997f257
updated to enable settings selection
Oct 3, 2021
0231d97
updated loading with non-standard first layers
Nov 14, 2021
2ad47c1
minor note https://github.com/joblib/threadpoolctl
Dec 9, 2021
fd07f2b
fixed shriver bug
Jan 21, 2022
fa1463b
updated settings
Jun 6, 2022
3acfd88
updated numpy/scipy versions
Aug 17, 2022
58cca56
added setting for contract_lp check epsilon
Aug 24, 2022
dc22d2a
updated travis ci version
Sep 12, 2022
baacfd6
updated python version
Sep 12, 2022
62b9e5e
updated readme link to travis ci page
Sep 12, 2022
125b3c1
updated travis ci file
Sep 12, 2022
ab50e01
fixing travis errors
Sep 12, 2022
21031a2
fixing more travis errors
Sep 12, 2022
1cd5614
travis ci 3.10
Sep 12, 2022
8cadc70
updated config to fix travis errors
Sep 12, 2022
d98a08f
added support for other unix
Nov 2, 2022
d792ae8
initialized manager later
Nov 2, 2022
e15a6d9
added check for qsize
Nov 2, 2022
c292c57
removed qsize from assert
Nov 2, 2022
cf7c0e7
adde empty to fakequeue
Nov 2, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ __pycache__
*branch_str.txt
*.mypy_cache
.coverage
examples/acasxu/out.txt
examples/acasxu/results/*
out.txt
17 changes: 17 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

# configuration file for continuous integration testing using travis-ci.com

dist:
- jammy

python: 3.8

services:
- docker

script:
# build Docker container
- docker build -t nnenum .

# run tests
- docker run nnenum
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# To get a shell after building the image:
# docker run -ir nnenum_image bash

FROM tensorflow/tensorflow:2.2.0
FROM python:3.10

COPY ./requirements.txt /work/requirements.txt

Expand All @@ -17,9 +17,12 @@ WORKDIR /work
RUN pip3 install -r requirements.txt

# set environment variables
ENV PYTHONPATH=$PYTHONPATH:/work/nnenum
ENV PYTHONPATH=$PYTHONPATH:/work/src
ENV OPENBLAS_NUM_THREADS=1
ENV OMP_NUM_THREADS=1

# copy remaining files to docker
COPY . /work
COPY . /work

# cmd, run one of each benchmark
CMD cd /work && ./run_tests.sh
40 changes: 35 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,47 @@
[![Build Status](https://travis-ci.com/stanleybak/nnenum.svg?branch=master)](https://app.travis-ci.com/github/stanleybak/nnenum)

# nnenum - The Neural Network Enumeration Tool
**nnenum** (pronounced *en-en-en-um*) is a high-performance neural network verification tool. Multiple levels of abstraction are used to quickly verify ReLU networks without sacrificing completeness. Analysis combines three types of zonotopes with star set (triangle) overapproximations, and uses [efficient parallelized ReLU case splitting](http://stanleybak.com/papers/bak2020cav.pdf). The verification tree search can be augmented with adversarial example generation using multiple attacks from the [foolbox library](https://github.com/bethgelab/foolbox) to quickly find property violations. The tool is written in Python 3, uses GLPK for LP solving and directly accepts [ONNX](https://github.com/onnx/onnx) network files as input. The [ImageStar trick](https://arxiv.org/abs/2004.05511) allows sets to be quickly propagated through all layers supported by the [ONNX runtime](https://github.com/microsoft/onnxruntime), such as convolutional layers with arbitrary parameters.
**nnenum** (pronounced *en-en-en-um*) is a high-performance neural network verification tool. Multiple levels of abstraction are used to quickly verify ReLU networks without sacrificing completeness. Analysis combines three types of zonotopes with star set (triangle) overapproximations, and uses [efficient parallelized ReLU case splitting](http://stanleybak.com/papers/bak2020cav.pdf). The tool is written in Python 3, uses GLPK for LP solving and directly accepts [ONNX](https://github.com/onnx/onnx) network files and `vnnlib` specifications as input. The [ImageStar trick](https://arxiv.org/abs/2004.05511) allows sets to be quickly propagated through all layers supported by the [ONNX runtime](https://github.com/microsoft/onnxruntime), such as convolutional layers with arbitrary parameters.

The tool is written by Stanley Bak ([homepage](http://stanleybak.com), [twitter](https://twitter.com/StanleyBak)).

### Getting Started
The `Dockerfile` shows how to install all the dependencies (mostly python packages) and set up the environment. Although the tool loads neural networks directly from ONNX files, the properties and initial sets and verification settings must be defined in python scripts.
The `Dockerfile` shows how to install all the dependencies (mostly python packages) and set up the environment. The tool loads neural networks directly from ONNX files and properties to check from `vnnlib` files.
For example, try running:

The best way to get started is to look at some of the examples. For example, in the `examples/acasxu` directory you can try to verify property 9 of network 3-3 of the [well-studied ACAS Xu neural network verification benchmarks](https://arxiv.org/abs/1702.01135) by running the command:
```
python3 -m nnenum.nnenum examples/acasxu/data/ACASXU_run2a_3_3_batch_2000.onnx examples/acasxu/data/prop_9.vnnlib
```

```python3 acasxu_single.py 3 3 9```
You can see a few more examples in `run_tests.sh`.

### VNN 2020 Neural Network Verification Competition (VNN-COMP) Version
The nnenum tool performed well in VNN-COMP 2020, being the only tool to verify all the ACAS-Xu benchmarks (each in under 10 seconds), as well as one of the best on the MNIST and CIFAR-10 benchmarks. The version used for the competition as well as model files and scripts to run the compeition benchmarks are in the `vnn2020` branch.
The nnenum tool performed well in VNN-COMP 2020, being the only tool to verify all the ACAS-Xu benchmarks (each in under 10 seconds). The version used for the competition as well as model files and scripts to run the compeition benchmarks are in the `vnn2020` branch.

### CAV 2020 Paper Version
The CAV 2020 paper ["Improved Geometric Path Enumeration for Verifying ReLU Neural Networks"](http://stanleybak.com/papers/bak2020cav.pdf) by S. Bak, H.D Tran, K. Hobbs and T. T. Johnson corresponds to optimizations integrated into the exact analysis mode of nnenum, which also benefits overapproximative analysis. The paper version and repeatability evaluation package instructions are available [here](http://stanleybak.com/papers/bak2020cav_repeatability.zip).

### Citing nnenum ###
The following citations can be used for nnenum:

```
@inproceedings{bak2021nfm,
title={nnenum: Verification of ReLU Neural Networks with Optimized Abstraction Refinement},
author={Bak, Stanley},
booktitle={NASA Formal Methods Symposium},
pages={19--36},
year={2021},
organization={Springer}
}
```

```
@inproceedings{bak2020cav,
title={Improved Geometric Path Enumeration for Verifying ReLU Neural Networks},
author={Bak, Stanley and Tran, Hoang-Dung and Hobbs, Kerianne and Johnson, Taylor T.},
booktitle={Proceedings of the 32nd International Conference on Computer Aided Verification},
year={2020},
organization={Springer}
}
```

2 changes: 1 addition & 1 deletion examples/acasxu/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
These are the well-studied ACAXU benchmarks from "Reluplex: An efficient SMT solver for verifying deep neural networks" by Katz, Guy, et al., CAV 2017.

To run a specific bencmark, such as network 3-3 with property 9, execute 'python3 acasxu_single.py 3 3 9'
To run a specific bencmark, such as network 3-3 with property 9, execute 'python3 -m nnenum.nnenum data/ACASXU_run2a_3_3_batch_2000.onnx data/prop_9.vnnlib'

To run all the benchmarks, run acasxu_all.py (results summary file is placed in results folder).
73 changes: 29 additions & 44 deletions examples/acasxu/acasxu_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,25 @@
Stanley Bak, 2020
'''

import os
import sys
import time
from pathlib import Path
import subprocess

from termcolor import cprint

from nnenum.settings import Settings
from acasxu_single import verify_acasxu

def main():
'main entry point'

start = time.time()

Settings.TIMING_STATS = False
Settings.PARALLEL_ROOT_LP = False
Settings.SPLIT_IF_IDLE = False
Settings.PRINT_OVERAPPROX_OUTPUT = False

full_filename = 'results/full_acasxu.dat'
hard_filename = 'results/hard_acasxu.dat'
timeout = 600.0

if len(sys.argv) > 1:
Settings.TIMEOUT = 60 * float(sys.argv[1])
print(f"Running measurements with timeout = {Settings.TIMEOUT} secs")
timeout = 60.0 * float(sys.argv[1])
print(f"Running measurements with timeout = {timeout} secs")

instances = []

Expand Down Expand Up @@ -69,39 +62,7 @@ def main():

cprint(f"\nRunning net {a_prev}-{tau} with spec {spec}", "grey", "on_green")

if spec == "7":
# ego / 10 processes is beter for deep counterexamples in prop 7
Settings.BRANCH_MODE = Settings.BRANCH_EGO
Settings.NUM_PROCESSES = 10

# property 7 is nondeterministic due to work sharing among processes... use median of 10 runs
pretimeout = Settings.TIMEOUT
Settings.TIMEOUT = min(5, pretimeout) # smaller timeout to make it go faster
runs = 10
print(f"\nTrying median of {runs} quick runs")
results = []

for i in range(runs):
print(f"\nTrial {i+1}/{runs}:")
res_str, secs = verify_acasxu(net_pair, spec)
results.append((secs, res_str))

results.sort()
print(f"results: {results}")
secs, res_str = results[runs // 2] # median

print(f"Median: {secs}, {res_str}")

Settings.TIMEOUT = pretimeout

if res_str == "timeout":
# median was timeout; run full
res_str, secs = verify_acasxu(net_pair, spec)
else:
Settings.BRANCH_MODE = Settings.BRANCH_OVERAPPROX
Settings.NUM_PROCESSES = len(os.sched_getaffinity(0))

res_str, secs = verify_acasxu(net_pair, spec)
res_str, secs = verify_acasxu(net_pair, spec, timeout)

s = f"{a_prev}_{tau}\t{spec}\t{res_str}\t{secs}"
f.write(s + "\n")
Expand All @@ -116,5 +77,29 @@ def main():

print(f"Completed all measurements in {round(mins, 2)} minutes")

def verify_acasxu(net_pair, spec, timeout):
'returns res_str, secs'

prev, tau = net_pair

onnx_path = f'./data/ACASXU_run2a_{prev}_{tau}_batch_2000.onnx'
spec_path = f'./data/prop_{spec}.vnnlib'

args = [sys.executable, '-m', 'nnenum.nnenum', onnx_path, spec_path, f'{timeout}', 'out.txt']

start = time.perf_counter()

result = subprocess.run(args, check=False)

if result.returncode == 0:
with open('out.txt', 'r') as f:
res_str = f.readline()
else:
res_str = 'error_exit_code_{result.returncode}'

diff = time.perf_counter() - start

return res_str, diff

if __name__ == '__main__':
main()
Loading