This repository has been archived by the owner on Oct 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 60
/
config.py
242 lines (239 loc) · 7 KB
/
config.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
# Copyright (c) Facebook, Inc. and its affiliates.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
#!/usr/bin/env python3
# command-line arguments with their default values
PARAMS_CONFIG = {
# env-specific
'env_params': {
'--distributed': {
'action': 'store_true',
'default': False,
'help': 'enable distributed training.'
'(otherwise will use all available GPUs with dataparallel)',
'dest': 'distributed'
},
'--local_rank': {
'type': int,
'default': 0,
'help': 'used in distributed training',
'dest': 'local_rank'
},
},
# data-specific
'data_params': {
'--data': {
'type': str,
'default': 'data/text8',
'help': 'data location '
'(must contain train.txt, valid.txt and test.txt)',
'dest': 'data_path'
},
'--data-unit': {
'type': str,
'default': 'bpc',
'choices': ['bpc', 'ppl'],
'help': 'loss unit to log',
'dest': 'data_unit'
},
},
# model-specific
'model_params': {
'--hid-sz': {
'type': int,
'default': 256,
'help': 'hidden size (i.e. model size)',
'dest': 'hidden_size'
},
'--inner-hid-sz': {
'type': int,
'default': 1024,
'help': 'inner hidden size of FF layer',
'dest': 'inner_hidden_size'
},
'--nlayers': {
'type': int,
'default': 8,
'help': 'number of layers',
'dest': 'nb_layers'
},
'--block-sz': {
'type': int,
'default': 64,
'help': 'block size '
'(the length of sequence to process in parallel)',
'dest': 'block_size'
},
'--nheads': {
'type': int,
'default': 2,
'help': 'number of self-attention heads',
'dest': 'nb_heads'
},
'--attn-span': {
'type': int,
'default': 32,
'help': 'length of the attention span',
'dest': 'attn_span'
},
'--dropout': {
'type': float,
'default': 0.2,
'help': 'dropout rate of ReLU and attention',
'dest': 'dropout'
},
'--emb-dropout': {
'type': float,
'default': 0.,
'help': 'the dropout rate applied on I/O embeddings',
'dest': 'emb_dropout'
},
},
# optimization-specific
'optim_params': {
'--lr': {
'type': float,
'default': 0.03,
'help': 'learning rate',
'dest': 'lr'
},
'--momentum': {
'type': float,
'default': 0.9,
'help': 'SGD momentum',
'dest': 'momentum'
},
'--optim': {
'type': str,
'default': 'sgd',
'help': 'optimization method: sgd | adagrad',
'dest': 'optim'
},
'--lr-warmup': {
'type': int,
'default': 0,
'help': 'linearly increase LR from 0 '
'during first lr_warmup updates',
'dest': 'lr_warmup'
},
'--grad-clip': {
'type': float,
'default': 0,
'help': '[only works with adagrad!] '
'clip gradient of each module parameters by a given '
'value',
'dest': 'grad_clip'
},
},
# trainer-specific
'trainer_params': {
'--batch-sz': {
'type': int,
'default': 64,
'help': 'batch size',
'dest': 'batch_size'
},
'--batch-split': {
'type': int,
'default': 1,
'help': 'split a batch into smaller parts to fit in GPU memory',
'dest': 'batch_split'
},
'--nbatches': {
'type': int,
'default': 1000,
'help': 'number of batches in each iteration',
'dest': 'nb_batches_per_iter'
},
'--niter': {
'type': int,
'default': 1000,
'help': 'number of iterations to train',
'dest': 'nb_iter'
},
'--checkpoint': {
'type': str,
'default': '',
'help': 'path to save/load model',
'dest': 'checkpoint_path'
},
'--full-eval-mode': {
'action': 'store_true',
'default': False,
'help': 'do evaluation on the whole validation and the test data',
'dest': 'full_eval_mode'
},
},
# adaptive I/O specific params
'adapt_io_params': {
'--adapt-io': {
'action': 'store_true',
'default': False,
'help': 'enable adaptive input and output representations',
'dest': 'adapt_io_enabled'
},
'--adapt-io-tied': {
'action': 'store_true',
'default': False,
'help': 'tie the input parameters with the output parameters',
'dest': 'adapt_io_tied'
},
'--adapt-io-divval': {
'type': int,
'default': 4,
'help': 'dimension division value',
'dest': 'adapt_io_divval'
},
'--adapt-io-cutoffs': {
'type': int,
'default': [20000, 40000, 200000],
'help': 'cutoffs values',
'dest': 'adapt_io_cutoffs'
},
},
# adaptive attention span specific params
'adapt_span_params': {
'--adapt-span': {
'action': 'store_true',
'default': False,
'help': 'enable adaptive attention span',
'dest': 'adapt_span_enabled'
},
'--adapt-span-loss': {
'type': float,
'default': 0,
'help': 'the loss coefficient for span lengths',
'dest': 'adapt_span_loss'
},
'--adapt-span-ramp': {
'type': int,
'default': 32,
'help': 'ramp length of the soft masking function',
'dest': 'adapt_span_ramp'
},
'--adapt-span-init': {
'type': float,
'default': 0,
'help': 'initial attention span ratio',
'dest': 'adapt_span_init'
},
'--adapt-span-cache': {
'action': 'store_true',
'default': False,
'help': 'adapt cache size as well to reduce memory usage',
'dest': 'adapt_span_cache'
},
},
# persistent memory specific params
'pers_mem_params': {
'--pers-mem-size': {
'type': int,
'default': 0,
'help': 'the number of persistent memory vectors',
'dest': 'pers_mem_size'
},
},
}