-
Notifications
You must be signed in to change notification settings - Fork 39
/
args.py
213 lines (191 loc) · 5.66 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
import argparse
def parse_args():
parser = argparse.ArgumentParser(description="PyTorch Training")
# primary
parser.add_argument(
"--configs", type=str, default=None, help="configs file",
)
parser.add_argument(
"--result-dir",
default="./trained_models",
type=str,
help="directory to save results",
)
parser.add_argument(
"--exp-name",
type=str,
help="Name of the experiment (creates dir with this name in --result-dir)",
)
parser.add_argument(
"--exp-mode",
type=str,
choices=("pretrain", "prune", "finetune"),
help="Train networks following one of these methods.",
)
# Model
parser.add_argument("--arch", type=str, help="Model achitecture")
parser.add_argument(
"--num-classes",
type=int,
default=10,
help="Number of output classes in the model",
)
parser.add_argument(
"--layer-type", type=str, choices=("dense", "unstructured", "channel", "filter"), help="dense | unstructured | channel | filter"
)
# Pruning
parser.add_argument(
"--k",
type=float,
default=1.0,
help="Fraction of weight variables kept in subnet",
)
parser.add_argument(
"--scaled-score-init",
action="store_true",
default=False,
help="Init importance scores proportaional to weights (default kaiming init)",
)
parser.add_argument(
"--scale-rand-init",
action="store_true",
default=False,
help="Init weight with scaling using pruning ratio",
)
parser.add_argument(
"--freeze-bn",
action="store_true",
default=False,
help="freeze batch-norm parameters in pruning",
)
parser.add_argument(
"--source-net",
type=str,
default=None,
help="Checkpoint which will be pruned/fine-tuned",
)
parser.add_argument(
"--scores-init-type",
choices=("kaiming_normal", "kaiming_uniform", "xavier_uniform", "xavier_normal"),
help="Which init to use for relevance scores",
)
# Data
parser.add_argument(
"--dataset",
type=str,
choices=["CIFAR10", "CIFAR100", "TinyImageNet", "ImageNet", "ImageNetOrigin", "ImageNetLMDB"],
help="Dataset for training and eval",
)
parser.add_argument(
"--batch-size",
type=int,
default=128,
metavar="N",
help="input batch size for training (default: 128)",
)
parser.add_argument(
"--num-workers",
type=int,
default=2,
metavar="N",
)
parser.add_argument(
"--test-batch-size",
type=int,
default=128,
metavar="N",
help="input batch size for testing (default: 128)",
)
parser.add_argument(
"--normalize",
action="store_true",
help="whether to normalize the data",
)
parser.add_argument(
"--data-dir", type=str, default="./data", help="path to datasets"
)
parser.add_argument(
"--image-dim", type=int, default=32, help="Image size: dim x dim x 3"
)
# Training
parser.add_argument(
"--trainer",
type=str,
default="base",
choices=["bilevel", "bilevel_finetune", "base"],
help="Natural (base) or adversarial or verifiable training",
)
parser.add_argument(
"--epochs", type=int, default=100, metavar="N", help="number of epochs to train"
)
parser.add_argument(
"--optimizer", type=str, default="sgd", choices=("sgd", "adam", "rmsprop")
)
parser.add_argument("--wd", default=5e-4, type=float, help="Weight decay")
parser.add_argument("--mask-lr", type=float, default=0.1, help="mask learning rate for bi-level only")
parser.add_argument("--lr", type=float, default=0.1, help="learning rate")
parser.add_argument(
"--mask-lr-schedule",
type=str,
default="cosine",
choices=("cosine", "step"),
help="lr scheduler for finetuning in bi-level problem"
)
parser.add_argument(
"--lr-schedule",
type=str,
default="cosine",
choices=("step", "cosine"),
help="Learning rate schedule",
)
parser.add_argument("--momentum", type=float, default=0.9, help="SGD momentum")
parser.add_argument(
"--warmup-epochs", type=int, default=0, help="Number of warmup epochs"
)
parser.add_argument(
"--warmup-lr", type=float, default=0.1, help="warmup learning rate"
)
parser.add_argument(
"--save-dense",
action="store_true",
default=False,
help="Save dense model alongwith subnets.",
)
# Evaluate
parser.add_argument(
"--evaluate", action="store_true", help="Evaluate model"
)
parser.add_argument(
"--val-method",
type=str,
default="base",
choices=["base"],
help="base: evaluation on unmodified inputs",
)
# Restart
parser.add_argument(
"--resume",
type=str,
default="",
help="path to latest checkpoint (default:None)",
)
# Additional
parser.add_argument("--seed", type=int, default=1234, help="random seed")
parser.add_argument(
"--print-freq",
type=int,
default=10,
help="Number of batches to wait before printing training logs",
)
parser.add_argument(
"--lr2",
type=float,
default=0.1,
help="learning rate for the second term",
)
parser.add_argument(
"--accelerate",
action="store_true",
help="Use PFTT to accelerate",
)
return parser.parse_args()