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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "da47e672",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [],
|
9 |
+
"source": [
|
10 |
+
"# !pip3 install https://github.com/casper-hansen/AutoAWQ/releases/download/v0.1.6/autoawq-0.1.6+cu118-cp310-cp310-linux_x86_64.whl"
|
11 |
+
]
|
12 |
+
},
|
13 |
+
{
|
14 |
+
"cell_type": "code",
|
15 |
+
"execution_count": 2,
|
16 |
+
"id": "27063032",
|
17 |
+
"metadata": {},
|
18 |
+
"outputs": [
|
19 |
+
{
|
20 |
+
"name": "stdout",
|
21 |
+
"output_type": "stream",
|
22 |
+
"text": [
|
23 |
+
"Tue Nov 7 14:32:21 2023 \r\n",
|
24 |
+
"+-----------------------------------------------------------------------------+\r\n",
|
25 |
+
"| NVIDIA-SMI 525.85.12 Driver Version: 525.85.12 CUDA Version: 12.0 |\r\n",
|
26 |
+
"|-------------------------------+----------------------+----------------------+\r\n",
|
27 |
+
"| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |\r\n",
|
28 |
+
"| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |\r\n",
|
29 |
+
"| | | MIG M. |\r\n",
|
30 |
+
"|===============================+======================+======================|\r\n",
|
31 |
+
"| 0 NVIDIA A100 80G... On | 00000001:00:00.0 Off | 0 |\r\n",
|
32 |
+
"| N/A 37C P0 66W / 300W | 5536MiB / 81920MiB | 0% Default |\r\n",
|
33 |
+
"| | | Disabled |\r\n",
|
34 |
+
"+-------------------------------+----------------------+----------------------+\r\n",
|
35 |
+
" \r\n",
|
36 |
+
"+-----------------------------------------------------------------------------+\r\n",
|
37 |
+
"| Processes: |\r\n",
|
38 |
+
"| GPU GI CI PID Type Process name GPU Memory |\r\n",
|
39 |
+
"| ID ID Usage |\r\n",
|
40 |
+
"|=============================================================================|\r\n",
|
41 |
+
"+-----------------------------------------------------------------------------+\r\n"
|
42 |
+
]
|
43 |
+
}
|
44 |
+
],
|
45 |
+
"source": [
|
46 |
+
"!nvidia-smi"
|
47 |
+
]
|
48 |
+
},
|
49 |
+
{
|
50 |
+
"cell_type": "code",
|
51 |
+
"execution_count": 3,
|
52 |
+
"id": "1bde5916",
|
53 |
+
"metadata": {
|
54 |
+
"scrolled": true
|
55 |
+
},
|
56 |
+
"outputs": [
|
57 |
+
{
|
58 |
+
"name": "stdout",
|
59 |
+
"output_type": "stream",
|
60 |
+
"text": [
|
61 |
+
"[2023-11-07 14:32:32,101] [INFO] [real_accelerator.py:133:get_accelerator] Setting ds_accelerator to cuda (auto detect)\n"
|
62 |
+
]
|
63 |
+
}
|
64 |
+
],
|
65 |
+
"source": [
|
66 |
+
"from awq import AutoAWQForCausalLM\n",
|
67 |
+
"from transformers import AutoConfig, AwqConfig, AutoTokenizer, AutoModelForCausalLM\n",
|
68 |
+
"import torch\n",
|
69 |
+
"\n",
|
70 |
+
"model_path = 'mesolitica/malaysian-llama2-7b-32k-instructions'"
|
71 |
+
]
|
72 |
+
},
|
73 |
+
{
|
74 |
+
"cell_type": "code",
|
75 |
+
"execution_count": 4,
|
76 |
+
"id": "c658280e",
|
77 |
+
"metadata": {},
|
78 |
+
"outputs": [],
|
79 |
+
"source": [
|
80 |
+
"# !pip3 install transformers==4.35.0"
|
81 |
+
]
|
82 |
+
},
|
83 |
+
{
|
84 |
+
"cell_type": "code",
|
85 |
+
"execution_count": 5,
|
86 |
+
"id": "803a0c91",
|
87 |
+
"metadata": {},
|
88 |
+
"outputs": [],
|
89 |
+
"source": [
|
90 |
+
"!rm -rf test"
|
91 |
+
]
|
92 |
+
},
|
93 |
+
{
|
94 |
+
"cell_type": "code",
|
95 |
+
"execution_count": 6,
|
96 |
+
"id": "838ddb85",
|
97 |
+
"metadata": {},
|
98 |
+
"outputs": [
|
99 |
+
{
|
100 |
+
"data": {
|
101 |
+
"application/vnd.jupyter.widget-view+json": {
|
102 |
+
"model_id": "f7b2ffd3bc464a598567299228d8966b",
|
103 |
+
"version_major": 2,
|
104 |
+
"version_minor": 0
|
105 |
+
},
|
106 |
+
"text/plain": [
|
107 |
+
"Loading checkpoint shards: 0%| | 0/2 [00:00<?, ?it/s]"
|
108 |
+
]
|
109 |
+
},
|
110 |
+
"metadata": {},
|
111 |
+
"output_type": "display_data"
|
112 |
+
}
|
113 |
+
],
|
114 |
+
"source": [
|
115 |
+
"model = AutoModelForCausalLM.from_pretrained(model_path, torch_dtype = torch.bfloat16)"
|
116 |
+
]
|
117 |
+
},
|
118 |
+
{
|
119 |
+
"cell_type": "code",
|
120 |
+
"execution_count": 7,
|
121 |
+
"id": "637b41e1",
|
122 |
+
"metadata": {},
|
123 |
+
"outputs": [],
|
124 |
+
"source": [
|
125 |
+
"model.save_pretrained('./test', safe_serialization = False)"
|
126 |
+
]
|
127 |
+
},
|
128 |
+
{
|
129 |
+
"cell_type": "code",
|
130 |
+
"execution_count": 8,
|
131 |
+
"id": "417dbbf5",
|
132 |
+
"metadata": {},
|
133 |
+
"outputs": [
|
134 |
+
{
|
135 |
+
"data": {
|
136 |
+
"application/vnd.jupyter.widget-view+json": {
|
137 |
+
"model_id": "13af4d1d7ddf4bae900710fcf9a9d775",
|
138 |
+
"version_major": 2,
|
139 |
+
"version_minor": 0
|
140 |
+
},
|
141 |
+
"text/plain": [
|
142 |
+
"Loading checkpoint shards: 0%| | 0/3 [00:00<?, ?it/s]"
|
143 |
+
]
|
144 |
+
},
|
145 |
+
"metadata": {},
|
146 |
+
"output_type": "display_data"
|
147 |
+
}
|
148 |
+
],
|
149 |
+
"source": [
|
150 |
+
"model = AutoAWQForCausalLM.from_pretrained('./test')"
|
151 |
+
]
|
152 |
+
},
|
153 |
+
{
|
154 |
+
"cell_type": "code",
|
155 |
+
"execution_count": 10,
|
156 |
+
"id": "212056b5",
|
157 |
+
"metadata": {
|
158 |
+
"scrolled": true
|
159 |
+
},
|
160 |
+
"outputs": [
|
161 |
+
{
|
162 |
+
"name": "stderr",
|
163 |
+
"output_type": "stream",
|
164 |
+
"text": [
|
165 |
+
"AWQ: 100%|██████████| 32/32 [08:38<00:00, 16.21s/it]\n"
|
166 |
+
]
|
167 |
+
}
|
168 |
+
],
|
169 |
+
"source": [
|
170 |
+
"quant_path = 'malaysian-llama2-7b-32k-instructions-awq'\n",
|
171 |
+
"quant_config = { \"zero_point\": True, \"q_group_size\": 128, \"w_bit\": 4, \"version\": \"GEMM\" }\n",
|
172 |
+
"\n",
|
173 |
+
"tokenizer = AutoTokenizer.from_pretrained(model_path, trust_remote_code=True)\n",
|
174 |
+
"model.quantize(tokenizer, quant_config=quant_config, calib_data = 'mesolitica/malaysian-calibration')"
|
175 |
+
]
|
176 |
+
},
|
177 |
+
{
|
178 |
+
"cell_type": "code",
|
179 |
+
"execution_count": 11,
|
180 |
+
"id": "77e03f18",
|
181 |
+
"metadata": {
|
182 |
+
"scrolled": true
|
183 |
+
},
|
184 |
+
"outputs": [
|
185 |
+
{
|
186 |
+
"name": "stderr",
|
187 |
+
"output_type": "stream",
|
188 |
+
"text": [
|
189 |
+
"WARNING:root:`quant_config.json` is being deprecated in the future in favor of quantization_config in config.json.\n"
|
190 |
+
]
|
191 |
+
},
|
192 |
+
{
|
193 |
+
"data": {
|
194 |
+
"text/plain": [
|
195 |
+
"('malaysian-llama2-7b-32k-instructions-awq/tokenizer_config.json',\n",
|
196 |
+
" 'malaysian-llama2-7b-32k-instructions-awq/special_tokens_map.json',\n",
|
197 |
+
" 'malaysian-llama2-7b-32k-instructions-awq/tokenizer.model',\n",
|
198 |
+
" 'malaysian-llama2-7b-32k-instructions-awq/added_tokens.json',\n",
|
199 |
+
" 'malaysian-llama2-7b-32k-instructions-awq/tokenizer.json')"
|
200 |
+
]
|
201 |
+
},
|
202 |
+
"execution_count": 11,
|
203 |
+
"metadata": {},
|
204 |
+
"output_type": "execute_result"
|
205 |
+
}
|
206 |
+
],
|
207 |
+
"source": [
|
208 |
+
"model.save_quantized(quant_path, safetensors = False)\n",
|
209 |
+
"tokenizer.save_pretrained(quant_path)"
|
210 |
+
]
|
211 |
+
},
|
212 |
+
{
|
213 |
+
"cell_type": "code",
|
214 |
+
"execution_count": 12,
|
215 |
+
"id": "fd35b057",
|
216 |
+
"metadata": {
|
217 |
+
"scrolled": false
|
218 |
+
},
|
219 |
+
"outputs": [
|
220 |
+
{
|
221 |
+
"data": {
|
222 |
+
"application/vnd.jupyter.widget-view+json": {
|
223 |
+
"model_id": "021e6f72e5594b4995338e27cfcc3a05",
|
224 |
+
"version_major": 2,
|
225 |
+
"version_minor": 0
|
226 |
+
},
|
227 |
+
"text/plain": [
|
228 |
+
"tokenizer.model: 0%| | 0.00/500k [00:00<?, ?B/s]"
|
229 |
+
]
|
230 |
+
},
|
231 |
+
"metadata": {},
|
232 |
+
"output_type": "display_data"
|
233 |
+
},
|
234 |
+
{
|
235 |
+
"data": {
|
236 |
+
"text/plain": [
|
237 |
+
"CommitInfo(commit_url='https://huggingface.co/mesolitica/malaysian-llama2-7b-32k-instructions-AWQ/commit/ea465a1be780a5091d89685d69ec7146ba0d69e4', commit_message='Upload tokenizer', commit_description='', oid='ea465a1be780a5091d89685d69ec7146ba0d69e4', pr_url=None, pr_revision=None, pr_num=None)"
|
238 |
+
]
|
239 |
+
},
|
240 |
+
"execution_count": 12,
|
241 |
+
"metadata": {},
|
242 |
+
"output_type": "execute_result"
|
243 |
+
}
|
244 |
+
],
|
245 |
+
"source": [
|
246 |
+
"tokenizer.push_to_hub('mesolitica/malaysian-llama2-7b-32k-instructions-AWQ')"
|
247 |
+
]
|
248 |
+
},
|
249 |
+
{
|
250 |
+
"cell_type": "code",
|
251 |
+
"execution_count": 14,
|
252 |
+
"id": "816dacc8",
|
253 |
+
"metadata": {},
|
254 |
+
"outputs": [
|
255 |
+
{
|
256 |
+
"data": {
|
257 |
+
"text/plain": [
|
258 |
+
"CommitInfo(commit_url='https://huggingface.co/mesolitica/malaysian-llama2-7b-32k-instructions-AWQ/commit/69be7a3e995592db52910fe2e848e85dc2637ad3', commit_message='Upload config', commit_description='', oid='69be7a3e995592db52910fe2e848e85dc2637ad3', pr_url=None, pr_revision=None, pr_num=None)"
|
259 |
+
]
|
260 |
+
},
|
261 |
+
"execution_count": 14,
|
262 |
+
"metadata": {},
|
263 |
+
"output_type": "execute_result"
|
264 |
+
}
|
265 |
+
],
|
266 |
+
"source": [
|
267 |
+
"quantization_config = AwqConfig(\n",
|
268 |
+
" bits=quant_config['w_bit'],\n",
|
269 |
+
" group_size=quant_config['q_group_size'],\n",
|
270 |
+
" zero_point=quant_config['zero_point'],\n",
|
271 |
+
" backend='autoawq',\n",
|
272 |
+
" version=quant_config['version'].lower(),\n",
|
273 |
+
")\n",
|
274 |
+
"\n",
|
275 |
+
"config = AutoConfig.from_pretrained(model_path)\n",
|
276 |
+
"config.quantization_config = quantization_config\n",
|
277 |
+
"\n",
|
278 |
+
"config.push_to_hub('mesolitica/malaysian-llama2-7b-32k-instructions-AWQ')"
|
279 |
+
]
|
280 |
+
},
|
281 |
+
{
|
282 |
+
"cell_type": "code",
|
283 |
+
"execution_count": 16,
|
284 |
+
"id": "846835fa",
|
285 |
+
"metadata": {},
|
286 |
+
"outputs": [],
|
287 |
+
"source": [
|
288 |
+
"from huggingface_hub import HfApi\n",
|
289 |
+
"\n",
|
290 |
+
"api = HfApi()"
|
291 |
+
]
|
292 |
+
},
|
293 |
+
{
|
294 |
+
"cell_type": "code",
|
295 |
+
"execution_count": 17,
|
296 |
+
"id": "f8c2bef7",
|
297 |
+
"metadata": {},
|
298 |
+
"outputs": [
|
299 |
+
{
|
300 |
+
"data": {
|
301 |
+
"application/vnd.jupyter.widget-view+json": {
|
302 |
+
"model_id": "c84977a07bc84c708cf3b9eea3672dda",
|
303 |
+
"version_major": 2,
|
304 |
+
"version_minor": 0
|
305 |
+
},
|
306 |
+
"text/plain": [
|
307 |
+
"pytorch_model.bin: 0%| | 0.00/3.89G [00:00<?, ?B/s]"
|
308 |
+
]
|
309 |
+
},
|
310 |
+
"metadata": {},
|
311 |
+
"output_type": "display_data"
|
312 |
+
},
|
313 |
+
{
|
314 |
+
"data": {
|
315 |
+
"text/plain": [
|
316 |
+
"'https://huggingface.co/mesolitica/malaysian-llama2-7b-32k-instructions-AWQ/blob/main/pytorch_model.bin'"
|
317 |
+
]
|
318 |
+
},
|
319 |
+
"execution_count": 17,
|
320 |
+
"metadata": {},
|
321 |
+
"output_type": "execute_result"
|
322 |
+
}
|
323 |
+
],
|
324 |
+
"source": [
|
325 |
+
"api.upload_file(\n",
|
326 |
+
" path_or_fileobj='malaysian-llama2-7b-32k-instructions-awq/pytorch_model.bin',\n",
|
327 |
+
" path_in_repo=\"pytorch_model.bin\",\n",
|
328 |
+
" repo_id='mesolitica/malaysian-llama2-7b-32k-instructions-AWQ',\n",
|
329 |
+
" repo_type=\"model\",\n",
|
330 |
+
")"
|
331 |
+
]
|
332 |
+
},
|
333 |
+
{
|
334 |
+
"cell_type": "code",
|
335 |
+
"execution_count": 18,
|
336 |
+
"id": "b6b0f30f",
|
337 |
+
"metadata": {
|
338 |
+
"scrolled": true
|
339 |
+
},
|
340 |
+
"outputs": [
|
341 |
+
{
|
342 |
+
"data": {
|
343 |
+
"application/vnd.jupyter.widget-view+json": {
|
344 |
+
"model_id": "cfd383ecaf3f42689d5e6e158a2b1a06",
|
345 |
+
"version_major": 2,
|
346 |
+
"version_minor": 0
|
347 |
+
},
|
348 |
+
"text/plain": [
|
349 |
+
"Downloading (…)lve/main/config.json: 0%| | 0.00/870 [00:00<?, ?B/s]"
|
350 |
+
]
|
351 |
+
},
|
352 |
+
"metadata": {},
|
353 |
+
"output_type": "display_data"
|
354 |
+
},
|
355 |
+
{
|
356 |
+
"name": "stderr",
|
357 |
+
"output_type": "stream",
|
358 |
+
"text": [
|
359 |
+
"You have loaded an AWQ model on CPU and have a CUDA device available, make sure to set your model on a GPU device in order to run your model.\n"
|
360 |
+
]
|
361 |
+
},
|
362 |
+
{
|
363 |
+
"data": {
|
364 |
+
"application/vnd.jupyter.widget-view+json": {
|
365 |
+
"model_id": "c88703bd0b8b40c5b25a4d8eb1fdfbe4",
|
366 |
+
"version_major": 2,
|
367 |
+
"version_minor": 0
|
368 |
+
},
|
369 |
+
"text/plain": [
|
370 |
+
"Downloading pytorch_model.bin: 0%| | 0.00/3.89G [00:00<?, ?B/s]"
|
371 |
+
]
|
372 |
+
},
|
373 |
+
"metadata": {},
|
374 |
+
"output_type": "display_data"
|
375 |
+
}
|
376 |
+
],
|
377 |
+
"source": [
|
378 |
+
"quantized_model = AutoModelForCausalLM.from_pretrained('mesolitica/malaysian-llama2-7b-32k-instructions-AWQ')\n",
|
379 |
+
"_ = quantized_model.cuda()"
|
380 |
+
]
|
381 |
+
},
|
382 |
+
{
|
383 |
+
"cell_type": "code",
|
384 |
+
"execution_count": 21,
|
385 |
+
"id": "698cd4c9",
|
386 |
+
"metadata": {},
|
387 |
+
"outputs": [],
|
388 |
+
"source": [
|
389 |
+
"def parse_llama_chat(messages):\n",
|
390 |
+
"\n",
|
391 |
+
" system = messages[0]['content']\n",
|
392 |
+
" user_query = messages[-1]['content']\n",
|
393 |
+
"\n",
|
394 |
+
" users, assistants = [], []\n",
|
395 |
+
" for q in messages[1:-1]:\n",
|
396 |
+
" if q['role'] == 'user':\n",
|
397 |
+
" users.append(q['content'])\n",
|
398 |
+
" elif q['role'] == 'assistant':\n",
|
399 |
+
" assistants.append(q['content'])\n",
|
400 |
+
"\n",
|
401 |
+
" texts = [f'<s>[INST] <<SYS>>\\n{system}\\n<</SYS>>\\n\\n']\n",
|
402 |
+
" for u, a in zip(users, assistants):\n",
|
403 |
+
" texts.append(f'{u.strip()} [/INST] {a.strip()} </s><s>[INST] ')\n",
|
404 |
+
" texts.append(f'{user_query.strip()} [/INST]')\n",
|
405 |
+
" prompt = ''.join(texts).strip()\n",
|
406 |
+
" return prompt"
|
407 |
+
]
|
408 |
+
},
|
409 |
+
{
|
410 |
+
"cell_type": "code",
|
411 |
+
"execution_count": 22,
|
412 |
+
"id": "63315893",
|
413 |
+
"metadata": {},
|
414 |
+
"outputs": [],
|
415 |
+
"source": [
|
416 |
+
"messages = [\n",
|
417 |
+
" {'role': 'system', 'content': 'awak adalah AI yang mampu jawab segala soalan'},\n",
|
418 |
+
" {'role': 'user', 'content': 'kwsp tu apa'}\n",
|
419 |
+
"]\n",
|
420 |
+
"prompt = parse_llama_chat(messages)\n",
|
421 |
+
"inputs = tokenizer([prompt], return_tensors='pt', add_special_tokens=False).to('cuda')"
|
422 |
+
]
|
423 |
+
},
|
424 |
+
{
|
425 |
+
"cell_type": "code",
|
426 |
+
"execution_count": 24,
|
427 |
+
"id": "8a3c15d8",
|
428 |
+
"metadata": {},
|
429 |
+
"outputs": [
|
430 |
+
{
|
431 |
+
"name": "stdout",
|
432 |
+
"output_type": "stream",
|
433 |
+
"text": [
|
434 |
+
"CPU times: user 7.54 s, sys: 3.84 ms, total: 7.54 s\n",
|
435 |
+
"Wall time: 7.54 s\n"
|
436 |
+
]
|
437 |
+
},
|
438 |
+
{
|
439 |
+
"data": {
|
440 |
+
"text/plain": [
|
441 |
+
"'<s> [INST] <<SYS>>\\nawak adalah AI yang mampu jawab segala soalan\\n<</SYS>>\\n\\nkwsp tu apa [/INST] KWSP adalah singkatan bagi \"Kumpulan Wang Simpanan Pekerja\", yang merujuk kepada skim simpanan persaraan yang dilaksanakan di Malaysia yang bertujuan untuk menyediakan dana persaraan untuk pekerja dan majikan. Program ini memerlukan majikan untuk menyumbang sejumlah wang bagi pihak pekerja, dan pekerja dikehendaki menyumbang sejumlah yang sama bagi pihak mereka sendiri. Dana ini dikumpulkan dalam dana berasingan dan dikawal selia oleh kerajaan. KWSP menyediakan faedah persaraan kepada ahlinya, seperti pengeluaran, pelaburan, dan pencen. Skim ini terkenal kerana tadbir urusnya yang baik dan reputasinya sebagai salah satu dana simpanan persaraan terbesar dan paling dipercayai di Asia. </s>'"
|
442 |
+
]
|
443 |
+
},
|
444 |
+
"execution_count": 24,
|
445 |
+
"metadata": {},
|
446 |
+
"output_type": "execute_result"
|
447 |
+
}
|
448 |
+
],
|
449 |
+
"source": [
|
450 |
+
"%%time\n",
|
451 |
+
"\n",
|
452 |
+
"generate_kwargs = dict(\n",
|
453 |
+
" inputs,\n",
|
454 |
+
" max_new_tokens=1024,\n",
|
455 |
+
" top_p=0.95,\n",
|
456 |
+
" top_k=50,\n",
|
457 |
+
" temperature=0.9,\n",
|
458 |
+
" do_sample=True,\n",
|
459 |
+
" num_beams=1,\n",
|
460 |
+
")\n",
|
461 |
+
"r = quantized_model.generate(**generate_kwargs)\n",
|
462 |
+
"tokenizer.decode(r[0])"
|
463 |
+
]
|
464 |
+
},
|
465 |
+
{
|
466 |
+
"cell_type": "code",
|
467 |
+
"execution_count": null,
|
468 |
+
"id": "d73d43a0",
|
469 |
+
"metadata": {},
|
470 |
+
"outputs": [],
|
471 |
+
"source": []
|
472 |
+
}
|
473 |
+
],
|
474 |
+
"metadata": {
|
475 |
+
"kernelspec": {
|
476 |
+
"display_name": "Python 3 (ipykernel)",
|
477 |
+
"language": "python",
|
478 |
+
"name": "python3"
|
479 |
+
},
|
480 |
+
"language_info": {
|
481 |
+
"codemirror_mode": {
|
482 |
+
"name": "ipython",
|
483 |
+
"version": 3
|
484 |
+
},
|
485 |
+
"file_extension": ".py",
|
486 |
+
"mimetype": "text/x-python",
|
487 |
+
"name": "python",
|
488 |
+
"nbconvert_exporter": "python",
|
489 |
+
"pygments_lexer": "ipython3",
|
490 |
+
"version": "3.10.12"
|
491 |
+
}
|
492 |
+
},
|
493 |
+
"nbformat": 4,
|
494 |
+
"nbformat_minor": 5
|
495 |
+
}
|