prepare dataset
Browse files- .gitignore +2 -1
- scripts/prepare_pretrain_dataset.py +179 -0
- scripts/requirements-lit.in +9 -0
- scripts/requirements.in +0 -1
.gitignore
CHANGED
@@ -161,4 +161,5 @@ cython_debug/
|
|
161 |
.idea/
|
162 |
|
163 |
.DS_Store
|
164 |
-
.ruff_cache
|
|
|
|
161 |
.idea/
|
162 |
|
163 |
.DS_Store
|
164 |
+
.ruff_cache
|
165 |
+
venv*/
|
scripts/prepare_pretrain_dataset.py
ADDED
@@ -0,0 +1,179 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gc
|
2 |
+
|
3 |
+
from datasets import load_dataset
|
4 |
+
from litdata import optimize, TokensLoader
|
5 |
+
from litgpt.tokenizer import Tokenizer
|
6 |
+
from functools import partial
|
7 |
+
|
8 |
+
|
9 |
+
def batch_iterator(name=None):
|
10 |
+
# code
|
11 |
+
if name in (None, 'bigcode/programming-languages-keywords'):
|
12 |
+
dataset = load_dataset('bigcode/programming-languages-keywords', split='train')
|
13 |
+
|
14 |
+
for row in dataset:
|
15 |
+
for n in row['keywords']:
|
16 |
+
yield n
|
17 |
+
|
18 |
+
del dataset
|
19 |
+
gc.collect()
|
20 |
+
|
21 |
+
# code
|
22 |
+
if name in (None, 'bigcode/the-stack-smol-xs'):
|
23 |
+
dataset = (
|
24 |
+
load_dataset('bigcode/the-stack-smol-xs', lang, split='train', trust_remote_code=True)
|
25 |
+
for lang in [
|
26 |
+
'ada', 'agda', 'alloy', 'antlr', 'applescript', 'assembly', 'augeas', 'awk', 'batchfile', 'bison', 'bluespec', 'c',
|
27 |
+
'c++', 'c-sharp', 'clojure', 'cmake', 'coffeescript', 'common-lisp', 'css', 'cuda', 'dart', 'dockerfile', 'elixir',
|
28 |
+
'elm', 'emacs-lisp','erlang', 'f-sharp', 'fortran', 'glsl', 'go', 'groovy', 'haskell','html', 'idris', 'isabelle', 'java',
|
29 |
+
'java-server-pages', 'javascript', 'julia', 'kotlin', 'lean', 'literate-agda', 'literate-coffeescript', 'literate-haskell',
|
30 |
+
'lua', 'makefile', 'maple', 'markdown', 'mathematica', 'matlab', 'ocaml', 'pascal', 'perl', 'php', 'powershell', 'prolog',
|
31 |
+
'protocol-buffer', 'python', 'r', 'racket', 'restructuredtext', 'rmarkdown', 'ruby', 'rust', 'sas', 'scala', 'scheme',
|
32 |
+
'shell', 'smalltalk', 'solidity', 'sparql', 'sql', 'stan', 'standard-ml', 'stata', 'systemverilog', 'tcl', 'tcsh', 'tex',
|
33 |
+
'thrift', 'typescript', 'verilog', 'vhdl', 'visual-basic', 'xslt', 'yacc', 'zig'
|
34 |
+
]
|
35 |
+
)
|
36 |
+
|
37 |
+
for d in dataset:
|
38 |
+
for row in d:
|
39 |
+
yield row['content']
|
40 |
+
|
41 |
+
del dataset
|
42 |
+
gc.collect()
|
43 |
+
|
44 |
+
# text
|
45 |
+
if name in (None, 'nampdn-ai/tiny-textbooks'):
|
46 |
+
dataset = load_dataset('nampdn-ai/tiny-textbooks', split='train')
|
47 |
+
|
48 |
+
for row in dataset:
|
49 |
+
yield row['text']
|
50 |
+
|
51 |
+
del dataset
|
52 |
+
gc.collect()
|
53 |
+
|
54 |
+
# text
|
55 |
+
if name in (None, 'xu-song/cc100-samples'):
|
56 |
+
dataset = (
|
57 |
+
load_dataset('xu-song/cc100-samples', lang, split='train')
|
58 |
+
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']
|
59 |
+
)
|
60 |
+
|
61 |
+
for d in dataset:
|
62 |
+
for row in d['text']:
|
63 |
+
yield row
|
64 |
+
|
65 |
+
del dataset
|
66 |
+
gc.collect()
|
67 |
+
|
68 |
+
# code
|
69 |
+
if name in (None, 'm-a-p/CodeFeedback-Filtered-Instruction'):
|
70 |
+
dataset = load_dataset('m-a-p/CodeFeedback-Filtered-Instruction', split='train')
|
71 |
+
|
72 |
+
for row in dataset:
|
73 |
+
yield row['query'] + '\n' + row['answer']
|
74 |
+
|
75 |
+
del dataset
|
76 |
+
gc.collect()
|
77 |
+
|
78 |
+
# code
|
79 |
+
if name in (None, 'nampdn-ai/tiny-codes'):
|
80 |
+
dataset = load_dataset('nampdn-ai/tiny-codes', split='train')
|
81 |
+
|
82 |
+
for row in dataset:
|
83 |
+
yield row['prompt'] + '\n' + row['response']
|
84 |
+
|
85 |
+
del dataset
|
86 |
+
gc.collect()
|
87 |
+
|
88 |
+
# math
|
89 |
+
if name in (None, 'ajibawa-2023/Maths-College'):
|
90 |
+
dataset = load_dataset('ajibawa-2023/Maths-College', split='train')
|
91 |
+
|
92 |
+
for row in dataset:
|
93 |
+
yield row['instruction'] + '\n' + row['output']
|
94 |
+
|
95 |
+
del dataset
|
96 |
+
gc.collect()
|
97 |
+
|
98 |
+
# math
|
99 |
+
if name in (None, 'microsoft/orca-math-word-problems-200k'):
|
100 |
+
dataset = load_dataset('microsoft/orca-math-word-problems-200k', split='train')
|
101 |
+
|
102 |
+
for row in dataset:
|
103 |
+
yield row['question'] + '\n' + row['answer']
|
104 |
+
|
105 |
+
del dataset
|
106 |
+
gc.collect()
|
107 |
+
|
108 |
+
# text
|
109 |
+
if name in (None, 'mlabonne/FineTome-100k'):
|
110 |
+
dataset = load_dataset('mlabonne/FineTome-100k', split='train')
|
111 |
+
|
112 |
+
for row in dataset['conversations']:
|
113 |
+
yield '\n'.join(n['value'] for n in row)
|
114 |
+
|
115 |
+
del dataset
|
116 |
+
gc.collect()
|
117 |
+
|
118 |
+
# instruction
|
119 |
+
if name in (None, 'arcee-ai/agent-data'):
|
120 |
+
dataset = load_dataset('arcee-ai/agent-data', split='train')
|
121 |
+
|
122 |
+
for row in dataset['conversations']:
|
123 |
+
yield '\n'.join(n['value'] for n in row)
|
124 |
+
|
125 |
+
del dataset
|
126 |
+
gc.collect()
|
127 |
+
|
128 |
+
# instruction
|
129 |
+
if name in (None, 'cognitivecomputations/SystemChat-2.0'):
|
130 |
+
dataset = (
|
131 |
+
load_dataset('cognitivecomputations/SystemChat-2.0', data_files='SystemChat_filtered.jsonl', split='train'),
|
132 |
+
load_dataset('cognitivecomputations/SystemChat-2.0', data_files='SystemChat_multilingual.jsonl', split='train'),
|
133 |
+
)
|
134 |
+
|
135 |
+
for d in dataset:
|
136 |
+
for row in d['messages']:
|
137 |
+
yield '\n'.join(n['content'] for n in row)
|
138 |
+
|
139 |
+
del dataset
|
140 |
+
gc.collect()
|
141 |
+
|
142 |
+
# emoji
|
143 |
+
if name in (None, 'badrex/llm-emoji-dataset'):
|
144 |
+
dataset = load_dataset('badrex/llm-emoji-dataset', split='train')
|
145 |
+
|
146 |
+
for row in dataset:
|
147 |
+
yield f'{row["character"]}\n{row["unicode"]}\n{row["short description"]}\n{row["tags"]}\n{row["LLM description"]}'
|
148 |
+
|
149 |
+
del dataset
|
150 |
+
gc.collect()
|
151 |
+
|
152 |
+
|
153 |
+
def tokenize_fn(dataset_name, tokenizer=None):
|
154 |
+
for text in batch_iterator(dataset_name):
|
155 |
+
text_ids = tokenizer.encode(text, bos=False, eos=True)
|
156 |
+
yield text_ids
|
157 |
+
|
158 |
+
datasets_names = [
|
159 |
+
'bigcode/programming-languages-keywords',
|
160 |
+
'bigcode/the-stack-smol-xs',
|
161 |
+
'nampdn-ai/tiny-textbooks',
|
162 |
+
'xu-song/cc100-samples',
|
163 |
+
'm-a-p/CodeFeedback-Filtered-Instruction',
|
164 |
+
'nampdn-ai/tiny-codes',
|
165 |
+
'ajibawa-2023/Maths-College',
|
166 |
+
'microsoft/orca-math-word-problems-200k',
|
167 |
+
'mlabonne/FineTome-100k',
|
168 |
+
'arcee-ai/agent-data',
|
169 |
+
'cognitivecomputations/SystemChat-2.0',
|
170 |
+
'badrex/llm-emoji-dataset',
|
171 |
+
]
|
172 |
+
|
173 |
+
outputs = optimize(
|
174 |
+
fn=partial(tokenize_fn, tokenizer=Tokenizer('..')),
|
175 |
+
inputs=datasets_names,
|
176 |
+
output_dir='../data/',
|
177 |
+
# Number of tokens to store by chunks. This is roughly 64MB of tokens per chunk.
|
178 |
+
chunk_size=(2049 * 8012),
|
179 |
+
)
|
scripts/requirements-lit.in
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu
|
2 |
+
tqdm
|
3 |
+
datasets
|
4 |
+
jinja2
|
5 |
+
transformers
|
6 |
+
bitsandbytes
|
7 |
+
wandb
|
8 |
+
litgpt[all]
|
9 |
+
litdata
|
scripts/requirements.in
CHANGED
@@ -2,6 +2,5 @@ tqdm
|
|
2 |
datasets
|
3 |
jinja2
|
4 |
transformers
|
5 |
-
jsonlines
|
6 |
bitsandbytes
|
7 |
wandb
|
|
|
2 |
datasets
|
3 |
jinja2
|
4 |
transformers
|
|
|
5 |
bitsandbytes
|
6 |
wandb
|