Transformers
Safetensors
Inference Endpoints
File size: 32,327 Bytes
8a7bf53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\Users\\X\\Anaconda3\\envs\\llama_factory\\lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
      "  from .autonotebook import tqdm as notebook_tqdm\n"
     ]
    }
   ],
   "source": [
    "import torch\n",
    "from transformers import AutoModelForCausalLM, AutoTokenizer\n",
    "from peft import PeftModel, PeftConfig\n",
    "\n",
    "device = 'cuda' if torch.cuda.is_available() else 'cpu'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "model_dir = 'D:/models/Qwen2.5-0.5B'\n",
    "lora_dir = 'train_2024-09-26-14-50-59'\n",
    "\n",
    "# tokenizers should be the same for base and lora models. No adjustments during training.\n",
    "tokenizer = AutoTokenizer.from_pretrained(model_dir)\n",
    "\n",
    "base = AutoModelForCausalLM.from_pretrained(model_dir).to(device)\n",
    "\n",
    "model = AutoModelForCausalLM.from_pretrained(model_dir).to(device)\n",
    "lora = PeftModel.from_pretrained(model, lora_dir).to(device)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Qwen2ForCausalLM(\n",
      "  (model): Qwen2Model(\n",
      "    (embed_tokens): Embedding(151936, 896)\n",
      "    (layers): ModuleList(\n",
      "      (0-23): 24 x Qwen2DecoderLayer(\n",
      "        (self_attn): Qwen2SdpaAttention(\n",
      "          (q_proj): Linear(in_features=896, out_features=896, bias=True)\n",
      "          (k_proj): Linear(in_features=896, out_features=128, bias=True)\n",
      "          (v_proj): Linear(in_features=896, out_features=128, bias=True)\n",
      "          (o_proj): Linear(in_features=896, out_features=896, bias=False)\n",
      "          (rotary_emb): Qwen2RotaryEmbedding()\n",
      "        )\n",
      "        (mlp): Qwen2MLP(\n",
      "          (gate_proj): Linear(in_features=896, out_features=4864, bias=False)\n",
      "          (up_proj): Linear(in_features=896, out_features=4864, bias=False)\n",
      "          (down_proj): Linear(in_features=4864, out_features=896, bias=False)\n",
      "          (act_fn): SiLU()\n",
      "        )\n",
      "        (input_layernorm): Qwen2RMSNorm((896,), eps=1e-06)\n",
      "        (post_attention_layernorm): Qwen2RMSNorm((896,), eps=1e-06)\n",
      "      )\n",
      "    )\n",
      "    (norm): Qwen2RMSNorm((896,), eps=1e-06)\n",
      "  )\n",
      "  (lm_head): Linear(in_features=896, out_features=151936, bias=False)\n",
      ")\n"
     ]
    }
   ],
   "source": [
    "print(base)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Qwen2ForCausalLM(\n",
      "  (model): Qwen2Model(\n",
      "    (embed_tokens): Embedding(151936, 896)\n",
      "    (layers): ModuleList(\n",
      "      (0-23): 24 x Qwen2DecoderLayer(\n",
      "        (self_attn): Qwen2SdpaAttention(\n",
      "          (q_proj): lora.Linear(\n",
      "            (base_layer): Linear(in_features=896, out_features=896, bias=True)\n",
      "            (lora_dropout): ModuleDict(\n",
      "              (default): Identity()\n",
      "            )\n",
      "            (lora_A): ModuleDict(\n",
      "              (default): Linear(in_features=896, out_features=1, bias=False)\n",
      "            )\n",
      "            (lora_B): ModuleDict(\n",
      "              (default): Linear(in_features=1, out_features=896, bias=False)\n",
      "            )\n",
      "            (lora_embedding_A): ParameterDict()\n",
      "            (lora_embedding_B): ParameterDict()\n",
      "            (lora_magnitude_vector): ModuleDict()\n",
      "          )\n",
      "          (k_proj): lora.Linear(\n",
      "            (base_layer): Linear(in_features=896, out_features=128, bias=True)\n",
      "            (lora_dropout): ModuleDict(\n",
      "              (default): Identity()\n",
      "            )\n",
      "            (lora_A): ModuleDict(\n",
      "              (default): Linear(in_features=896, out_features=1, bias=False)\n",
      "            )\n",
      "            (lora_B): ModuleDict(\n",
      "              (default): Linear(in_features=1, out_features=128, bias=False)\n",
      "            )\n",
      "            (lora_embedding_A): ParameterDict()\n",
      "            (lora_embedding_B): ParameterDict()\n",
      "            (lora_magnitude_vector): ModuleDict()\n",
      "          )\n",
      "          (v_proj): lora.Linear(\n",
      "            (base_layer): Linear(in_features=896, out_features=128, bias=True)\n",
      "            (lora_dropout): ModuleDict(\n",
      "              (default): Identity()\n",
      "            )\n",
      "            (lora_A): ModuleDict(\n",
      "              (default): Linear(in_features=896, out_features=1, bias=False)\n",
      "            )\n",
      "            (lora_B): ModuleDict(\n",
      "              (default): Linear(in_features=1, out_features=128, bias=False)\n",
      "            )\n",
      "            (lora_embedding_A): ParameterDict()\n",
      "            (lora_embedding_B): ParameterDict()\n",
      "            (lora_magnitude_vector): ModuleDict()\n",
      "          )\n",
      "          (o_proj): lora.Linear(\n",
      "            (base_layer): Linear(in_features=896, out_features=896, bias=False)\n",
      "            (lora_dropout): ModuleDict(\n",
      "              (default): Identity()\n",
      "            )\n",
      "            (lora_A): ModuleDict(\n",
      "              (default): Linear(in_features=896, out_features=1, bias=False)\n",
      "            )\n",
      "            (lora_B): ModuleDict(\n",
      "              (default): Linear(in_features=1, out_features=896, bias=False)\n",
      "            )\n",
      "            (lora_embedding_A): ParameterDict()\n",
      "            (lora_embedding_B): ParameterDict()\n",
      "            (lora_magnitude_vector): ModuleDict()\n",
      "          )\n",
      "          (rotary_emb): Qwen2RotaryEmbedding()\n",
      "        )\n",
      "        (mlp): Qwen2MLP(\n",
      "          (gate_proj): lora.Linear(\n",
      "            (base_layer): Linear(in_features=896, out_features=4864, bias=False)\n",
      "            (lora_dropout): ModuleDict(\n",
      "              (default): Identity()\n",
      "            )\n",
      "            (lora_A): ModuleDict(\n",
      "              (default): Linear(in_features=896, out_features=1, bias=False)\n",
      "            )\n",
      "            (lora_B): ModuleDict(\n",
      "              (default): Linear(in_features=1, out_features=4864, bias=False)\n",
      "            )\n",
      "            (lora_embedding_A): ParameterDict()\n",
      "            (lora_embedding_B): ParameterDict()\n",
      "            (lora_magnitude_vector): ModuleDict()\n",
      "          )\n",
      "          (up_proj): lora.Linear(\n",
      "            (base_layer): Linear(in_features=896, out_features=4864, bias=False)\n",
      "            (lora_dropout): ModuleDict(\n",
      "              (default): Identity()\n",
      "            )\n",
      "            (lora_A): ModuleDict(\n",
      "              (default): Linear(in_features=896, out_features=1, bias=False)\n",
      "            )\n",
      "            (lora_B): ModuleDict(\n",
      "              (default): Linear(in_features=1, out_features=4864, bias=False)\n",
      "            )\n",
      "            (lora_embedding_A): ParameterDict()\n",
      "            (lora_embedding_B): ParameterDict()\n",
      "            (lora_magnitude_vector): ModuleDict()\n",
      "          )\n",
      "          (down_proj): lora.Linear(\n",
      "            (base_layer): Linear(in_features=4864, out_features=896, bias=False)\n",
      "            (lora_dropout): ModuleDict(\n",
      "              (default): Identity()\n",
      "            )\n",
      "            (lora_A): ModuleDict(\n",
      "              (default): Linear(in_features=4864, out_features=1, bias=False)\n",
      "            )\n",
      "            (lora_B): ModuleDict(\n",
      "              (default): Linear(in_features=1, out_features=896, bias=False)\n",
      "            )\n",
      "            (lora_embedding_A): ParameterDict()\n",
      "            (lora_embedding_B): ParameterDict()\n",
      "            (lora_magnitude_vector): ModuleDict()\n",
      "          )\n",
      "          (act_fn): SiLU()\n",
      "        )\n",
      "        (input_layernorm): Qwen2RMSNorm((896,), eps=1e-06)\n",
      "        (post_attention_layernorm): Qwen2RMSNorm((896,), eps=1e-06)\n",
      "      )\n",
      "    )\n",
      "    (norm): Qwen2RMSNorm((896,), eps=1e-06)\n",
      "  )\n",
      "  (lm_head): Linear(in_features=896, out_features=151936, bias=False)\n",
      ")\n"
     ]
    }
   ],
   "source": [
    "print(model)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Which is bigger? 9.9 or 9.11\n",
      "base model\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "response='Which is bigger? 9.9 or 9.1100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000'\n",
      "lora model\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "response_lora='Which is bigger? 9.9 or 9.11\\n\\nTo determine which is bigger, we can compare the two numbers directly. The first number is 9.9, and the second number is 9.11. Since 9.9 is greater than 9.11, the answer is 9.9. \\n\\n9.9 > 9.11<|endoftext|>'\n",
      "---------------\n",
      "How many r's in the word strawberry?\n",
      "base model\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "response=\"How many r's in the word strawberry? - Answers\\\\nMath and Arithmetic\\\\nHow many r's in the word strawberry?\\\\nWiki User\\\\n∙ 2011-09-28 19:52:27\\\\nStudy now\\\\nSee answer (1)\\\\nBest Answer\\\\nCopy\\\\nThere are 3 r's in the word strawberry.\\\\nWiki User\\\\n∙ 2011-09-28 19:52:27\\\\nThis answer is:\\\\n👍\\\\n🙏\\\\n0\\\\n🤨\\\\n0\\\\n😮\\\\n0\\\\nAdd a Comment\\\\nStudy guides\\\\nAlgebra\\\\n20 cards\\\\nA polynomial of degree zero is a constant term\\\\nThe grouping method of factoring can still be used when only some of the terms share a common factor A True B False\\\\nThe sum or difference of p and q is the of the x-term in the trinomial\\\\nA number a power of a variable or a product of the two is a monomial while a polynomial is the of monomials\\\\n➡️\\\\nSee all cards\\\\n3.75\\\\n☆★☆★☆★☆★☆★\\\\n524 Reviews\\\\nStudy now\\\\nAdd your answer:\\\\nEarn +20 pts\\\\nQ: How many r's in the word strawberry?\\\\nSubmit\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many r's in the word strawberry?\\\\n3\\\\nHow many\"\n",
      "lora model\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "response_lora=\"How many r's in the word strawberry? The word strawberry has 5 r's.  What is 5 r's in the word strawberry? The answer is 5.<|endoftext|>\"\n",
      "---------------\n",
      "Given the vectors \\( \\mathbf{v}_1 = (3, -2, 5) \\) and \\( \\mathbf{v}_2 = (1, 4, -1) \\), compute the dot product \\( \\mathbf{v}_1 \\cdot \\mathbf{v}_2 \\).\n",
      "base model\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "response='Given the vectors \\\\( \\\\mathbf{v}_1 = (3, -2, 5) \\\\) and \\\\( \\\\mathbf{v}_2 = (1, 4, -1) \\\\), compute the dot product \\\\( \\\\mathbf{v}_1 \\\\cdot \\\\mathbf{v}_2 \\\\). To compute the dot product of two vectors \\\\(\\\\mathbf{v}_1 = (3, -2, 5)\\\\) and \\\\(\\\\mathbf{v}_2 = (1, 4, -1)\\\\), we use the formula for the dot product of two vectors in three-dimensional space:\\n\\n\\\\[\\n\\\\mathbf{v}_1 \\\\cdot \\\\mathbf{v}_2 = v_1 \\\\cdot v_2 = v_1_1 \\\\cdot v_2_1 + v_1_2 \\\\cdot v_2_2 + v_1_3 \\\\cdot v_2_3\\n\\\\]\\n\\nHere, the components of the vectors are:\\n\\\\[\\nv_1_1 = 3, \\\\quad v_1_2 = -2, \\\\quad v_1_3 = 5\\n\\\\]\\n\\\\[\\nv_2_1 = 1, \\\\quad v_2_2 = 4, \\\\quad v_2_3 = -1\\n\\\\]\\n\\nSubstituting these values into the formula, we get:\\n\\\\[\\n\\\\mathbf{v}_1 \\\\cdot \\\\mathbf{v}_2 = (3)(1) + (-2)(4) + (5)(-1)\\n\\\\]\\n\\nNow, we perform the multiplications:\\n\\\\[\\n(3)(1) = 3\\n\\\\]\\n\\\\[\\n(-2)(4) = -8\\n\\\\]\\n\\\\[\\n(5)(-1) = -5\\n\\\\]\\n\\nAdding these results together gives:\\n\\\\[\\n3 + (-8) + (-5) = 3 - 8 - 5 = -10\\n\\\\]\\n\\nTherefore, the dot product of \\\\(\\\\mathbf{v}_1\\\\) and \\\\(\\\\mathbf{v}_2\\\\) is \\\\(\\\\boxed{-10}\\\\).<|endoftext|>'\n",
      "lora model\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "response_lora=\"Given the vectors \\\\( \\\\mathbf{v}_1 = (3, -2, 5) \\\\) and \\\\( \\\\mathbf{v}_2 = (1, 4, -1) \\\\), compute the dot product \\\\( \\\\mathbf{v}_1 \\\\cdot \\\\mathbf{v}_2 \\\\). To find the dot product of two vectors \\\\(\\\\mathbf{v}_1 = (3, -2, 5)\\\\) and \\\\(\\\\mathbf{v}_2 = (1, 4, -1)\\\\), we use the formula for the dot product of two vectors in three-dimensional space:\\n\\n\\\\[\\n\\\\mathbf{v}_1 \\\\cdot \\\\mathbf{v}_2 = v_1 \\\\cdot v_2 = 3 \\\\cdot 1 + (-2) \\\\cdot 4 + 5 \\\\cdot (-1)\\n\\\\]\\n\\nLet's calculate this step by step using Python.\\n```python\\n# Define the vectors\\nv1 = (3, -2, 5)\\nv2 = (1, 4, -1)\\n\\n# Calculate the dot product\\ndot_product = v1[0] * v2[0] + v1[1] * v2[1] + v1[2] * v2[2]\\nprint(dot_product)\\n```\\n```output\\n-10\\n```\\nThe dot product of the vectors \\\\(\\\\mathbf{v}_1 = (3, -2, 5)\\\\) and \\\\(\\\\mathbf{v}_2 = (1, 4, -1)\\\\) is \\\\(\\\\boxed{-10}\\\\).<|endoftext|>\"\n",
      "---------------\n",
      "Find the derivative of the function \\( f(x) = 3x^4 - 5x^3 + 2x - 7 \\) with respect to \\( x \\).\n",
      "base model\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "response=\"Find the derivative of the function \\\\( f(x) = 3x^4 - 5x^3 + 2x - 7 \\\\) with respect to \\\\( x \\\\). To find the derivative of the function \\\\( f(x) = 3x^4 - 5x^3 + 2x - 7 \\\\) with respect to \\\\( x \\\\), we will apply the power rule to each term of the function. The power rule states that if \\\\( f(x) = x^n \\\\), then \\\\( f'(x) = nx^{n-1} \\\\).\\n\\nLet's break it down term by term:\\n\\n1. For the term \\\\( 3x^4 \\\\):\\n   \\\\[\\n   \\\\frac{d}{dx}(3x^4) = 3 \\\\cdot 4x^{4-1} = 12x^3\\n   \\\\]\\n\\n2. For the term \\\\( -5x^3 \\\\):\\n   \\\\[\\n   \\\\frac{d}{dx}(-5x^3) = -5 \\\\cdot 3x^{3-1} = -15x^2\\n   \\\\]\\n\\n3. For the term \\\\( 2x \\\\):\\n   \\\\[\\n   \\\\frac{d}{dx}(2x) = 2 \\\\cdot 1x^{1-1} = 2\\n   \\\\]\\n\\n4. For the constant term \\\\( -7 \\\\):\\n   \\\\[\\n   \\\\frac{d}{dx}(-7) = 0\\n   \\\\]\\n\\nNow, we combine the derivatives of all the terms:\\n\\\\[\\nf'(x) = 12x^3 - 15x^2 + 2\\n\\\\]\\n\\nTherefore, the derivative of the function \\\\( f(x) = 3x^4 - 5x^3 + 2x - 7 \\\\) with respect to \\\\( x \\\\) is \\\\(\\\\boxed{12x^3 - 15x^2 + 2}\\\\).<|endoftext|>\"\n",
      "lora model\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "response_lora=\"Find the derivative of the function \\\\( f(x) = 3x^4 - 5x^3 + 2x - 7 \\\\) with respect to \\\\( x \\\\). To find the derivative of the function \\\\( f(x) = 3x^4 - 5x^3 + 2x - 7 \\\\) with respect to \\\\( x \\\\), we will apply the power rule to each term. The power rule states that if \\\\( f(x) = x^n \\\\), then \\\\( f'(x) = nx^{n-1} \\\\).\\n\\nLet's break down the function and apply the power rule to each term:\\n\\n1. For the term \\\\( 3x^4 \\\\):\\n   \\\\[\\n   \\\\frac{d}{dx}(3x^4) = 3 \\\\cdot 4x^{4-1} = 12x^3\\n   \\\\]\\n\\n2. For the term \\\\( -5x^3 \\\\):\\n   \\\\[\\n   \\\\frac{d}{dx}(-5x^3) = -5 \\\\cdot 3x^{3-1} = -15x^2\\n   \\\\]\\n\\n3. For the term \\\\( 2x \\\\):\\n   \\\\[\\n   \\\\frac{d}{dx}(2x) = 2 \\\\cdot 1x^{1-1} = 2\\n   \\\\]\\n\\n4. For the constant term \\\\( -7 \\\\):\\n   \\\\[\\n   \\\\frac{d}{dx}(-7) = 0\\n   \\\\]\\n\\nNow, we combine the derivatives of each term to get the derivative of the entire function:\\n\\\\[\\nf'(x) = 12x^3 - 15x^2 + 2\\n\\\\]\\n\\nThus, the derivative of the function \\\\( f(x) = 3x^4 - 5x^3 + 2x - 7 \\\\) with respect to \\\\( x \\\\) is \\\\(\\\\boxed{12x^3 - 15x^2 + 2}\\\\).<|endoftext|>\"\n",
      "---------------\n",
      "Find the area of a triangle with vertices at points \\( (1, 2) \\), \\( (4, 6) \\), and \\( (7, 2) \\).\n",
      "base model\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "Setting `pad_token_id` to `eos_token_id`:151643 for open-end generation.\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "response='Find the area of a triangle with vertices at points \\\\( (1, 2) \\\\), \\\\( (4, 6) \\\\), and \\\\( (7, 2) \\\\). To find the area of a triangle with vertices at points \\\\((1, 2)\\\\), \\\\((4, 6)\\\\), and \\\\((7, 2)\\\\), we can use the formula for the area of a triangle given its vertices \\\\((x_1, y_1)\\\\), \\\\((x_2, y_2)\\\\), and \\\\((x_3, y_3)\\\\):\\n\\n\\\\[\\n\\\\text{Area} = \\\\frac{1}{2} \\\\left| x_1(y_2 - y_3) + x_2(y_3 - y_1) + x_3(y_1 - y_2) \\\\right|\\n\\\\]\\n\\nSubstituting the coordinates of the vertices \\\\((1, 2)\\\\), \\\\((4, 6)\\\\), and \\\\((7, 2)\\\\) into the formula, we get:\\n\\n\\\\[\\n\\\\text{Area} = \\\\frac{1}{2} \\\\left| 1(6 - 2) + 4(2 - 2) + 7(2 - 6) \\\\right|\\n\\\\]\\n\\nSimplifying inside the absolute value:\\n\\n\\\\[\\n\\\\text{Area} = \\\\frac{1}{2} \\\\left| 1 \\\\cdot 4 + 4 \\\\cdot 0 + 7 \\\\cdot (-4) \\\\right| = \\\\frac{1}{2} \\\\left| 4 + 0 - 28 \\\\right| = \\\\frac{1}{2} \\\\left| -24 \\\\right| = \\\\frac{1}{2} \\\\cdot 24 = 12\\n\\\\]\\n\\nThus, the area of the triangle is \\\\(\\\\boxed{12}\\\\).<|endoftext|>'\n",
      "lora model\n",
      "response_lora=\"Find the area of a triangle with vertices at points \\\\( (1, 2) \\\\), \\\\( (4, 6) \\\\), and \\\\( (7, 2) \\\\). To find the area of a triangle with vertices at points \\\\((x_1, y_1)\\\\), \\\\((x_2, y_2)\\\\), and \\\\((x_3, y_3)\\\\), we can use the following formula:\\n\\n\\\\[\\n\\\\text{Area} = \\\\frac{1}{2} \\\\left| x_1(y_2 - y_3) + x_2(y_3 - y_1) + x_3(y_1 - y_2) \\\\right|\\n\\\\]\\n\\nGiven the vertices \\\\((1, 2)\\\\), \\\\((4, 6)\\\\), and \\\\((7, 2)\\\\), we can substitute these coordinates into the formula:\\n\\n\\\\[\\n\\\\text{Area} = \\\\frac{1}{2} \\\\left| 1(6 - 2) + 4(2 - 2) + 7(2 - 6) \\\\right|\\n\\\\]\\n\\nSimplify the expression inside the absolute value:\\n\\n\\\\[\\n\\\\text{Area} = \\\\frac{1}{2} \\\\left| 1 \\\\cdot 4 + 4 \\\\cdot 0 + 7 \\\\cdot (-4) \\\\right| = \\\\frac{1}{2} \\\\left| 4 - 28 \\\\right| = \\\\frac{1}{2} \\\\left| -24 \\\\right| = \\\\frac{1}{2} \\\\cdot 24 = 12\\n\\\\]\\n\\nThus, the area of the triangle is \\\\(12\\\\). Let's confirm this with Python code.\\n```python\\n# Define the vertices\\nx1, y1 = 1, 2\\nx2, y2 = 4, 6\\nx3, y3 = 7, 2\\n\\n# Calculate the area using the formula\\narea = 0.5 * abs(x1*(y2 - y3) + x2*(y3 - y1) + x3*(y1 - y2))\\nprint(area)\\n```\\n```output\\n12.0\\n```\\nThe area of the triangle with vertices at points \\\\((1, 2)\\\\), \\\\((4, 6)\\\\), and \\\\((7, 2)\\\\) is \\\\(\\\\boxed{12}\\\\).<|endoftext|>\"\n",
      "---------------\n"
     ]
    }
   ],
   "source": [
    "import warnings\n",
    "\n",
    "# Suppress all warnings\n",
    "warnings.filterwarnings(\"ignore\")\n",
    "\n",
    "# The last three problems are generated by GPT-4o\n",
    "texts = ['Which is bigger? 9.9 or 9.11',\n",
    "         'How many r\\'s in the word strawberry?',\n",
    "         'Given the vectors \\( \\mathbf{v}_1 = (3, -2, 5) \\) and \\( \\mathbf{v}_2 = (1, 4, -1) \\), compute the dot product \\( \\mathbf{v}_1 \\cdot \\mathbf{v}_2 \\).',\n",
    "         'Find the derivative of the function \\( f(x) = 3x^4 - 5x^3 + 2x - 7 \\) with respect to \\( x \\).',\n",
    "         'Find the area of a triangle with vertices at points \\( (1, 2) \\), \\( (4, 6) \\), and \\( (7, 2) \\).'\n",
    "         ]\n",
    "for t in texts:\n",
    "    print(t)\n",
    "    inputs = tokenizer([t], return_tensors='pt').to(device)\n",
    "\n",
    "    print('base model')\n",
    "    outputs = base.generate(**inputs)\n",
    "    response = tokenizer.decode(outputs[0], max_new_tokens=128)\n",
    "    print(f'{response=}')\n",
    "\n",
    "    print('lora model')\n",
    "\n",
    "    outputs_lora = lora.generate(**inputs)\n",
    "    response_lora = tokenizer.decode(outputs_lora[0], max_new_tokens=128)\n",
    "    print(f'{response_lora=}')\n",
    "    print('---------------')"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "llama_factory",
   "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.10.14"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}