-
Notifications
You must be signed in to change notification settings - Fork 3
/
run.py
146 lines (128 loc) · 3.15 KB
/
run.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
from src.preproc.preproc import preproc
from src.train.train_codet5 import train_codet5
from src.eval.eval_codet5 import eval_codet5
import argparse
import numpy as np
import random
import torch
def add_general_args(parser):
parser.add_argument(
"--program_only", action="store_true"
)
parser.add_argument(
"--seed", type=int,
default=42
)
parser.add_argument(
"--gpu", type=int,
default=0
)
parser.add_argument(
"--beam_size", type=int,
default=3
)
return parser
def add_file_args(parser):
parser.add_argument(
"--spider_train_fname", type=str,
default="data/spider/train_spider.json"
)
parser.add_argument(
"--spider_dev_fname", type=str,
default="data/spider/dev.json"
)
parser.add_argument(
"--sqledit_train_fname", type=str,
default="data/sqledit-train.json"
)
parser.add_argument(
"--sqledit_dev_fname", type=str,
default="data/sqledit-dev.json"
)
parser.add_argument(
"--sqledit_test_fname", type=str,
default="data/sqledit-test.json"
)
parser.add_argument(
"--load_checkpoint", type=str,
default="Salesforce/codet5-base"
)
parser.add_argument(
"--save_checkpoint", type=str,
default="model/"
)
return parser
def add_preproc_args(parser):
parser.add_argument(
"--preproc", action="store_true"
)
parser.add_argument(
"--use_content", action="store_true"
)
parser.add_argument(
"--query_type", type=str,
default="pydict"
)
parser.add_argument(
"--edit_type", type=str,
default="program"
)
parser.add_argument(
"--base_parser", type=str,
default="codet5"
)
return parser
def add_train_args(parser):
parser.add_argument(
"--train", action="store_true"
)
parser.add_argument(
"--epochs", type=int,
default=10
)
parser.add_argument(
"--lr", type=float,
default=3e-5
)
parser.add_argument(
"--batch_size", type=int,
default=8
)
parser.add_argument(
"--grad_accum", type=int,
default=2
)
return parser
def add_eval_args(parser):
parser.add_argument(
"--eval", action="store_true"
)
parser.add_argument(
"--etype", type=str,
default="all" #all, exec, match
)
return parser
def get_args():
parser = argparse.ArgumentParser()
parser = add_general_args(parser)
parser = add_file_args(parser)
parser = add_preproc_args(parser)
parser = add_train_args(parser)
parser = add_eval_args(parser)
return parser.parse_args()
def set_seed(seed):
torch.manual_seed(seed)
random.seed(seed)
np.random.seed(seed)
torch.cuda.manual_seed_all(seed)
if __name__ == "__main__":
args = get_args()
set_seed(args.seed)
if args.preproc:
preproc(args)
elif args.train:
train_codet5(args)
elif args.eval:
eval_codet5(args)
else:
print("Error: must specify preproc/train/eval in args")