added config
Browse files- .gitattributes +1 -0
- config.json +3 -0
- scripts/train_model.py +0 -264
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
*.json filter=lfs diff=lfs merge=lfs -text
|
config.json
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:94e73e086a5ed14149cee99a1aa3e2563ec7ab536c1653ff332999afa3520694
|
3 |
+
size 546
|
scripts/train_model.py
DELETED
@@ -1,264 +0,0 @@
|
|
1 |
-
import gc
|
2 |
-
|
3 |
-
import torch
|
4 |
-
from torch.optim import AdamW
|
5 |
-
import bitsandbytes as bnb
|
6 |
-
from datasets import load_dataset, Dataset
|
7 |
-
|
8 |
-
from transformers import (
|
9 |
-
AutoConfig,
|
10 |
-
AutoTokenizer,
|
11 |
-
AutoModelForCausalLM,
|
12 |
-
TrainingArguments,
|
13 |
-
Trainer,
|
14 |
-
DataCollatorForLanguageModeling,
|
15 |
-
)
|
16 |
-
|
17 |
-
|
18 |
-
def _batch_iterator():
|
19 |
-
## code
|
20 |
-
# dataset = load_dataset('bigcode/programming-languages-keywords', split='train')
|
21 |
-
|
22 |
-
# for row in dataset:
|
23 |
-
# for n in row['keywords']:
|
24 |
-
# yield n
|
25 |
-
|
26 |
-
# del dataset
|
27 |
-
# gc.collect()
|
28 |
-
# return
|
29 |
-
|
30 |
-
# code
|
31 |
-
dataset = (
|
32 |
-
load_dataset('bigcode/the-stack-smol-xs', lang, split='train', trust_remote_code=True)
|
33 |
-
for lang in [
|
34 |
-
'ada', 'agda', 'alloy', 'antlr', 'applescript', 'assembly', 'augeas', 'awk', 'batchfile', 'bison', 'bluespec', 'c',
|
35 |
-
'c++', 'c-sharp', 'clojure', 'cmake', 'coffeescript', 'common-lisp', 'css', 'cuda', 'dart', 'dockerfile', 'elixir',
|
36 |
-
'elm', 'emacs-lisp','erlang', 'f-sharp', 'fortran', 'glsl', 'go', 'groovy', 'haskell','html', 'idris', 'isabelle', 'java',
|
37 |
-
'java-server-pages', 'javascript', 'julia', 'kotlin', 'lean', 'literate-agda', 'literate-coffeescript', 'literate-haskell',
|
38 |
-
'lua', 'makefile', 'maple', 'markdown', 'mathematica', 'matlab', 'ocaml', 'pascal', 'perl', 'php', 'powershell', 'prolog',
|
39 |
-
'protocol-buffer', 'python', 'r', 'racket', 'restructuredtext', 'rmarkdown', 'ruby', 'rust', 'sas', 'scala', 'scheme',
|
40 |
-
'shell', 'smalltalk', 'solidity', 'sparql', 'sql', 'stan', 'standard-ml', 'stata', 'systemverilog', 'tcl', 'tcsh', 'tex',
|
41 |
-
'thrift', 'typescript', 'verilog', 'vhdl', 'visual-basic', 'xslt', 'yacc', 'zig'
|
42 |
-
]
|
43 |
-
)
|
44 |
-
|
45 |
-
for d in dataset:
|
46 |
-
for row in d:
|
47 |
-
yield row['content']
|
48 |
-
|
49 |
-
del dataset
|
50 |
-
gc.collect()
|
51 |
-
|
52 |
-
# text
|
53 |
-
dataset = load_dataset('nampdn-ai/tiny-textbooks', split='train')
|
54 |
-
|
55 |
-
for row in dataset:
|
56 |
-
yield row['text']
|
57 |
-
|
58 |
-
del dataset
|
59 |
-
gc.collect()
|
60 |
-
|
61 |
-
## text
|
62 |
-
# dataset = (
|
63 |
-
# load_dataset('wikimedia/wikisource', lang, split='train')
|
64 |
-
# for lang in ['20231201.ar', '20231201.as', '20231201.az', '20231201.ban', '20231201.be', '20231201.bg', '20231201.bn', '20231201.br', '20231201.bs', '20231201.ca', '20231201.cs', '20231201.cy', '20231201.da', '20231201.de', '20231201.el', '20231201.en', '20231201.eo', '20231201.es', '20231201.et', '20231201.eu', '20231201.fa', '20231201.fi', '20231201.fo', '20231201.fr', '20231201.gl', '20231201.gu', '20231201.he', '20231201.hi', '20231201.hr', '20231201.hu', '20231201.hy', '20231201.id', '20231201.is', '20231201.it', '20231201.ja', '20231201.jv', '20231201.kn', '20231201.ko', '20231201.la', '20231201.li', '20231201.lij', '20231201.lt', '20231201.mk', '20231201.ml', '20231201.mr', '20231201.nap', '20231201.nl', '20231201.no', '20231201.or', '20231201.pa', '20231201.pl', '20231201.pms', '20231201.pt', '20231201.ro', '20231201.ru', '20231201.sa', '20231201.sah', '20231201.sk', '20231201.sl', '20231201.sr', '20231201.su', '20231201.sv', '20231201.ta', '20231201.te', '20231201.th', '20231201.tr', '20231201.uk', '20231201.vec', '20231201.vi', '20231201.wa', '20231201.yi', '20231201.zh', '20231201.zh-min-nan']
|
65 |
-
# )
|
66 |
-
#
|
67 |
-
# for d in dataset:
|
68 |
-
# for row in d['text']:
|
69 |
-
# yield row
|
70 |
-
#
|
71 |
-
# del dataset
|
72 |
-
# gc.collect()
|
73 |
-
|
74 |
-
# text
|
75 |
-
dataset = (
|
76 |
-
load_dataset('xu-song/cc100-samples', lang, split='train')
|
77 |
-
for lang in ['am', 'ar', 'as', 'az', 'be', 'bg', 'bn', 'bn_rom', 'br', 'bs', 'ca', 'cs', 'cy', 'da', 'de', 'el', 'en', 'eo', 'es', 'et', 'eu', 'fa', 'ff', 'fi', 'fr', 'fy', 'ga', 'gd', 'gl', 'gn', 'gu', 'ha', 'he', 'hi', 'hi_rom', 'hr', 'ht', 'hu', 'hy', 'id', 'ig', 'is', 'it', 'ja', 'jv', 'ka', 'kk', 'km', 'kn', 'ko', 'ku', 'ky', 'la', 'lg', 'li', 'ln', 'lo', 'lt', 'lv', 'mg', 'mk', 'ml', 'mn', 'mr', 'ms', 'my', 'my_zaw', 'ne', 'nl', 'no', 'ns', 'om', 'or', 'pa', 'pl', 'ps', 'pt', 'qu', 'rm', 'ro', 'ru', 'sa', 'si', 'sc', 'sd', 'sk', 'sl', 'so', 'sq', 'sr', 'ss', 'su', 'sv', 'sw', 'ta', 'ta_rom', 'te', 'te_rom', 'th', 'tl', 'tn', 'tr', 'ug', 'uk', 'ur', 'ur_rom', 'uz', 'vi', 'wo', 'xh', 'yi', 'yo', 'zh-Hans', 'zh-Hant', 'zu']
|
78 |
-
)
|
79 |
-
|
80 |
-
for d in dataset:
|
81 |
-
for row in d['text']:
|
82 |
-
yield row
|
83 |
-
|
84 |
-
del dataset
|
85 |
-
gc.collect()
|
86 |
-
|
87 |
-
## text
|
88 |
-
# dataset = (
|
89 |
-
# load_dataset('csebuetnlp/xlsum', lang, split='train')
|
90 |
-
# for lang in ['amharic', 'arabic', 'azerbaijani', 'bengali', 'burmese', 'chinese_simplified', 'chinese_traditional', 'english', 'french', 'gujarati', 'hausa', 'hindi', 'igbo', 'indonesian', 'japanese', 'kirundi', 'korean', 'kyrgyz', 'marathi', 'nepali', 'oromo', 'pashto', 'persian', 'pidgin', 'portuguese', 'punjabi', 'russian', 'scottish_gaelic', 'serbian_cyrillic', 'serbian_latin', 'sinhala', 'somali', 'spanish', 'swahili', 'tamil', 'telugu', 'thai', 'tigrinya', 'turkish', 'ukrainian', 'urdu', 'uzbek', 'vietnamese', 'welsh', 'yoruba']
|
91 |
-
# )
|
92 |
-
#
|
93 |
-
# for d in dataset:
|
94 |
-
# for row in d['text']:
|
95 |
-
# yield row
|
96 |
-
#
|
97 |
-
# del dataset
|
98 |
-
# gc.collect()
|
99 |
-
|
100 |
-
## text
|
101 |
-
# dataset = load_dataset('recursal/SuperWikiNEXT-32B', split='train')
|
102 |
-
#
|
103 |
-
# for row in dataset['text']:
|
104 |
-
# yield row
|
105 |
-
#
|
106 |
-
# del dataset
|
107 |
-
# gc.collect()
|
108 |
-
|
109 |
-
# code
|
110 |
-
dataset = load_dataset('m-a-p/CodeFeedback-Filtered-Instruction', split='train')
|
111 |
-
|
112 |
-
for row in dataset:
|
113 |
-
yield row['query'] + '\n' + row['answer']
|
114 |
-
|
115 |
-
del dataset
|
116 |
-
gc.collect()
|
117 |
-
|
118 |
-
# code
|
119 |
-
dataset = load_dataset('nampdn-ai/tiny-codes', split='train')
|
120 |
-
|
121 |
-
for row in dataset:
|
122 |
-
yield row['prompt'] + '\n' + row['response']
|
123 |
-
|
124 |
-
del dataset
|
125 |
-
gc.collect()
|
126 |
-
|
127 |
-
# math
|
128 |
-
dataset = load_dataset('ajibawa-2023/Maths-College', split='train')
|
129 |
-
|
130 |
-
for row in dataset:
|
131 |
-
yield row['instruction'] + '\n' + row['output']
|
132 |
-
|
133 |
-
del dataset
|
134 |
-
gc.collect()
|
135 |
-
|
136 |
-
# math
|
137 |
-
dataset = load_dataset('microsoft/orca-math-word-problems-200k', split='train')
|
138 |
-
|
139 |
-
for row in dataset:
|
140 |
-
yield row['question'] + '\n' + row['answer']
|
141 |
-
|
142 |
-
del dataset
|
143 |
-
gc.collect()
|
144 |
-
|
145 |
-
# text
|
146 |
-
dataset = load_dataset('mlabonne/FineTome-100k', split='train')
|
147 |
-
|
148 |
-
for row in dataset['conversations']:
|
149 |
-
yield '\n'.join(n['value'] for n in row)
|
150 |
-
|
151 |
-
del dataset
|
152 |
-
gc.collect()
|
153 |
-
|
154 |
-
# instruction
|
155 |
-
dataset = load_dataset('arcee-ai/agent-data', split='train')
|
156 |
-
|
157 |
-
for row in dataset['conversations']:
|
158 |
-
yield '\n'.join(n['value'] for n in row)
|
159 |
-
|
160 |
-
del dataset
|
161 |
-
gc.collect()
|
162 |
-
|
163 |
-
# instruction
|
164 |
-
dataset = (
|
165 |
-
load_dataset('cognitivecomputations/SystemChat-2.0', data_files='SystemChat_filtered.jsonl', split='train'),
|
166 |
-
load_dataset('cognitivecomputations/SystemChat-2.0', data_files='SystemChat_multilingual.jsonl', split='train'),
|
167 |
-
)
|
168 |
-
|
169 |
-
for d in dataset:
|
170 |
-
for row in d['messages']:
|
171 |
-
yield '\n'.join(n['content'] for n in row)
|
172 |
-
|
173 |
-
del dataset
|
174 |
-
gc.collect()
|
175 |
-
|
176 |
-
# emoji
|
177 |
-
dataset = load_dataset('badrex/llm-emoji-dataset', split='train')
|
178 |
-
|
179 |
-
for row in dataset:
|
180 |
-
yield f'{row["character"]}\n{row["unicode"]}\n{row["short description"]}\n{row["tags"]}\n{row["LLM description"]}'
|
181 |
-
|
182 |
-
del dataset
|
183 |
-
gc.collect()
|
184 |
-
|
185 |
-
|
186 |
-
def batch_iterator():
|
187 |
-
for text in _batch_iterator():
|
188 |
-
for i in range(0, len(text), 2048):
|
189 |
-
chunk = text[i:i + 2048]
|
190 |
-
tokenized = tokenize_function(chunk)
|
191 |
-
yield tokenized
|
192 |
-
|
193 |
-
|
194 |
-
def tokenize_function(text):
|
195 |
-
outputs = tokenizer(text, truncation=True, padding='max_length', max_length=2048)
|
196 |
-
outputs['labels'] = outputs['input_ids'].copy()
|
197 |
-
return outputs
|
198 |
-
|
199 |
-
|
200 |
-
tokenizer = AutoTokenizer.from_pretrained('../')
|
201 |
-
print(tokenizer)
|
202 |
-
|
203 |
-
config = AutoConfig.from_pretrained('mistralai/Mistral-7B-Instruct-v0.3')
|
204 |
-
config.bos_token_id = tokenizer.bos_token_id
|
205 |
-
config.eos_token_id = tokenizer.eos_token_id
|
206 |
-
config.unk_token_id = tokenizer.unk_token_id
|
207 |
-
config.pad_token_id = tokenizer.pad_token_id
|
208 |
-
config.hidden_size = 512
|
209 |
-
config.intermediate_size = 1792 # int(512 * 3.5)
|
210 |
-
config.max_position_embeddings = 32768 # 32 * 1024
|
211 |
-
config.num_attention_heads = 12
|
212 |
-
config.num_hidden_layers = 10
|
213 |
-
config.num_key_value_heads = 4
|
214 |
-
config.rope_theta = 1_000_000.0
|
215 |
-
config.sliding_window = 4096
|
216 |
-
config.torch_dtype = torch.bfloat16
|
217 |
-
config.use_cache = False
|
218 |
-
print(config)
|
219 |
-
|
220 |
-
model = AutoModelForCausalLM.from_config(config)
|
221 |
-
print(model)
|
222 |
-
|
223 |
-
dataset = Dataset.from_generator(batch_iterator)
|
224 |
-
print(dataset)
|
225 |
-
|
226 |
-
data_collator = DataCollatorForLanguageModeling(tokenizer=tokenizer, mlm=False)
|
227 |
-
print(data_collator)
|
228 |
-
|
229 |
-
optimizer = bnb.optim.AdamW8bit(
|
230 |
-
model.parameters(),
|
231 |
-
lr=1e-5,
|
232 |
-
betas=(0.9, 0.95),
|
233 |
-
weight_decay=0.1,
|
234 |
-
)
|
235 |
-
print(optimizer)
|
236 |
-
|
237 |
-
training_args = TrainingArguments(
|
238 |
-
output_dir='./mistral-custom',
|
239 |
-
num_train_epochs=3,
|
240 |
-
per_device_train_batch_size=1,
|
241 |
-
gradient_accumulation_steps=8,
|
242 |
-
warmup_steps=500,
|
243 |
-
learning_rate=1e-5,
|
244 |
-
fp16=False,
|
245 |
-
bf16=True,
|
246 |
-
logging_dir='./logs',
|
247 |
-
logging_steps=10,
|
248 |
-
evaluation_strategy='no',
|
249 |
-
save_strategy='epoch',
|
250 |
-
torch_compile=True,
|
251 |
-
)
|
252 |
-
print(training_args)
|
253 |
-
|
254 |
-
trainer = Trainer(
|
255 |
-
model=model,
|
256 |
-
args=training_args,
|
257 |
-
train_dataset=dataset,
|
258 |
-
data_collator=data_collator,
|
259 |
-
optimizers=(optimizer, None)
|
260 |
-
)
|
261 |
-
print(trainer)
|
262 |
-
|
263 |
-
trainer.train()
|
264 |
-
trainer.save_model('./mistral-custom-final')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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