-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
170 lines (162 loc) · 4.18 KB
/
Copy pathconfig.py
File metadata and controls
170 lines (162 loc) · 4.18 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import argparse
import json
def load_config(args):
args_dict = vars(args)
parser = get_args_parser()
with open(args.config, "r") as f:
raw_args = json.loads(f.read()).get("args")
raw_args = [str(arg) for arg in raw_args]
args_new = parser.parse_args(raw_args)
args_dict.update(vars(args_new))
args = argparse.Namespace(**args_dict)
return args
def get_args_parser():
parser = argparse.ArgumentParser()
# config file
parser.add_argument(
"--config",
type=str,
default=None,
help="path to the configuration file"
)
# models
parser.add_argument(
"--model_gen",
type=str,
default="./model_gen",
help="path to the model to be estimated"
)
parser.add_argument(
"--model_est",
type=str,
default="./model_est",
help="path to the estimator model"
)
parser.add_argument(
"--thread",
type=int,
default=1,
help="number of threads for generation, each thread will use one gpu"
)
# data
parser.add_argument(
"--data",
type=str,
default="./data",
help="path to the data to be estimated on"
)
parser.add_argument(
"--data_size",
type=int,
default=1000,
help="maximum lines to read from data"
)
parser.add_argument(
"--content_length",
type=int,
default=1024,
help="groundtruth text length of generation"
)
parser.add_argument(
"--prompt_length",
type=int,
default=256,
help="prompt length for generation"
)
parser.add_argument(
"--parse",
action="store_true",
help="try to parse data to prompt and content"
)
parser.add_argument(
"--parse_columns",
type=str,
default="prompt prompts title content contents",
help="columns to parse from data"
)
parser.add_argument(
"--parse_seperator",
type=str,
default="\n",
help="seperator appended between columns when parsed as one"
)
# generation configs
parser.add_argument(
"--gen_max_tokens",
type=int,
default=1024,
help="maximum generation length in tokens"
)
parser.add_argument(
"--gen_min_tokens",
type=int,
default=1024,
help="minimum generation length in tokens"
)
parser.add_argument(
"--gen_top_k",
type=int,
default=40,
help="top k for generation"
)
parser.add_argument(
"--gen_temperature",
type=float,
default=0.8,
help="temperature for generation"
)
parser.add_argument(
"--gen_do_sample",
action="store_true",
help="do sample for generation"
)
parser.add_argument(
"--gen_penalty",
type=float,
default=1.2,
help="repetition penalty for generation"
)
parser.add_argument(
"--gen_overwrite",
action="store_true",
help="overwrite the existing generation results"
)
parser.add_argument(
"--gen_save_path",
type=str,
default=None,
help="path to save generation results, none for not saving(default)"
)
parser.add_argument(
"--gen_save_stepwise",
action="store_true",
help="save generation results stepwise"
)
parser.add_argument(
"--est_token_length",
type=int,
default=1024,
help="maximum token length for logits generation"
)
parser.add_argument(
"--est_overwrite",
action="store_true",
help="overwrite the existing logits generation results"
)
parser.add_argument(
"--est_save_path",
type=str,
default=None,
help="path to save logits generation results, none for not saving(default)"
)
parser.add_argument(
"--est_save_stepwise",
action="store_true",
help="save logits generation results stepwise"
)
parser.add_argument(
"--log_transform",
action="store_true",
help="apply log transform on logits"
)
return parser