MLGOATKOJI commited on
Commit
d9f772b
·
verified ·
1 Parent(s): 4a9e56a

Upload prep.ipynb

Browse files
Files changed (1) hide show
  1. prep.ipynb +248 -0
prep.ipynb ADDED
@@ -0,0 +1,248 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "3282ec4a",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stderr",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "/usr/local/lib/python3.12/dist-packages/huggingface_hub/utils/_auth.py:138: UserWarning: \n",
14
+ "Error while fetching `HF_TOKEN` secret value from your vault: 'Requesting secret HF_TOKEN timed out. Secrets can only be fetched when running from the Colab UI.'.\n",
15
+ " warnings.warn(f\"\\nError while fetching `HF_TOKEN` secret value from your vault: '{str(e)}'.\")\n"
16
+ ]
17
+ },
18
+ {
19
+ "data": {
20
+ "application/vnd.jupyter.widget-view+json": {
21
+ "model_id": "07435d1af4f64845b0d67576071b74bc",
22
+ "version_major": 2,
23
+ "version_minor": 0
24
+ },
25
+ "text/plain": [
26
+ "README.md: 0%| | 0.00/26.4k [00:00<?, ?B/s]"
27
+ ]
28
+ },
29
+ "metadata": {},
30
+ "output_type": "display_data"
31
+ },
32
+ {
33
+ "name": "stderr",
34
+ "output_type": "stream",
35
+ "text": [
36
+ "Warning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads.\n",
37
+ "WARNING:huggingface_hub.utils._http:Warning: You are sending unauthenticated requests to the HF Hub. Please set a HF_TOKEN to enable higher rate limits and faster downloads.\n"
38
+ ]
39
+ },
40
+ {
41
+ "data": {
42
+ "application/vnd.jupyter.widget-view+json": {
43
+ "model_id": "e0550b531d5840b9b7c57f98084d036a",
44
+ "version_major": 2,
45
+ "version_minor": 0
46
+ },
47
+ "text/plain": [
48
+ "Resolving data files: 0%| | 0/2410 [00:00<?, ?it/s]"
49
+ ]
50
+ },
51
+ "metadata": {},
52
+ "output_type": "display_data"
53
+ },
54
+ {
55
+ "data": {
56
+ "application/vnd.jupyter.widget-view+json": {
57
+ "model_id": "dfba8eef1d774165854440c0bcbad299",
58
+ "version_major": 2,
59
+ "version_minor": 0
60
+ },
61
+ "text/plain": [
62
+ "Resolving data files: 0%| | 0/2410 [00:00<?, ?it/s]"
63
+ ]
64
+ },
65
+ "metadata": {},
66
+ "output_type": "display_data"
67
+ }
68
+ ],
69
+ "source": [
70
+ "import torch\n",
71
+ "import numpy as np\n",
72
+ "import tiktoken\n",
73
+ "\n",
74
+ "enc = tiktoken.get_encoding(\"gpt2\")\n",
75
+ "from datasets import load_dataset\n",
76
+ "\n",
77
+ "dataset = load_dataset(\n",
78
+ " \"HuggingFaceFW/fineweb-edu\",\n",
79
+ " split=\"train\",\n",
80
+ " streaming=True\n",
81
+ ")"
82
+ ]
83
+ },
84
+ {
85
+ "cell_type": "code",
86
+ "execution_count": 12,
87
+ "id": "bb9ff2be",
88
+ "metadata": {},
89
+ "outputs": [
90
+ {
91
+ "data": {
92
+ "application/vnd.jupyter.widget-view+json": {
93
+ "model_id": "9b5d482ebadf4b388c643ec03b11be00",
94
+ "version_major": 2,
95
+ "version_minor": 0
96
+ },
97
+ "text/plain": [
98
+ "Downloading bytes: | 0.00B "
99
+ ]
100
+ },
101
+ "metadata": {},
102
+ "output_type": "display_data"
103
+ },
104
+ {
105
+ "data": {
106
+ "application/vnd.jupyter.widget-view+json": {
107
+ "model_id": "9a9ec6fcc7df4b26814f151544b62dc6",
108
+ "version_major": 2,
109
+ "version_minor": 0
110
+ },
111
+ "text/plain": [
112
+ "Reconstructing (incomplete total...): | | 0.00B / 0.00B "
113
+ ]
114
+ },
115
+ "metadata": {},
116
+ "output_type": "display_data"
117
+ },
118
+ {
119
+ "data": {
120
+ "application/vnd.jupyter.widget-view+json": {
121
+ "model_id": "bc7bb2435f2a4f78b93f64e15c2b1465",
122
+ "version_major": 2,
123
+ "version_minor": 0
124
+ },
125
+ "text/plain": [
126
+ "Fetching 5 files: 0%| | 0/5 [00:00<?, ?it/s]"
127
+ ]
128
+ },
129
+ "metadata": {},
130
+ "output_type": "display_data"
131
+ },
132
+ {
133
+ "data": {
134
+ "application/vnd.google.colaboratory.intrinsic+json": {
135
+ "type": "string"
136
+ },
137
+ "text/plain": [
138
+ "'/content/tokensstore'"
139
+ ]
140
+ },
141
+ "execution_count": 12,
142
+ "metadata": {},
143
+ "output_type": "execute_result"
144
+ }
145
+ ],
146
+ "source": [
147
+ "import warnings\n",
148
+ "from huggingface_hub import HfApi\n",
149
+ "warnings.filterwarnings(\"ignore\", category=UserWarning)\n",
150
+ "warnings.filterwarnings(\"ignore\", category=FutureWarning)\n",
151
+ "\n",
152
+ "from huggingface_hub import snapshot_download\n",
153
+ "from huggingface_hub import hf_hub_download\n",
154
+ "\n",
155
+ "snapshot_download(\n",
156
+ " repo_id=\"MLGOATKOJI/preprocceses\",\n",
157
+ " repo_type=\"dataset\",\n",
158
+ " local_dir=\"./tokensstore\"\n",
159
+ ")\n",
160
+ "\n",
161
+ "\n"
162
+ ]
163
+ },
164
+ {
165
+ "cell_type": "code",
166
+ "execution_count": null,
167
+ "id": "53fa23c2",
168
+ "metadata": {},
169
+ "outputs": [],
170
+ "source": [
171
+ "\n",
172
+ "\n",
173
+ "\n",
174
+ "\n",
175
+ "enc = tiktoken.get_encoding(\"gpt2\")\n",
176
+ "target_tokens = 5_000_000_000\n",
177
+ "total = 0\n",
178
+ "\n",
179
+ "with open(\"./tokensstore/5btokens.bin\", \"wb\") as out:\n",
180
+ "\n",
181
+ " for item in dataset:\n",
182
+ " \n",
183
+ " if total >= target_tokens:\n",
184
+ " break\n",
185
+ "\n",
186
+ " ids = enc.encode(\n",
187
+ " item[\"text\"]\n",
188
+ " )\n",
189
+ "\n",
190
+ " remaining = target_tokens - total\n",
191
+ "\n",
192
+ " # Trim if this document exceeds remaining tokens\n",
193
+ " if len(ids) > remaining:\n",
194
+ " ids = ids[:remaining]\n",
195
+ "\n",
196
+ " ids = np.array(ids, dtype=np.uint16)\n",
197
+ " ids.tofile(out)\n",
198
+ "\n",
199
+ " total += len(ids)\n",
200
+ "\n",
201
+ " print(f\"{total:,}/{target_tokens}\")#why isnt this ending anything to my train.bin?"
202
+ ]
203
+ },
204
+ {
205
+ "cell_type": "code",
206
+ "execution_count": null,
207
+ "id": "e68f049c",
208
+ "metadata": {},
209
+ "outputs": [
210
+ {
211
+ "data": {
212
+ "application/vnd.google.colaboratory.intrinsic+json": {
213
+ "type": "string"
214
+ },
215
+ "text/plain": [
216
+ "CommitInfo(commit_url='https://huggingface.co/datasets/MLGOATKOJI/preprocceses/commit/15019f40f6b650d77448fdc7afa2e7c028288e5d', commit_message='Upload folder using huggingface_hub', commit_description='', oid='15019f40f6b650d77448fdc7afa2e7c028288e5d', pr_url=None, repo_url=RepoUrl('https://huggingface.co/datasets/MLGOATKOJI/preprocceses', endpoint='https://huggingface.co', repo_type='dataset', repo_id='MLGOATKOJI/preprocceses'), pr_revision=None, pr_num=None)"
217
+ ]
218
+ },
219
+ "execution_count": 11,
220
+ "metadata": {},
221
+ "output_type": "execute_result"
222
+ }
223
+ ],
224
+ "source": [
225
+ "\n",
226
+ "from huggingface_hub import login\n",
227
+ "from huggingface_hub import HfApi\n",
228
+ "\n",
229
+ "login()\n",
230
+ "\n",
231
+ "api.upload_folder(\n",
232
+ " folder_path=\"./tokensstore\",\n",
233
+ " repo_id=\"MLGOATKOJI/preprocceses\",\n",
234
+ " repo_type=\"dataset\"\n",
235
+ ")"
236
+ ]
237
+ }
238
+ ],
239
+ "metadata": {
240
+ "kernelspec": {
241
+ "display_name": "Python 3 (ipykernel)",
242
+ "language": "python",
243
+ "name": "python3"
244
+ }
245
+ },
246
+ "nbformat": 4,
247
+ "nbformat_minor": 5
248
+ }