-
Notifications
You must be signed in to change notification settings - Fork 0
/
args.py
259 lines (234 loc) · 7.2 KB
/
args.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
import parser as _parser
import argparse
import sys
import yaml
args = None
def parse_arguments():
# Training settings
parser = argparse.ArgumentParser(description="SupSup")
parser.add_argument(
"--config", type=str, default=None, help="Config file to use, YAML format"
)
parser.add_argument(
"--optimizer", type=str, default="sgd", help="Which optimizer to use"
)
parser.add_argument(
"--batch-size",
type=int,
default=128,
metavar="N",
help="input batch size for training (default: 64)",
)
parser.add_argument(
"--test-batch-size",
type=int,
default=128,
metavar="N",
help="input batch size for testing (default: 128)",
)
parser.add_argument(
"--epochs",
type=int,
default=100,
metavar="N",
help="number of epochs to train (default: 100)",
)
parser.add_argument(
"--lr",
type=float,
default=0.1,
metavar="LR",
help="learning rate (default: 0.1)",
)
parser.add_argument(
"--momentum",
type=float,
default=0.9,
metavar="M",
help="Momentum (default: 0.9)",
)
parser.add_argument(
"--wd",
type=float,
default=0.0001,
metavar="M",
help="Weight decay (default: 0.0001)",
)
parser.add_argument(
"--seed", type=int, default=1, metavar="S", help="random seed (default: 1)"
)
parser.add_argument(
"--log-interval",
type=int,
default=10,
metavar="N",
help="how many batches to wait before logging training status",
)
parser.add_argument("--workers", type=int, default=4, help="how many cpu workers")
parser.add_argument(
"--output-size",
type=int,
default=10,
help="how many total neurons in last layer",
)
parser.add_argument(
"--real-neurons", type=int, default=10, help="how many real neurons"
)
parser.add_argument("--name", type=str, default="default", help="Experiment id.")
parser.add_argument(
"--data", type=str, help="Location to store data",
)
parser.add_argument(
"--log-dir",
type=str,
help="Location to logs/checkpoints",
)
parser.add_argument("--resume", type=str, default=None, help='optionally resume')
parser.add_argument(
"--sparsity", type=float, default=0.5, help="how sparse is each layer, when using MultitaskMaskConv"
)
parser.add_argument("--gamma", type=float, default=0.0)
parser.add_argument(
"--width-mult", type=float, default=1.0, help="how wide is each layer"
)
parser.add_argument(
"--hop-weight", type=float, default=1e-3, help="how wide is each layer"
)
parser.add_argument(
"--conv_type", type=str, default="StandardConv", help="Type of conv layer"
)
parser.add_argument(
"--bn_type", type=str, default="StandardBN", help="Type of batch norm layer."
)
parser.add_argument(
"--conv-init",
type=str,
default="default",
help="How to initialize the conv weights.",
)
parser.add_argument("--model", type=str, help="Type of model.")
parser.add_argument(
"--multigpu",
default=None,
type=lambda x: [int(a) for a in x.split(",")],
help="Which GPUs to use for multigpu training",
)
parser.add_argument(
"--eval-ckpts",
default=None,
type=lambda x: [int(a) for a in x.split(",")],
help="After learning n tasks for n in eval_ckpts we perform evaluation on all tasks learned so far",
)
parser.add_argument("--mode", default="fan_in", help="Weight initialization mode")
parser.add_argument(
"--nonlinearity", default="relu", help="Nonlinearity used by initialization"
)
parser.add_argument(
"--num-tasks",
default=None,
type=int,
help="Number of tasks, None if no adaptation is necessary",
)
parser.add_argument(
"--adaptor",
default="gt",
help="Which adaptor to use, see adaptors.py",
)
parser.add_argument("--set", type=str, help="Which dataset to use")
parser.add_argument("--er-sparsity", action="store_true", default=False)
parser.add_argument(
"--trainer",
default=None,
type=str,
help="Which trainer to use, default in trainers/default.py",
)
parser.add_argument(
"--log-base",
default=2,
type=int,
help="keep the bottom 1/log_base elements during binary optimization",
)
parser.add_argument(
"--save", action="store_true", default=False, help="save checkpoints"
)
parser.add_argument(
"--train-weight-tasks",
type=int,
default=0,
metavar="N",
help="number of tasks to train the weights, e.g. 1 for batchensembles. -1 for all tasks",
)
parser.add_argument(
"--train-weight-lr",
default=0.1,
type=float,
help="While training the weights, which LR to use.",
)
parser.add_argument(
"--individual-heads",
action="store_true",
help="Seperate head for each batch_ensembles task!",
)
parser.add_argument("--no-scheduler", action="store_true", help="constant LR")
parser.add_argument(
"--iter-lim", default=-1, type=int,
)
parser.add_argument(
"--ortho-group", action="store_true", default=False,
)
# TODO: task-eval move out to diff main
parser.add_argument("--lr-policy", default=None, help="Scheduler to use")
parser.add_argument(
"--task-eval",
default=None,
type=int,
help="Only evaluate on this task (for memory efficiency and grounded task info",
)
parser.add_argument(
"-f",
"--dummy",
default=None,
help="Dummy to use for ipython notebook compatibility",
)
parser.add_argument(
"--warmup-length", default=0, type=int,
)
parser.add_argument(
"--reinit-most-recent-k",
default=None,
type=int,
help="Whether or not to include a memory buffer for reinit training. Currently only works with binary reinit_adaptor",
)
parser.add_argument(
"--reinit-adapt",
type=str,
default="binary",
help="Adaptor for reinitialization experiments",
)
parser.add_argument(
"--data-to-repeat", default=1, type=int,
)
parser.add_argument(
"--unshared_labels", action="store_true", default=False,
)
args = parser.parse_args()
# Allow for use from notebook without config file
if args.config is not None:
get_config(args)
return args
def get_config(args):
# get commands from command line
override_args = _parser.argv_to_vars(sys.argv)
# load yaml file
yaml_txt = open(args.config).read()
# override args
loaded_yaml = yaml.load(yaml_txt, Loader=yaml.FullLoader)
for v in override_args:
loaded_yaml[v] = getattr(args, v)
print(f"=> Reading YAML config from {args.config}")
args.__dict__.update(loaded_yaml)
def run_args():
global args
if args is None:
args = parse_arguments()
run_args()