-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathargs.py
194 lines (182 loc) · 7.96 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
from dataclasses import dataclass, field
from typing import Optional, List, Union
from transformers import MODEL_FOR_CAUSAL_LM_MAPPING
from transformers import TrainingArguments as HfTrainingArguments
MODEL_CONFIG_CLASSES = list(MODEL_FOR_CAUSAL_LM_MAPPING.keys())
MODEL_TYPES = tuple(conf.model_type for conf in MODEL_CONFIG_CLASSES)
@dataclass
class TrainingArguments(HfTrainingArguments):
max_position_embeddings: Optional[int] = field(
default=None,
metadata={"help": "The maximum position embedding per segment."}
)
summary_length: int = field(
default=0,
metadata={"help": "Number of summary tokens. 0 allocates no space for summary tokens."}
)
accumulate_summary: bool = field(
default=False,
metadata={"help": "If True, summary tokens of all past segments will be accumulated "
"when passed to the next segment."}
)
training_substeps: Optional[int] = field(
default=1,
metadata={"help": "How often to detach gradients (1 substep=standard training)"}
)
randomize_substeps: Optional[bool] = field(
default=False,
metadata={"help": "apply strategy to determine substep lengths in each substep"}
)
segments_per_substep: int = field(
default=2,
metadata={"help": "Number of substeps per segments when using --randomize_substep"}
)
segment_lengths: List[int] = field(
default_factory=list,
metadata={"help": "Max. number of tokens compressed per segment in a substep. Applies only when substeps are not randomized."}
)
segment_gradient_checkpointing: bool = field(
default=False,
metadata={"help": "If True, gradient checkpointing will be used after each segment."}
)
fast_attention: bool = field(
default=False,
metadata={"help": "Use fast attention during training (experimental)"}
)
@dataclass
class ModelArguments:
"""
Arguments pertaining to which model/config/tokenizer we are going to fine-tune, or train from scratch.
"""
model_name_or_path: Optional[str] = field(
default=None,
metadata={
"help": (
"The model checkpoint for weights initialization.Don't set if you want to train a model from scratch."
)
},
)
model_type: Optional[str] = field(
default=None,
metadata={"help": "If training from scratch, pass a model type from the list: " + ", ".join(MODEL_TYPES)},
)
config_overrides: Optional[str] = field(
default=None,
metadata={
"help": (
"Override some existing default config settings when a model is trained from scratch. Example: "
"n_embd=10,resid_pdrop=0.2,scale_attn_weights=false,summary_type=cls_index"
)
},
)
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 huggingface.co"},
)
use_fast_tokenizer: bool = field(
default=True,
metadata={"help": "Whether to use one of the fast tokenizer (backed by the tokenizers library) or not."},
)
model_revision: str = field(
default="main",
metadata={"help": "The specific model version to use (can be a branch name, tag name or commit id)."},
)
use_auth_token: bool = field(
default=False,
metadata={
"help": (
"Will use the token generated when running `huggingface-cli login` (necessary to use this script "
"with private models)."
)
},
)
lora: bool = field(default=False, metadata={"help": "Whether to use parameter efficient fine-tuning."})
lora_path: str = field(default=None, metadata={"help": "Path to the lora model."})
lora_modules_to_save: Optional[List[str]] = field(
default=None,
metadata={
"help": "List of modules apart from LoRA layers to be set as trainable and saved in the final checkpoint. "
"For example, in Sequence Classification or Token Classification tasks, "
"the final layer `classifier/score` are randomly initialized and as such need to be trainable and saved."
},
)
lora_r: int = field(default=8, metadata={"help": "Lora attention dimension"})
lora_target_modules: List[str] = field(
default=None,
metadata={
"help": "List of module names or regex expression of the module names to replace with Lora."
"For example, ['q', 'v'] or '.*decoder.*(SelfAttention|EncDecAttention).*(q|v)$' "
},
)
lora_alpha: int = field(default=16, metadata={"help": "Lora alpha"})
lora_dropout: float = field(default=0.05, metadata={"help": "Lora dropout"})
@dataclass
class DataTrainingArguments:
"""
Arguments pertaining to what data we are going to input our model for training and eval.
"""
dataset_name: Optional[str] = field(
default=None, metadata={"help": "The name of the dataset to use (via the datasets library)."}
)
dataset_config_name: Optional[str] = field(
default=None, metadata={"help": "The configuration name of the dataset to use (via the datasets library)."}
)
train_file: Optional[str] = field(default=None, metadata={"help": "The input training data file (a text file)."})
validation_file: Optional[str] = field(
default=None,
metadata={"help": "An optional input evaluation data file to evaluate the perplexity on (a text file)."},
)
max_train_samples: Optional[int] = field(
default=None,
metadata={
"help": (
"For debugging purposes or quicker training, truncate the number of training examples to this "
"value if set."
)
},
)
max_eval_samples: Optional[int] = field(
default=None,
metadata={
"help": (
"For debugging purposes or quicker training, truncate the number of evaluation examples to this "
"value if set."
)
},
)
overwrite_cache: bool = field(
default=False, metadata={"help": "Overwrite the cached training and evaluation sets"}
)
validation_split_percentage: Optional[int] = field(
default=5,
metadata={
"help": "The percentage of the train set used as validation set in case there's no validation split"
},
)
preprocessing_num_workers: Optional[int] = field(
default=None,
metadata={"help": "The number of processes to use for the preprocessing."},
)
keep_linebreaks: bool = field(
default=True, metadata={"help": "Whether to keep line breaks when using TXT files or not."}
)
# for loading preprocessed data
preprocessed_train_datasets: List[str] = field(default_factory=list)
preprocessed_validation_datasets: List[str] = field(default_factory=list)
add_special_tokens: Optional[bool] = field(default=False, metadata={"help": "Whether to add special tokens."})
def __post_init__(self):
# if self.dataset_name is None and self.train_file is None and self.validation_file is None:
# raise ValueError("Need either a dataset name or a training/validation file.")
# else:
if self.train_file is not None:
extension = self.train_file.split(".")[-1]
assert extension in ["csv", "json", "txt", "pt"], "`train_file` should be a csv, a json or a txt file."
if self.validation_file is not None:
extension = self.validation_file.split(".")[-1]
assert extension in ["csv", "json", "txt"], "`validation_file` should be a csv, a json or a txt file."