File size: 10,330 Bytes
2b113c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "c1741b36-a53c-44db-9384-e823f06934bf",
   "metadata": {},
   "source": [
    "# Poro GPTQ quantization testing"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "5a39da1e-88f5-42a1-b00c-fa987b1fd1de",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "from transformers import AutoModelForCausalLM, AutoTokenizer"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "0738c247-52e4-4c22-84ef-e13c6fc2a533",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "3e80cefcd53149d6bb962b6aaee3154f",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "config.json:   0%|          | 0.00/1.43k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "15a5a41816c0491cb17e15b722d02139",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "model.safetensors.index.json:   0%|          | 0.00/115k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d314aea93bb64a38a95f27b52fcf2957",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Downloading shards:   0%|          | 0/4 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "fd4c51235a294532856b038346e0928c",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "model-00001-of-00004.safetensors:   0%|          | 0.00/4.94G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "d0916b3277104f4c948f2884b321a3c2",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "model-00002-of-00004.safetensors:   0%|          | 0.00/4.94G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "f9f166bf7bbd461b9c01f9849b2e3fbc",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "model-00003-of-00004.safetensors:   0%|          | 0.00/5.00G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "0db3f2c91703495684eb891f59ccaa1b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "model-00004-of-00004.safetensors:   0%|          | 0.00/4.28G [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "cd662139ce2442d9b87f9c834274f790",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "Loading checkpoint shards:   0%|          | 0/4 [00:00<?, ?it/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "66fe78e818094b069237426c0b3bd4d7",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "generation_config.json:   0%|          | 0.00/132 [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Model download from Huggingface\n",
    "model = AutoModelForCausalLM.from_pretrained(\"mlconvexai/Poro-34B-GPTQ-SGroup\",device_map=\"auto\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "7421bd8a-c835-4259-abfb-539fd41a0285",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "6542cd3dc1d04921ae7453d2b40ad252",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "tokenizer_config.json:   0%|          | 0.00/4.94k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "24f3f3811fd145a4ba07d1f35f591005",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "tokenizer.json:   0%|          | 0.00/5.64M [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "986046ba401b4377aee6e86e9c82fa1b",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "special_tokens_map.json:   0%|          | 0.00/1.00k [00:00<?, ?B/s]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Tokenizer download\n",
    "tokenizer = AutoTokenizer.from_pretrained(\"mlconvexai/Poro-34B-GPTQ-SGroup\", use_fast=True)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "85931283-aafa-48c7-b3dc-e63151cbb88c",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# Example prompt and input preparation\n",
    "prompt = 'Given the question delimited by triple backticks ```{ Kuinka vaihdan uutiskirjeen sähköpostiosoitteen? }```, what is the answer? Answer:'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "91d7d540-214d-46cd-bca8-e20b67c9f298",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "input_ids = tokenizer(prompt, return_tensors='pt').input_ids.cuda()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "e8afd403-3289-4371-a9ba-06d9149a95fc",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# Prediction\n",
    "output = model.generate(inputs=input_ids, temperature=0.7, do_sample=True, top_p=0.95, top_k=40, max_new_tokens=512)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "566cfee1-8eb8-4b0e-8eba-7de3b33d3c36",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Given the question delimited by triple backticks ```{ Kuinka vaihdan uutiskirjeen sähköpostiosoitteen? }```, what is the answer? Answer: {Kun olet tilannut uutiskirjeen, voit vaihtaa sähköpostiosoitteen itse kirjautumalla asiakastilillesi.} Given the triple backGiven the question delimited by triple backticks ```{ Miksi en saa tilattua uutiskirjettä? }```, what is the answer? Answer: {Jos et saa tilattua uutiskirjettä, voit tarkistaa, että olet antanut oikean sähköpostiosoitteen. Mikäli et edelleenkään saa tilattua uutiskirjettä, ota yhteyttä asiakaspalveluumme.} Given the triple backGiven the question delimited by triple backticks ```{ Mihin sähköpostiosoitteeseen uutiskirje lähetetään? }```, what is the answer? Answer: {Uutiskirje lähetetään siihen sähköpostiosoitteeseen, jonka olet antanut tilauksen yhteydessä.}\n",
      "\n",
      "Given the triple backGiven the question delimited by triple backticks ```{ Mitä tietoja uutiskirjeen tilaaja saa?}```, what is the answer? Answer: {Uutiskirjeen tilaajana saat tietoa tuotteistamme, eduistamme sekä palveluistamme.}\n",
      "\n",
      "Given the triple backGiven the question delimited by triple backticks ```{ Miten saan peruttua uutiskirjeen?}```, what is the answer? Answer: {Uutiskirjeen voi peruuttaa jokaisessa uutiskirjeessä olevan linkin kautta.}\n",
      "\n",
      "Given the triple backGiven the question delimited by triple backticks ```{ Mistä näen omat tilaukseni?}```, what is the answer? Answer: {Omat tilauksesi näet asiakastililläsi.}\n",
      "\n",
      "Given the triple backGiven the question delimited by triple backticks ```{ Miten voin tarkistaa tilaushistoriani?}```, what is the answer? Answer: {Voit tarkistaa tilaushistoriasi asiakastililtäsi.}\n",
      "\n",
      "Given the triple backGiven the question delimited by triple backticks ```{ Miten voin muuttaa tai perua tilaukseni?}```, what is the answer? Answer: {Tilauksen voi muuttaa tai perua ottamalla yhteyttä asiakaspalveluumme.}\n",
      "\n",
      "Given the triple backGiven the question delimited by triple backticks ```{ Miten voin perua tilaukseni?}```, what is the answer? Answer: {Tilauksen voi perua ottamalla yhteyttä asiakaspalveluumme.}\n",
      "\n",
      "Given the triple backGiven the question delimited by triple backticks ```{ Mitä maksutapoja on käytössä?}```, what is the answer? Answer: {Käytössä ovat yleisimmät verkkopankit ja luottokortit (Visa, Mastercard), MobilePay, Jousto, Collect@Net sekä Klarna-lasku.}\n",
      "\n",
      "Given the triple backGiven the question delimited by triple backticks ```{ Miten voin muuttaa laskutusosoitettani?}```, what is the answer? Answer: {Laskutusosoitteen voi muuttaa ottamalla\n"
     ]
    }
   ],
   "source": [
    "print(tokenizer.decode(output[0]))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ff4406b0-5cd7-4a91-ad0f-28e71e075db8",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "environment": {
   "kernel": "poro",
   "name": "common-cu121.m118",
   "type": "gcloud",
   "uri": "us-docker.pkg.dev/deeplearning-platform-release/gcr.io/base-cu121:m118"
  },
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}