File size: 10,146 Bytes
e75a247
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import argparse

parser = argparse.ArgumentParser()

######### Data-related arguments #########

parser.add_argument("-c", "--data-config", type=str, help="data config YAML file", default="config_files/config_jets.yaml")

parser.add_argument(
    "-train",
    "--data-train",
    nargs="*",
    default=[],
    help="training files; supported syntax:"
    " (a) plain list, `--data-train /path/to/a/* /path/to/b/*`;"
    " (b) (named) groups [Recommended], `--data-train a:/path/to/a/* b:/path/to/b/*`,"
    " the file splitting (for each dataloader worker) will be performed per group,"
    " and then mixed together, to ensure a uniform mixing from all groups for each worker.",
)
parser.add_argument(
    "-val",
    "--data-val",
    nargs="*",
    help="validation files",
)
parser.add_argument(
    "-tag",
    "--tag",
    type=str,
    required=False
)
parser.add_argument(
    "-ckpt-step",
    "--ckpt-step",
    type=int,
    required=False,
    default=0
) # to make it easier to find the actual number of steps

parser.add_argument(
    "-load-from-run",
    "--load-from-run",
    required=False,
    default="",
    type=str,
    help="WandB run name from which to pull the training settings"
)

parser.add_argument("--train-dataset-size", type=int, default=None, help="number of events to use from the training dataset")
parser.add_argument("--val-dataset-size", type=int, default=None, help="number of events to use from the validation dataset")
parser.add_argument("--test-dataset-max-size", type=int, default=None, help="number of events to use from the testing dataset (per signal hypothesis)")

parser.add_argument(
    "-test",
    "--data-test",
    nargs="*",
    default=[],
    help="testing files; supported syntax:"
    " (a) plain list, `--data-test /path/to/a/* /path/to/b/*`;"
    " (b) keyword-based, `--data-test a:/path/to/a/* b:/path/to/b/*`, will produce output_a, output_b;"
    " (c) split output per N input files, `--data-test a%10:/path/to/a/*`, will split per 10 input files",
)

######### Model and training-related arguments #########

parser.add_argument(
    "-net",
    "--network-config",
    type=str,
    help="network architecture configuration file; the path must be relative to the current dir",
)

parser.add_argument(
    "-n-blocks",
    "--num-blocks",
    type=int,
    help="Number of blocks for GATr/LGATr/Transformer",
    required=False,
    default=10
)

##### Transformer-specific arguments #####

parser.add_argument(
    "-internal-dim",
    "--internal-dim",
    type=int,
    help="Internal dim for transformer",
    required=False,
    default=128
)


parser.add_argument("--no-pid", "-np", action="store_true", help="If turned on, the PID is not going to be used as an input feature")
parser.add_argument(
    "-heads",
    "--n-heads",
    type=int,
    help="N attention heads for transformer",
    required=False,
    default=4
)

##### L-GATr-specific arguments #####

parser.add_argument(
    "-mv-ch",
    "--hidden-mv-channels",
    type=int,
    help="Hidden multivector channels for GATr and L-GATr",
    required=False,
    default=16
)

parser.add_argument(
    "-s-ch",
    "--hidden-s-channels",
    type=int,
    help="Hidden scalar channels for GATr and L-GATr",
    required=False,
    default=64
)

parser.add_argument(
    "--load-model-weights",
    type=str,
    default=None,
    help="initialize model with pre-trained weights",
)

parser.add_argument(
    "--run-name",
    type=str,
    help="The name of the run. The wandb name and the folder it gets saved to will be this name + timestamp.",
)

parser.add_argument(
    "--prefix",
    type=str,
    default="",
    help="Path to the results folder, if empty, it will be set to the results folder in the current environment.",
)

parser.add_argument(
    "--debug",
    action="store_true",
    default=False,
    help="quickly test the setup by running over only a small number of events - use for debugging",
)

parser.add_argument(
    "--wandb-projectname", type=str, help="project where the run is stored inside wandb", default="svj_clustering"
)

parser.add_argument("--batch-size", "-bs", type=int, default=128, help="batch size")
parser.add_argument("--num-epochs", type=int, default=20, help="number of epochs")
parser.add_argument("--num-steps", type=int, default=-1, help="Number of steps. If set to -1, it will be ignored and only num_epochs will be considered. Otherwise, training will stop after the reached number of steps.")

parser.add_argument(
    "--gpus",
    type=str,
    default="0",
    help='device for the training/testing; to use CPU, set to empty string (""); to use multiple gpu, set it as a comma separated list, e.g., `1,2,3,4`',
)

parser.add_argument(
    "--num-workers",
    type=int,
    default=1,
    help="number of threads to load the dataset; memory consumption and disk access load increases (~linearly) with this numbers",
)


### Loss-related arguments ###

parser.add_argument(
    "--loss",
    type=str,
    default="oc",
    choices=["oc", "quark_distance"],
    help="Loss function to use (oc is object condensation, quark_distance aims to cluster things around the corresponding dark quark)"
)

parser.add_argument("--gt-radius", type=float, default=0.8, help="GT radius R - within the radius of a dark quark, GT points to the dark quark, out of the radius it's noise")

parser.add_argument("--attr-loss-weight", type=float, default=1.0, help="weight for the attractive loss")
parser.add_argument("--repul-loss-weight", type=float, default=1.0, help="weight for the repulsive loss")
parser.add_argument("--coord-loss-weight", type=float, default=0.0, help="weight for the coordinate loss")
parser.add_argument(
    "--beta-type",
    type=str,
    default="default",
    choices=["default", "pt", "pt+bc"],
    help="How to predict betas",
)

parser.add_argument(
    "--lorentz-norm",
    help="Whether the norm in clustering space should be the Lorentz one (otherwise it's usual Euclidean 2-norm)",
    action="store_true",
    default=False,
)

parser.add_argument(
    "--scalars-oc",
    help="For L-GATr, use scalar virtual coordinates in the OC loss",
    action="store_true",
    default=False,
)

parser.add_argument(
    "--spatial-part-only",
    help="For L-GATr: if turned on, the spatial part is only going to be used for the loss.",
    action="store_true",
    default=False,
)


# defaults: --min-cluster-size 11 --min-samples 18 --epsilon 0.48

parser.add_argument(
    "--min-cluster-size",
    help="parameter of the HDBSCAN clustering",
    type=int,
    default=2
)

parser.add_argument(
    "--min-samples",
    help="parameter of the HDBSCAN clustering",
    type=int,
    default=1
)

parser.add_argument(
    "--parton-level",
    help="Run on parton-level particles",
    action="store_true"
)

parser.add_argument(
    "--gen-level",
    help="Run on gen-level final particles",
    action="store_true"
)

parser.add_argument(
    "--epsilon",
    help="parameter of the HDBSCAN clustering",
    type=float,
    default=0.3
)


parser.add_argument(
    "-embed-as-vectors",
    "--embed-as-vectors",
    action="store_true",
    default=False,
    help="Whether to embed the input p_xyz as vectors (translations) or points",
)

#### Optimizer and LR-related arguments ####

parser.add_argument(
    "--optimizer",
    type=str,
    default="ranger",
    choices=["adam", "adamW", "radam", "ranger"],
    help="optimizer for the training",
)
parser.add_argument(
    "--optimizer-option",
    nargs=2,
    action="append",
    default=[],
    help="options to pass to the optimizer class constructor, e.g., `--optimizer-option weight_decay 1e-4`",
)
parser.add_argument(
    "--lr-scheduler",
    type=str,
    default="flat+decay",
    choices=[
        "none",
        "steps",
        "flat+decay",
        "flat+linear",
        "flat+cos",
        "one-cycle",
        "reduceplateau",
    ],
    help="learning rate scheduler",
)
parser.add_argument("--start-lr", type=float, default=5e-3, help="start learning rate")
parser.add_argument("--validation-steps", type=float, default=1000, help="Run eval on validation set every x steps")



parser.add_argument(
    "--backend",
    type=str,
    choices=["gloo", "nccl", "mpi"],
    default=None,
    help="backend for distributed training",
)
parser.add_argument(
    "--log",
    type=str,
    default="",
    help="path to the log file; `{auto}` can be used as part of the path to auto-generate a name, based on the timestamp and network configuration",
)
parser.add_argument(
    "--use-amp",
    action="store_true",
    default=False,
    help="use mixed precision training (fp16)",
)


# Objectness score submodel settings

parser.add_argument(
    "-obj-score",
    "--train-objectness-score",
    action="store_true",
    help="Whether to train the objectness classifier next to the usual clustering loss",
)

parser.add_argument(
    "--obj-score-module",
    default="src/models/transformer/transformer.py",
    help="Path to the objectness score model",
    type=str
)

parser.add_argument(
    "-obj-score-gt",
    "--objectness-score-gt-mode",
    default="all_in_radius",
    choices=["all_in_radius", "closest_only"],
    help="Whether to train the objectness classifier next to the usual clustering loss",
)

parser.add_argument(
    "-obj-score-weights",
    "--load-objectness-score-weights",
    type=str,
    help="Ckpt file for the objectness score model",
    default=None,
    required=False
)

parser.add_argument(
    "--global-features-obj-score",
    "-global-features-os",
    action="store_true",
    help="Whether to use global features in the objectness score model",
    default=False
)

parser.add_argument(
    "--augment-soft-particles",
    "-aug-soft",
    help="add soft particles to the event - will add 10, 100, 1000, 10000 soft particles to the events (alternating in this order) and will split an energy of 0.5 GeV evenly among them",
    action="store_true",
    default=False
)

parser.add_argument(
    "--irc-safety-loss",
    "-irc",
    help="add an IRC safety loss term",
    action="store_true",
    default=False
)