File size: 15,624 Bytes
fd468b1
716dba4
fd468b1
 
 
 
 
 
 
716dba4
 
c62a845
716dba4
c62a845
716dba4
c62a845
 
 
 
 
 
 
 
 
54c27fe
 
 
 
 
 
 
c62a845
 
 
 
fd468b1
716dba4
fd468b1
716dba4
c62a845
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd468b1
 
 
 
 
 
 
 
 
c62a845
716dba4
 
c62a845
54c27fe
 
c62a845
 
 
 
 
716dba4
 
54c27fe
 
9255616
 
55dc3c2
54c27fe
 
 
 
 
 
716dba4
049be21
716dba4
c62a845
 
41211a9
54c27fe
 
 
 
 
716dba4
54c27fe
716dba4
54c27fe
 
 
c62a845
 
 
 
abd5982
716dba4
 
abd5982
 
54c27fe
 
 
 
 
abd5982
 
 
 
fd468b1
716dba4
fd468b1
716dba4
fd468b1
c62a845
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd468b1
 
 
 
54c27fe
 
fd468b1
 
 
 
abd5982
716dba4
 
abd5982
 
54c27fe
 
 
 
 
abd5982
 
 
 
c62a845
716dba4
 
abd5982
fd468b1
54c27fe
 
 
 
 
abd5982
fd468b1
 
 
abd5982
716dba4
 
fd468b1
 
54c27fe
 
 
 
 
 
 
abd5982
 
 
 
 
716dba4
54c27fe
716dba4
abd5982
54c27fe
 
 
 
 
 
fd468b1
54c27fe
 
fd468b1
c62a845
716dba4
 
fd468b1
54c27fe
 
fd468b1
 
 
 
7854677
716dba4
7854677
716dba4
7854677
 
54c27fe
 
 
 
 
7854677
 
 
 
fd468b1
716dba4
 
fd468b1
 
54c27fe
 
 
 
 
fd468b1
 
 
 
 
716dba4
 
fd468b1
 
54c27fe
 
 
 
 
fd468b1
 
 
 
54c27fe
716dba4
012c999
716dba4
54c27fe
 
 
55dc3c2
54c27fe
55dc3c2
54c27fe
 
 
 
 
 
716dba4
 
fd468b1
 
54c27fe
 
 
 
 
 
 
fd468b1
 
 
 
 
716dba4
 
fd468b1
 
80f3ec1
54c27fe
 
 
 
 
 
0abae5c
54c27fe
80f3ec1
 
fd468b1
 
 
716dba4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd468b1
 
 
716dba4
fd468b1
c62a845
854297e
7854677
54c27fe
 
fd468b1
54c27fe
abd5982
c62a845
54c27fe
abd5982
cbbac33
7854677
854297e
54c27fe
fd468b1
54c27fe
 
fd468b1
 
716dba4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fd468b1
 
 
716dba4
1816ac6
fd468b1
54c27fe
716dba4
fd468b1
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
import gc
from typing import Optional

from datasets import load_dataset
from litdata import optimize, TokensLoader
from litgpt.tokenizer import Tokenizer
from functools import partial


"""
def batch_iterator_1(path=None):
    # text
    if path in (None, 'saillab/taco-datasets'):
        dataset = (
            load_dataset(path, data_dir=data_dir, split='train')
            for data_dir in [
                'multilingual-instruction-tuning-dataset /multilingual-alpaca-52k-gpt-4',
                'multilingual-instruction-tuning-dataset /multilinugal-dolly-15k',
            ]
        )

        for d in dataset:
            for row in d:
                for n in row:
                    yield (
                        row['instruction'] +
                        ' ' +
                        row['input'] +
                        ' ' +
                        row['output']
                    )

        del dataset
        gc.collect()

    # text
    if path in (None, 'xu-song/cc100-samples'):
        dataset = (
            load_dataset(path, lang, split='train')
            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',
            ]
        )

        for d in dataset:
            for row in d['text']:
                yield row

        del dataset
        gc.collect()

    # text
    if path in (None, 'ontocord/fineweb-permissive-multilingual-2m'):
        dataset = load_dataset(path, split='train')
        
        for row in dataset['text']:
            yield row
        
        del dataset
        gc.collect()

    # text
    if path in (None, 'MuskumPillerum/General-Knowledge'):
        dataset = load_dataset(path, split='train')

        for row in dataset:
            if not row['Question'] or not row['Answer']:
                continue

            yield row['Question'] + ' ' + row['Answer']

        del dataset
        gc.collect()

    # text
    if path in (None, 'yirenc/general_knowledge_boolean'):
        for split in ['train', 'validation']:
            dataset = load_dataset(path, split=split)

            for row in dataset:
                yield row['question'] + '? ' + str(row['answer']) + '. ' + row['passage']

            del dataset
            gc.collect()

    # text
    if path in (None, 'nampdn-ai/tiny-textbooks'):
        for split in ['train', 'test']:
            dataset = load_dataset(path, split=split)

            for row in dataset['textbook']:
                yield row

            del dataset
            gc.collect()

    # code
    if path in (None, 'nampdn-ai/tiny-codes'):
        dataset = load_dataset(path, split='train')
        
        for row in dataset:
            yield (
                row['prompt'] +
                ' ' +
                row['response']
            )
        
        del dataset
        gc.collect()

    # code
    if path in (None, 'bigcode/the-stack-smol-xs'):
        dataset = (
            load_dataset(path, lang, split='train', trust_remote_code=True)
            for lang in [
                'ada', 'agda', 'alloy', 'antlr', 'applescript', 'assembly',
                'augeas', 'awk', 'batchfile', 'bison', 'bluespec', 'c',
                'c++', 'c-sharp', 'clojure', 'cmake', 'coffeescript', 'common-lisp',
                'css', 'cuda', 'dart', 'dockerfile', 'elixir',
                'elm', 'emacs-lisp','erlang', 'f-sharp', 'fortran', 'glsl', 'go',
                'groovy', 'haskell','html', 'idris', 'isabelle', 'java', 
                'java-server-pages', 'javascript', 'julia', 'kotlin', 'lean',
                'literate-agda', 'literate-coffeescript', 'literate-haskell',
                'lua', 'makefile', 'maple', 'markdown', 'mathematica', 'matlab',
                'ocaml', 'pascal', 'perl', 'php', 'powershell', 'prolog',
                'protocol-buffer', 'python', 'r', 'racket', 'restructuredtext',
                'rmarkdown', 'ruby', 'rust', 'sas', 'scala', 'scheme', 
                'shell', 'smalltalk', 'solidity', 'sparql', 'sql', 'stan',
                'standard-ml', 'stata', 'systemverilog', 'tcl', 'tcsh', 'tex', 
                'thrift', 'typescript', 'verilog', 'vhdl', 'visual-basic', 'xslt',
                'yacc', 'zig',
            ]
        )

        for d in dataset:
            for row in d['content']:
                yield row

        del dataset
        gc.collect()

    # text + code
    if path in (None, 'm-a-p/CodeFeedback-Filtered-Instruction'):
        dataset = load_dataset(path, split='train')

        for row in dataset:
            yield (
                row['query'] +
                ' ' +
                row['answer']
            )

        del dataset
        gc.collect()

    # code
    if path in (None, 'jtatman/python-code-dataset-500k'):
        dataset = load_dataset(path, split='train')

        for row in dataset:
            yield (
                row['instruction'] +
                ' ' +
                row['output']
            )

        del dataset
        gc.collect()

    # code
    if path in (None, 'iamtarun/python_code_instructions_18k_alpaca'):
        dataset = load_dataset(path, split='train')

        for row in dataset:
            yield (
                row['instruction'] +
                ' ' +
                row['input'] +
                ' ' +
                row['output']
            )

        del dataset
        gc.collect()

    # code
    if path in (None, 'HuggingFaceH4/CodeAlpaca_20K'):
        for split in ['train', 'test']:
            dataset = load_dataset(path, split=split)

            for row in dataset:
                yield (
                    row['prompt'] +
                    ' ' +
                    row['completion']
                )

            del dataset
            gc.collect()

    # math
    if path in (None, 'gair-prox/open-web-math-pro'):
        dataset = load_dataset(path, split='train')
        
        for row in dataset['text']:
            yield row
        
        del dataset
        gc.collect()

    # math
    if path in (None, 'rvv-karma/Math-QA'):
        for split in ['train', 'val', 'test']:
            dataset = load_dataset(path, split=split)
            
            for row in dataset:
                yield (
                    row['question'] +
                    ' ' +
                    row['answer']
                )
            
            del dataset
            gc.collect()

    # math
    if path in (None, 'ajibawa-2023/Maths-College'):
        dataset = load_dataset(path, split='train')
        
        for row in dataset:
            yield (
                row['instruction'] +
                ' ' +
                row['output']
            )
        
        del dataset
        gc.collect()

    # math
    if path in (None, 'microsoft/orca-math-word-problems-200k'):
        dataset = load_dataset(path, split='train')

        for row in dataset:
            yield (
                row['question'] +
                ' ' +
                row['answer']
            )

        del dataset
        gc.collect()

    # math
    if path in (None, 'fblgit/simple-math'):
        for split in ['train', 'test']:
            dataset = load_dataset(path, revision='refs/convert/parquet', split=split)

            for row in dataset:
                yield (
                    str(row['instruction']) +
                    ' = ' +
                    str(row['output'])
                )

            del dataset
            gc.collect()

    # reasoning
    if path in (None, 'SkunkworksAI/reasoning-0.01'):
        dataset = load_dataset(path, split='train')

        for row in dataset:
            yield (
                row['instruction'] +
                ' ' +
                row['reasoning'] +
                ' ' +
                row['output']
            )

        del dataset
        gc.collect()

    # emoji
    if path in (None, 'badrex/llm-emoji-dataset'):
        dataset = load_dataset(path, split='train')
        
        for row in dataset:
            yield (
                row['character'] +
                ' ' +
                row['unicode'] +
                ' ' +
                row['short description'] +
                ' ' +
                str(row['tags']) +
                ' ' +
                row['LLM description']
            )
        
        del dataset
        gc.collect()
"""

def batch_iterator(path: str,
                   name: Optional[str]=None,
                   data_dir: Optional[str]=None,
                   data_files: Optional[str]=None,
                   revision: Optional[str]=None,
                   split: str='train',
                   format: Optional[str]=None):
    assert format is not None
    
    dataset = load_dataset(path=path,
                           name=name,
                           data_dir=data_dir,
                           data_files=data_files,
                           revision=revision,
                           split=split,
                           trust_remote_code=True)

    for row in dataset:
        text = format.format(**row)
        yield text


def tokenize_fn(datasets_config, tokenizer=None):
    for text in batch_iterator(**datasets_config):
        text_ids = tokenizer.encode(text, bos=False, eos=True)
        yield text_ids

"""
datasets_names = [
    'saillab/taco-datasets',
    # 'xu-song/cc100-samples',
    # 'ontocord/fineweb-permissive-multilingual-2m',
    'MuskumPillerum/General-Knowledge',
    'yirenc/general_knowledge_boolean',
    'nampdn-ai/tiny-textbooks',
    # 'nampdn-ai/tiny-codes',
    'bigcode/the-stack-smol-xs',
    'm-a-p/CodeFeedback-Filtered-Instruction',
    # 'jtatman/python-code-dataset-500k',
    'iamtarun/python_code_instructions_18k_alpaca',
    'HuggingFaceH4/CodeAlpaca_20K',
    # 'gair-prox/open-web-math-pro',
    'rvv-karma/Math-QA',
    # 'ajibawa-2023/Maths-College',
    'microsoft/orca-math-word-problems-200k',
    'fblgit/simple-math',
    # 'SkunkworksAI/reasoning-0.01',
    'badrex/llm-emoji-dataset',
]
"""

datasets_configs = [
    {'path': 'yahma/alpaca-cleaned', 'format': '{instruction} {input} {output}'},
    {'path': 'gbharti/wealth-alpaca_lora', 'format': '{instruction} {input} {output}'},
    *[
        {'path': 'saillab/taco-datasets', 'data_dir': data_dir, 'split': 'train[:10%]', 'format': '{instruction} {input} {output}'}
        for data_dir in [
            'multilingual-instruction-tuning-dataset /multilingual-alpaca-52k-gpt-4',
            'multilingual-instruction-tuning-dataset /multilinugal-dolly-15k',
        ]
    ],
    *[
        {'path': 'xu-song/cc100-samples', 'name': name, 'split': 'train[:10%]', 'format': '{text}'}
        for name 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',
        ]
    ],
    {'path': 'ontocord/fineweb-permissive-multilingual-2m', 'split': 'train[:5%]', 'format': '{text}'},
    {'path': 'MuskumPillerum/General-Knowledge', 'format': '{Question} {Answer}'},
    {'path': 'yirenc/general_knowledge_boolean', 'split': 'train+validation', 'format': '{question}? {answer}. {passage}'},
    {'path': 'nampdn-ai/tiny-textbooks', 'split': 'train+test', 'format': '{textbook}'},
    {'path': 'nampdn-ai/tiny-codes', 'split': 'train[:5%]', 'format': '{prompt} {response}'},
    *[
        {'path': 'bigcode/the-stack-smol-xs', 'name': name, 'format': '{content}'}
        for name in [
            'ada', 'agda', 'alloy', 'antlr', 'applescript', 'assembly',
            'augeas', 'awk', 'batchfile', 'bison', 'bluespec', 'c',
            'c++', 'c-sharp', 'clojure', 'cmake', 'coffeescript', 'common-lisp',
            'css', 'cuda', 'dart', 'dockerfile', 'elixir',
            'elm', 'emacs-lisp','erlang', 'f-sharp', 'fortran', 'glsl', 'go',
            'groovy', 'haskell','html', 'idris', 'isabelle', 'java', 
            'java-server-pages', 'javascript', 'julia', 'kotlin', 'lean',
            'literate-agda', 'literate-coffeescript', 'literate-haskell',
            'lua', 'makefile', 'maple', 'markdown', 'mathematica', 'matlab',
            'ocaml', 'pascal', 'perl', 'php', 'powershell', 'prolog',
            'protocol-buffer', 'python', 'r', 'racket', 'restructuredtext',
            'rmarkdown', 'ruby', 'rust', 'sas', 'scala', 'scheme', 
            'shell', 'smalltalk', 'solidity', 'sparql', 'sql', 'stan',
            'standard-ml', 'stata', 'systemverilog', 'tcl', 'tcsh', 'tex', 
            'thrift', 'typescript', 'verilog', 'vhdl', 'visual-basic', 'xslt',
            'yacc', 'zig',
        ]
    ],
    {'path': 'm-a-p/CodeFeedback-Filtered-Instruction', 'split': 'train', 'format': '{query} {answer}'},
    {'path': 'jtatman/python-code-dataset-500k', 'format': '{instruction} {output}'},
    {'path': 'iamtarun/python_code_instructions_18k_alpaca', 'format': '{instruction} {input} {output}'},
    {'path': 'HuggingFaceH4/CodeAlpaca_20K', 'split': 'train+test', 'format': '{prompt} {completion}'},
    {'path': 'gair-prox/open-web-math-pro', 'split': 'train[:5%]', 'format': '{text}'},
    {'path': 'rvv-karma/Math-QA', 'split': 'train+val+test', 'format': '{question} {answer}'},
    {'path': 'ajibawa-2023/Maths-College', 'split': 'train[:10%]', 'format': '{instruction} {output}'},
    {'path': 'microsoft/orca-math-word-problems-200k', 'format': '{question} {answer}'},
    {'path': 'fblgit/simple-math', 'revision': 'refs/convert/parquet', 'split': 'train+test', 'format': '{instruction} = {output}'},
    {'path': 'SkunkworksAI/reasoning-0.01', 'format': '{instruction} {reasoning} {output}'},
    {'path': 'badrex/llm-emoji-dataset', 'format': '{character} {unicode} {short description} {tags} {LLM description}'},
]

outputs = optimize(
    fn=partial(tokenize_fn, tokenizer=Tokenizer('..')),
    inputs=datasets_configs,
    output_dir='../pretrain-data/',
    # Number of tokens to store by chunks. This is roughly 64MB of tokens per chunk.
    chunk_size=(2049 * 8012),
    num_workers=32,
)