-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtraining_args.py
More file actions
314 lines (299 loc) · 11.1 KB
/
training_args.py
File metadata and controls
314 lines (299 loc) · 11.1 KB
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
"""Defines the arguments used for training and evaluation."""
import logging
from dataclasses import dataclass, field
from transformers import TrainingArguments
from transformers.optimization import (
get_constant_schedule,
get_constant_schedule_with_warmup,
get_cosine_schedule_with_warmup,
get_cosine_with_hard_restarts_schedule_with_warmup,
get_linear_schedule_with_warmup,
get_polynomial_decay_schedule_with_warmup,
)
from typing import Optional, List, Tuple
arg_to_scheduler = {
"cosine_w_restarts": get_cosine_with_hard_restarts_schedule_with_warmup,
"polynomial": get_polynomial_decay_schedule_with_warmup,
"constant": get_constant_schedule,
"linear": get_linear_schedule_with_warmup,
"cosine": get_cosine_schedule_with_warmup,
"constant_w_warmup": get_constant_schedule_with_warmup,
}
logger = logging.getLogger(__name__)
@dataclass
class Seq2SeqTrainingArguments(TrainingArguments):
"""
Contains different training parameters such as dropout, optimizers parameters, ... .
"""
label_smoothing: Optional[float] = field(
default=0.0,
metadata={"help": "The label smoothing epsilon to apply (if not zero)."},
)
loss_scaling: Optional[bool] = field(
default=True,
metadata={"help": "Whether to scale loss by number of tokens."},
)
predict_with_generate: bool = field(
default=False,
metadata={
"help": "Whether to use generate to calculate generative metrics (ROUGE, BLEU)."
},
)
adafactor: bool = field(
default=False, metadata={"help": "whether to use adafactor"}
)
encoder_layerdrop: Optional[float] = field(
default=None,
metadata={"help": "Encoder layer dropout probability. Goes into model.config."},
)
decoder_layerdrop: Optional[float] = field(
default=None,
metadata={"help": "Decoder layer dropout probability. Goes into model.config."},
)
dropout: Optional[float] = field(
default=None, metadata={"help": "Dropout probability. Goes into model.config."}
)
attention_dropout: Optional[float] = field(
default=None,
metadata={"help": "Attention dropout probability. Goes into model.config."},
)
lr_scheduler: Optional[str] = field(
default="linear",
metadata={
"help": f"Which lr scheduler to use. Selected in {sorted(arg_to_scheduler.keys())}"
},
)
temperature: Optional[int] = field(
default=1,
metadata={
"help": "Defines the temperature"
"value for sampling across the multiple datasets."
},
)
do_test: bool = field(
default=False,
metadata={"help": "Whether to comptue evaluation metrics on the test sets."},
)
eval_output_dir: Optional[str] = field(
default=None,
metadata={
"help": "The output directory where the evaluation of the model and checkpoints during "
"evaluation will be written. Would use the original output_dir if not specified."
},
)
generate_classifier_weights: Optional[bool] = field(
default=False,
metadata={
"help": "If set, generates the weights of the classifier by using a hyper-network."
},
)
optimize_from_scratch: Optional[bool] = field(
default=False,
metadata={
"help": "If set, this does not load the optimizers from"
"the given model path."
},
)
optimize_from_scratch_with_loading_model: Optional[bool] = field(
default=False,
metadata={
"help": "If set, it loads the model still but optimize from scratch."
},
)
split_validation_test: Optional[bool] = field(
default=False,
metadata={
"help": "If set, for the datasets which do not"
"have the test set, we use validation set as their"
"test set and make a validation set from either"
"splitting the validation set into half (for smaller"
"than 10K samples datasets), or by using 1K examples"
"from training set as validation set (for larger"
" datasets)."
},
)
print_num_parameters: Optional[str] = field(
default=False,
metadata={"help": "If specified, prints the total number of parameters."},
)
compute_memory: Optional[bool] = field(
default=False, metadata={"help": "If specified, measures the memory needed."}
)
compute_time: Optional[bool] = field(
default=False, metadata={"help": "If specified, measures the time needed."}
)
report_to: Optional[List[str]] = field(
default="none",
metadata={
"help": "The list of integrations to report the results and logs to."
},
)
@dataclass
class ModelArguments:
"""
Contains the arguments defining model, tokenizer, and config which we use for finetuning.
Also, it defines which parameters of the model needs to be freezed during finetuning.
"""
model_name_or_path: str = field(
metadata={
"help": "Path to pretrained model or model identifier from huggingface.co/models"
}
)
not_load_t5_checkpoint: bool = field(
default=False, metadata={"help": "whether to load the checkpoint."}
)
config_name: Optional[str] = field(
default=None,
metadata={
"help": "Pretrained config name or path if not the same as model_name"
},
)
tokenizer_name: Optional[str] = field(
default=None,
metadata={
"help": "Pretrained tokenizer name or path if not the same as model_name"
},
)
cache_dir: Optional[str] = field(
default=None,
metadata={
"help": "Where do you want to store the pretrained models downloaded from s3"
},
)
freeze_model: bool = field(
default=True, metadata={"help": "Whether to freeze the model."}
)
unfreeze_encoder_adapters: bool = field(
default=True, metadata={"help": "Whether to unfreeze the encoder adapters."}
)
unfreeze_decoder_adapters: bool = field(
default=True, metadata={"help": "Whether to unfreeze the decoder adapters."}
)
unfreeze_encoder: bool = field(
default=False, metadata={"help": "Whether to unfreeze the encoder."}
)
unfreeze_decoder: bool = field(
default=False, metadata={"help": "Whether to unfreeze the decoder."}
)
unfreeze_layer_norms: bool = field(
default=False, metadata={"help": "Whether to unfreeze the layer norms."}
)
@dataclass
class DataTrainingArguments:
"""
Arguments related to data used for training and evaluation.
"""
tasks: Optional[List[str]] = field(
default="MRPC",
metadata={"help": "Task name from the list of registered tasks."},
)
eval_tasks: Optional[List[str]] = field(
default="MRPC",
metadata={"help": "Evaluation task name from the list of registered tasks."},
)
adapters: Optional[List[str]] = field(
default=None,
metadata={"help": "Defines a dictionary from adapters to the tasks."},
)
task_embeddings: Optional[List[str]] = field(
default=None,
metadata={"help": "Defines a dictionary from tasks to the tasks embeddings."},
)
max_source_length: Optional[int] = field(
default=128,
metadata={
"help": "The maximum total input sequence length after tokenization. Sequences longer "
"than this will be truncated, sequences shorter will be padded."
},
)
max_target_length: Optional[int] = field(
default=128,
metadata={
"help": "The maximum total sequence length for target text after tokenization. Sequences longer "
"than this will be truncated, sequences shorter will be padded."
},
)
val_max_target_length: Optional[int] = field(
default=128,
metadata={
"help": "The maximum total sequence length for validation target text after tokenization. Sequences longer "
"than this will be truncated, sequences shorter will be padded."
},
)
test_max_target_length: Optional[int] = field(
default=128,
metadata={
"help": "The maximum total sequence length for test target text after tokenization. Sequences longer "
"than this will be truncated, sequences shorter will be padded."
},
)
percent_train: Optional[float] = field(
default=1.0, metadata={"help": "# proportions of training examples. 1 means use all."}
)
n_train: Optional[int] = field(
default=-1, metadata={"help": "# training examples. -1 means use all."}
)
n_val: Optional[int] = field(
default=-1, metadata={"help": "# validation examples. -1 means use all."}
)
n_test: Optional[int] = field(
default=-1, metadata={"help": "# test examples. -1 means use all."}
)
eval_beams: Optional[int] = field(
default=None, metadata={"help": "# num_beams to use for evaluation."}
)
ignore_pad_token_for_loss: bool = field(
default=True,
metadata={
"help": "If only pad tokens should be ignored. This assumes that `config.pad_token_id` is defined."
},
)
data_seed: Optional[int] = field(
default=32, metadata={"help": "The seed used to subsample the datasets."}
)
ignore_metric_keys: Optional[Tuple[str]] = field(
default=("xsum_eval_rouge1", "xsum_eval_rougeL", "xsum_eval_rougeLsum", "qqp_eval_f1", "stsb_eval_spearman_corrcoef","mrpc_eval_f1"),
metadata={
"help": "Metric keys to ignore in calculating average for best model"
},
)
filter_nulls: bool = field(
default=False,
metadata={
"help": "Whether to filter out nulls from the dataset. Only valid when using the chunked mrqa dataset"
},
)
@dataclass
class AdapterTrainingArguments:
"""Defines the adapters parameters."""
encoder_adapter: Optional[str] = field(
default="manual", metadata={"help": "The encoder adapter to use."}
)
decoder_adapter: Optional[str] = field(
default="generated", metadata={"help": "The decoder adapter to use."}
)
encoder_adapter_dim: Optional[int] = field(
default=64, metadata={"help": "size of adapters in encoder."}
)
decoder_adapter_dim: Optional[int] = field(
default=64, metadata={"help": "size of adapters in decoder."}
)
hypernetwork_bottleneck: Optional[int] = field(
default=128, metadata={"help": "size of hypernetwork bottleneck dim"}
)
adapter_norm_input: bool = field(
default=False,
metadata={"help": "Whether to use layer normed input into adapters or not."},
)
mean_task_embeddings: bool = field(
default=False,
metadata={
"help": "Whether to use average task embedding instead of task-specific or not."
},
)
process_encoder_output: bool = field(
default=True,
metadata={
"help": "Whether to pass the encoder output through a MLP before mean-pooling or not."
},
)