-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathoptions.py
411 lines (393 loc) · 12.3 KB
/
options.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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
import os
import time
import argparse
import torch
def get_options(args=None):
parser = argparse.ArgumentParser(
description="Attention-based model for solving the Online Bipartite matching Problem with Reinforcement Learning"
)
# Data
parser.add_argument(
"--problem",
type=str,
default="obm",
help="Problem: 'obm', 'e-obm', 'adwords' or 'displayads'",
)
parser.add_argument(
"--graph_size", type=int, default=20, help="The size of the problem graph"
)
parser.add_argument(
"--batch_size",
type=int,
default=1,
help="Number of instances per batch during training",
)
parser.add_argument(
"--u_size", type=int, default=10, help="Number of nodes in U-set"
)
parser.add_argument(
"--v_size", type=int, default=10, help="Number of nodes in the V-set"
)
parser.add_argument(
"--graph_family",
type=str,
default="er",
help="family of graphs to generate (er, ba, etc)",
)
parser.add_argument(
"--num_edges",
type=int,
default=20,
help="Number of edges in the Bipartite graph",
)
# parser.add_argument(
# "--epoch_size",
# type=int,
# default=100,
# help="Number of instances per epoch during training",
# )
parser.add_argument(
"--val_size",
type=int,
default=1000,
help="Number of instances used for reporting validation performance",
)
parser.add_argument(
"--val_dataset",
type=str,
default="dataset/val",
help="Dataset file to use for validation",
)
parser.add_argument(
"--train_dataset",
type=str,
default="dataset/train",
help="Dataset file to use for training",
)
parser.add_argument(
"--dataset_size", type=int, default=1000, help="Dataset size for training",
)
parser.add_argument(
"--weight_distribution",
type=str,
default="uniform",
help="Distribution of weights in graphs",
)
# Model
parser.add_argument(
"--model",
default="attention",
help="Model, 'attention' (default) or 'pointer or Feed forward'",
)
parser.add_argument(
"--encoder",
default="attention",
help="Encoder, 'attention' (default) or 'mpnn'",
)
parser.add_argument(
"--embedding_dim", type=int, default=16, help="Dimension of input embedding"
)
parser.add_argument(
"--hidden_dim",
type=int,
default=16,
help="Dimension of hidden layers in Enc/Dec",
)
parser.add_argument(
"--n_heads", type=int, default=2, help="Number of heads in Enc",
)
parser.add_argument(
"--n_encode_layers",
type=int,
default=3,
help="Number of layers in the encoder/critic network",
)
parser.add_argument(
"--tanh_clipping",
type=float,
default=10.0,
help="Clip the parameters to within +- this value using tanh. "
"Set to 0 to not perform any clipping.",
)
parser.add_argument(
"--normalization",
default="batch",
help="Normalization type, 'batch' (default) or 'instance'",
)
parser.add_argument(
"--n_step", action="store_true", help="Set to peform n-step training",
)
parser.add_argument(
"--max_steps",
type=int,
default=10,
help="Maximum number of steps before performing backward pass (used in n-step training)",
)
# Training
parser.add_argument(
"--lr_model",
type=float,
default=1e-3,
help="Set the learning rate for the actor network",
)
parser.add_argument(
"--lr_critic",
type=float,
default=1e-4,
help="Set the learning rate for the critic network",
)
parser.add_argument(
"--lr_decay", type=float, default=0.99, help="Learning rate decay per epoch"
)
parser.add_argument(
"--n_epochs", type=int, default=1000, help="The number of epochs to train"
)
parser.add_argument("--seed", type=int, default=1234, help="Random seed to use")
parser.add_argument(
"--max_grad_norm",
type=float,
default=1.0,
help="Maximum L2 norm for gradient clipping, default 1.0 (0 to disable clipping)",
)
parser.add_argument("--no_cuda", action="store_true", help="Disable CUDA")
parser.add_argument(
"--exp_beta",
type=float,
default=0.8,
help="Exponential moving average baseline decay (default 0.8)",
)
parser.add_argument(
"--ent_rate", type=float, default=0.1, help="entropy regularization rate",
)
parser.add_argument(
"--baseline",
default=None,
help="Baseline to use: 'rollout', 'critic' or 'exponential'. Defaults to no baseline.",
)
parser.add_argument(
"--bl_alpha",
type=float,
default=0.05,
help="Significance in the t-test for updating rollout baseline",
)
parser.add_argument(
"--bl_warmup_epochs",
type=int,
default=None,
help="Number of epochs to warmup the baseline, default None means 1 for rollout (exponential "
"used for warmup phase), 0 otherwise. Can only be used with rollout baseline.",
)
parser.add_argument(
"--max_weight", type=int, default=100, help="Maximum edge weight in the graph"
)
parser.add_argument(
"--eval_batch_size",
type=int,
default=10,
help="Batch size to use during (baseline) evaluation",
)
parser.add_argument(
"--checkpoint_encoder",
action="store_true",
help="Set to decrease memory usage by checkpointing encoder",
)
parser.add_argument(
"--checkpoint_every",
type=int,
default=1,
help="checkpoint encoder every x epochs. NOTE: checkpointing here does not mean saving model.",
)
parser.add_argument(
"--shrink_size",
type=int,
default=None,
help="Shrink the batch size if at least this many instances in the batch are finished"
" to save memory (default None means no shrinking)",
)
parser.add_argument(
"--data_distribution",
type=str,
default=None,
help="Data distribution to use during training, defaults and options depend on problem.",
)
parser.add_argument(
"--weight_distribution_param",
nargs="+",
default=[5, 100],
help="parameters of weight distribtion ",
)
parser.add_argument(
"--graph_family_parameter",
type=float,
default=0.6,
help="parameter of the graph family distribution",
)
# Evaluation
parser.add_argument(
"--eval_num",
type=int,
default=5,
help="Number of U to V ratio's to evaluate the model on",
)
parser.add_argument(
"--eval_size",
type=int,
default=10000,
help="Number of examples in an evaluation dataset.",
)
parser.add_argument(
"--eval_dataset",
type=str,
help="path to folder containing all evaluation datasets",
)
parser.add_argument(
"--eval_baselines",
nargs="+",
help="Different models to evaluate on",
# Example: ["greedy", "greedy-rt"]
)
parser.add_argument(
"--eval_only",
action="store_true",
help="Set this value to only evaluate model on a specific graph size",
)
parser.add_argument(
"--eval_plot", action="store_true", help="plot results on test data",
)
parser.add_argument(
"--eval_results_file", type=str, help="file that containes test results",
)
parser.add_argument(
"--eval_range",
nargs="+",
help="evaluate model over a range of graph family parameters",
)
# parser.add_argument(
# "--eval_model_paths", nargs="+", help="paths to trained models files",
# )
parser.add_argument(
"--load_path",
default=None,
help="Path to load model parameters and optimizer state from",
)
parser.add_argument(
"--ff_models", nargs="+", help="list of trained ff models, seperated by space",
)
parser.add_argument(
"--inv_ff_models",
nargs="+",
help="list of trained inv-ff models, seperated by space",
)
parser.add_argument(
"--ff_hist_models",
nargs="+",
help="list of trained ff-hist models, seperated by space",
)
parser.add_argument(
"--ff_supervised_models",
nargs="+",
help="list of trained ff-supervised models, seperated by space",
)
parser.add_argument(
"--inv_ff_hist_models",
nargs="+",
help="list of trained inv-ff-hist models, seperated by space",
)
parser.add_argument(
"--gnn_hist_models",
nargs="+",
help="list of trained gnn-hist models, seperated by space",
)
parser.add_argument(
"--attention_models",
nargs="+",
help="list of path to trained attention models, seperated by space",
)
parser.add_argument(
"--eval_models", nargs="+", help="type of models to evaluate",
)
parser.add_argument(
"--eval_set", nargs="+", help="Set of family parameters to evaluate models on",
)
parser.add_argument(
"--eval_num_range",
type=int,
default=10,
help="Number of grpah family parameter to evaluate model on over a specific range",
)
# parser.add_argument(
# "--eval_family",
# action="store_true",
# help="Set this to true if you evaluating the model over a family of graphs",
# )
parser.add_argument(
"--eval_output", type=str, default=".", help="path to output evaulation plots",
)
# Misc
parser.add_argument(
"--tune",
action="store_true",
help="Set this to true if you want to tune the hyperparameters",
)
parser.add_argument(
"--tune_wandb",
action="store_true",
help="if you want to tune the hyperparameters with wandb",
)
parser.add_argument(
"--sweep_id", type=str, default="rpg62e3n", help="Sweep id of wandb tuning"
)
parser.add_argument(
"--num_per_agent", type=int, default=5, help="Number of hyper params per agent"
)
parser.add_argument(
"--log_step", type=int, default=50, help="Log info every log_step steps"
)
parser.add_argument(
"--log_dir",
default="logs",
help="Directory to write TensorBoard information to",
)
parser.add_argument("--run_name", default="run", help="Name to identify the run")
parser.add_argument(
"--output_dir", default="outputs", help="Directory to write output models to"
)
parser.add_argument(
"--epoch_start",
type=int,
default=0,
help="Start at epoch # (relevant for learning rate decay)",
)
parser.add_argument(
"--checkpoint_epochs",
type=int,
default=0,
help="Save checkpoint every n epochs (default 1), 0 to save no checkpoints",
)
parser.add_argument(
"--load_path2",
help="Path to load second model parameters and optimizer state from",
)
parser.add_argument(
"--save_dir", help="Path to save the checkpoints",
)
parser.add_argument("--resume", help="Resume from previous checkpoint file")
parser.add_argument(
"--no_tensorboard",
action="store_true",
help="Disable logging TensorBoard files",
)
parser.add_argument(
"--no_progress_bar", action="store_true", help="Disable progress bar"
)
opts = parser.parse_args(args)
opts.use_cuda = torch.cuda.is_available() and not opts.no_cuda
opts.run_name = "{}_{}".format(opts.run_name, time.strftime("%Y%m%dT%H%M%S"))
opts.save_dir = os.path.join(opts.output_dir, opts.model, opts.run_name)
if opts.bl_warmup_epochs is None:
opts.bl_warmup_epochs = 1 if opts.baseline == "rollout" else 0
assert (opts.bl_warmup_epochs == 0) or (opts.baseline == "rollout")
assert (
opts.dataset_size % opts.batch_size == 0
), "Epoch size must be integer multiple of batch size!"
return opts