forked from rkansal47/MPGAN
-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_training.py
1598 lines (1345 loc) · 50.3 KB
/
setup_training.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
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import argparse
import sys
import os
from os import listdir
import pathlib
import torch
import torch.optim as optim
import numpy as np
from copy import deepcopy
import logging
def add_bool_arg(parser, name, help, default=False, no_name=None):
varname = "_".join(name.split("-")) # change hyphens to underscores
group = parser.add_mutually_exclusive_group(required=False)
group.add_argument("--" + name, dest=varname, action="store_true", help=help)
if no_name is None:
no_name = "no-" + name
no_help = "don't " + help
else:
no_help = help
group.add_argument("--" + no_name, dest=varname, action="store_false", help=no_help)
parser.set_defaults(**{varname: default})
class CustomFormatter(logging.Formatter):
"""Logging Formatter to add colors and count warning / errors"""
grey = "\x1b[38;21m"
green = "\x1b[1;32m"
yellow = "\x1b[33;21m"
red = "\x1b[31;21m"
bold_red = "\x1b[31;1m"
blue = "\x1b[1;34m"
light_blue = "\x1b[1;36m"
purple = "\x1b[1;35m"
reset = "\x1b[0m"
info_format = "%(asctime)s %(message)s"
debug_format = "%(asctime)s [%(filename)s:%(lineno)d in %(funcName)s] %(message)s"
def __init__(self, args):
if args.log_file == "stdout":
self.FORMATS = {
logging.DEBUG: self.blue + self.debug_format + self.reset,
logging.INFO: self.grey + self.info_format + self.reset,
logging.WARNING: self.yellow + self.debug_format + self.reset,
logging.ERROR: self.red + self.debug_format + self.reset,
logging.CRITICAL: self.bold_red + self.debug_format + self.reset,
}
else:
self.FORMATS = {
logging.DEBUG: self.debug_format,
logging.INFO: self.info_format,
logging.WARNING: self.debug_format,
logging.ERROR: self.debug_format,
logging.CRITICAL: self.debug_format,
}
def format(self, record):
log_fmt = self.FORMATS.get(record.levelno)
formatter = logging.Formatter(log_fmt, datefmt="%d/%m %H:%M:%S")
return formatter.format(record)
class objectview(object):
"""converts a dict into an object"""
def __init__(self, d):
self.__dict__ = d
def parse_args():
parser = argparse.ArgumentParser()
##########################################################
# Meta
##########################################################
parser.add_argument(
"--name",
type=str,
default="test",
help="name or tag for model; will be appended with other info",
)
parser.add_argument(
"--dataset",
type=str,
default="jets",
help="dataset to use",
choices=["jets", "mnist"],
)
parser.add_argument("--ttsplit", type=float, default=0.7, help="ratio of train/test split")
parser.add_argument(
"--model",
type=str,
default="mpgan",
help="model to run",
choices=["mpgan", "rgan", "graphcnngan", "treegan", "pcgan", "gapt"],
)
parser.add_argument(
"--model-D",
type=str,
default="",
help="model discriminator, mpgan default is mpgan, rgan. graphcnngan, treegan default is rgan, pcgan default is pcgan, gapt default is gapt",
choices=["mpgan", "rgan", "pointnet", "pcgan"],
)
add_bool_arg(parser, "load-model", "load a pretrained model", default=True)
add_bool_arg(
parser,
"override-load-check",
"override check for whether name has already been used",
default=False,
)
add_bool_arg(
parser,
"override-args",
"override original model args when loading with new args",
default=False,
)
parser.add_argument(
"--start-epoch",
type=int,
default=-1,
help="which epoch to start training on, only applies if loading a model, by default start at the highest epoch model",
)
parser.add_argument("--num-epochs", type=int, default=2000, help="number of epochs to train")
parser.add_argument("--dir-path", type=str, default="", help="path where output will be stored")
parser.add_argument("--datasets-path", type=str, default="", help="path to datasets")
parser.add_argument(
"--num-samples", type=int, default=50000, help="num samples to evaluate every 5 epochs"
)
add_bool_arg(parser, "n", "run on nautilus cluster", default=False)
add_bool_arg(parser, "bottleneck", "use torch.utils.bottleneck settings", default=False)
add_bool_arg(parser, "lx", "run on lxplus", default=False)
add_bool_arg(parser, "save-zero", "save the initial figure", default=False)
add_bool_arg(parser, "no-save-zero-or", "override --n save-zero default", default=False)
parser.add_argument(
"--save-epochs", type=int, default=0, help="save outputs per how many epochs"
)
parser.add_argument(
"--save-model-epochs", type=int, default=0, help="save models per how many epochs"
)
add_bool_arg(parser, "debug", "debug mode", default=False)
add_bool_arg(parser, "break-zero", "break after 1 iteration", default=False)
add_bool_arg(parser, "low-samples", "small number of samples for debugging", default=False)
add_bool_arg(parser, "const-ylim", "const ylim in plots", default=False)
parser.add_argument(
"--jets",
type=str,
default="g",
help="jet type",
choices=["g", "t", "w", "z", "q", "sig", "bg"],
)
add_bool_arg(parser, "real-only", "use jets with ony real particles", default=False)
add_bool_arg(parser, "multi-gpu", "use multiple gpus if possible", default=False)
parser.add_argument(
"--log-file", type=str, default="", help='path to log file ; "stdout" prints to console'
)
parser.add_argument(
"--log",
type=str,
default="INFO",
help="log level",
choices=["DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"],
)
parser.add_argument("--seed", type=int, default=4, help="torch seed")
parse_mpgan_args(parser)
parse_masking_args(parser)
parse_optimization_args(parser)
parse_regularization_args(parser)
parse_evaluation_args(parser)
parse_augmentation_args(parser)
parse_mnist_args(parser)
parse_gapt_args(parser)
parse_ext_models_args(parser)
args = parser.parse_args()
return args
def parse_optimization_args(parser):
parser.add_argument(
"--optimizer",
type=str,
default="rmsprop",
help="pick optimizer",
choices=["adam", "rmsprop", "adadelta", "agcd"],
)
parser.add_argument(
"--loss",
type=str,
default="ls",
help="loss to use - options are og, ls, w, hinge",
choices=["og", "ls", "w", "hinge"],
)
parser.add_argument(
"--lr-disc",
type=float,
default=0,
help="learning rate for discriminator; defaults are 3e-5, 6e-5, and 1.5e-5 for gluon, top, and quark jet resp.",
)
parser.add_argument(
"--lr-gen",
type=float,
default=0,
help="learning rate for generator; defaults are 1e-5, 2e-5, and 0.5e-5 for gluon, top, and quark jet resp.",
)
parser.add_argument(
"--lr-x",
type=float,
default=1,
help="multiply default learning rates by this amount (doesn't do anything if LRs are already specified explicitly)",
)
parser.add_argument("--beta1", type=float, default=0.9, help="Adam optimizer beta1")
parser.add_argument("--beta2", type=float, default=0.999, help="Adam optimizer beta2")
parser.add_argument("--batch-size", type=int, default=0, help="batch size")
parser.add_argument(
"--num-critic",
type=int,
default=1,
help="number of critic updates for each generator update",
)
parser.add_argument(
"--num-gen",
type=int,
default=1,
help="number of generator updates for each critic update (num-critic must be 1 for this to apply)",
)
def parse_regularization_args(parser):
add_bool_arg(parser, "batch-norm-disc", "use batch normalization", default=False)
add_bool_arg(parser, "batch-norm-gen", "use batch normalization", default=False)
add_bool_arg(parser, "spectral-norm", "use spectral normalization in G and D", default=False)
add_bool_arg(
parser, "spectral-norm-disc", "use spectral normalization in discriminator", default=False
)
add_bool_arg(
parser, "spectral-norm-gen", "use spectral normalization in generator", default=False
)
parser.add_argument(
"--disc-dropout", type=float, default=0.5, help="fraction of discriminator dropout"
)
parser.add_argument(
"--gen-dropout", type=float, default=0, help="fraction of generator dropout"
)
add_bool_arg(parser, "label-smoothing", "use label smoothing with discriminator", default=False)
parser.add_argument(
"--label-noise", type=float, default=0, help="discriminator label noise (between 0 and 1)"
)
parser.add_argument(
"--gp", type=float, default=0, help="WGAN generator penalty weight - 0 means not used"
)
def parse_evaluation_args(parser):
add_bool_arg(parser, "fpnd", "calc fpnd", default=False)
add_bool_arg(parser, "fpd", "calc fpd (coming soon)", default=False)
add_bool_arg(parser, "efp", "calc w1efp", default=False)
# parser.add_argument("--fid-eval-size", type=int, default=8192, help="number of samples generated for evaluating fid")
parser.add_argument(
"--fpnd-batch-size",
type=int,
default=256,
help="batch size when generating samples for fpnd eval",
)
parser.add_argument(
"--efp-jobs",
type=int,
default=0,
help="# of processes to use for calculating EFPs - by default it will use the # of CPU cores",
)
parser.add_argument("--gpu-batch", type=int, default=50, help="")
add_bool_arg(
parser, "eval", "calculate the evaluation metrics: W1, FNPD, coverage, mmd", default=True
)
parser.add_argument(
"--eval-tot-samples",
type=int,
default=50000,
help="tot # of jets to generate to sample from",
)
parser.add_argument(
"--w1-num-samples",
type=int,
nargs="+",
default=[50000],
help="array of # of jet samples to test",
)
parser.add_argument(
"--cov-mmd-num-samples",
type=int,
default=100,
help="size of samples to use for calculating coverage and MMD",
)
parser.add_argument(
"--cov-mmd-num-batches",
type=int,
default=10,
help="# of batches to average coverage and MMD over",
)
parser.add_argument(
"--jf", type=str, nargs="*", default=["mass", "pt"], help="jet level features to evaluate"
)
def parse_masking_args(parser):
add_bool_arg(parser, "mask-feat", "add mask as continuous fourth feature", default=False)
add_bool_arg(parser, "mask-feat-bin", "add mask as binary fourth feature", default=False)
add_bool_arg(parser, "mask-weights", "weight D nodes by mask", default=False)
add_bool_arg(
parser,
"mask-manual",
"manually mask generated nodes with pT less than cutoff",
default=False,
)
add_bool_arg(
parser,
"mask-exp",
"exponentially decaying or binary mask; relevant only if mask-manual is true",
default=False,
)
add_bool_arg(parser, "mask-real-only", "only use masking for real jets", default=False)
add_bool_arg(
parser, "mask-learn", "learn mask from latent vars only use during gen", default=False
)
add_bool_arg(parser, "mask-learn-bin", "binary or continuous learnt mask", default=True)
add_bool_arg(parser, "mask-learn-sep", "learn mask from separate noise vector", default=False)
add_bool_arg(parser, "mask-disc-sep", "separate disc network for # particles", default=False)
add_bool_arg(
parser,
"mask-fnd-np",
"use num masked particles as an additional arg in D (dea will automatically be set true)",
default=False,
)
add_bool_arg(parser, "mask-c", "conditional mask", default=True)
add_bool_arg(
parser, "mask-fne-np", "pass num particles as features into fn and fe", default=False
)
parser.add_argument(
"--mask-epoch", type=int, default=0, help="# of epochs after which to start masking"
)
add_bool_arg(
parser,
"noise-padding",
"use Gaussian noise instead of zero-padding for fake particles",
default=False,
)
def parse_augmentation_args(parser):
# remember to add any new args to the if statement below
add_bool_arg(parser, "aug-t", "augment with translations", default=False)
add_bool_arg(parser, "aug-f", "augment with flips", default=False)
add_bool_arg(parser, "aug-r90", "augment with 90 deg rotations", default=False)
add_bool_arg(parser, "aug-s", "augment with scalings", default=False)
parser.add_argument(
"--translate-ratio", type=float, default=0.125, help="random translate ratio"
)
parser.add_argument(
"--scale-sd", type=float, default=0.125, help="random scale lognormal standard deviation"
)
parser.add_argument(
"--translate-pn-ratio", type=float, default=0.05, help="random translate per node ratio"
)
add_bool_arg(parser, "adaptive-prob", "adaptive augment probability", default=False)
parser.add_argument(
"--aug-prob", type=float, default=1.0, help="probability of being augmented"
)
def parse_mnist_args(parser):
parser.add_argument(
"--mnist-num", type=int, default=-1, help="mnist number to generate, -1 means all"
)
parser.add_argument(
"--fid-eval-samples", type=int, default=8192, help="# of samples for evaluating fid"
)
def parse_mpgan_args(parser):
parser.add_argument("--num-hits", type=int, default=30, help="number of hits")
parser.add_argument(
"--coords",
type=str,
default="polarrel",
help="cartesian, polarrel or polarrelabspt",
choices=["cartesian, polarrel, polarrelabspt"],
)
parser.add_argument(
"--norm", type=float, default=1, help="normalizing max value of features to this value"
)
parser.add_argument("--sd", type=float, default=0.2, help="standard deviation of noise")
parser.add_argument("--node-feat-size", type=int, default=3, help="node feature size")
parser.add_argument(
"--hidden-node-size",
type=int,
default=32,
help="hidden vector size of each node (incl node feature size)",
)
parser.add_argument(
"--latent-node-size",
type=int,
default=0,
help="latent vector size of each node - 0 means same as hidden node size",
)
parser.add_argument(
"--clabels",
type=int,
default=0,
help="0 - no clabels, 1 - clabels with pt only, 2 - clabels with pt and eta",
choices=[0, 1, 2],
)
add_bool_arg(parser, "clabels-fl", "use conditional labels in first layer", default=True)
add_bool_arg(parser, "clabels-hl", "use conditional labels in hidden layers", default=True)
parser.add_argument(
"--fn", type=int, nargs="*", default=[256, 256], help="hidden fn layers e.g. 256 256"
)
parser.add_argument(
"--fe1g",
type=int,
nargs="*",
default=0,
help="hidden and output gen fe layers e.g. 64 128 in the first iteration - 0 means same as fe",
)
parser.add_argument(
"--fe1d",
type=int,
nargs="*",
default=0,
help="hidden and output disc fe layers e.g. 64 128 in the first iteration - 0 means same as fe",
)
parser.add_argument(
"--fe",
type=int,
nargs="+",
default=[96, 160, 192],
help="hidden and output fe layers e.g. 64 128",
)
parser.add_argument(
"--fmg",
type=int,
nargs="*",
default=[64],
help="mask network layers e.g. 64; input 0 for no intermediate layers",
)
parser.add_argument(
"--mp-iters-gen",
type=int,
default=0,
help="number of message passing iterations in the generator",
)
parser.add_argument(
"--mp-iters-disc",
type=int,
default=0,
help="number of message passing iterations in the discriminator (if applicable)",
)
parser.add_argument(
"--mp-iters",
type=int,
default=2,
help="number of message passing iterations in gen and disc both - will be overwritten by gen or disc specific args if given",
)
add_bool_arg(parser, "sum", "mean or sum in models", default=True, no_name="mean")
add_bool_arg(parser, "int-diffs", "use int diffs", default=False)
add_bool_arg(parser, "pos-diffs", "use pos diffs", default=False)
add_bool_arg(parser, "all-ef", "use all node features for edge distance", default=False)
# add_bool_arg(parser, "scalar-diffs", "use scalar diff (as opposed to vector)", default=True)
add_bool_arg(parser, "deltar", "use delta r as an edge feature", default=False)
add_bool_arg(parser, "deltacoords", "use delta coords as edge features", default=False)
parser.add_argument("--leaky-relu-alpha", type=float, default=0.2, help="leaky relu alpha")
add_bool_arg(parser, "dea", "use early averaging discriminator", default=True)
parser.add_argument(
"--fnd", type=int, nargs="*", default=[], help="hidden disc output layers e.g. 128 64"
)
add_bool_arg(
parser,
"lfc",
"use a fully connected network to go from noise vector to initial graph",
default=False,
)
parser.add_argument(
"--lfc-latent-size", type=int, default=128, help="size of lfc latent vector"
)
add_bool_arg(parser, "fully-connected", "use a fully connected graph", default=True)
parser.add_argument(
"--num-knn",
type=int,
default=10,
help="# of nearest nodes to connect to (if not fully connected)",
)
add_bool_arg(
parser,
"self-loops",
"use self loops in graph - always true for fully connected",
default=True,
)
parser.add_argument(
"--glorot", type=float, default=0, help="gain of glorot - if zero then glorot not used"
)
# add_bool_arg(parser, "dearlysigmoid", "use early sigmoid in d", default=False)
add_bool_arg(parser, "gtanh", "use tanh for g output", default=True)
def parse_gapt_args(parser):
parser.add_argument(
"--sab-layers-gen",
type=int,
default=4,
help="number of attention layers in the generator",
)
parser.add_argument(
"--sab-layers-disc",
type=int,
default=2,
help="number of attention layers in the discriminator (if applicable)",
)
# parser.add_argument(
# "--sab-layers",
# type=int,
# default=2,
# help="number of message passing iterations in gen and disc both - will be overwritten by gen or disc specific args if given",
# )
parser.add_argument(
"--num-heads",
type=int,
default=4,
help="number of multi-head attention heads",
)
parser.add_argument(
"--gapt-embed-dim",
type=int,
default=64,
help="size of node, Q, K, V, embeddings",
)
parser.add_argument(
"--sab-fc-layers",
type=int,
nargs="*",
default=[],
help="self attention block's feedforward network's intermediate layers",
)
parser.add_argument(
"--final-fc-layers-gen",
type=int,
nargs="*",
default=[],
help="final FC in GAPT generator's intermediate layers",
)
parser.add_argument(
"--final-fc-layers-disc",
type=int,
nargs="*",
default=[],
help="final FC in GAPT discriminator's intermediate layers",
)
parser.add_argument(
"--num-isab-nodes",
type=int,
default=10,
help="number of induced nodes in ISAB blocks, if using ISAB blocks",
)
add_bool_arg(parser, "gapt-mask", "use mask in GAPT", default=True)
add_bool_arg(parser, "use-isab", "use ISAB in GAPT", default=False)
add_bool_arg(parser, "layer-norm", "use layer normalization in G and D", default=False)
add_bool_arg(parser, "layer-norm-disc", "use layer normalization in generator", default=False)
add_bool_arg(
parser, "layer-norm-gen", "use layer normalization in discriminator", default=False
)
def parse_ext_models_args(parser):
parser.add_argument("--latent-dim", type=int, default=128, help="")
parser.add_argument(
"--rgang-fc", type=int, nargs="+", default=[64, 128], help="rGAN generator layer node sizes"
)
parser.add_argument(
"--rgand-sfc",
type=int,
nargs="*",
default=0,
help="rGAN discriminator convolutional layer node sizes",
)
parser.add_argument(
"--rgand-fc", type=int, nargs="*", default=0, help="rGAN discriminator layer node sizes"
)
parser.add_argument(
"--pointnetd-pointfc",
type=int,
nargs="*",
default=[64, 128, 1024],
help="pointnet discriminator point layer node sizes",
)
parser.add_argument(
"--pointnetd-fc",
type=int,
nargs="*",
default=[512],
help="pointnet discriminator final layer node sizes",
)
parser.add_argument(
"--graphcnng-layers",
type=int,
nargs="+",
default=[32, 24],
help="GraphCNN-GAN generator layer node sizes",
)
add_bool_arg(
parser,
"graphcnng-tanh",
"use tanh activation for final graphcnn generator output",
default=False,
)
parser.add_argument(
"--treegang-degrees",
type=int,
nargs="+",
default=[2, 2, 2, 2, 2],
help="TreeGAN generator upsampling per layer",
)
parser.add_argument(
"--treegang-features",
type=int,
nargs="+",
default=[96, 64, 64, 64, 64, 3],
help="TreeGAN generator features per node per layer",
)
parser.add_argument(
"--treegang-support", type=int, default=10, help="Support value for TreeGCN loop term."
)
parser.add_argument(
"--pcgan-latent-dim",
type=int,
default=128,
help="Latent dim for object representation sampling",
)
parser.add_argument(
"--pcgan-z1-dim",
type=int,
default=256,
help="Object representation latent dim - has to be the same as the pre-trained point sampling network",
)
parser.add_argument(
"--pcgan-z2-dim",
type=int,
default=10,
help="Point latent dim - has to be the same as the pre-trained point sampling network",
)
parser.add_argument(
"--pcgan-d-dim",
type=int,
default=256,
help="PCGAN hidden dim - has to be the same as the pre-trained network",
)
parser.add_argument(
"--pcgan-pool",
type=str,
default="max1",
choices=["max", "max1", "mean"],
help="PCGAN inference network pooling - has to be the same as the pre-trained network",
)
def check_args_errors(args):
if args.real_only and (not args.jets == "t" or not args.num_hits == 30):
logging.error("real only arg works only with 30p jets - exiting")
sys.exit()
if args.int_diffs:
logging.error("int_diffs not supported yet - exiting")
sys.exit()
if args.optimizer == "acgd" and (args.num_critic != 1 or args.num_gen != 1):
logging.error("acgd can't have num critic or num gen > 1 - exiting")
sys.exit()
if args.n and args.lx:
logging.error("can't be on nautilus and lxplus both - exiting")
sys.exit()
if args.latent_node_size and args.latent_node_size < 3:
logging.error("latent node size can't be less than 2 - exiting")
sys.exit()
if args.all_ef and args.deltacoords:
logging.error("all ef + delta coords not supported yet - exiting")
sys.exit()
if args.multi_gpu and args.loss != "ls":
logging.warning("multi gpu not implemented for non-mse loss")
args.multi_gpu = False
def process_args(args):
check_args_errors(args)
##########################################################
# Meta
##########################################################
if args.debug:
args.save_zero = True
args.low_samples = True
args.break_zero = True
if torch.cuda.device_count() <= 1:
args.multi_gpu = False
if args.bottleneck:
args.save_zero = False
if args.n:
if not (args.no_save_zero_or or args.num_hits == 100):
args.save_zero = True
if args.efp_jobs == 0:
if args.n:
args.efp_jobs = 6 # otherwise leads to a spike in memory usage on PRP
else:
args.efp_jobs = None
if args.lx:
if not args.no_save_zero_or:
args.save_zero = True
if args.save_epochs == 0:
if args.num_hits <= 30 or args.model == "gapt":
args.save_epochs = 5
else:
args.save_epochs = 1
if args.save_model_epochs == 0:
if args.num_hits <= 30:
args.save_model_epochs = 5
else:
args.save_model_epochs = 1
if args.low_samples:
args.eval_tot_samples = 1000
args.w1_num_samples = [100]
args.num_samples = 1000
if args.fpnd:
if (args.num_hits != 30 or args.jets not in ["g", "t", "q"]) and args.dataset != "mnist":
args.fpnd = False
logging.warn(f"FPND is not possible for this dataset currently - setting to False")
process_optimization_args(args)
process_regularization_args(args)
process_mpgan_args(args)
process_gapt_args(args)
process_masking_args(args)
process_external_models_args(args)
return args
def process_optimization_args(args):
if args.batch_size == 0:
if args.model == "mpgan" or args.model_D == "mpgan":
if args.multi_gpu:
if args.num_hits <= 30:
args.batch_size = 128
else:
args.batch_size = 32
else:
if args.fully_connected:
if args.num_hits <= 30:
args.batch_size = 256
else:
args.batch_size = 32
else:
if args.num_hits <= 30 or args.num_knn <= 10:
args.batch_size = 320
else:
if args.num_knn <= 20:
args.batch_size = 160
elif args.num_knn <= 30:
args.batch_size = 100
else:
args.batch_size = 32
elif args.model == "gapt" or args.model_D == "gapt":
if args.dataset == "jets":
args.batch_size = 512
elif args.dataset == "mnist":
if args.gapt_embed_dim < 64:
args.batch_size = 128
elif args.gapt_embed_dim < 128:
args.batch_size = 64
else:
args.batch_size = 32
if args.lr_disc == 0:
if args.model == "mpgan":
if args.jets == "g":
args.lr_disc = 3e-5
elif args.jets == "t":
args.lr_disc = 6e-5
elif args.jets == "q":
args.lr_disc = 1.5e-5
elif args.model == "gapt":
args.lr_disc = 1.5e-4
args.lr_disc *= args.lr_x
if args.lr_gen == 0:
if args.model == "mpgan":
if args.jets == "g":
args.lr_gen = 1e-5
elif args.jets == "t":
args.lr_gen = 2e-5
elif args.jets == "q":
args.lr_gen = 0.5e-5
elif args.model == "gapt":
args.lr_gen = 0.5e-4
args.lr_gen *= args.lr_x
if args.aug_t or args.aug_f or args.aug_r90 or args.aug_s:
args.augment = True
else:
args.augment = False
if args.augment:
logging.warning("augmentation is very experimental - try at your own risk")
def process_regularization_args(args):
if args.spectral_norm:
args.spectral_norm_disc, args.spectral_norm_gen = True, True
if args.layer_norm:
args.layer_norm_disc, args.layer_norm_gen = True, True
def process_mpgan_args(args):
if not args.mp_iters_gen:
args.mp_iters_gen = args.mp_iters
if not args.mp_iters_disc:
args.mp_iters_disc = args.mp_iters
args.clabels_first_layer = args.clabels if args.clabels_fl else 0
args.clabels_hidden_layers = args.clabels if args.clabels_hl else 0
if args.latent_node_size == 0:
args.latent_node_size = args.hidden_node_size
def process_gapt_args(args):
if args.gapt_mask:
args.mask = True
# if not args.sab_layers_gen:
# args.sab_layers_gen = args.sab_layers
# if not args.sab_layers_disc:
# args.sab_layers_disc = args.sab_layers
def process_masking_args(args):
if args.model == "mpgan" and (
args.mask_feat
or args.mask_manual
or args.mask_learn
or args.mask_real_only
or args.mask_c
or args.mask_learn_sep
):
args.mask = True
elif args.model == "gapt" and args.gapt_mask:
args.mask = True
args.mask_c = True
else:
args.mask = False
args.mask_c = False
if args.mask_fnd_np:
logging.info("setting dea true due to mask-fnd-np arg")
args.dea = True
if args.noise_padding and not args.mask:
logging.error("noise padding only works with masking - exiting")
sys.exit()
if args.mask_feat:
args.node_feat_size += 1
if args.mask_learn:
if args.fmg == [0]:
args.fmg = []
def process_external_models_args(args):
if args.model_D == "":
if args.model == "mpgan":
args.model_D = "mpgan"
elif args.model == "pcgan":
args.model_D = "pcgan"
elif args.model == "gapt":
args.model_D = "gapt"
else:
args.model_D = "rgan"
if args.model == "rgan":
args.optimizer = "adam"
args.beta1 = 0.5
args.lr_disc = 0.0001
args.lr_gen = 0.0001
if args.model_D == "rgan":
args.batch_size = 50
args.num_epochs = 2000
args.loss = "w"
args.gp = 10
args.num_critic = 5
if args.rgand_sfc == 0:
args.rgand_sfc = [64, 128, 256, 256, 512]
if args.rgand_fc == 0:
args.rgand_fc = [128, 64]
args.leaky_relu_alpha = 0.2
if args.model == "graphcnngan":
args.optimizer = "rmsprop"
args.lr_disc = 0.0001
args.lr_gen = 0.0001
if args.model_D == "rgan":
args.batch_size = 50
args.num_epochs = 1000
if args.rgand_sfc == 0:
args.rgand_sfc = [64, 128, 256, 512]
if args.rgand_fc == 0:
args.rgand_fc = [128, 64]
args.loss = "w"
args.gp = 10
args.num_critic = 5
args.leaky_relu_alpha = 0.2
args.num_knn = 20
args.pad_hits = 0
if args.model == "treegan":
# for treegan pad num hits to the next power of 2 (i.e. 30 -> 32)
import math