-
Notifications
You must be signed in to change notification settings - Fork 6
/
run_all_models.py
69 lines (51 loc) · 1.74 KB
/
run_all_models.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# %%
import subprocess
import yaml
import subprocess
import argparse
import threading
import os
# %%
parser = argparse.ArgumentParser()
parser.add_argument('--save_path', default='eval')
parser.add_argument('--trials', default=1, type=int)
parser.add_argument('--models', nargs='+', type=str, default=None)
parser.add_argument('--do_description', action='store_true')
parser.add_argument('--do_binary_classification', action='store_true')
parser.add_argument('--do_multiple_classification', action='store_true')
parser.add_argument('--concurrency', default=10, type=int)
args = parser.parse_args()
# %%
def run_worker(model_name):
concurrency = args.concurrency
exp_to_conduct = ' '
if args.do_binary_classification:
exp_to_conduct += ' --do_binary_classification '
if args.do_multiple_classification:
exp_to_conduct += ' --do_multiple_classification '
if args.do_description:
exp_to_conduct += ' --do_description '
cmd = f'''python3 query.py \
--concurrency {concurrency} --trials {args.trials} \
--db_path {args.save_path}/{model_name}.db \
--api_endpoint http://localhost:8080 \
--model "{model_name}" \
{exp_to_conduct} \
d2a ctf magma big-vul devign'''
with open(f'{args.save_path}/{model_name}.log', 'a+') as f, \
open(f'{args.save_path}/{model_name}.stderr', 'a+') as ferr:
subprocess.run(
cmd, shell=True,
stdout=f, stderr=ferr
)
models = args.models
os.makedirs(args.save_path, exist_ok=True)
threads = []
for model_name in models:
print(model_name)
t = threading.Thread(target=run_worker, args=(model_name, ))
threads.append(t)
for t in threads:
t.start()
for t in threads:
t.join()