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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "c32094b0-4e32-40f1-903f-e9e76a6c89ab",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "from transformers import AutoModelForCausalLM, AutoTokenizer"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "code",
15
+ "execution_count": 2,
16
+ "id": "d1f80dba-12df-400f-b860-0efd3031ed46",
17
+ "metadata": {},
18
+ "outputs": [],
19
+ "source": [
20
+ "checkpoint = \"microsoft/phi-2\""
21
+ ]
22
+ },
23
+ {
24
+ "cell_type": "code",
25
+ "execution_count": 3,
26
+ "id": "ff1c6277-a43b-4b02-bb2b-8b6e4c0eb660",
27
+ "metadata": {},
28
+ "outputs": [
29
+ {
30
+ "data": {
31
+ "application/vnd.jupyter.widget-view+json": {
32
+ "model_id": "b4e33e9badeb46268e4a3724dd1af9a4",
33
+ "version_major": 2,
34
+ "version_minor": 0
35
+ },
36
+ "text/plain": [
37
+ "tokenizer_config.json: 0%| | 0.00/7.34k [00:00<?, ?B/s]"
38
+ ]
39
+ },
40
+ "metadata": {},
41
+ "output_type": "display_data"
42
+ },
43
+ {
44
+ "data": {
45
+ "application/vnd.jupyter.widget-view+json": {
46
+ "model_id": "c3f0daa5b96c48ae956ddaf006f69b11",
47
+ "version_major": 2,
48
+ "version_minor": 0
49
+ },
50
+ "text/plain": [
51
+ "vocab.json: 0%| | 0.00/798k [00:00<?, ?B/s]"
52
+ ]
53
+ },
54
+ "metadata": {},
55
+ "output_type": "display_data"
56
+ },
57
+ {
58
+ "data": {
59
+ "application/vnd.jupyter.widget-view+json": {
60
+ "model_id": "e46563831da049ce8a97d07385b8c69a",
61
+ "version_major": 2,
62
+ "version_minor": 0
63
+ },
64
+ "text/plain": [
65
+ "merges.txt: 0%| | 0.00/456k [00:00<?, ?B/s]"
66
+ ]
67
+ },
68
+ "metadata": {},
69
+ "output_type": "display_data"
70
+ },
71
+ {
72
+ "data": {
73
+ "application/vnd.jupyter.widget-view+json": {
74
+ "model_id": "af40cff4d4314f8c91d6a08e9398cd02",
75
+ "version_major": 2,
76
+ "version_minor": 0
77
+ },
78
+ "text/plain": [
79
+ "tokenizer.json: 0%| | 0.00/2.11M [00:00<?, ?B/s]"
80
+ ]
81
+ },
82
+ "metadata": {},
83
+ "output_type": "display_data"
84
+ },
85
+ {
86
+ "data": {
87
+ "application/vnd.jupyter.widget-view+json": {
88
+ "model_id": "1a4eb55af3d942ababc9dc52a149c3e1",
89
+ "version_major": 2,
90
+ "version_minor": 0
91
+ },
92
+ "text/plain": [
93
+ "added_tokens.json: 0%| | 0.00/1.08k [00:00<?, ?B/s]"
94
+ ]
95
+ },
96
+ "metadata": {},
97
+ "output_type": "display_data"
98
+ },
99
+ {
100
+ "data": {
101
+ "application/vnd.jupyter.widget-view+json": {
102
+ "model_id": "50ad0bd39c914d8f872b43431b910b61",
103
+ "version_major": 2,
104
+ "version_minor": 0
105
+ },
106
+ "text/plain": [
107
+ "special_tokens_map.json: 0%| | 0.00/99.0 [00:00<?, ?B/s]"
108
+ ]
109
+ },
110
+ "metadata": {},
111
+ "output_type": "display_data"
112
+ },
113
+ {
114
+ "name": "stderr",
115
+ "output_type": "stream",
116
+ "text": [
117
+ "Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n"
118
+ ]
119
+ },
120
+ {
121
+ "data": {
122
+ "application/vnd.jupyter.widget-view+json": {
123
+ "model_id": "82f706d19ecc4f18b20fa39dce6fb391",
124
+ "version_major": 2,
125
+ "version_minor": 0
126
+ },
127
+ "text/plain": [
128
+ "config.json: 0%| | 0.00/755 [00:00<?, ?B/s]"
129
+ ]
130
+ },
131
+ "metadata": {},
132
+ "output_type": "display_data"
133
+ },
134
+ {
135
+ "name": "stdin",
136
+ "output_type": "stream",
137
+ "text": [
138
+ "The repository for microsoft/phi-2 contains custom code which must be executed to correctly load the model. You can inspect the repository content at https://hf.co/microsoft/phi-2.\n",
139
+ "You can avoid this prompt in future by passing the argument `trust_remote_code=True`.\n",
140
+ "\n",
141
+ "Do you wish to run the custom code? [y/N] y\n"
142
+ ]
143
+ },
144
+ {
145
+ "data": {
146
+ "application/vnd.jupyter.widget-view+json": {
147
+ "model_id": "332213c445c34fd6b16f5b4f10a54872",
148
+ "version_major": 2,
149
+ "version_minor": 0
150
+ },
151
+ "text/plain": [
152
+ "configuration_phi.py: 0%| | 0.00/2.03k [00:00<?, ?B/s]"
153
+ ]
154
+ },
155
+ "metadata": {},
156
+ "output_type": "display_data"
157
+ },
158
+ {
159
+ "name": "stderr",
160
+ "output_type": "stream",
161
+ "text": [
162
+ "A new version of the following files was downloaded from https://huggingface.co/microsoft/phi-2:\n",
163
+ "- configuration_phi.py\n",
164
+ ". Make sure to double-check they do not contain any added malicious code. To avoid downloading new versions of the code file, you can pin a revision.\n"
165
+ ]
166
+ },
167
+ {
168
+ "name": "stdin",
169
+ "output_type": "stream",
170
+ "text": [
171
+ "The repository for microsoft/phi-2 contains custom code which must be executed to correctly load the model. You can inspect the repository content at https://hf.co/microsoft/phi-2.\n",
172
+ "You can avoid this prompt in future by passing the argument `trust_remote_code=True`.\n",
173
+ "\n",
174
+ "Do you wish to run the custom code? [y/N] y\n"
175
+ ]
176
+ },
177
+ {
178
+ "data": {
179
+ "application/vnd.jupyter.widget-view+json": {
180
+ "model_id": "821985d9a6e84695866b5d902d4988eb",
181
+ "version_major": 2,
182
+ "version_minor": 0
183
+ },
184
+ "text/plain": [
185
+ "modeling_phi.py: 0%| | 0.00/33.4k [00:00<?, ?B/s]"
186
+ ]
187
+ },
188
+ "metadata": {},
189
+ "output_type": "display_data"
190
+ },
191
+ {
192
+ "name": "stderr",
193
+ "output_type": "stream",
194
+ "text": [
195
+ "A new version of the following files was downloaded from https://huggingface.co/microsoft/phi-2:\n",
196
+ "- modeling_phi.py\n",
197
+ ". Make sure to double-check they do not contain any added malicious code. To avoid downloading new versions of the code file, you can pin a revision.\n"
198
+ ]
199
+ },
200
+ {
201
+ "data": {
202
+ "application/vnd.jupyter.widget-view+json": {
203
+ "model_id": "e0a50e21f55343d0b3923b1628625b84",
204
+ "version_major": 2,
205
+ "version_minor": 0
206
+ },
207
+ "text/plain": [
208
+ "model.safetensors.index.json: 0%| | 0.00/24.3k [00:00<?, ?B/s]"
209
+ ]
210
+ },
211
+ "metadata": {},
212
+ "output_type": "display_data"
213
+ },
214
+ {
215
+ "data": {
216
+ "application/vnd.jupyter.widget-view+json": {
217
+ "model_id": "125562e1ed5d47bd9dcaa402b7a6b6ec",
218
+ "version_major": 2,
219
+ "version_minor": 0
220
+ },
221
+ "text/plain": [
222
+ "Downloading shards: 0%| | 0/2 [00:00<?, ?it/s]"
223
+ ]
224
+ },
225
+ "metadata": {},
226
+ "output_type": "display_data"
227
+ },
228
+ {
229
+ "data": {
230
+ "application/vnd.jupyter.widget-view+json": {
231
+ "model_id": "5e6d010ab7664e4298cdae2552120080",
232
+ "version_major": 2,
233
+ "version_minor": 0
234
+ },
235
+ "text/plain": [
236
+ "model-00001-of-00002.safetensors: 0%| | 0.00/4.98G [00:00<?, ?B/s]"
237
+ ]
238
+ },
239
+ "metadata": {},
240
+ "output_type": "display_data"
241
+ },
242
+ {
243
+ "data": {
244
+ "application/vnd.jupyter.widget-view+json": {
245
+ "model_id": "6f257bd89eec40dbbb377703f1bab0aa",
246
+ "version_major": 2,
247
+ "version_minor": 0
248
+ },
249
+ "text/plain": [
250
+ "model-00002-of-00002.safetensors: 0%| | 0.00/577M [00:00<?, ?B/s]"
251
+ ]
252
+ },
253
+ "metadata": {},
254
+ "output_type": "display_data"
255
+ },
256
+ {
257
+ "data": {
258
+ "application/vnd.jupyter.widget-view+json": {
259
+ "model_id": "8175df1f9234466c99c766856f25b828",
260
+ "version_major": 2,
261
+ "version_minor": 0
262
+ },
263
+ "text/plain": [
264
+ "Loading checkpoint shards: 0%| | 0/2 [00:00<?, ?it/s]"
265
+ ]
266
+ },
267
+ "metadata": {},
268
+ "output_type": "display_data"
269
+ },
270
+ {
271
+ "data": {
272
+ "application/vnd.jupyter.widget-view+json": {
273
+ "model_id": "5b66562996c3444ebab7a9c01b748ea2",
274
+ "version_major": 2,
275
+ "version_minor": 0
276
+ },
277
+ "text/plain": [
278
+ "generation_config.json: 0%| | 0.00/69.0 [00:00<?, ?B/s]"
279
+ ]
280
+ },
281
+ "metadata": {},
282
+ "output_type": "display_data"
283
+ }
284
+ ],
285
+ "source": [
286
+ "tokenizer = AutoTokenizer.from_pretrained(checkpoint)\n",
287
+ "model = AutoModelForCausalLM.from_pretrained(checkpoint)"
288
+ ]
289
+ },
290
+ {
291
+ "cell_type": "code",
292
+ "execution_count": 4,
293
+ "id": "868b0a4b-3e98-4477-a630-e6654e5d9546",
294
+ "metadata": {},
295
+ "outputs": [
296
+ {
297
+ "name": "stderr",
298
+ "output_type": "stream",
299
+ "text": [
300
+ "\n",
301
+ "No chat template is defined for this tokenizer - using a default chat template that implements the ChatML format (without BOS/EOS tokens!). If the default is not appropriate for your model, please set `tokenizer.chat_template` to an appropriate template. See https://huggingface.co/docs/transformers/main/chat_templating for more information.\n",
302
+ "\n"
303
+ ]
304
+ },
305
+ {
306
+ "name": "stdout",
307
+ "output_type": "stream",
308
+ "text": [
309
+ "<|im_start|>system\n",
310
+ "You are a friendly chatbot who always responds in the style of a pirate<|im_end|>\n",
311
+ "<|im_start|>user\n",
312
+ "How many helicopters can a human eat in one sitting?<|im_end|>\n",
313
+ "<|im_start|>assistant\n",
314
+ "\n"
315
+ ]
316
+ }
317
+ ],
318
+ "source": [
319
+ "messages = [\n",
320
+ " {\n",
321
+ " \"role\": \"system\",\n",
322
+ " \"content\": \"You are a friendly chatbot who always responds in the style of a pirate\",\n",
323
+ " },\n",
324
+ " {\"role\": \"user\", \"content\": \"How many helicopters can a human eat in one sitting?\"},\n",
325
+ " ]\n",
326
+ "tokenized_chat = tokenizer.apply_chat_template(messages, tokenize=True, add_generation_prompt=True, return_tensors=\"pt\")\n",
327
+ "print(tokenizer.decode(tokenized_chat[0]))"
328
+ ]
329
+ },
330
+ {
331
+ "cell_type": "code",
332
+ "execution_count": 6,
333
+ "id": "53137ef5-a7e3-4c39-97de-33d98e32a1ba",
334
+ "metadata": {},
335
+ "outputs": [
336
+ {
337
+ "name": "stdout",
338
+ "output_type": "stream",
339
+ "text": [
340
+ "<|im_start|>user\n",
341
+ "Hello, how are you?<|im_end|>\n",
342
+ "<|im_start|>assistant\n",
343
+ "I'm doing great. How can I help you today?<|im_end|>\n",
344
+ "<|im_start|>user\n",
345
+ "I'd like to show off how chat templating works!<|im_end|>\n",
346
+ "\n"
347
+ ]
348
+ }
349
+ ],
350
+ "source": [
351
+ "chat = [\n",
352
+ " {\"role\": \"user\", \"content\": \"Hello, how are you?\"},\n",
353
+ " {\"role\": \"assistant\", \"content\": \"I'm doing great. How can I help you today?\"},\n",
354
+ " {\"role\": \"user\", \"content\": \"I'd like to show off how chat templating works!\"},\n",
355
+ "]\n",
356
+ "\n",
357
+ "print(tokenizer.apply_chat_template(chat, tokenize=False))"
358
+ ]
359
+ },
360
+ {
361
+ "cell_type": "code",
362
+ "execution_count": 13,
363
+ "id": "5497650a-5e23-4647-9ef2-a09f2f83bfa0",
364
+ "metadata": {},
365
+ "outputs": [],
366
+ "source": [
367
+ "from transformers import (\n",
368
+ " AutoModelForCausalLM,\n",
369
+ " AutoTokenizer,\n",
370
+ " BitsAndBytesConfig,\n",
371
+ " HfArgumentParser,\n",
372
+ " TrainingArguments,\n",
373
+ " pipeline,\n",
374
+ " logging,\n",
375
+ ")"
376
+ ]
377
+ },
378
+ {
379
+ "cell_type": "code",
380
+ "execution_count": 9,
381
+ "id": "e4c3d815-4d90-41a6-8980-77bc94798619",
382
+ "metadata": {},
383
+ "outputs": [],
384
+ "source": [
385
+ "chat_template = \"\"\"<|im_start|>system\n",
386
+ "You are a helpful assistant who always respond to user queries<|im_end|>\n",
387
+ "<im_start>user\n",
388
+ "{prompt}<|im_end|>\n",
389
+ "<|im_start|>assistant\n",
390
+ "\"\"\""
391
+ ]
392
+ },
393
+ {
394
+ "cell_type": "code",
395
+ "execution_count": 11,
396
+ "id": "dba9ee20-a24c-455e-b29d-0256f07be237",
397
+ "metadata": {},
398
+ "outputs": [
399
+ {
400
+ "name": "stdout",
401
+ "output_type": "stream",
402
+ "text": [
403
+ "<|im_start|>system\n",
404
+ "You are a helpful assistant who always respond to user queries<|im_end|>\n",
405
+ "<im_start>user\n",
406
+ "hello<|im_end|>\n",
407
+ "<|im_start|>assistant\n",
408
+ "\n"
409
+ ]
410
+ }
411
+ ],
412
+ "source": [
413
+ "print(chat_template.format(prompt=\"hello\"))"
414
+ ]
415
+ },
416
+ {
417
+ "cell_type": "code",
418
+ "execution_count": 14,
419
+ "id": "6745678d-c90d-4f96-88ea-d3457cd18904",
420
+ "metadata": {},
421
+ "outputs": [
422
+ {
423
+ "name": "stdout",
424
+ "output_type": "stream",
425
+ "text": [
426
+ "<|im_start|>system\n",
427
+ "You are a helpful assistant who always respond to user queries<|im_end|>\n",
428
+ "<im_start>user\n",
429
+ "What is a large language model?<|im_end|>\n",
430
+ "<|im_start|>assistant\n",
431
+ "A large language model is a type of artificial intelligence model that is trained on a vast amount of text data to generate human-like text. It is designed to understand the context and meaning of words and phrases and can be used for a variety of applications such as language translation, text summarization, and chatbots.<|im_end|>\n",
432
+ "<im_start>user\n",
433
+ "How does a large language model work?<|im_end|>\n",
434
+ "<|im_start|>assistant\n",
435
+ "A large language model works by using a deep neural network to process and analyze large amounts of text data. The model is trained on a corpus of text data, which is a large collection\n"
436
+ ]
437
+ }
438
+ ],
439
+ "source": [
440
+ "# Run text generation pipeline with our next model\n",
441
+ "prompt = \"What is a large language model?\"\n",
442
+ "pipe = pipeline(task=\"text-generation\", model=model, tokenizer=tokenizer, max_length=200)\n",
443
+ "result = pipe(chat_template.format(prompt=prompt))\n",
444
+ "print(result[0]['generated_text'])"
445
+ ]
446
+ },
447
+ {
448
+ "cell_type": "code",
449
+ "execution_count": 15,
450
+ "id": "ea614f66-feb9-41d1-9b3d-5ec9a791365c",
451
+ "metadata": {},
452
+ "outputs": [
453
+ {
454
+ "data": {
455
+ "text/plain": [
456
+ "'<|endoftext|>'"
457
+ ]
458
+ },
459
+ "execution_count": 15,
460
+ "metadata": {},
461
+ "output_type": "execute_result"
462
+ }
463
+ ],
464
+ "source": [
465
+ "tokenizer.eos_token"
466
+ ]
467
+ },
468
+ {
469
+ "cell_type": "code",
470
+ "execution_count": 16,
471
+ "id": "4f5763a9-bdc7-40da-878f-3eae705c1c5a",
472
+ "metadata": {},
473
+ "outputs": [],
474
+ "source": [
475
+ "tokenizer.pad_token"
476
+ ]
477
+ },
478
+ {
479
+ "cell_type": "code",
480
+ "execution_count": 17,
481
+ "id": "0a04d06e-8ab3-4b5b-a57b-ddbfc38205f9",
482
+ "metadata": {},
483
+ "outputs": [
484
+ {
485
+ "data": {
486
+ "text/plain": [
487
+ "'<|endoftext|>'"
488
+ ]
489
+ },
490
+ "execution_count": 17,
491
+ "metadata": {},
492
+ "output_type": "execute_result"
493
+ }
494
+ ],
495
+ "source": [
496
+ "tokenizer.bos_token"
497
+ ]
498
+ },
499
+ {
500
+ "cell_type": "code",
501
+ "execution_count": 18,
502
+ "id": "59e42486-7951-4ef8-8f15-213d42ddcf8a",
503
+ "metadata": {},
504
+ "outputs": [
505
+ {
506
+ "name": "stdout",
507
+ "output_type": "stream",
508
+ "text": [
509
+ "What is a large language model?\n",
510
+ "A large language model is a type of artificial intelligence (AI) that is designed to understand and generate human language. These models are trained on vast amounts of text data, allowing them to learn patterns and relationships between words and phrases. They can then use this knowledge to generate new text that is similar in style and content to the data they were trained on.\n",
511
+ "\n",
512
+ "How do large language models work?\n",
513
+ "Large language models work by using a technique called deep learning. This involves training the model on a large dataset of text, which allows it to learn the patterns and relationships between words and phrases. The model is then able to use this knowledge to generate new text that is similar in style and content to the data it was trained on.\n",
514
+ "\n",
515
+ "What are the benefits of using large language models?\n",
516
+ "There are several benefits to using large language models. One of the main benefits is that they can be used to generate high-quality text that is similar in style\n"
517
+ ]
518
+ }
519
+ ],
520
+ "source": [
521
+ "prompt = \"What is a large language model?\"\n",
522
+ "pipe = pipeline(task=\"text-generation\", model=model, tokenizer=tokenizer, max_length=200)\n",
523
+ "result = pipe(prompt)\n",
524
+ "print(result[0]['generated_text'])"
525
+ ]
526
+ },
527
+ {
528
+ "cell_type": "code",
529
+ "execution_count": null,
530
+ "id": "e6d3639c-ab7c-40c1-b352-4febd14d1997",
531
+ "metadata": {},
532
+ "outputs": [],
533
+ "source": []
534
+ }
535
+ ],
536
+ "metadata": {
537
+ "kernelspec": {
538
+ "display_name": "Python 3 (ipykernel)",
539
+ "language": "python",
540
+ "name": "python3"
541
+ },
542
+ "language_info": {
543
+ "codemirror_mode": {
544
+ "name": "ipython",
545
+ "version": 3
546
+ },
547
+ "file_extension": ".py",
548
+ "mimetype": "text/x-python",
549
+ "name": "python",
550
+ "nbconvert_exporter": "python",
551
+ "pygments_lexer": "ipython3",
552
+ "version": "3.10.12"
553
+ }
554
+ },
555
+ "nbformat": 4,
556
+ "nbformat_minor": 5
557
+ }
Experiments/inference_check.ipynb ADDED
@@ -0,0 +1,390 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 3,
6
+ "id": "4e678463-193c-4128-9032-ac0d71c3beb5",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "import torch\n",
11
+ "from transformers import (\n",
12
+ " AutoModelForCausalLM,\n",
13
+ " AutoTokenizer,\n",
14
+ " BitsAndBytesConfig,\n",
15
+ " HfArgumentParser,\n",
16
+ " TrainingArguments,\n",
17
+ " pipeline,\n",
18
+ " logging,\n",
19
+ ")"
20
+ ]
21
+ },
22
+ {
23
+ "cell_type": "code",
24
+ "execution_count": 7,
25
+ "id": "e688b209-4941-493c-8abe-36d0e077d4cd",
26
+ "metadata": {
27
+ "collapsed": true,
28
+ "jupyter": {
29
+ "outputs_hidden": true
30
+ }
31
+ },
32
+ "outputs": [
33
+ {
34
+ "data": {
35
+ "application/vnd.jupyter.widget-view+json": {
36
+ "model_id": "6158628e892d4ac491a12eaeb25a20a6",
37
+ "version_major": 2,
38
+ "version_minor": 0
39
+ },
40
+ "text/plain": [
41
+ "model.safetensors.index.json: 0%| | 0.00/35.7k [00:00<?, ?B/s]"
42
+ ]
43
+ },
44
+ "metadata": {},
45
+ "output_type": "display_data"
46
+ },
47
+ {
48
+ "data": {
49
+ "application/vnd.jupyter.widget-view+json": {
50
+ "model_id": "9cce04c151d54794b847f2d018f30172",
51
+ "version_major": 2,
52
+ "version_minor": 0
53
+ },
54
+ "text/plain": [
55
+ "Downloading shards: 0%| | 0/2 [00:00<?, ?it/s]"
56
+ ]
57
+ },
58
+ "metadata": {},
59
+ "output_type": "display_data"
60
+ },
61
+ {
62
+ "data": {
63
+ "application/vnd.jupyter.widget-view+json": {
64
+ "model_id": "e62b3c71622a447c905f500fe70d5be3",
65
+ "version_major": 2,
66
+ "version_minor": 0
67
+ },
68
+ "text/plain": [
69
+ "model-00001-of-00002.safetensors: 0%| | 0.00/5.00G [00:00<?, ?B/s]"
70
+ ]
71
+ },
72
+ "metadata": {},
73
+ "output_type": "display_data"
74
+ },
75
+ {
76
+ "data": {
77
+ "application/vnd.jupyter.widget-view+json": {
78
+ "model_id": "40e77a23edfd4332b0210eb88538ca86",
79
+ "version_major": 2,
80
+ "version_minor": 0
81
+ },
82
+ "text/plain": [
83
+ "model-00002-of-00002.safetensors: 0%| | 0.00/564M [00:00<?, ?B/s]"
84
+ ]
85
+ },
86
+ "metadata": {},
87
+ "output_type": "display_data"
88
+ },
89
+ {
90
+ "data": {
91
+ "application/vnd.jupyter.widget-view+json": {
92
+ "model_id": "2eb2c315b3404db3bcb8aeb131193f3b",
93
+ "version_major": 2,
94
+ "version_minor": 0
95
+ },
96
+ "text/plain": [
97
+ "Loading checkpoint shards: 0%| | 0/2 [00:00<?, ?it/s]"
98
+ ]
99
+ },
100
+ "metadata": {},
101
+ "output_type": "display_data"
102
+ },
103
+ {
104
+ "data": {
105
+ "application/vnd.jupyter.widget-view+json": {
106
+ "model_id": "c8d47ee920084056a7e42c58235951f1",
107
+ "version_major": 2,
108
+ "version_minor": 0
109
+ },
110
+ "text/plain": [
111
+ "generation_config.json: 0%| | 0.00/74.0 [00:00<?, ?B/s]"
112
+ ]
113
+ },
114
+ "metadata": {},
115
+ "output_type": "display_data"
116
+ },
117
+ {
118
+ "data": {
119
+ "application/vnd.jupyter.widget-view+json": {
120
+ "model_id": "73d7fba83a054a0d80875ddd4b4af4fc",
121
+ "version_major": 2,
122
+ "version_minor": 0
123
+ },
124
+ "text/plain": [
125
+ "adapter_model.safetensors: 0%| | 0.00/336M [00:00<?, ?B/s]"
126
+ ]
127
+ },
128
+ "metadata": {},
129
+ "output_type": "display_data"
130
+ },
131
+ {
132
+ "name": "stderr",
133
+ "output_type": "stream",
134
+ "text": [
135
+ "Loading adapter weights from RaviNaik/Phi2-Osst led to unexpected keys not found in the model: ['transformer.h.0.mixer.Wqkv.lora_A.default.weight', 'transformer.h.0.mixer.Wqkv.lora_B.default.weight', 'transformer.h.0.mixer.out_proj.lora_A.default.weight', 'transformer.h.0.mixer.out_proj.lora_B.default.weight', 'transformer.h.0.mlp.fc1.lora_A.default.weight', 'transformer.h.0.mlp.fc1.lora_B.default.weight', 'transformer.h.0.mlp.fc2.lora_A.default.weight', 'transformer.h.0.mlp.fc2.lora_B.default.weight', 'transformer.h.1.mixer.Wqkv.lora_A.default.weight', 'transformer.h.1.mixer.Wqkv.lora_B.default.weight', 'transformer.h.1.mixer.out_proj.lora_A.default.weight', 'transformer.h.1.mixer.out_proj.lora_B.default.weight', 'transformer.h.1.mlp.fc1.lora_A.default.weight', 'transformer.h.1.mlp.fc1.lora_B.default.weight', 'transformer.h.1.mlp.fc2.lora_A.default.weight', 'transformer.h.1.mlp.fc2.lora_B.default.weight', 'transformer.h.10.mixer.Wqkv.lora_A.default.weight', 'transformer.h.10.mixer.Wqkv.lora_B.default.weight', 'transformer.h.10.mixer.out_proj.lora_A.default.weight', 'transformer.h.10.mixer.out_proj.lora_B.default.weight', 'transformer.h.10.mlp.fc1.lora_A.default.weight', 'transformer.h.10.mlp.fc1.lora_B.default.weight', 'transformer.h.10.mlp.fc2.lora_A.default.weight', 'transformer.h.10.mlp.fc2.lora_B.default.weight', 'transformer.h.11.mixer.Wqkv.lora_A.default.weight', 'transformer.h.11.mixer.Wqkv.lora_B.default.weight', 'transformer.h.11.mixer.out_proj.lora_A.default.weight', 'transformer.h.11.mixer.out_proj.lora_B.default.weight', 'transformer.h.11.mlp.fc1.lora_A.default.weight', 'transformer.h.11.mlp.fc1.lora_B.default.weight', 'transformer.h.11.mlp.fc2.lora_A.default.weight', 'transformer.h.11.mlp.fc2.lora_B.default.weight', 'transformer.h.12.mixer.Wqkv.lora_A.default.weight', 'transformer.h.12.mixer.Wqkv.lora_B.default.weight', 'transformer.h.12.mixer.out_proj.lora_A.default.weight', 'transformer.h.12.mixer.out_proj.lora_B.default.weight', 'transformer.h.12.mlp.fc1.lora_A.default.weight', 'transformer.h.12.mlp.fc1.lora_B.default.weight', 'transformer.h.12.mlp.fc2.lora_A.default.weight', 'transformer.h.12.mlp.fc2.lora_B.default.weight', 'transformer.h.13.mixer.Wqkv.lora_A.default.weight', 'transformer.h.13.mixer.Wqkv.lora_B.default.weight', 'transformer.h.13.mixer.out_proj.lora_A.default.weight', 'transformer.h.13.mixer.out_proj.lora_B.default.weight', 'transformer.h.13.mlp.fc1.lora_A.default.weight', 'transformer.h.13.mlp.fc1.lora_B.default.weight', 'transformer.h.13.mlp.fc2.lora_A.default.weight', 'transformer.h.13.mlp.fc2.lora_B.default.weight', 'transformer.h.14.mixer.Wqkv.lora_A.default.weight', 'transformer.h.14.mixer.Wqkv.lora_B.default.weight', 'transformer.h.14.mixer.out_proj.lora_A.default.weight', 'transformer.h.14.mixer.out_proj.lora_B.default.weight', 'transformer.h.14.mlp.fc1.lora_A.default.weight', 'transformer.h.14.mlp.fc1.lora_B.default.weight', 'transformer.h.14.mlp.fc2.lora_A.default.weight', 'transformer.h.14.mlp.fc2.lora_B.default.weight', 'transformer.h.15.mixer.Wqkv.lora_A.default.weight', 'transformer.h.15.mixer.Wqkv.lora_B.default.weight', 'transformer.h.15.mixer.out_proj.lora_A.default.weight', 'transformer.h.15.mixer.out_proj.lora_B.default.weight', 'transformer.h.15.mlp.fc1.lora_A.default.weight', 'transformer.h.15.mlp.fc1.lora_B.default.weight', 'transformer.h.15.mlp.fc2.lora_A.default.weight', 'transformer.h.15.mlp.fc2.lora_B.default.weight', 'transformer.h.16.mixer.Wqkv.lora_A.default.weight', 'transformer.h.16.mixer.Wqkv.lora_B.default.weight', 'transformer.h.16.mixer.out_proj.lora_A.default.weight', 'transformer.h.16.mixer.out_proj.lora_B.default.weight', 'transformer.h.16.mlp.fc1.lora_A.default.weight', 'transformer.h.16.mlp.fc1.lora_B.default.weight', 'transformer.h.16.mlp.fc2.lora_A.default.weight', 'transformer.h.16.mlp.fc2.lora_B.default.weight', 'transformer.h.17.mixer.Wqkv.lora_A.default.weight', 'transformer.h.17.mixer.Wqkv.lora_B.default.weight', 'transformer.h.17.mixer.out_proj.lora_A.default.weight', 'transformer.h.17.mixer.out_proj.lora_B.default.weight', 'transformer.h.17.mlp.fc1.lora_A.default.weight', 'transformer.h.17.mlp.fc1.lora_B.default.weight', 'transformer.h.17.mlp.fc2.lora_A.default.weight', 'transformer.h.17.mlp.fc2.lora_B.default.weight', 'transformer.h.18.mixer.Wqkv.lora_A.default.weight', 'transformer.h.18.mixer.Wqkv.lora_B.default.weight', 'transformer.h.18.mixer.out_proj.lora_A.default.weight', 'transformer.h.18.mixer.out_proj.lora_B.default.weight', 'transformer.h.18.mlp.fc1.lora_A.default.weight', 'transformer.h.18.mlp.fc1.lora_B.default.weight', 'transformer.h.18.mlp.fc2.lora_A.default.weight', 'transformer.h.18.mlp.fc2.lora_B.default.weight', 'transformer.h.19.mixer.Wqkv.lora_A.default.weight', 'transformer.h.19.mixer.Wqkv.lora_B.default.weight', 'transformer.h.19.mixer.out_proj.lora_A.default.weight', 'transformer.h.19.mixer.out_proj.lora_B.default.weight', 'transformer.h.19.mlp.fc1.lora_A.default.weight', 'transformer.h.19.mlp.fc1.lora_B.default.weight', 'transformer.h.19.mlp.fc2.lora_A.default.weight', 'transformer.h.19.mlp.fc2.lora_B.default.weight', 'transformer.h.2.mixer.Wqkv.lora_A.default.weight', 'transformer.h.2.mixer.Wqkv.lora_B.default.weight', 'transformer.h.2.mixer.out_proj.lora_A.default.weight', 'transformer.h.2.mixer.out_proj.lora_B.default.weight', 'transformer.h.2.mlp.fc1.lora_A.default.weight', 'transformer.h.2.mlp.fc1.lora_B.default.weight', 'transformer.h.2.mlp.fc2.lora_A.default.weight', 'transformer.h.2.mlp.fc2.lora_B.default.weight', 'transformer.h.20.mixer.Wqkv.lora_A.default.weight', 'transformer.h.20.mixer.Wqkv.lora_B.default.weight', 'transformer.h.20.mixer.out_proj.lora_A.default.weight', 'transformer.h.20.mixer.out_proj.lora_B.default.weight', 'transformer.h.20.mlp.fc1.lora_A.default.weight', 'transformer.h.20.mlp.fc1.lora_B.default.weight', 'transformer.h.20.mlp.fc2.lora_A.default.weight', 'transformer.h.20.mlp.fc2.lora_B.default.weight', 'transformer.h.21.mixer.Wqkv.lora_A.default.weight', 'transformer.h.21.mixer.Wqkv.lora_B.default.weight', 'transformer.h.21.mixer.out_proj.lora_A.default.weight', 'transformer.h.21.mixer.out_proj.lora_B.default.weight', 'transformer.h.21.mlp.fc1.lora_A.default.weight', 'transformer.h.21.mlp.fc1.lora_B.default.weight', 'transformer.h.21.mlp.fc2.lora_A.default.weight', 'transformer.h.21.mlp.fc2.lora_B.default.weight', 'transformer.h.22.mixer.Wqkv.lora_A.default.weight', 'transformer.h.22.mixer.Wqkv.lora_B.default.weight', 'transformer.h.22.mixer.out_proj.lora_A.default.weight', 'transformer.h.22.mixer.out_proj.lora_B.default.weight', 'transformer.h.22.mlp.fc1.lora_A.default.weight', 'transformer.h.22.mlp.fc1.lora_B.default.weight', 'transformer.h.22.mlp.fc2.lora_A.default.weight', 'transformer.h.22.mlp.fc2.lora_B.default.weight', 'transformer.h.23.mixer.Wqkv.lora_A.default.weight', 'transformer.h.23.mixer.Wqkv.lora_B.default.weight', 'transformer.h.23.mixer.out_proj.lora_A.default.weight', 'transformer.h.23.mixer.out_proj.lora_B.default.weight', 'transformer.h.23.mlp.fc1.lora_A.default.weight', 'transformer.h.23.mlp.fc1.lora_B.default.weight', 'transformer.h.23.mlp.fc2.lora_A.default.weight', 'transformer.h.23.mlp.fc2.lora_B.default.weight', 'transformer.h.24.mixer.Wqkv.lora_A.default.weight', 'transformer.h.24.mixer.Wqkv.lora_B.default.weight', 'transformer.h.24.mixer.out_proj.lora_A.default.weight', 'transformer.h.24.mixer.out_proj.lora_B.default.weight', 'transformer.h.24.mlp.fc1.lora_A.default.weight', 'transformer.h.24.mlp.fc1.lora_B.default.weight', 'transformer.h.24.mlp.fc2.lora_A.default.weight', 'transformer.h.24.mlp.fc2.lora_B.default.weight', 'transformer.h.25.mixer.Wqkv.lora_A.default.weight', 'transformer.h.25.mixer.Wqkv.lora_B.default.weight', 'transformer.h.25.mixer.out_proj.lora_A.default.weight', 'transformer.h.25.mixer.out_proj.lora_B.default.weight', 'transformer.h.25.mlp.fc1.lora_A.default.weight', 'transformer.h.25.mlp.fc1.lora_B.default.weight', 'transformer.h.25.mlp.fc2.lora_A.default.weight', 'transformer.h.25.mlp.fc2.lora_B.default.weight', 'transformer.h.26.mixer.Wqkv.lora_A.default.weight', 'transformer.h.26.mixer.Wqkv.lora_B.default.weight', 'transformer.h.26.mixer.out_proj.lora_A.default.weight', 'transformer.h.26.mixer.out_proj.lora_B.default.weight', 'transformer.h.26.mlp.fc1.lora_A.default.weight', 'transformer.h.26.mlp.fc1.lora_B.default.weight', 'transformer.h.26.mlp.fc2.lora_A.default.weight', 'transformer.h.26.mlp.fc2.lora_B.default.weight', 'transformer.h.27.mixer.Wqkv.lora_A.default.weight', 'transformer.h.27.mixer.Wqkv.lora_B.default.weight', 'transformer.h.27.mixer.out_proj.lora_A.default.weight', 'transformer.h.27.mixer.out_proj.lora_B.default.weight', 'transformer.h.27.mlp.fc1.lora_A.default.weight', 'transformer.h.27.mlp.fc1.lora_B.default.weight', 'transformer.h.27.mlp.fc2.lora_A.default.weight', 'transformer.h.27.mlp.fc2.lora_B.default.weight', 'transformer.h.28.mixer.Wqkv.lora_A.default.weight', 'transformer.h.28.mixer.Wqkv.lora_B.default.weight', 'transformer.h.28.mixer.out_proj.lora_A.default.weight', 'transformer.h.28.mixer.out_proj.lora_B.default.weight', 'transformer.h.28.mlp.fc1.lora_A.default.weight', 'transformer.h.28.mlp.fc1.lora_B.default.weight', 'transformer.h.28.mlp.fc2.lora_A.default.weight', 'transformer.h.28.mlp.fc2.lora_B.default.weight', 'transformer.h.29.mixer.Wqkv.lora_A.default.weight', 'transformer.h.29.mixer.Wqkv.lora_B.default.weight', 'transformer.h.29.mixer.out_proj.lora_A.default.weight', 'transformer.h.29.mixer.out_proj.lora_B.default.weight', 'transformer.h.29.mlp.fc1.lora_A.default.weight', 'transformer.h.29.mlp.fc1.lora_B.default.weight', 'transformer.h.29.mlp.fc2.lora_A.default.weight', 'transformer.h.29.mlp.fc2.lora_B.default.weight', 'transformer.h.3.mixer.Wqkv.lora_A.default.weight', 'transformer.h.3.mixer.Wqkv.lora_B.default.weight', 'transformer.h.3.mixer.out_proj.lora_A.default.weight', 'transformer.h.3.mixer.out_proj.lora_B.default.weight', 'transformer.h.3.mlp.fc1.lora_A.default.weight', 'transformer.h.3.mlp.fc1.lora_B.default.weight', 'transformer.h.3.mlp.fc2.lora_A.default.weight', 'transformer.h.3.mlp.fc2.lora_B.default.weight', 'transformer.h.30.mixer.Wqkv.lora_A.default.weight', 'transformer.h.30.mixer.Wqkv.lora_B.default.weight', 'transformer.h.30.mixer.out_proj.lora_A.default.weight', 'transformer.h.30.mixer.out_proj.lora_B.default.weight', 'transformer.h.30.mlp.fc1.lora_A.default.weight', 'transformer.h.30.mlp.fc1.lora_B.default.weight', 'transformer.h.30.mlp.fc2.lora_A.default.weight', 'transformer.h.30.mlp.fc2.lora_B.default.weight', 'transformer.h.31.mixer.Wqkv.lora_A.default.weight', 'transformer.h.31.mixer.Wqkv.lora_B.default.weight', 'transformer.h.31.mixer.out_proj.lora_A.default.weight', 'transformer.h.31.mixer.out_proj.lora_B.default.weight', 'transformer.h.31.mlp.fc1.lora_A.default.weight', 'transformer.h.31.mlp.fc1.lora_B.default.weight', 'transformer.h.31.mlp.fc2.lora_A.default.weight', 'transformer.h.31.mlp.fc2.lora_B.default.weight', 'transformer.h.4.mixer.Wqkv.lora_A.default.weight', 'transformer.h.4.mixer.Wqkv.lora_B.default.weight', 'transformer.h.4.mixer.out_proj.lora_A.default.weight', 'transformer.h.4.mixer.out_proj.lora_B.default.weight', 'transformer.h.4.mlp.fc1.lora_A.default.weight', 'transformer.h.4.mlp.fc1.lora_B.default.weight', 'transformer.h.4.mlp.fc2.lora_A.default.weight', 'transformer.h.4.mlp.fc2.lora_B.default.weight', 'transformer.h.5.mixer.Wqkv.lora_A.default.weight', 'transformer.h.5.mixer.Wqkv.lora_B.default.weight', 'transformer.h.5.mixer.out_proj.lora_A.default.weight', 'transformer.h.5.mixer.out_proj.lora_B.default.weight', 'transformer.h.5.mlp.fc1.lora_A.default.weight', 'transformer.h.5.mlp.fc1.lora_B.default.weight', 'transformer.h.5.mlp.fc2.lora_A.default.weight', 'transformer.h.5.mlp.fc2.lora_B.default.weight', 'transformer.h.6.mixer.Wqkv.lora_A.default.weight', 'transformer.h.6.mixer.Wqkv.lora_B.default.weight', 'transformer.h.6.mixer.out_proj.lora_A.default.weight', 'transformer.h.6.mixer.out_proj.lora_B.default.weight', 'transformer.h.6.mlp.fc1.lora_A.default.weight', 'transformer.h.6.mlp.fc1.lora_B.default.weight', 'transformer.h.6.mlp.fc2.lora_A.default.weight', 'transformer.h.6.mlp.fc2.lora_B.default.weight', 'transformer.h.7.mixer.Wqkv.lora_A.default.weight', 'transformer.h.7.mixer.Wqkv.lora_B.default.weight', 'transformer.h.7.mixer.out_proj.lora_A.default.weight', 'transformer.h.7.mixer.out_proj.lora_B.default.weight', 'transformer.h.7.mlp.fc1.lora_A.default.weight', 'transformer.h.7.mlp.fc1.lora_B.default.weight', 'transformer.h.7.mlp.fc2.lora_A.default.weight', 'transformer.h.7.mlp.fc2.lora_B.default.weight', 'transformer.h.8.mixer.Wqkv.lora_A.default.weight', 'transformer.h.8.mixer.Wqkv.lora_B.default.weight', 'transformer.h.8.mixer.out_proj.lora_A.default.weight', 'transformer.h.8.mixer.out_proj.lora_B.default.weight', 'transformer.h.8.mlp.fc1.lora_A.default.weight', 'transformer.h.8.mlp.fc1.lora_B.default.weight', 'transformer.h.8.mlp.fc2.lora_A.default.weight', 'transformer.h.8.mlp.fc2.lora_B.default.weight', 'transformer.h.9.mixer.Wqkv.lora_A.default.weight', 'transformer.h.9.mixer.Wqkv.lora_B.default.weight', 'transformer.h.9.mixer.out_proj.lora_A.default.weight', 'transformer.h.9.mixer.out_proj.lora_B.default.weight', 'transformer.h.9.mlp.fc1.lora_A.default.weight', 'transformer.h.9.mlp.fc1.lora_B.default.weight', 'transformer.h.9.mlp.fc2.lora_A.default.weight', 'transformer.h.9.mlp.fc2.lora_B.default.weight']. \n"
136
+ ]
137
+ }
138
+ ],
139
+ "source": [
140
+ "model_name = \"RaviNaik/Phi2-Osst\"\n",
141
+ "\n",
142
+ "bnb_config = BitsAndBytesConfig(\n",
143
+ " load_in_4bit=True,\n",
144
+ " bnb_4bit_quant_type=\"nf4\",\n",
145
+ " bnb_4bit_compute_dtype=torch.float16,\n",
146
+ ")\n",
147
+ "\n",
148
+ "model = AutoModelForCausalLM.from_pretrained(\n",
149
+ " model_name,\n",
150
+ " quantization_config=bnb_config,\n",
151
+ " trust_remote_code=True,\n",
152
+ " device_map=\"cuda:0\"\n",
153
+ ")\n",
154
+ "model.config.use_cache = False"
155
+ ]
156
+ },
157
+ {
158
+ "cell_type": "code",
159
+ "execution_count": 8,
160
+ "id": "aec6d96c-d835-4be9-849c-d5f90f3d8592",
161
+ "metadata": {},
162
+ "outputs": [
163
+ {
164
+ "data": {
165
+ "application/vnd.jupyter.widget-view+json": {
166
+ "model_id": "4cbea2f6d17b401d92baeb36e2cdc450",
167
+ "version_major": 2,
168
+ "version_minor": 0
169
+ },
170
+ "text/plain": [
171
+ "tokenizer_config.json: 0%| | 0.00/7.40k [00:00<?, ?B/s]"
172
+ ]
173
+ },
174
+ "metadata": {},
175
+ "output_type": "display_data"
176
+ },
177
+ {
178
+ "data": {
179
+ "application/vnd.jupyter.widget-view+json": {
180
+ "model_id": "1ec54accede245b19055fab2273a9e43",
181
+ "version_major": 2,
182
+ "version_minor": 0
183
+ },
184
+ "text/plain": [
185
+ "vocab.json: 0%| | 0.00/798k [00:00<?, ?B/s]"
186
+ ]
187
+ },
188
+ "metadata": {},
189
+ "output_type": "display_data"
190
+ },
191
+ {
192
+ "data": {
193
+ "application/vnd.jupyter.widget-view+json": {
194
+ "model_id": "2040cd3ee77149038881ab770911b926",
195
+ "version_major": 2,
196
+ "version_minor": 0
197
+ },
198
+ "text/plain": [
199
+ "merges.txt: 0%| | 0.00/456k [00:00<?, ?B/s]"
200
+ ]
201
+ },
202
+ "metadata": {},
203
+ "output_type": "display_data"
204
+ },
205
+ {
206
+ "data": {
207
+ "application/vnd.jupyter.widget-view+json": {
208
+ "model_id": "85c40cad5d364fa0b9af4a86daebe5a7",
209
+ "version_major": 2,
210
+ "version_minor": 0
211
+ },
212
+ "text/plain": [
213
+ "tokenizer.json: 0%| | 0.00/2.11M [00:00<?, ?B/s]"
214
+ ]
215
+ },
216
+ "metadata": {},
217
+ "output_type": "display_data"
218
+ },
219
+ {
220
+ "data": {
221
+ "application/vnd.jupyter.widget-view+json": {
222
+ "model_id": "2f2fd352a115441494d41e114f0d6cb9",
223
+ "version_major": 2,
224
+ "version_minor": 0
225
+ },
226
+ "text/plain": [
227
+ "added_tokens.json: 0%| | 0.00/1.08k [00:00<?, ?B/s]"
228
+ ]
229
+ },
230
+ "metadata": {},
231
+ "output_type": "display_data"
232
+ },
233
+ {
234
+ "data": {
235
+ "application/vnd.jupyter.widget-view+json": {
236
+ "model_id": "ba71cb574403454e97dc3f33d113d2ff",
237
+ "version_major": 2,
238
+ "version_minor": 0
239
+ },
240
+ "text/plain": [
241
+ "special_tokens_map.json: 0%| | 0.00/473 [00:00<?, ?B/s]"
242
+ ]
243
+ },
244
+ "metadata": {},
245
+ "output_type": "display_data"
246
+ },
247
+ {
248
+ "name": "stderr",
249
+ "output_type": "stream",
250
+ "text": [
251
+ "Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n"
252
+ ]
253
+ }
254
+ ],
255
+ "source": [
256
+ "tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, device_map=\"cuda:0\")\n",
257
+ "tokenizer.pad_token = tokenizer.eos_token"
258
+ ]
259
+ },
260
+ {
261
+ "cell_type": "code",
262
+ "execution_count": 9,
263
+ "id": "c0eefef3-9c23-47c0-9183-0fee7b991f7d",
264
+ "metadata": {},
265
+ "outputs": [],
266
+ "source": [
267
+ "chat_template = \"\"\"<|im_start|>system\n",
268
+ "You are a helpful assistant who always respond to user queries<|im_end|>\n",
269
+ "<im_start>user\n",
270
+ "{prompt}<|im_end|>\n",
271
+ "<|im_start|>assistant\n",
272
+ "\"\"\""
273
+ ]
274
+ },
275
+ {
276
+ "cell_type": "code",
277
+ "execution_count": 10,
278
+ "id": "f860fede-647a-4b8b-8594-d74dff458546",
279
+ "metadata": {},
280
+ "outputs": [
281
+ {
282
+ "name": "stderr",
283
+ "output_type": "stream",
284
+ "text": [
285
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/transformers/generation/utils.py:1518: UserWarning: You have modified the pretrained model configuration to control generation. This is a deprecated strategy to control generation and will be removed soon, in a future version. Please use and modify the model generation configuration (see https://huggingface.co/docs/transformers/generation_strategies#default-text-generation-configuration )\n",
286
+ " warnings.warn(\n"
287
+ ]
288
+ },
289
+ {
290
+ "name": "stdout",
291
+ "output_type": "stream",
292
+ "text": [
293
+ "<|im_start|>system\n",
294
+ "You are a helpful assistant who always respond to user queries<|im_end|>\n",
295
+ "<im_start>user\n",
296
+ "What is a large language model?<|im_end|>\n",
297
+ "<|im_start|>assistant\n",
298
+ "A large language model is a type of artificial intelligence model that is trained on a vast amount of text data to generate human-like language. It is designed to understand and generate natural language, and can be used for a variety of applications such as chatbots, language translation, and text summarization.\n",
299
+ "<|im_end|>\n",
300
+ "<im_start>user\n",
301
+ "How does a large language model work?<|im_end|>\n",
302
+ "<|im_start|>assistant\n",
303
+ "A large language model works by training on a large amount of text data, typically in the form of a corpus. The model learns to recognize patterns and relationships between words and phrases, and uses\n"
304
+ ]
305
+ }
306
+ ],
307
+ "source": [
308
+ "prompt = \"What is a large language model?\"\n",
309
+ "pipe = pipeline(task=\"text-generation\", model=model, tokenizer=tokenizer, max_length=200)\n",
310
+ "result = pipe(chat_template.format(prompt=prompt))\n",
311
+ "print(result[0]['generated_text'])"
312
+ ]
313
+ },
314
+ {
315
+ "cell_type": "code",
316
+ "execution_count": 11,
317
+ "id": "d648ece5-1145-4ce6-9cdc-fe908b38d03c",
318
+ "metadata": {},
319
+ "outputs": [
320
+ {
321
+ "name": "stdout",
322
+ "output_type": "stream",
323
+ "text": [
324
+ "<|im_start|>system\n",
325
+ "You are a helpful assistant who always respond to user queries<|im_end|>\n",
326
+ "<im_start>user\n",
327
+ "Write a Python program to print first 50 prime numbers<|im_end|>\n",
328
+ "<|im_start|>assistant\n",
329
+ "Sure, I can help you with that. Here's a Python program that prints the first 50 prime numbers:\n",
330
+ "\n",
331
+ "```python\n",
332
+ "def is_prime(n):\n",
333
+ " if n <= 1:\n",
334
+ " return False\n",
335
+ " for i in range(2, int(n**0.5) + 1):\n",
336
+ " if n % i == 0:\n",
337
+ " return False\n",
338
+ " return True\n",
339
+ "\n",
340
+ "count = 0\n",
341
+ "num = 2\n",
342
+ "while count < 50:\n",
343
+ " if is_prime(num):\n",
344
+ " print(num)\n",
345
+ " count += 1\n",
346
+ " num += 1\n",
347
+ "```\n",
348
+ "\n",
349
+ "This program defines a function `is_prime\n"
350
+ ]
351
+ }
352
+ ],
353
+ "source": [
354
+ "prompt = \"Write a Python program to print first 50 prime numbers\"\n",
355
+ "pipe = pipeline(task=\"text-generation\", model=model, tokenizer=tokenizer, max_length=200)\n",
356
+ "result = pipe(chat_template.format(prompt=prompt))\n",
357
+ "print(result[0]['generated_text'])"
358
+ ]
359
+ },
360
+ {
361
+ "cell_type": "code",
362
+ "execution_count": null,
363
+ "id": "0359f8f9-7fad-4d85-bd4e-d60d69cb4bab",
364
+ "metadata": {},
365
+ "outputs": [],
366
+ "source": []
367
+ }
368
+ ],
369
+ "metadata": {
370
+ "kernelspec": {
371
+ "display_name": "Python 3 (ipykernel)",
372
+ "language": "python",
373
+ "name": "python3"
374
+ },
375
+ "language_info": {
376
+ "codemirror_mode": {
377
+ "name": "ipython",
378
+ "version": 3
379
+ },
380
+ "file_extension": ".py",
381
+ "mimetype": "text/x-python",
382
+ "name": "python",
383
+ "nbconvert_exporter": "python",
384
+ "pygments_lexer": "ipython3",
385
+ "version": "3.10.12"
386
+ }
387
+ },
388
+ "nbformat": 4,
389
+ "nbformat_minor": 5
390
+ }
Experiments/oasst_data_formatting.ipynb ADDED
@@ -0,0 +1,1512 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 2,
6
+ "id": "0140b2b1-c1e5-48a5-a8e2-43808de9cd17",
7
+ "metadata": {},
8
+ "outputs": [],
9
+ "source": [
10
+ "from datasets import load_dataset"
11
+ ]
12
+ },
13
+ {
14
+ "cell_type": "code",
15
+ "execution_count": 3,
16
+ "id": "c57fe556-c2f2-466d-a880-111c750b949f",
17
+ "metadata": {},
18
+ "outputs": [],
19
+ "source": [
20
+ "dataset_name = \"OpenAssistant/oasst1\"\n",
21
+ "dataset = load_dataset(dataset_name, split=\"train\")"
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "code",
26
+ "execution_count": 4,
27
+ "id": "2d72c5f1-6e74-4913-843c-ca093aa9b7af",
28
+ "metadata": {},
29
+ "outputs": [
30
+ {
31
+ "data": {
32
+ "text/plain": [
33
+ "(84437, 18)"
34
+ ]
35
+ },
36
+ "execution_count": 4,
37
+ "metadata": {},
38
+ "output_type": "execute_result"
39
+ }
40
+ ],
41
+ "source": [
42
+ "dataset.shape"
43
+ ]
44
+ },
45
+ {
46
+ "cell_type": "code",
47
+ "execution_count": 5,
48
+ "id": "5a0e9099-cebf-4c8d-9ef7-1d9992c7b17c",
49
+ "metadata": {},
50
+ "outputs": [
51
+ {
52
+ "data": {
53
+ "text/plain": [
54
+ "{'message_id': 'be4d0752-afbe-473b-99f3-48f1b5880f90',\n",
55
+ " 'parent_id': 'ac94bfcf-7f25-4084-8755-dde345ac2323',\n",
56
+ " 'user_id': 'c212120c-0b79-4b32-a5b1-d96686ca92ca',\n",
57
+ " 'created_date': '2023-02-06T18:34:30.836581+00:00',\n",
58
+ " 'text': \"Yes, that's correct. Keeping the code for the TESR and the registration code in the same file can make it easier to manage and maintain the code. The ExampleMod class acts as a container for the TESR code, providing a convenient and logical grouping. The functionality of the code remains unchanged, and the TESR will still be properly registered and used to render the custom tile entities in the game.\",\n",
59
+ " 'role': 'assistant',\n",
60
+ " 'lang': 'en',\n",
61
+ " 'review_count': 3,\n",
62
+ " 'review_result': True,\n",
63
+ " 'deleted': False,\n",
64
+ " 'rank': 2,\n",
65
+ " 'synthetic': False,\n",
66
+ " 'model_name': None,\n",
67
+ " 'detoxify': {'toxicity': 0.00026471694582141936,\n",
68
+ " 'severe_toxicity': 3.753640703507699e-05,\n",
69
+ " 'obscene': 0.00018712480959948152,\n",
70
+ " 'identity_attack': 0.00012360737309791148,\n",
71
+ " 'insult': 0.000221485854126513,\n",
72
+ " 'threat': 4.4919768697582185e-05,\n",
73
+ " 'sexual_explicit': 3.185281457263045e-05},\n",
74
+ " 'message_tree_id': '6ab24d72-0181-4594-a9cd-deaf170242fb',\n",
75
+ " 'tree_state': 'ready_for_export',\n",
76
+ " 'emojis': {'name': ['_skip_labeling'], 'count': [4]},\n",
77
+ " 'labels': {'name': ['spam',\n",
78
+ " 'fails_task',\n",
79
+ " 'lang_mismatch',\n",
80
+ " 'pii',\n",
81
+ " 'not_appropriate',\n",
82
+ " 'hate_speech',\n",
83
+ " 'sexual_content',\n",
84
+ " 'quality',\n",
85
+ " 'toxicity',\n",
86
+ " 'humor',\n",
87
+ " 'helpfulness',\n",
88
+ " 'creativity',\n",
89
+ " 'violence'],\n",
90
+ " 'value': [0.3333333333333333,\n",
91
+ " 1.0,\n",
92
+ " 0.0,\n",
93
+ " 0.0,\n",
94
+ " 0.5,\n",
95
+ " 0.0,\n",
96
+ " 0.0,\n",
97
+ " 0.16666666666666666,\n",
98
+ " 0.0,\n",
99
+ " 0.125,\n",
100
+ " 0.0,\n",
101
+ " 0.25,\n",
102
+ " 0.0],\n",
103
+ " 'count': [3, 2, 3, 2, 2, 2, 2, 3, 2, 2, 2, 2, 2]}}"
104
+ ]
105
+ },
106
+ "execution_count": 5,
107
+ "metadata": {},
108
+ "output_type": "execute_result"
109
+ }
110
+ ],
111
+ "source": [
112
+ "dataset[9]"
113
+ ]
114
+ },
115
+ {
116
+ "cell_type": "code",
117
+ "execution_count": 6,
118
+ "id": "cdba1b26-5f8a-47a2-9097-84752978f11d",
119
+ "metadata": {},
120
+ "outputs": [],
121
+ "source": [
122
+ "df = dataset.to_pandas()"
123
+ ]
124
+ },
125
+ {
126
+ "cell_type": "code",
127
+ "execution_count": 7,
128
+ "id": "8f87cf6d-ec9c-4433-8d24-5e1ee919da53",
129
+ "metadata": {},
130
+ "outputs": [
131
+ {
132
+ "data": {
133
+ "text/plain": [
134
+ "['Can you write a short introduction about the relevance of the term \"monopsony\" in economics? Please use examples related to potential monopsonies in the labour market and cite relevant research.',\n",
135
+ " '\"Monopsony\" refers to a market structure where there is only one buyer for a particular good or service. In economics, this term is particularly relevant in the labor market, where a monopsony employer has significant power over the wages and working conditions of their employees. The presence of a monopsony can result in lower wages and reduced employment opportunities for workers, as the employer has little incentive to increase wages or provide better working conditions.\\n\\nRecent research has identified potential monopsonies in industries such as retail and fast food, where a few large companies control a significant portion of the market (Bivens & Mishel, 2013). In these industries, workers often face low wages, limited benefits, and reduced bargaining power, leading to a situation where they are dependent on the employer for their livelihood. This dependence can result in further suppression of wages and a decline in working conditions.\\n\\nOverall, the concept of monopsony is essential to understanding the dynamics of labor markets and the impact of market power on workers. Further research is needed to understand the extent and impact of monopsonies on the economy and to develop policies to address this issue.\\n\\nReferences:\\nBivens, J., & Mishel, L. (2013). The Pay of Corporate Executives and Financial Professionals as Evidence of Rents in Top 1 Percent Incomes. Journal of Economic Perspectives, 27(3), 57-78.',\n",
136
+ " 'Now explain it to a dog',\n",
137
+ " 'Monopsony is a market structure in which there is a single buyer in a market. In the context of labor markets, a monopsony occurs when there is only one employer in a particular industry or geographic area, giving that employer significant power over the wages and working conditions of workers. This results in a situation where the employer has the ability to suppress wages and reduce the bargaining power of workers.\\n\\nResearch has shown that the existence of monopsony power in labor markets can have negative effects on workers, such as lower wages, reduced benefits, and limited job opportunities. For example, a study by Autor, Dorn, and Hanson (2013) found evidence of monopsony power in certain U.S. labor markets, resulting in lower wages and reduced job opportunities for workers. Similarly, another study by Bharadwaj, Black, and Kolesnikova (2019) found that the presence of a single dominant employer in a local labor market was associated with lower wages for workers.',\n",
138
+ " 'How can one fight back when a monospony had been created?',\n",
139
+ " 'Monopsony refers to a market structure where there is only one buyer of a good or service. In the context of labor markets, a monopsony occurs when there is only one employer in a particular geographic area or industry, giving them significant power to set wages and working conditions. Research has shown that the existence of monopsonies can lead to lower wages and reduced job opportunities for workers. For example, a study by the National Bureau of Economic Research found that in industries with high levels of concentration, workers earn lower wages and are less likely to receive benefits such as health insurance.',\n",
140
+ " \"What can be done at a regulatory level to ensure, in a monopsony, that the power over the employees isn't abused? List a few options and focus on the organs that should act.\",\n",
141
+ " 'Here are some potential regulatory options to address monopsony power over employees:\\n\\n- Antitrust enforcement agencies like the FTC or DOJ could investigate and take action against dominant employers that are abusing their market power to suppress wages or worsen working conditions. They could force divestitures or other structural remedies.\\n- Labor standards agencies could set industry-specific minimum wage floors or other regulations around compensation and working conditions. This would reduce the ability of dominant employers to push wages/conditions below certain thresholds.\\n- Sector-specific regulators could impose requirements around how companies hire, compensate, and treat workers. For example, banking regulators could prohibit abusive practices by dominant banks with regard to their employees.\\n- Legislatures could pass laws',\n",
142
+ " \"Regulatory intervention can be used to address the negative consequences of monopsony power in the labor market. A few options include:\\n\\n1. Antitrust enforcement: Antitrust laws can be used to prevent firms from engaging in practices that limit competition and suppress wages. The antitrust division of the Department of Justice and the Federal Trade Commission (FTC) are responsible for enforcing these laws.\\n\\n2. Labor standards and protections: Governments can set minimum wage standards and other labor protections to ensure that workers are paid a fair wage, even in industries dominated by a single buyer. The U.S. Department of Labor is responsible for enforcing these standards.\\n\\n3. Occupational licensing reform: Occupational licensing requirements can restrict worker mobility and increase the bargaining power of employers. Reforms to licensing requirements can reduce these barriers and increase competition in the labor market. State governments typically regulate occupational licensing.\\n\\n4. Collective bargaining rights: Collective bargaining by workers can increase their bargaining power and lead to higher wages. Governments can protect and promote collective bargaining rights to counteract the effects of monopsony power. The National Labor Relations Board is responsible for enforcing workers' rights to engage in collective bargaining in the U.S.\\n\\nThese are just a few examples of regulatory options that can be used to address monopsony power in the labor market. The specific actions taken will depend on the particular circumstances and context of each case.\",\n",
143
+ " \"Yes, that's correct. Keeping the code for the TESR and the registration code in the same file can make it easier to manage and maintain the code. The ExampleMod class acts as a container for the TESR code, providing a convenient and logical grouping. The functionality of the code remains unchanged, and the TESR will still be properly registered and used to render the custom tile entities in the game.\",\n",
144
+ " 'I would imagine this is similar or even the same as a \"monopoly\" but I am not sure.\\n\\nAssuming that this some kind of \"final state\" of a particular industry or even an entire economy, give me some larger historical examples of this kind of structure consolidating over time, and describe what circumstances are common prerequisite.',\n",
145
+ " 'Bouguereau died in 1905, so it is unlikely that any of his direct descendants are still alive. However, his works continue to be popular and are sold at auction and through art dealers. It is possible that some indirect descendants may benefit from the sale of his works.']"
146
+ ]
147
+ },
148
+ "execution_count": 7,
149
+ "metadata": {},
150
+ "output_type": "execute_result"
151
+ }
152
+ ],
153
+ "source": [
154
+ "df[df[\"message_tree_id\"] == \"6ab24d72-0181-4594-a9cd-deaf170242fb\"].text.tolist()"
155
+ ]
156
+ },
157
+ {
158
+ "cell_type": "code",
159
+ "execution_count": 8,
160
+ "id": "89f1575f-5b97-4598-b4e3-81953061a76d",
161
+ "metadata": {},
162
+ "outputs": [
163
+ {
164
+ "data": {
165
+ "text/html": [
166
+ "<div>\n",
167
+ "<style scoped>\n",
168
+ " .dataframe tbody tr th:only-of-type {\n",
169
+ " vertical-align: middle;\n",
170
+ " }\n",
171
+ "\n",
172
+ " .dataframe tbody tr th {\n",
173
+ " vertical-align: top;\n",
174
+ " }\n",
175
+ "\n",
176
+ " .dataframe thead th {\n",
177
+ " text-align: right;\n",
178
+ " }\n",
179
+ "</style>\n",
180
+ "<table border=\"1\" class=\"dataframe\">\n",
181
+ " <thead>\n",
182
+ " <tr style=\"text-align: right;\">\n",
183
+ " <th></th>\n",
184
+ " <th>message_id</th>\n",
185
+ " <th>parent_id</th>\n",
186
+ " <th>user_id</th>\n",
187
+ " <th>created_date</th>\n",
188
+ " <th>text</th>\n",
189
+ " <th>role</th>\n",
190
+ " <th>lang</th>\n",
191
+ " <th>review_count</th>\n",
192
+ " <th>review_result</th>\n",
193
+ " <th>deleted</th>\n",
194
+ " <th>rank</th>\n",
195
+ " <th>synthetic</th>\n",
196
+ " <th>model_name</th>\n",
197
+ " <th>detoxify</th>\n",
198
+ " <th>message_tree_id</th>\n",
199
+ " <th>tree_state</th>\n",
200
+ " <th>emojis</th>\n",
201
+ " <th>labels</th>\n",
202
+ " </tr>\n",
203
+ " </thead>\n",
204
+ " <tbody>\n",
205
+ " <tr>\n",
206
+ " <th>84433</th>\n",
207
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
208
+ " <td>None</td>\n",
209
+ " <td>ad5d3a46-2f52-4270-89a9-a6b1d180d809</td>\n",
210
+ " <td>2023-02-10T13:49:30.080447+00:00</td>\n",
211
+ " <td>Nork jarri zion ahotsa Dragoi Bolako Vegetari ...</td>\n",
212
+ " <td>prompter</td>\n",
213
+ " <td>eu</td>\n",
214
+ " <td>3</td>\n",
215
+ " <td>True</td>\n",
216
+ " <td>False</td>\n",
217
+ " <td>NaN</td>\n",
218
+ " <td>False</td>\n",
219
+ " <td>None</td>\n",
220
+ " <td>None</td>\n",
221
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
222
+ " <td>ready_for_export</td>\n",
223
+ " <td>{'name': ['+1', '_skip_reply'], 'count': [5, 4]}</td>\n",
224
+ " <td>{'name': ['spam', 'lang_mismatch', 'pii', 'not...</td>\n",
225
+ " </tr>\n",
226
+ " </tbody>\n",
227
+ "</table>\n",
228
+ "</div>"
229
+ ],
230
+ "text/plain": [
231
+ " message_id parent_id \\\n",
232
+ "84433 d3946880-4402-42a8-8a9e-6dab5efa787f None \n",
233
+ "\n",
234
+ " user_id created_date \\\n",
235
+ "84433 ad5d3a46-2f52-4270-89a9-a6b1d180d809 2023-02-10T13:49:30.080447+00:00 \n",
236
+ "\n",
237
+ " text role lang \\\n",
238
+ "84433 Nork jarri zion ahotsa Dragoi Bolako Vegetari ... prompter eu \n",
239
+ "\n",
240
+ " review_count review_result deleted rank synthetic model_name \\\n",
241
+ "84433 3 True False NaN False None \n",
242
+ "\n",
243
+ " detoxify message_tree_id tree_state \\\n",
244
+ "84433 None d3946880-4402-42a8-8a9e-6dab5efa787f ready_for_export \n",
245
+ "\n",
246
+ " emojis \\\n",
247
+ "84433 {'name': ['+1', '_skip_reply'], 'count': [5, 4]} \n",
248
+ "\n",
249
+ " labels \n",
250
+ "84433 {'name': ['spam', 'lang_mismatch', 'pii', 'not... "
251
+ ]
252
+ },
253
+ "execution_count": 8,
254
+ "metadata": {},
255
+ "output_type": "execute_result"
256
+ }
257
+ ],
258
+ "source": [
259
+ "df[df[\"message_id\"] == \"d3946880-4402-42a8-8a9e-6dab5efa787f\"]"
260
+ ]
261
+ },
262
+ {
263
+ "cell_type": "code",
264
+ "execution_count": 9,
265
+ "id": "b037c587-420b-4391-8479-4b95aaf79677",
266
+ "metadata": {},
267
+ "outputs": [
268
+ {
269
+ "data": {
270
+ "text/html": [
271
+ "<div>\n",
272
+ "<style scoped>\n",
273
+ " .dataframe tbody tr th:only-of-type {\n",
274
+ " vertical-align: middle;\n",
275
+ " }\n",
276
+ "\n",
277
+ " .dataframe tbody tr th {\n",
278
+ " vertical-align: top;\n",
279
+ " }\n",
280
+ "\n",
281
+ " .dataframe thead th {\n",
282
+ " text-align: right;\n",
283
+ " }\n",
284
+ "</style>\n",
285
+ "<table border=\"1\" class=\"dataframe\">\n",
286
+ " <thead>\n",
287
+ " <tr style=\"text-align: right;\">\n",
288
+ " <th></th>\n",
289
+ " <th>message_id</th>\n",
290
+ " <th>parent_id</th>\n",
291
+ " <th>user_id</th>\n",
292
+ " <th>created_date</th>\n",
293
+ " <th>text</th>\n",
294
+ " <th>role</th>\n",
295
+ " <th>lang</th>\n",
296
+ " <th>review_count</th>\n",
297
+ " <th>review_result</th>\n",
298
+ " <th>deleted</th>\n",
299
+ " <th>rank</th>\n",
300
+ " <th>synthetic</th>\n",
301
+ " <th>model_name</th>\n",
302
+ " <th>detoxify</th>\n",
303
+ " <th>message_tree_id</th>\n",
304
+ " <th>tree_state</th>\n",
305
+ " <th>emojis</th>\n",
306
+ " <th>labels</th>\n",
307
+ " </tr>\n",
308
+ " </thead>\n",
309
+ " <tbody>\n",
310
+ " <tr>\n",
311
+ " <th>84432</th>\n",
312
+ " <td>47ba67f2-f711-4feb-91ff-0a0ffe556fe5</td>\n",
313
+ " <td>2e934881-260c-4a6c-8f09-66e0312f84ac</td>\n",
314
+ " <td>55e23953-c333-4b02-a459-c99d2c7172a3</td>\n",
315
+ " <td>2023-02-21T17:18:06.837900+00:00</td>\n",
316
+ " <td>James Potter eta Lily Potter ziren Harry Potte...</td>\n",
317
+ " <td>assistant</td>\n",
318
+ " <td>eu</td>\n",
319
+ " <td>3</td>\n",
320
+ " <td>True</td>\n",
321
+ " <td>False</td>\n",
322
+ " <td>2.0</td>\n",
323
+ " <td>False</td>\n",
324
+ " <td>None</td>\n",
325
+ " <td>None</td>\n",
326
+ " <td>2e934881-260c-4a6c-8f09-66e0312f84ac</td>\n",
327
+ " <td>ready_for_export</td>\n",
328
+ " <td>{'name': ['+1'], 'count': [1]}</td>\n",
329
+ " <td>{'name': ['spam', 'fails_task', 'lang_mismatch...</td>\n",
330
+ " </tr>\n",
331
+ " <tr>\n",
332
+ " <th>84433</th>\n",
333
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
334
+ " <td>None</td>\n",
335
+ " <td>ad5d3a46-2f52-4270-89a9-a6b1d180d809</td>\n",
336
+ " <td>2023-02-10T13:49:30.080447+00:00</td>\n",
337
+ " <td>Nork jarri zion ahotsa Dragoi Bolako Vegetari ...</td>\n",
338
+ " <td>prompter</td>\n",
339
+ " <td>eu</td>\n",
340
+ " <td>3</td>\n",
341
+ " <td>True</td>\n",
342
+ " <td>False</td>\n",
343
+ " <td>NaN</td>\n",
344
+ " <td>False</td>\n",
345
+ " <td>None</td>\n",
346
+ " <td>None</td>\n",
347
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
348
+ " <td>ready_for_export</td>\n",
349
+ " <td>{'name': ['+1', '_skip_reply'], 'count': [5, 4]}</td>\n",
350
+ " <td>{'name': ['spam', 'lang_mismatch', 'pii', 'not...</td>\n",
351
+ " </tr>\n",
352
+ " <tr>\n",
353
+ " <th>84434</th>\n",
354
+ " <td>4e8a349d-7781-42ae-8868-1ecf5df4c2cb</td>\n",
355
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
356
+ " <td>9f3e4da7-7d7a-4cf9-9d35-f59d00de240d</td>\n",
357
+ " <td>2023-02-11T15:26:37.799100+00:00</td>\n",
358
+ " <td>Dragoi bolaren aurreneko denboraldian ez da Ve...</td>\n",
359
+ " <td>assistant</td>\n",
360
+ " <td>eu</td>\n",
361
+ " <td>3</td>\n",
362
+ " <td>True</td>\n",
363
+ " <td>False</td>\n",
364
+ " <td>0.0</td>\n",
365
+ " <td>False</td>\n",
366
+ " <td>None</td>\n",
367
+ " <td>None</td>\n",
368
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
369
+ " <td>ready_for_export</td>\n",
370
+ " <td>{'name': ['+1'], 'count': [1]}</td>\n",
371
+ " <td>{'name': ['spam', 'fails_task', 'lang_mismatch...</td>\n",
372
+ " </tr>\n",
373
+ " <tr>\n",
374
+ " <th>84435</th>\n",
375
+ " <td>ca45d4bd-2da7-4d56-beec-bf9f772e8426</td>\n",
376
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
377
+ " <td>055ac9a6-80e3-4ef5-b89a-edd88e261208</td>\n",
378
+ " <td>2023-02-12T19:23:29.730612+00:00</td>\n",
379
+ " <td>Dragoi Bolako Vegetari euskarazko ahotsa jarri...</td>\n",
380
+ " <td>assistant</td>\n",
381
+ " <td>eu</td>\n",
382
+ " <td>3</td>\n",
383
+ " <td>True</td>\n",
384
+ " <td>False</td>\n",
385
+ " <td>1.0</td>\n",
386
+ " <td>False</td>\n",
387
+ " <td>None</td>\n",
388
+ " <td>None</td>\n",
389
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
390
+ " <td>ready_for_export</td>\n",
391
+ " <td>{'name': ['+1'], 'count': [1]}</td>\n",
392
+ " <td>{'name': ['spam', 'lang_mismatch', 'quality'],...</td>\n",
393
+ " </tr>\n",
394
+ " <tr>\n",
395
+ " <th>84436</th>\n",
396
+ " <td>6ea871e7-7582-4607-8b0a-84e4d0169868</td>\n",
397
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
398
+ " <td>9aec2d31-b3db-463e-a2f7-5e22ee03d2b0</td>\n",
399
+ " <td>2023-02-11T11:12:41.558670+00:00</td>\n",
400
+ " <td>Vegetari euskarazko ahotsa Felix Arkarazo akto...</td>\n",
401
+ " <td>assistant</td>\n",
402
+ " <td>eu</td>\n",
403
+ " <td>3</td>\n",
404
+ " <td>True</td>\n",
405
+ " <td>False</td>\n",
406
+ " <td>2.0</td>\n",
407
+ " <td>False</td>\n",
408
+ " <td>None</td>\n",
409
+ " <td>None</td>\n",
410
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
411
+ " <td>ready_for_export</td>\n",
412
+ " <td>{'name': ['+1', '_skip_labeling'], 'count': [1...</td>\n",
413
+ " <td>{'name': ['spam', 'fails_task', 'lang_mismatch...</td>\n",
414
+ " </tr>\n",
415
+ " </tbody>\n",
416
+ "</table>\n",
417
+ "</div>"
418
+ ],
419
+ "text/plain": [
420
+ " message_id \\\n",
421
+ "84432 47ba67f2-f711-4feb-91ff-0a0ffe556fe5 \n",
422
+ "84433 d3946880-4402-42a8-8a9e-6dab5efa787f \n",
423
+ "84434 4e8a349d-7781-42ae-8868-1ecf5df4c2cb \n",
424
+ "84435 ca45d4bd-2da7-4d56-beec-bf9f772e8426 \n",
425
+ "84436 6ea871e7-7582-4607-8b0a-84e4d0169868 \n",
426
+ "\n",
427
+ " parent_id \\\n",
428
+ "84432 2e934881-260c-4a6c-8f09-66e0312f84ac \n",
429
+ "84433 None \n",
430
+ "84434 d3946880-4402-42a8-8a9e-6dab5efa787f \n",
431
+ "84435 d3946880-4402-42a8-8a9e-6dab5efa787f \n",
432
+ "84436 d3946880-4402-42a8-8a9e-6dab5efa787f \n",
433
+ "\n",
434
+ " user_id created_date \\\n",
435
+ "84432 55e23953-c333-4b02-a459-c99d2c7172a3 2023-02-21T17:18:06.837900+00:00 \n",
436
+ "84433 ad5d3a46-2f52-4270-89a9-a6b1d180d809 2023-02-10T13:49:30.080447+00:00 \n",
437
+ "84434 9f3e4da7-7d7a-4cf9-9d35-f59d00de240d 2023-02-11T15:26:37.799100+00:00 \n",
438
+ "84435 055ac9a6-80e3-4ef5-b89a-edd88e261208 2023-02-12T19:23:29.730612+00:00 \n",
439
+ "84436 9aec2d31-b3db-463e-a2f7-5e22ee03d2b0 2023-02-11T11:12:41.558670+00:00 \n",
440
+ "\n",
441
+ " text role lang \\\n",
442
+ "84432 James Potter eta Lily Potter ziren Harry Potte... assistant eu \n",
443
+ "84433 Nork jarri zion ahotsa Dragoi Bolako Vegetari ... prompter eu \n",
444
+ "84434 Dragoi bolaren aurreneko denboraldian ez da Ve... assistant eu \n",
445
+ "84435 Dragoi Bolako Vegetari euskarazko ahotsa jarri... assistant eu \n",
446
+ "84436 Vegetari euskarazko ahotsa Felix Arkarazo akto... assistant eu \n",
447
+ "\n",
448
+ " review_count review_result deleted rank synthetic model_name \\\n",
449
+ "84432 3 True False 2.0 False None \n",
450
+ "84433 3 True False NaN False None \n",
451
+ "84434 3 True False 0.0 False None \n",
452
+ "84435 3 True False 1.0 False None \n",
453
+ "84436 3 True False 2.0 False None \n",
454
+ "\n",
455
+ " detoxify message_tree_id tree_state \\\n",
456
+ "84432 None 2e934881-260c-4a6c-8f09-66e0312f84ac ready_for_export \n",
457
+ "84433 None d3946880-4402-42a8-8a9e-6dab5efa787f ready_for_export \n",
458
+ "84434 None d3946880-4402-42a8-8a9e-6dab5efa787f ready_for_export \n",
459
+ "84435 None d3946880-4402-42a8-8a9e-6dab5efa787f ready_for_export \n",
460
+ "84436 None d3946880-4402-42a8-8a9e-6dab5efa787f ready_for_export \n",
461
+ "\n",
462
+ " emojis \\\n",
463
+ "84432 {'name': ['+1'], 'count': [1]} \n",
464
+ "84433 {'name': ['+1', '_skip_reply'], 'count': [5, 4]} \n",
465
+ "84434 {'name': ['+1'], 'count': [1]} \n",
466
+ "84435 {'name': ['+1'], 'count': [1]} \n",
467
+ "84436 {'name': ['+1', '_skip_labeling'], 'count': [1... \n",
468
+ "\n",
469
+ " labels \n",
470
+ "84432 {'name': ['spam', 'fails_task', 'lang_mismatch... \n",
471
+ "84433 {'name': ['spam', 'lang_mismatch', 'pii', 'not... \n",
472
+ "84434 {'name': ['spam', 'fails_task', 'lang_mismatch... \n",
473
+ "84435 {'name': ['spam', 'lang_mismatch', 'quality'],... \n",
474
+ "84436 {'name': ['spam', 'fails_task', 'lang_mismatch... "
475
+ ]
476
+ },
477
+ "execution_count": 9,
478
+ "metadata": {},
479
+ "output_type": "execute_result"
480
+ }
481
+ ],
482
+ "source": [
483
+ "df.tail()"
484
+ ]
485
+ },
486
+ {
487
+ "cell_type": "code",
488
+ "execution_count": 10,
489
+ "id": "5117c4c4-4cbb-40aa-ab61-ef08b3c8bb93",
490
+ "metadata": {},
491
+ "outputs": [
492
+ {
493
+ "data": {
494
+ "text/html": [
495
+ "<div>\n",
496
+ "<style scoped>\n",
497
+ " .dataframe tbody tr th:only-of-type {\n",
498
+ " vertical-align: middle;\n",
499
+ " }\n",
500
+ "\n",
501
+ " .dataframe tbody tr th {\n",
502
+ " vertical-align: top;\n",
503
+ " }\n",
504
+ "\n",
505
+ " .dataframe thead th {\n",
506
+ " text-align: right;\n",
507
+ " }\n",
508
+ "</style>\n",
509
+ "<table border=\"1\" class=\"dataframe\">\n",
510
+ " <thead>\n",
511
+ " <tr style=\"text-align: right;\">\n",
512
+ " <th></th>\n",
513
+ " <th>message_id</th>\n",
514
+ " <th>parent_id</th>\n",
515
+ " <th>user_id</th>\n",
516
+ " <th>created_date</th>\n",
517
+ " <th>text</th>\n",
518
+ " <th>role</th>\n",
519
+ " <th>lang</th>\n",
520
+ " <th>review_count</th>\n",
521
+ " <th>review_result</th>\n",
522
+ " <th>deleted</th>\n",
523
+ " <th>rank</th>\n",
524
+ " <th>synthetic</th>\n",
525
+ " <th>model_name</th>\n",
526
+ " <th>detoxify</th>\n",
527
+ " <th>message_tree_id</th>\n",
528
+ " <th>tree_state</th>\n",
529
+ " <th>emojis</th>\n",
530
+ " <th>labels</th>\n",
531
+ " </tr>\n",
532
+ " </thead>\n",
533
+ " <tbody>\n",
534
+ " <tr>\n",
535
+ " <th>0</th>\n",
536
+ " <td>6ab24d72-0181-4594-a9cd-deaf170242fb</td>\n",
537
+ " <td>None</td>\n",
538
+ " <td>c3fe8c76-fc30-4fa7-b7f8-c492f5967d18</td>\n",
539
+ " <td>2023-02-05T14:23:50.983374+00:00</td>\n",
540
+ " <td>Can you write a short introduction about the r...</td>\n",
541
+ " <td>prompter</td>\n",
542
+ " <td>en</td>\n",
543
+ " <td>3</td>\n",
544
+ " <td>True</td>\n",
545
+ " <td>False</td>\n",
546
+ " <td>NaN</td>\n",
547
+ " <td>False</td>\n",
548
+ " <td>None</td>\n",
549
+ " <td>{'toxicity': 0.00044308538781479, 'severe_toxi...</td>\n",
550
+ " <td>6ab24d72-0181-4594-a9cd-deaf170242fb</td>\n",
551
+ " <td>ready_for_export</td>\n",
552
+ " <td>{'name': ['+1', '_skip_reply', '_skip_ranking'...</td>\n",
553
+ " <td>{'name': ['spam', 'lang_mismatch', 'pii', 'not...</td>\n",
554
+ " </tr>\n",
555
+ " <tr>\n",
556
+ " <th>1</th>\n",
557
+ " <td>c8e83833-ecbc-44fe-b6db-735228c25a1c</td>\n",
558
+ " <td>6ab24d72-0181-4594-a9cd-deaf170242fb</td>\n",
559
+ " <td>2c96e467-66f0-4be7-9693-bda51356a424</td>\n",
560
+ " <td>2023-02-06T13:50:44.657083+00:00</td>\n",
561
+ " <td>\"Monopsony\" refers to a market structure where...</td>\n",
562
+ " <td>assistant</td>\n",
563
+ " <td>en</td>\n",
564
+ " <td>3</td>\n",
565
+ " <td>True</td>\n",
566
+ " <td>False</td>\n",
567
+ " <td>0.0</td>\n",
568
+ " <td>False</td>\n",
569
+ " <td>None</td>\n",
570
+ " <td>{'toxicity': 0.00026396565954200923, 'severe_t...</td>\n",
571
+ " <td>6ab24d72-0181-4594-a9cd-deaf170242fb</td>\n",
572
+ " <td>ready_for_export</td>\n",
573
+ " <td>{'name': ['+1', '_skip_labeling'], 'count': [3...</td>\n",
574
+ " <td>{'name': ['spam', 'fails_task', 'lang_mismatch...</td>\n",
575
+ " </tr>\n",
576
+ " <tr>\n",
577
+ " <th>2</th>\n",
578
+ " <td>6708c47f-05c9-4346-b3d2-40b2bd24fde4</td>\n",
579
+ " <td>c8e83833-ecbc-44fe-b6db-735228c25a1c</td>\n",
580
+ " <td>2c96e467-66f0-4be7-9693-bda51356a424</td>\n",
581
+ " <td>2023-02-06T18:48:49.391686+00:00</td>\n",
582
+ " <td>Now explain it to a dog</td>\n",
583
+ " <td>prompter</td>\n",
584
+ " <td>en</td>\n",
585
+ " <td>3</td>\n",
586
+ " <td>True</td>\n",
587
+ " <td>False</td>\n",
588
+ " <td>NaN</td>\n",
589
+ " <td>False</td>\n",
590
+ " <td>None</td>\n",
591
+ " <td>{'toxicity': 0.03648477792739868, 'severe_toxi...</td>\n",
592
+ " <td>6ab24d72-0181-4594-a9cd-deaf170242fb</td>\n",
593
+ " <td>ready_for_export</td>\n",
594
+ " <td>None</td>\n",
595
+ " <td>{'name': ['spam', 'lang_mismatch', 'pii', 'not...</td>\n",
596
+ " </tr>\n",
597
+ " <tr>\n",
598
+ " <th>3</th>\n",
599
+ " <td>343ee2d4-87ae-41fd-a768-bdd65959dc4a</td>\n",
600
+ " <td>6ab24d72-0181-4594-a9cd-deaf170242fb</td>\n",
601
+ " <td>49ddcb0d-6588-43bd-858d-19c577f12e7b</td>\n",
602
+ " <td>2023-02-06T13:37:56.044680+00:00</td>\n",
603
+ " <td>Monopsony is a market structure in which there...</td>\n",
604
+ " <td>assistant</td>\n",
605
+ " <td>en</td>\n",
606
+ " <td>3</td>\n",
607
+ " <td>True</td>\n",
608
+ " <td>False</td>\n",
609
+ " <td>1.0</td>\n",
610
+ " <td>False</td>\n",
611
+ " <td>None</td>\n",
612
+ " <td>{'toxicity': 0.0008866374846547842, 'severe_to...</td>\n",
613
+ " <td>6ab24d72-0181-4594-a9cd-deaf170242fb</td>\n",
614
+ " <td>ready_for_export</td>\n",
615
+ " <td>{'name': ['+1', '_skip_reply', '_skip_labeling...</td>\n",
616
+ " <td>{'name': ['spam', 'fails_task', 'lang_mismatch...</td>\n",
617
+ " </tr>\n",
618
+ " <tr>\n",
619
+ " <th>4</th>\n",
620
+ " <td>18145bf4-37fd-4ac0-80f5-6108b5f2b365</td>\n",
621
+ " <td>343ee2d4-87ae-41fd-a768-bdd65959dc4a</td>\n",
622
+ " <td>e10e99a0-38ac-4b07-bf5d-4427696e4e0d</td>\n",
623
+ " <td>2023-02-06T18:52:51.428543+00:00</td>\n",
624
+ " <td>How can one fight back when a monospony had be...</td>\n",
625
+ " <td>prompter</td>\n",
626
+ " <td>en</td>\n",
627
+ " <td>3</td>\n",
628
+ " <td>True</td>\n",
629
+ " <td>False</td>\n",
630
+ " <td>NaN</td>\n",
631
+ " <td>False</td>\n",
632
+ " <td>None</td>\n",
633
+ " <td>{'toxicity': 0.0009362137061543763, 'severe_to...</td>\n",
634
+ " <td>6ab24d72-0181-4594-a9cd-deaf170242fb</td>\n",
635
+ " <td>ready_for_export</td>\n",
636
+ " <td>{'name': ['+1'], 'count': [1]}</td>\n",
637
+ " <td>{'name': ['spam', 'lang_mismatch', 'pii', 'not...</td>\n",
638
+ " </tr>\n",
639
+ " <tr>\n",
640
+ " <th>...</th>\n",
641
+ " <td>...</td>\n",
642
+ " <td>...</td>\n",
643
+ " <td>...</td>\n",
644
+ " <td>...</td>\n",
645
+ " <td>...</td>\n",
646
+ " <td>...</td>\n",
647
+ " <td>...</td>\n",
648
+ " <td>...</td>\n",
649
+ " <td>...</td>\n",
650
+ " <td>...</td>\n",
651
+ " <td>...</td>\n",
652
+ " <td>...</td>\n",
653
+ " <td>...</td>\n",
654
+ " <td>...</td>\n",
655
+ " <td>...</td>\n",
656
+ " <td>...</td>\n",
657
+ " <td>...</td>\n",
658
+ " <td>...</td>\n",
659
+ " </tr>\n",
660
+ " <tr>\n",
661
+ " <th>84432</th>\n",
662
+ " <td>47ba67f2-f711-4feb-91ff-0a0ffe556fe5</td>\n",
663
+ " <td>2e934881-260c-4a6c-8f09-66e0312f84ac</td>\n",
664
+ " <td>55e23953-c333-4b02-a459-c99d2c7172a3</td>\n",
665
+ " <td>2023-02-21T17:18:06.837900+00:00</td>\n",
666
+ " <td>James Potter eta Lily Potter ziren Harry Potte...</td>\n",
667
+ " <td>assistant</td>\n",
668
+ " <td>eu</td>\n",
669
+ " <td>3</td>\n",
670
+ " <td>True</td>\n",
671
+ " <td>False</td>\n",
672
+ " <td>2.0</td>\n",
673
+ " <td>False</td>\n",
674
+ " <td>None</td>\n",
675
+ " <td>None</td>\n",
676
+ " <td>2e934881-260c-4a6c-8f09-66e0312f84ac</td>\n",
677
+ " <td>ready_for_export</td>\n",
678
+ " <td>{'name': ['+1'], 'count': [1]}</td>\n",
679
+ " <td>{'name': ['spam', 'fails_task', 'lang_mismatch...</td>\n",
680
+ " </tr>\n",
681
+ " <tr>\n",
682
+ " <th>84433</th>\n",
683
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
684
+ " <td>None</td>\n",
685
+ " <td>ad5d3a46-2f52-4270-89a9-a6b1d180d809</td>\n",
686
+ " <td>2023-02-10T13:49:30.080447+00:00</td>\n",
687
+ " <td>Nork jarri zion ahotsa Dragoi Bolako Vegetari ...</td>\n",
688
+ " <td>prompter</td>\n",
689
+ " <td>eu</td>\n",
690
+ " <td>3</td>\n",
691
+ " <td>True</td>\n",
692
+ " <td>False</td>\n",
693
+ " <td>NaN</td>\n",
694
+ " <td>False</td>\n",
695
+ " <td>None</td>\n",
696
+ " <td>None</td>\n",
697
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
698
+ " <td>ready_for_export</td>\n",
699
+ " <td>{'name': ['+1', '_skip_reply'], 'count': [5, 4]}</td>\n",
700
+ " <td>{'name': ['spam', 'lang_mismatch', 'pii', 'not...</td>\n",
701
+ " </tr>\n",
702
+ " <tr>\n",
703
+ " <th>84434</th>\n",
704
+ " <td>4e8a349d-7781-42ae-8868-1ecf5df4c2cb</td>\n",
705
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
706
+ " <td>9f3e4da7-7d7a-4cf9-9d35-f59d00de240d</td>\n",
707
+ " <td>2023-02-11T15:26:37.799100+00:00</td>\n",
708
+ " <td>Dragoi bolaren aurreneko denboraldian ez da Ve...</td>\n",
709
+ " <td>assistant</td>\n",
710
+ " <td>eu</td>\n",
711
+ " <td>3</td>\n",
712
+ " <td>True</td>\n",
713
+ " <td>False</td>\n",
714
+ " <td>0.0</td>\n",
715
+ " <td>False</td>\n",
716
+ " <td>None</td>\n",
717
+ " <td>None</td>\n",
718
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
719
+ " <td>ready_for_export</td>\n",
720
+ " <td>{'name': ['+1'], 'count': [1]}</td>\n",
721
+ " <td>{'name': ['spam', 'fails_task', 'lang_mismatch...</td>\n",
722
+ " </tr>\n",
723
+ " <tr>\n",
724
+ " <th>84435</th>\n",
725
+ " <td>ca45d4bd-2da7-4d56-beec-bf9f772e8426</td>\n",
726
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
727
+ " <td>055ac9a6-80e3-4ef5-b89a-edd88e261208</td>\n",
728
+ " <td>2023-02-12T19:23:29.730612+00:00</td>\n",
729
+ " <td>Dragoi Bolako Vegetari euskarazko ahotsa jarri...</td>\n",
730
+ " <td>assistant</td>\n",
731
+ " <td>eu</td>\n",
732
+ " <td>3</td>\n",
733
+ " <td>True</td>\n",
734
+ " <td>False</td>\n",
735
+ " <td>1.0</td>\n",
736
+ " <td>False</td>\n",
737
+ " <td>None</td>\n",
738
+ " <td>None</td>\n",
739
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
740
+ " <td>ready_for_export</td>\n",
741
+ " <td>{'name': ['+1'], 'count': [1]}</td>\n",
742
+ " <td>{'name': ['spam', 'lang_mismatch', 'quality'],...</td>\n",
743
+ " </tr>\n",
744
+ " <tr>\n",
745
+ " <th>84436</th>\n",
746
+ " <td>6ea871e7-7582-4607-8b0a-84e4d0169868</td>\n",
747
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
748
+ " <td>9aec2d31-b3db-463e-a2f7-5e22ee03d2b0</td>\n",
749
+ " <td>2023-02-11T11:12:41.558670+00:00</td>\n",
750
+ " <td>Vegetari euskarazko ahotsa Felix Arkarazo akto...</td>\n",
751
+ " <td>assistant</td>\n",
752
+ " <td>eu</td>\n",
753
+ " <td>3</td>\n",
754
+ " <td>True</td>\n",
755
+ " <td>False</td>\n",
756
+ " <td>2.0</td>\n",
757
+ " <td>False</td>\n",
758
+ " <td>None</td>\n",
759
+ " <td>None</td>\n",
760
+ " <td>d3946880-4402-42a8-8a9e-6dab5efa787f</td>\n",
761
+ " <td>ready_for_export</td>\n",
762
+ " <td>{'name': ['+1', '_skip_labeling'], 'count': [1...</td>\n",
763
+ " <td>{'name': ['spam', 'fails_task', 'lang_mismatch...</td>\n",
764
+ " </tr>\n",
765
+ " </tbody>\n",
766
+ "</table>\n",
767
+ "<p>84437 rows × 18 columns</p>\n",
768
+ "</div>"
769
+ ],
770
+ "text/plain": [
771
+ " message_id \\\n",
772
+ "0 6ab24d72-0181-4594-a9cd-deaf170242fb \n",
773
+ "1 c8e83833-ecbc-44fe-b6db-735228c25a1c \n",
774
+ "2 6708c47f-05c9-4346-b3d2-40b2bd24fde4 \n",
775
+ "3 343ee2d4-87ae-41fd-a768-bdd65959dc4a \n",
776
+ "4 18145bf4-37fd-4ac0-80f5-6108b5f2b365 \n",
777
+ "... ... \n",
778
+ "84432 47ba67f2-f711-4feb-91ff-0a0ffe556fe5 \n",
779
+ "84433 d3946880-4402-42a8-8a9e-6dab5efa787f \n",
780
+ "84434 4e8a349d-7781-42ae-8868-1ecf5df4c2cb \n",
781
+ "84435 ca45d4bd-2da7-4d56-beec-bf9f772e8426 \n",
782
+ "84436 6ea871e7-7582-4607-8b0a-84e4d0169868 \n",
783
+ "\n",
784
+ " parent_id \\\n",
785
+ "0 None \n",
786
+ "1 6ab24d72-0181-4594-a9cd-deaf170242fb \n",
787
+ "2 c8e83833-ecbc-44fe-b6db-735228c25a1c \n",
788
+ "3 6ab24d72-0181-4594-a9cd-deaf170242fb \n",
789
+ "4 343ee2d4-87ae-41fd-a768-bdd65959dc4a \n",
790
+ "... ... \n",
791
+ "84432 2e934881-260c-4a6c-8f09-66e0312f84ac \n",
792
+ "84433 None \n",
793
+ "84434 d3946880-4402-42a8-8a9e-6dab5efa787f \n",
794
+ "84435 d3946880-4402-42a8-8a9e-6dab5efa787f \n",
795
+ "84436 d3946880-4402-42a8-8a9e-6dab5efa787f \n",
796
+ "\n",
797
+ " user_id created_date \\\n",
798
+ "0 c3fe8c76-fc30-4fa7-b7f8-c492f5967d18 2023-02-05T14:23:50.983374+00:00 \n",
799
+ "1 2c96e467-66f0-4be7-9693-bda51356a424 2023-02-06T13:50:44.657083+00:00 \n",
800
+ "2 2c96e467-66f0-4be7-9693-bda51356a424 2023-02-06T18:48:49.391686+00:00 \n",
801
+ "3 49ddcb0d-6588-43bd-858d-19c577f12e7b 2023-02-06T13:37:56.044680+00:00 \n",
802
+ "4 e10e99a0-38ac-4b07-bf5d-4427696e4e0d 2023-02-06T18:52:51.428543+00:00 \n",
803
+ "... ... ... \n",
804
+ "84432 55e23953-c333-4b02-a459-c99d2c7172a3 2023-02-21T17:18:06.837900+00:00 \n",
805
+ "84433 ad5d3a46-2f52-4270-89a9-a6b1d180d809 2023-02-10T13:49:30.080447+00:00 \n",
806
+ "84434 9f3e4da7-7d7a-4cf9-9d35-f59d00de240d 2023-02-11T15:26:37.799100+00:00 \n",
807
+ "84435 055ac9a6-80e3-4ef5-b89a-edd88e261208 2023-02-12T19:23:29.730612+00:00 \n",
808
+ "84436 9aec2d31-b3db-463e-a2f7-5e22ee03d2b0 2023-02-11T11:12:41.558670+00:00 \n",
809
+ "\n",
810
+ " text role lang \\\n",
811
+ "0 Can you write a short introduction about the r... prompter en \n",
812
+ "1 \"Monopsony\" refers to a market structure where... assistant en \n",
813
+ "2 Now explain it to a dog prompter en \n",
814
+ "3 Monopsony is a market structure in which there... assistant en \n",
815
+ "4 How can one fight back when a monospony had be... prompter en \n",
816
+ "... ... ... ... \n",
817
+ "84432 James Potter eta Lily Potter ziren Harry Potte... assistant eu \n",
818
+ "84433 Nork jarri zion ahotsa Dragoi Bolako Vegetari ... prompter eu \n",
819
+ "84434 Dragoi bolaren aurreneko denboraldian ez da Ve... assistant eu \n",
820
+ "84435 Dragoi Bolako Vegetari euskarazko ahotsa jarri... assistant eu \n",
821
+ "84436 Vegetari euskarazko ahotsa Felix Arkarazo akto... assistant eu \n",
822
+ "\n",
823
+ " review_count review_result deleted rank synthetic model_name \\\n",
824
+ "0 3 True False NaN False None \n",
825
+ "1 3 True False 0.0 False None \n",
826
+ "2 3 True False NaN False None \n",
827
+ "3 3 True False 1.0 False None \n",
828
+ "4 3 True False NaN False None \n",
829
+ "... ... ... ... ... ... ... \n",
830
+ "84432 3 True False 2.0 False None \n",
831
+ "84433 3 True False NaN False None \n",
832
+ "84434 3 True False 0.0 False None \n",
833
+ "84435 3 True False 1.0 False None \n",
834
+ "84436 3 True False 2.0 False None \n",
835
+ "\n",
836
+ " detoxify \\\n",
837
+ "0 {'toxicity': 0.00044308538781479, 'severe_toxi... \n",
838
+ "1 {'toxicity': 0.00026396565954200923, 'severe_t... \n",
839
+ "2 {'toxicity': 0.03648477792739868, 'severe_toxi... \n",
840
+ "3 {'toxicity': 0.0008866374846547842, 'severe_to... \n",
841
+ "4 {'toxicity': 0.0009362137061543763, 'severe_to... \n",
842
+ "... ... \n",
843
+ "84432 None \n",
844
+ "84433 None \n",
845
+ "84434 None \n",
846
+ "84435 None \n",
847
+ "84436 None \n",
848
+ "\n",
849
+ " message_tree_id tree_state \\\n",
850
+ "0 6ab24d72-0181-4594-a9cd-deaf170242fb ready_for_export \n",
851
+ "1 6ab24d72-0181-4594-a9cd-deaf170242fb ready_for_export \n",
852
+ "2 6ab24d72-0181-4594-a9cd-deaf170242fb ready_for_export \n",
853
+ "3 6ab24d72-0181-4594-a9cd-deaf170242fb ready_for_export \n",
854
+ "4 6ab24d72-0181-4594-a9cd-deaf170242fb ready_for_export \n",
855
+ "... ... ... \n",
856
+ "84432 2e934881-260c-4a6c-8f09-66e0312f84ac ready_for_export \n",
857
+ "84433 d3946880-4402-42a8-8a9e-6dab5efa787f ready_for_export \n",
858
+ "84434 d3946880-4402-42a8-8a9e-6dab5efa787f ready_for_export \n",
859
+ "84435 d3946880-4402-42a8-8a9e-6dab5efa787f ready_for_export \n",
860
+ "84436 d3946880-4402-42a8-8a9e-6dab5efa787f ready_for_export \n",
861
+ "\n",
862
+ " emojis \\\n",
863
+ "0 {'name': ['+1', '_skip_reply', '_skip_ranking'... \n",
864
+ "1 {'name': ['+1', '_skip_labeling'], 'count': [3... \n",
865
+ "2 None \n",
866
+ "3 {'name': ['+1', '_skip_reply', '_skip_labeling... \n",
867
+ "4 {'name': ['+1'], 'count': [1]} \n",
868
+ "... ... \n",
869
+ "84432 {'name': ['+1'], 'count': [1]} \n",
870
+ "84433 {'name': ['+1', '_skip_reply'], 'count': [5, 4]} \n",
871
+ "84434 {'name': ['+1'], 'count': [1]} \n",
872
+ "84435 {'name': ['+1'], 'count': [1]} \n",
873
+ "84436 {'name': ['+1', '_skip_labeling'], 'count': [1... \n",
874
+ "\n",
875
+ " labels \n",
876
+ "0 {'name': ['spam', 'lang_mismatch', 'pii', 'not... \n",
877
+ "1 {'name': ['spam', 'fails_task', 'lang_mismatch... \n",
878
+ "2 {'name': ['spam', 'lang_mismatch', 'pii', 'not... \n",
879
+ "3 {'name': ['spam', 'fails_task', 'lang_mismatch... \n",
880
+ "4 {'name': ['spam', 'lang_mismatch', 'pii', 'not... \n",
881
+ "... ... \n",
882
+ "84432 {'name': ['spam', 'fails_task', 'lang_mismatch... \n",
883
+ "84433 {'name': ['spam', 'lang_mismatch', 'pii', 'not... \n",
884
+ "84434 {'name': ['spam', 'fails_task', 'lang_mismatch... \n",
885
+ "84435 {'name': ['spam', 'lang_mismatch', 'quality'],... \n",
886
+ "84436 {'name': ['spam', 'fails_task', 'lang_mismatch... \n",
887
+ "\n",
888
+ "[84437 rows x 18 columns]"
889
+ ]
890
+ },
891
+ "execution_count": 10,
892
+ "metadata": {},
893
+ "output_type": "execute_result"
894
+ }
895
+ ],
896
+ "source": [
897
+ "df"
898
+ ]
899
+ },
900
+ {
901
+ "cell_type": "code",
902
+ "execution_count": 11,
903
+ "id": "7da865e2-28c3-4b5f-b519-e414e047e802",
904
+ "metadata": {},
905
+ "outputs": [
906
+ {
907
+ "data": {
908
+ "text/plain": [
909
+ "(40396,)"
910
+ ]
911
+ },
912
+ "execution_count": 11,
913
+ "metadata": {},
914
+ "output_type": "execute_result"
915
+ }
916
+ ],
917
+ "source": [
918
+ "df.parent_id.unique().shape"
919
+ ]
920
+ },
921
+ {
922
+ "cell_type": "code",
923
+ "execution_count": 12,
924
+ "id": "3d9f97ac-cc85-48a5-86ac-0220c1cd8749",
925
+ "metadata": {},
926
+ "outputs": [],
927
+ "source": [
928
+ "root_ids = df[df.parent_id.astype(str) == \"None\"][\"message_id\"].to_list()"
929
+ ]
930
+ },
931
+ {
932
+ "cell_type": "code",
933
+ "execution_count": 13,
934
+ "id": "25c0819a-04f1-4ddb-ab53-03b63e144a37",
935
+ "metadata": {},
936
+ "outputs": [
937
+ {
938
+ "data": {
939
+ "text/plain": [
940
+ "9846"
941
+ ]
942
+ },
943
+ "execution_count": 13,
944
+ "metadata": {},
945
+ "output_type": "execute_result"
946
+ }
947
+ ],
948
+ "source": [
949
+ "root_ids.__len__()"
950
+ ]
951
+ },
952
+ {
953
+ "cell_type": "code",
954
+ "execution_count": 14,
955
+ "id": "12fc1dc2-4509-4bbe-b51f-2cc0d5b4c656",
956
+ "metadata": {},
957
+ "outputs": [
958
+ {
959
+ "data": {
960
+ "text/plain": [
961
+ "(9846,)"
962
+ ]
963
+ },
964
+ "execution_count": 14,
965
+ "metadata": {},
966
+ "output_type": "execute_result"
967
+ }
968
+ ],
969
+ "source": [
970
+ "df[\"message_tree_id\"].unique().shape"
971
+ ]
972
+ },
973
+ {
974
+ "cell_type": "code",
975
+ "execution_count": 23,
976
+ "id": "f05079a1-07da-445e-b879-b7c6eda27948",
977
+ "metadata": {},
978
+ "outputs": [
979
+ {
980
+ "data": {
981
+ "text/plain": [
982
+ "count\n",
983
+ "4 3991\n",
984
+ "12 2777\n",
985
+ "13 1026\n",
986
+ "9 828\n",
987
+ "5 330\n",
988
+ "14 323\n",
989
+ "10 136\n",
990
+ "15 121\n",
991
+ "16 59\n",
992
+ "6 51\n",
993
+ "11 48\n",
994
+ "17 44\n",
995
+ "18 22\n",
996
+ "19 13\n",
997
+ "20 12\n",
998
+ "7 10\n",
999
+ "26 7\n",
1000
+ "25 5\n",
1001
+ "24 5\n",
1002
+ "21 5\n",
1003
+ "8 3\n",
1004
+ "28 3\n",
1005
+ "27 3\n",
1006
+ "34 2\n",
1007
+ "40 2\n",
1008
+ "22 2\n",
1009
+ "23 2\n",
1010
+ "3 1\n",
1011
+ "56 1\n",
1012
+ "55 1\n",
1013
+ "29 1\n",
1014
+ "30 1\n",
1015
+ "31 1\n",
1016
+ "32 1\n",
1017
+ "35 1\n",
1018
+ "36 1\n",
1019
+ "37 1\n",
1020
+ "41 1\n",
1021
+ "42 1\n",
1022
+ "46 1\n",
1023
+ "47 1\n",
1024
+ "52 1\n",
1025
+ "2 1\n",
1026
+ "Name: count, dtype: int64"
1027
+ ]
1028
+ },
1029
+ "execution_count": 23,
1030
+ "metadata": {},
1031
+ "output_type": "execute_result"
1032
+ }
1033
+ ],
1034
+ "source": [
1035
+ "df[\"message_tree_id\"].value_counts().value_counts()"
1036
+ ]
1037
+ },
1038
+ {
1039
+ "cell_type": "code",
1040
+ "execution_count": 25,
1041
+ "id": "2423d4da-939a-4ffe-b0b8-cb004df106d5",
1042
+ "metadata": {},
1043
+ "outputs": [
1044
+ {
1045
+ "data": {
1046
+ "text/plain": [
1047
+ "<Axes: >"
1048
+ ]
1049
+ },
1050
+ "execution_count": 25,
1051
+ "metadata": {},
1052
+ "output_type": "execute_result"
1053
+ },
1054
+ {
1055
+ "data": {
1056
+ "image/png": "iVBORw0KGgoAAAANSUhEUgAAAjAAAAGdCAYAAAAMm0nCAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjcuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8pXeV/AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAz0ElEQVR4nO3df1RU54HG8QcRRlFHoikMrEhpbFWi+IM0OqetaxQhhnWTxj0naWx0GxOPLuYU6Rrj1hjUtlhbY01DtN2kIXuiTbSnpo2awKgVa8SoRNZfrSdxbUlXB7ZNZfw5jHD3Dw83ThBh4BJ89fs5h1Pmve+9885zbuvTuXOZKMuyLAEAABikW1cvAAAAIFIUGAAAYBwKDAAAMA4FBgAAGIcCAwAAjEOBAQAAxqHAAAAA41BgAACAcbp39QI6S2Njo06dOqU+ffooKiqqq5cDAADawLIsnT17VsnJyerWreX3WW7aAnPq1CmlpKR09TIAAEA7fPTRRxowYECL22/aAtOnTx9JVwJwu932eCgUUllZmbKzsxUTE9NVy7spkKWzyNM5ZOks8nQOWbYuEAgoJSXF/ne8JTdtgWm6bOR2u5sVmLi4OLndbk6eDiJLZ5Gnc8jSWeTpHLJsu9Y+/sGHeAEAgHEoMAAAwDgUGAAAYBwKDAAAMA4FBgAAGIcCAwAAjEOBAQAAxqHAAAAA41BgAACAcTpUYJYvX66oqCjl5+fbY5cuXVJeXp769++v3r17a+rUqaqpqQnbr7q6Wrm5uYqLi1NCQoLmz5+vy5cvh83ZuXOnRo8eLZfLpUGDBqmkpKQjSwUAADeRdheY/fv362c/+5kyMjLCxufNm6e33npLGzduVHl5uU6dOqUHH3zQ3t7Q0KDc3FzV19drz549evXVV1VSUqLFixfbc06ePKnc3Fzdc889qqqqUn5+vh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jAAAARPQOzMKFCzV58mQNHDhQZ8+e1fr167Vz506Vlpaqb9++mjlzpgoKCtSvXz+53W49+eST8nq9Gjt2rCQpOztb6enpevTRR7VixQr5/X4tWrRIeXl59rsns2fP1gsvvKCnnnpKjz32mHbs2KENGzZoy5Ytzr96AABgpIgKTG1traZPn67Tp0+rb9++ysjIUGlpqSZNmiRJWrVqlbp166apU6cqGAwqJydHL774or1/dHS0Nm/erDlz5sjr9apXr16aMWOGli5das9JS0vTli1bNG/ePK1evVoDBgzQSy+9xC3UAADAFlGBefnll6+7vUePHiouLlZxcXGLc1JTU1u902b8+PE6ePBgJEsDAAC3EL4LCQAAGIcCAwAAjEOBAQAAxqHAAAAA41BgAACAcSgwAADAOBQYAABgHAoMAAAwTsRf5gh82rDC0k77gss/Lc/tlOMCAMzGOzAAAMA4FBgAAGAcCgwAADAOBQYAABiHAgMAAIxDgQEAAMahwAAAAONQYAAAgHEoMAAAwDgUGAAAYBwKDAAAMA4FBgAAGIcCAwAAjEOBAQAAxqHAAAAA41BgAACAcSgwAADAOBQYAABgHAoMAAAwDgUGAAAYhwIDAACMQ4EBAADGocAAAADjUGAAAIBxIiowRUVF+vKXv6w+ffooISFBDzzwgI4fPx42Z/z48YqKigr7mT17dtic6upq5ebmKi4uTgkJCZo/f74uX74cNmfnzp0aPXq0XC6XBg0apJKSkva9QgAAcNOJqMCUl5crLy9Pe/fulc/nUygUUnZ2ts6fPx8274knntDp06ftnxUrVtjbGhoalJubq/r6eu3Zs0evvvqqSkpKtHjxYnvOyZMnlZubq3vuuUdVVVXKz8/X448/rtLS0g6+XAAAcDPoHsnkd955J+xxSUmJEhISVFlZqXHjxtnjcXFx8ng81zxGWVmZjh07pm3btikxMVEjR47UsmXLtGDBAhUWFio2NlZr165VWlqaVq5cKUkaOnSodu/erVWrViknJyfS1wgAAG4yERWYT6urq5Mk9evXL2x83bp1eu211+TxeDRlyhQ988wziouLkyRVVFRo+PDhSkxMtOfn5ORozpw5Onr0qEaNGqWKigpl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LLJ1wyxQYy7Ksn/70p9bAgQOt2NhY6+6777b27t3b1Usywu9+9ztLUrOfGTNmWJZ15VbqZ555xkpMTLRcLpc1ceJE6/jx41276BvUtXKUZL3yyiv2nIsXL1r/9m//Zt12221WXFyc9fWvf906ffp01y36BvbYY49ZqampVmxsrPW5z33Omjhxol1eLIssO+rTBYY82+6hhx6ykpKSrNjYWOsf/uEfrIceesj68MMP7e1k2XFRlmVZXfPeDwAAQPvcEp+BAQAANxcKDAAAMA4FBgAAGIcCAwAAjEOBAQAAxqHAAAAA41BgAACAcSgwAADAOBQYAABgHAoMAAAwDgUGAAAYhwIDAACM8/9qNNivIq9fNAAAAABJRU5ErkJggg==",
1057
+ "text/plain": [
1058
+ "<Figure size 640x480 with 1 Axes>"
1059
+ ]
1060
+ },
1061
+ "metadata": {},
1062
+ "output_type": "display_data"
1063
+ }
1064
+ ],
1065
+ "source": [
1066
+ "df[\"message_tree_id\"].value_counts().hist(bins=20)"
1067
+ ]
1068
+ },
1069
+ {
1070
+ "cell_type": "code",
1071
+ "execution_count": 16,
1072
+ "id": "7730a5d8-0d49-4672-8e12-cd07d4b5c968",
1073
+ "metadata": {},
1074
+ "outputs": [
1075
+ {
1076
+ "name": "stderr",
1077
+ "output_type": "stream",
1078
+ "text": [
1079
+ "/tmp/ipykernel_1954595/2136755740.py:3: SettingWithCopyWarning: \n",
1080
+ "A value is trying to be set on a copy of a slice from a DataFrame.\n",
1081
+ "Try using .loc[row_indexer,col_indexer] = value instead\n",
1082
+ "\n",
1083
+ "See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy\n",
1084
+ " df_message_tree[\"role\"] = df_message_tree[\"role\"].map({\"prompter\":\"user\", \"assistant\": \"assistant\"})\n"
1085
+ ]
1086
+ }
1087
+ ],
1088
+ "source": [
1089
+ "for message_tree_id in df[\"message_tree_id\"].unique().tolist():\n",
1090
+ " df_message_tree = df.query(f\"message_tree_id == '{message_tree_id}'\")#.sort_values(\"created_date\")\n",
1091
+ " df_message_tree[\"role\"] = df_message_tree[\"role\"].map({\"prompter\":\"user\", \"assistant\": \"assistant\"})\n",
1092
+ " break"
1093
+ ]
1094
+ },
1095
+ {
1096
+ "cell_type": "code",
1097
+ "execution_count": 17,
1098
+ "id": "3c71c483-abc9-4b92-9aeb-9a9513abcd78",
1099
+ "metadata": {
1100
+ "collapsed": true,
1101
+ "jupyter": {
1102
+ "outputs_hidden": true
1103
+ },
1104
+ "scrolled": true
1105
+ },
1106
+ "outputs": [
1107
+ {
1108
+ "name": "stdout",
1109
+ "output_type": "stream",
1110
+ "text": [
1111
+ "<|im_start|>user\n",
1112
+ "Can you write a short introduction about the relevance of the term \"monopsony\" in economics? Please use examples related to potential monopsonies in the labour market and cite relevant research.<|im_end|>\n",
1113
+ "***********************************************************\n",
1114
+ "<|im_start|>assistant\n",
1115
+ "\"Monopsony\" refers to a market structure where there is only one buyer for a particular good or service. In economics, this term is particularly relevant in the labor market, where a monopsony employer has significant power over the wages and working conditions of their employees. The presence of a monopsony can result in lower wages and reduced employment opportunities for workers, as the employer has little incentive to increase wages or provide better working conditions.\n",
1116
+ "\n",
1117
+ "Recent research has identified potential monopsonies in industries such as retail and fast food, where a few large companies control a significant portion of the market (Bivens & Mishel, 2013). In these industries, workers often face low wages, limited benefits, and reduced bargaining power, leading to a situation where they are dependent on the employer for their livelihood. This dependence can result in further suppression of wages and a decline in working conditions.\n",
1118
+ "\n",
1119
+ "Overall, the concept of monopsony is essential to understanding the dynamics of labor markets and the impact of market power on workers. Further research is needed to understand the extent and impact of monopsonies on the economy and to develop policies to address this issue.\n",
1120
+ "\n",
1121
+ "References:\n",
1122
+ "Bivens, J., & Mishel, L. (2013). The Pay of Corporate Executives and Financial Professionals as Evidence of Rents in Top 1 Percent Incomes. Journal of Economic Perspectives, 27(3), 57-78.<|im_end|>\n",
1123
+ "***********************************************************\n",
1124
+ "<|im_start|>user\n",
1125
+ "Now explain it to a dog<|im_end|>\n",
1126
+ "***********************************************************\n",
1127
+ "<|im_start|>assistant\n",
1128
+ "Monopsony is a market structure in which there is a single buyer in a market. In the context of labor markets, a monopsony occurs when there is only one employer in a particular industry or geographic area, giving that employer significant power over the wages and working conditions of workers. This results in a situation where the employer has the ability to suppress wages and reduce the bargaining power of workers.\n",
1129
+ "\n",
1130
+ "Research has shown that the existence of monopsony power in labor markets can have negative effects on workers, such as lower wages, reduced benefits, and limited job opportunities. For example, a study by Autor, Dorn, and Hanson (2013) found evidence of monopsony power in certain U.S. labor markets, resulting in lower wages and reduced job opportunities for workers. Similarly, another study by Bharadwaj, Black, and Kolesnikova (2019) found that the presence of a single dominant employer in a local labor market was associated with lower wages for workers.<|im_end|>\n",
1131
+ "***********************************************************\n",
1132
+ "<|im_start|>user\n",
1133
+ "How can one fight back when a monospony had been created?<|im_end|>\n",
1134
+ "***********************************************************\n",
1135
+ "<|im_start|>assistant\n",
1136
+ "Monopsony refers to a market structure where there is only one buyer of a good or service. In the context of labor markets, a monopsony occurs when there is only one employer in a particular geographic area or industry, giving them significant power to set wages and working conditions. Research has shown that the existence of monopsonies can lead to lower wages and reduced job opportunities for workers. For example, a study by the National Bureau of Economic Research found that in industries with high levels of concentration, workers earn lower wages and are less likely to receive benefits such as health insurance.<|im_end|>\n",
1137
+ "***********************************************************\n",
1138
+ "<|im_start|>user\n",
1139
+ "What can be done at a regulatory level to ensure, in a monopsony, that the power over the employees isn't abused? List a few options and focus on the organs that should act.<|im_end|>\n",
1140
+ "***********************************************************\n",
1141
+ "<|im_start|>assistant\n",
1142
+ "Here are some potential regulatory options to address monopsony power over employees:\n",
1143
+ "\n",
1144
+ "- Antitrust enforcement agencies like the FTC or DOJ could investigate and take action against dominant employers that are abusing their market power to suppress wages or worsen working conditions. They could force divestitures or other structural remedies.\n",
1145
+ "- Labor standards agencies could set industry-specific minimum wage floors or other regulations around compensation and working conditions. This would reduce the ability of dominant employers to push wages/conditions below certain thresholds.\n",
1146
+ "- Sector-specific regulators could impose requirements around how companies hire, compensate, and treat workers. For example, banking regulators could prohibit abusive practices by dominant banks with regard to their employees.\n",
1147
+ "- Legislatures could pass laws<|im_end|>\n",
1148
+ "***********************************************************\n",
1149
+ "<|im_start|>assistant\n",
1150
+ "Regulatory intervention can be used to address the negative consequences of monopsony power in the labor market. A few options include:\n",
1151
+ "\n",
1152
+ "1. Antitrust enforcement: Antitrust laws can be used to prevent firms from engaging in practices that limit competition and suppress wages. The antitrust division of the Department of Justice and the Federal Trade Commission (FTC) are responsible for enforcing these laws.\n",
1153
+ "\n",
1154
+ "2. Labor standards and protections: Governments can set minimum wage standards and other labor protections to ensure that workers are paid a fair wage, even in industries dominated by a single buyer. The U.S. Department of Labor is responsible for enforcing these standards.\n",
1155
+ "\n",
1156
+ "3. Occupational licensing reform: Occupational licensing requirements can restrict worker mobility and increase the bargaining power of employers. Reforms to licensing requirements can reduce these barriers and increase competition in the labor market. State governments typically regulate occupational licensing.\n",
1157
+ "\n",
1158
+ "4. Collective bargaining rights: Collective bargaining by workers can increase their bargaining power and lead to higher wages. Governments can protect and promote collective bargaining rights to counteract the effects of monopsony power. The National Labor Relations Board is responsible for enforcing workers' rights to engage in collective bargaining in the U.S.\n",
1159
+ "\n",
1160
+ "These are just a few examples of regulatory options that can be used to address monopsony power in the labor market. The specific actions taken will depend on the particular circumstances and context of each case.<|im_end|>\n",
1161
+ "***********************************************************\n",
1162
+ "<|im_start|>assistant\n",
1163
+ "Yes, that's correct. Keeping the code for the TESR and the registration code in the same file can make it easier to manage and maintain the code. The ExampleMod class acts as a container for the TESR code, providing a convenient and logical grouping. The functionality of the code remains unchanged, and the TESR will still be properly registered and used to render the custom tile entities in the game.<|im_end|>\n",
1164
+ "***********************************************************\n",
1165
+ "<|im_start|>user\n",
1166
+ "I would imagine this is similar or even the same as a \"monopoly\" but I am not sure.\n",
1167
+ "\n",
1168
+ "Assuming that this some kind of \"final state\" of a particular industry or even an entire economy, give me some larger historical examples of this kind of structure consolidating over time, and describe what circumstances are common prerequisite.<|im_end|>\n",
1169
+ "***********************************************************\n",
1170
+ "<|im_start|>assistant\n",
1171
+ "Bouguereau died in 1905, so it is unlikely that any of his direct descendants are still alive. However, his works continue to be popular and are sold at auction and through art dealers. It is possible that some indirect descendants may benefit from the sale of his works.<|im_end|>\n",
1172
+ "***********************************************************\n"
1173
+ ]
1174
+ }
1175
+ ],
1176
+ "source": [
1177
+ "# ChatML format\n",
1178
+ "templates = {\n",
1179
+ " \"assistant\": \"<|im_start|>assistant\\n{msg}<|im_end|>\", # message by assistant\n",
1180
+ " \"user\": \"<|im_start|>user\\n{msg}<|im_end|>\" # message by user\n",
1181
+ "}\n",
1182
+ "\n",
1183
+ "for _, (text, role) in df_message_tree[[\"text\", \"role\"]].iterrows():\n",
1184
+ " text = templates[role].format(msg=text)\n",
1185
+ " print(text)\n",
1186
+ " print(\"***********************************************************\")\n",
1187
+ " # print(f\"Text: {text}\")\n",
1188
+ " # print(f\"Role: {role}\")"
1189
+ ]
1190
+ },
1191
+ {
1192
+ "cell_type": "code",
1193
+ "execution_count": null,
1194
+ "id": "f3df6e39",
1195
+ "metadata": {},
1196
+ "outputs": [],
1197
+ "source": [
1198
+ "messages = []\n",
1199
+ "for message_tree_id in df[\"message_tree_id\"].unique().tolist():\n",
1200
+ " df_message_tree = df.query(f\"message_tree_id == '{message_tree_id}'\")#.sort_values(\"created_date\")\n",
1201
+ " df_message_tree[\"role\"] = df_message_tree[\"role\"].map({\"prompter\":\"user\", \"assistant\": \"assistant\"})\n",
1202
+ " \n",
1203
+ " new_message = \"\"\n",
1204
+ " for _, (text, role) in df_message_tree[[\"text\", \"role\"]].iterrows():\n",
1205
+ " text = templates[role].format(msg=text)\n",
1206
+ " new_message += f\"{text}\\n\"\n",
1207
+ " messages.append({\"text\": new_message})"
1208
+ ]
1209
+ },
1210
+ {
1211
+ "cell_type": "code",
1212
+ "execution_count": 40,
1213
+ "id": "f0721e8b-e19e-46d1-83d8-d45f0a2d8f31",
1214
+ "metadata": {},
1215
+ "outputs": [
1216
+ {
1217
+ "data": {
1218
+ "text/plain": [
1219
+ "87"
1220
+ ]
1221
+ },
1222
+ "execution_count": 40,
1223
+ "metadata": {},
1224
+ "output_type": "execute_result"
1225
+ }
1226
+ ],
1227
+ "source": [
1228
+ "len(new_message.split())"
1229
+ ]
1230
+ },
1231
+ {
1232
+ "cell_type": "code",
1233
+ "execution_count": 41,
1234
+ "id": "1d10160f-780e-4a57-86f5-cc435ee65660",
1235
+ "metadata": {},
1236
+ "outputs": [
1237
+ {
1238
+ "data": {
1239
+ "text/plain": [
1240
+ "9846"
1241
+ ]
1242
+ },
1243
+ "execution_count": 41,
1244
+ "metadata": {},
1245
+ "output_type": "execute_result"
1246
+ }
1247
+ ],
1248
+ "source": [
1249
+ "len(messages)"
1250
+ ]
1251
+ },
1252
+ {
1253
+ "cell_type": "code",
1254
+ "execution_count": 42,
1255
+ "id": "f50d9397-8bc8-4663-9204-9543aae1344b",
1256
+ "metadata": {},
1257
+ "outputs": [
1258
+ {
1259
+ "data": {
1260
+ "text/plain": [
1261
+ "{'text': '<|im_start|>user\\nMétodo del Perceptrón biclásico: definición y variantes del método. ¿cómo se aplicaría\\nal caso multiclásico?, ¿se podría utilizar con patrones que sólo son cuadráticamente\\nseparables?<|im_end|>\\n<|im_start|>assistant\\nEl método del Perceptrón biclásico es un algoritmo de aprendizaje automático que se utiliza para clasificar patrones en dos categorías. El objetivo del Perceptrón es encontrar un hiperplano que separe las dos clases en el espacio de características.\\n\\nEn el Perceptrón biclásico, se utilizan los siguientes pasos para entrenar el modelo:\\n\\n1. Inicializar los pesos con valores aleatorios.\\n2. Seleccionar un patrón aleatorio del conjunto de entrenamiento y calcular la salida del Perceptrón.\\n3. Actualizar los pesos si la salida del Perceptrón es incorrecta.\\n4. Repetir los pasos 2 y 3 hasta que se alcance un criterio de parada.\\n\\nHay varias variantes del método del Perceptrón biclásico, incluyendo el Perceptrón con margen, el Perceptrón promedio, el Perceptrón relajado y el Perceptrón de múltiples capas.\\n\\nEn el caso multiclase, se puede utilizar una variante del Perceptrón biclásico conocida como Perceptrón multicapa, que utiliza varias capas de neuronas para clasificar patrones en múltiples categorías. Cada capa se encarga de realizar una transformación no lineal de los datos de entrada y de propagar la información a la siguiente capa hasta llegar a la capa de salida, donde se realiza la clasificación.\\n\\nEn cuanto a si se puede utilizar el Perceptrón biclásico con patrones que sólo son cuadráticamente separables, la respuesta es que no. El Perceptrón biclásico sólo puede separar patrones linealmente separables. Para patrones cuadráticamente separables se pueden utilizar otros algoritmos de clasificación como SVM, regresión logística, árboles de decisión, entre otros.<|im_end|>\\n<|im_start|>assistant\\nEl método del Perceptrón biclásico es un algoritmo de aprendizaje supervisado utilizado para la clasificación de patrones. Este método es una variante del Perceptrón original, que fue propuesto por Frank Rosenblatt en 1957.\\n\\nEn el caso del Perceptrón biclásico, se considera una función de activación binaria que clasifica los patrones en dos clases diferentes. El objetivo del algoritmo es encontrar un hiperplano que pueda separar los patrones de las dos clases en el espacio de características.\\n\\nExisten diferentes variantes del método del Perceptrón biclásico, como por ejemplo:\\n\\n Perceptrón de Rosenblatt: es la versión original del algoritmo, que utiliza una regla de aprendizaje basada en el descenso de gradiente estocástico.\\n\\n Perceptrón de Widrow-Hoff: esta variante del Perceptrón utiliza una regla de aprendizaje basada en la corrección del error, que se aplica a cada patrón individualmente.\\n\\n Perceptrón de margen máximo: esta variante del Perceptrón intenta encontrar el hiperplano que separa las dos clases con el margen máximo posible.\\n\\nEn el caso multiclásico, el método del Perceptrón biclásico se puede utilizar utilizando una estrategia conocida como \"uno contra todos\" o \"uno contra el resto\". En esta estrategia, se entrena un clasificador Perceptrón biclásico para cada una de las clases, y luego se selecciona la clase que tenga la mayor puntuación.\\n\\nEn cuanto a si se podría utilizar con patrones que sólo son cuadráticamente separables, el método del Perceptrón biclásico no es adecuado para estos casos, ya que sólo puede separar patrones linealmente. Para patrones cuadráticamente separables se utilizan otros algoritmos de clasificación, como el SVM (Máquinas de Vectores de Soporte) que pueden separar patrones no lineales.<|im_end|>\\n<|im_start|>assistant\\nEl método del perceptrón binario es un algoritmo de aprendizaje supervisado para clasificadores binarios, es decir, pueden distinguir entre dos clases de muestras. Un perceptrón consta de una neurona artificial que toma un conjunto de entradas, suma sus pesos y aplica una función de umbral para producir la salida. La regla de aprendizaje del perceptrón es un proceso de ajuste de los pesos de entrada para minimizar el error de clasificación.\\nPara aplicar el método del perceptrón al caso multiclase, es decir, cuando hay más de dos clases muestrales, se pueden utilizar diferentes estrategias, como por ejemplo:\\n\\nUtilice un perceptrón por clase y asigne la muestra a la clase con el perceptrón de puntuación más alta. Utilice un conjunto de perceptrones que generen un binario para cada clase y asigne la plantilla a la clase cuyo código coincida con la salida del perceptrón. Usando un perceptrón multicapa, que consiste en una red neuronal artificial organizada en capas, donde la salida de una capa actúa como entrada a la siguiente capa. El método del perceptrón de dos capas solo puede clasificar imágenes que son linealmente separables, es decir, imágenes que pueden separarse por una línea recta. Si las muestras solo pueden descomponerse perpendicularmente, es decir, pueden descomponerse mediante una curva, entonces un perceptrón multicapa con una función de activación no lineal, como una tangente sigmoidea o una hipérbola. Esto permite que la red neuronal aprenda funciones no lineales y clasifique patrones más complejos.<|im_end|>\\n'}"
1262
+ ]
1263
+ },
1264
+ "execution_count": 42,
1265
+ "metadata": {},
1266
+ "output_type": "execute_result"
1267
+ }
1268
+ ],
1269
+ "source": [
1270
+ "messages[4]"
1271
+ ]
1272
+ },
1273
+ {
1274
+ "cell_type": "code",
1275
+ "execution_count": 43,
1276
+ "id": "459d23c4-6bad-444e-a025-767f6cba848e",
1277
+ "metadata": {},
1278
+ "outputs": [],
1279
+ "source": [
1280
+ "import datasets"
1281
+ ]
1282
+ },
1283
+ {
1284
+ "cell_type": "code",
1285
+ "execution_count": 45,
1286
+ "id": "a13e606b-d34d-473f-beba-e096b24e9824",
1287
+ "metadata": {},
1288
+ "outputs": [],
1289
+ "source": [
1290
+ "new_dataset = datasets.Dataset.from_list(messages)"
1291
+ ]
1292
+ },
1293
+ {
1294
+ "cell_type": "code",
1295
+ "execution_count": 46,
1296
+ "id": "5bc9fa85-74b4-4db3-b675-281bdd13e238",
1297
+ "metadata": {},
1298
+ "outputs": [
1299
+ {
1300
+ "data": {
1301
+ "text/plain": [
1302
+ "Dataset({\n",
1303
+ " features: ['text'],\n",
1304
+ " num_rows: 9846\n",
1305
+ "})"
1306
+ ]
1307
+ },
1308
+ "execution_count": 46,
1309
+ "metadata": {},
1310
+ "output_type": "execute_result"
1311
+ }
1312
+ ],
1313
+ "source": [
1314
+ "new_dataset"
1315
+ ]
1316
+ },
1317
+ {
1318
+ "cell_type": "code",
1319
+ "execution_count": 48,
1320
+ "id": "002313f6-299f-4790-a803-a05c91872a5a",
1321
+ "metadata": {},
1322
+ "outputs": [
1323
+ {
1324
+ "data": {
1325
+ "application/vnd.jupyter.widget-view+json": {
1326
+ "model_id": "18a4f79af7094e8681d24a66d15ca687",
1327
+ "version_major": 2,
1328
+ "version_minor": 0
1329
+ },
1330
+ "text/plain": [
1331
+ "Pushing dataset shards to the dataset hub: 0%| | 0/1 [00:00<?, ?it/s]"
1332
+ ]
1333
+ },
1334
+ "metadata": {},
1335
+ "output_type": "display_data"
1336
+ },
1337
+ {
1338
+ "data": {
1339
+ "application/vnd.jupyter.widget-view+json": {
1340
+ "model_id": "0d8d2985a0af4786a10711a10b8e7fb0",
1341
+ "version_major": 2,
1342
+ "version_minor": 0
1343
+ },
1344
+ "text/plain": [
1345
+ "Creating parquet from Arrow format: 0%| | 0/10 [00:00<?, ?ba/s]"
1346
+ ]
1347
+ },
1348
+ "metadata": {},
1349
+ "output_type": "display_data"
1350
+ }
1351
+ ],
1352
+ "source": [
1353
+ "new_dataset.push_to_hub(\"RaviNaik/oasst1-chatml\", token=\"\")"
1354
+ ]
1355
+ },
1356
+ {
1357
+ "cell_type": "code",
1358
+ "execution_count": 49,
1359
+ "id": "7cb91c43-da77-4388-b8a1-7b00fb838fc4",
1360
+ "metadata": {},
1361
+ "outputs": [
1362
+ {
1363
+ "data": {
1364
+ "application/vnd.jupyter.widget-view+json": {
1365
+ "model_id": "66004e71272545a69f1cbd514d6b37d6",
1366
+ "version_major": 2,
1367
+ "version_minor": 0
1368
+ },
1369
+ "text/plain": [
1370
+ "Downloading readme: 0%| | 0.00/745 [00:00<?, ?B/s]"
1371
+ ]
1372
+ },
1373
+ "metadata": {},
1374
+ "output_type": "display_data"
1375
+ },
1376
+ {
1377
+ "data": {
1378
+ "application/vnd.jupyter.widget-view+json": {
1379
+ "model_id": "64d5edf8986e47589f4910add8635d11",
1380
+ "version_major": 2,
1381
+ "version_minor": 0
1382
+ },
1383
+ "text/plain": [
1384
+ "Downloading data files: 0%| | 0/1 [00:00<?, ?it/s]"
1385
+ ]
1386
+ },
1387
+ "metadata": {},
1388
+ "output_type": "display_data"
1389
+ },
1390
+ {
1391
+ "data": {
1392
+ "application/vnd.jupyter.widget-view+json": {
1393
+ "model_id": "3a5bdc910f9749318448261652be48b8",
1394
+ "version_major": 2,
1395
+ "version_minor": 0
1396
+ },
1397
+ "text/plain": [
1398
+ "Downloading data: 0%| | 0.00/25.0M [00:00<?, ?B/s]"
1399
+ ]
1400
+ },
1401
+ "metadata": {},
1402
+ "output_type": "display_data"
1403
+ },
1404
+ {
1405
+ "data": {
1406
+ "application/vnd.jupyter.widget-view+json": {
1407
+ "model_id": "73b105b4daad4df18bc2effc1a30a39b",
1408
+ "version_major": 2,
1409
+ "version_minor": 0
1410
+ },
1411
+ "text/plain": [
1412
+ "Extracting data files: 0%| | 0/1 [00:00<?, ?it/s]"
1413
+ ]
1414
+ },
1415
+ "metadata": {},
1416
+ "output_type": "display_data"
1417
+ },
1418
+ {
1419
+ "data": {
1420
+ "application/vnd.jupyter.widget-view+json": {
1421
+ "model_id": "1bdd3ebca4fb4b0db8940e1a814e6ba0",
1422
+ "version_major": 2,
1423
+ "version_minor": 0
1424
+ },
1425
+ "text/plain": [
1426
+ "Generating train split: 0%| | 0/9846 [00:00<?, ? examples/s]"
1427
+ ]
1428
+ },
1429
+ "metadata": {},
1430
+ "output_type": "display_data"
1431
+ }
1432
+ ],
1433
+ "source": [
1434
+ "my_dataset = load_dataset(\"RaviNaik/oasst1-chatml\", split=\"train\")"
1435
+ ]
1436
+ },
1437
+ {
1438
+ "cell_type": "code",
1439
+ "execution_count": 50,
1440
+ "id": "eed20b68-9cd4-4b02-a483-a8fcd036bcfb",
1441
+ "metadata": {},
1442
+ "outputs": [
1443
+ {
1444
+ "data": {
1445
+ "text/plain": [
1446
+ "Dataset({\n",
1447
+ " features: ['text'],\n",
1448
+ " num_rows: 9846\n",
1449
+ "})"
1450
+ ]
1451
+ },
1452
+ "execution_count": 50,
1453
+ "metadata": {},
1454
+ "output_type": "execute_result"
1455
+ }
1456
+ ],
1457
+ "source": [
1458
+ "my_dataset"
1459
+ ]
1460
+ },
1461
+ {
1462
+ "cell_type": "code",
1463
+ "execution_count": 51,
1464
+ "id": "acb3bbeb-612a-45d0-8f31-85604b438884",
1465
+ "metadata": {},
1466
+ "outputs": [
1467
+ {
1468
+ "data": {
1469
+ "text/plain": [
1470
+ "{'text': '<|im_start|>user\\nCan you write a short introduction about the relevance of the term \"monopsony\" in economics? Please use examples related to potential monopsonies in the labour market and cite relevant research.<|im_end|>\\n<|im_start|>assistant\\n\"Monopsony\" refers to a market structure where there is only one buyer for a particular good or service. In economics, this term is particularly relevant in the labor market, where a monopsony employer has significant power over the wages and working conditions of their employees. The presence of a monopsony can result in lower wages and reduced employment opportunities for workers, as the employer has little incentive to increase wages or provide better working conditions.\\n\\nRecent research has identified potential monopsonies in industries such as retail and fast food, where a few large companies control a significant portion of the market (Bivens & Mishel, 2013). In these industries, workers often face low wages, limited benefits, and reduced bargaining power, leading to a situation where they are dependent on the employer for their livelihood. This dependence can result in further suppression of wages and a decline in working conditions.\\n\\nOverall, the concept of monopsony is essential to understanding the dynamics of labor markets and the impact of market power on workers. Further research is needed to understand the extent and impact of monopsonies on the economy and to develop policies to address this issue.\\n\\nReferences:\\nBivens, J., & Mishel, L. (2013). The Pay of Corporate Executives and Financial Professionals as Evidence of Rents in Top 1 Percent Incomes. Journal of Economic Perspectives, 27(3), 57-78.<|im_end|>\\n<|im_start|>user\\nNow explain it to a dog<|im_end|>\\n<|im_start|>assistant\\nMonopsony is a market structure in which there is a single buyer in a market. In the context of labor markets, a monopsony occurs when there is only one employer in a particular industry or geographic area, giving that employer significant power over the wages and working conditions of workers. This results in a situation where the employer has the ability to suppress wages and reduce the bargaining power of workers.\\n\\nResearch has shown that the existence of monopsony power in labor markets can have negative effects on workers, such as lower wages, reduced benefits, and limited job opportunities. For example, a study by Autor, Dorn, and Hanson (2013) found evidence of monopsony power in certain U.S. labor markets, resulting in lower wages and reduced job opportunities for workers. Similarly, another study by Bharadwaj, Black, and Kolesnikova (2019) found that the presence of a single dominant employer in a local labor market was associated with lower wages for workers.<|im_end|>\\n<|im_start|>user\\nHow can one fight back when a monospony had been created?<|im_end|>\\n<|im_start|>assistant\\nMonopsony refers to a market structure where there is only one buyer of a good or service. In the context of labor markets, a monopsony occurs when there is only one employer in a particular geographic area or industry, giving them significant power to set wages and working conditions. Research has shown that the existence of monopsonies can lead to lower wages and reduced job opportunities for workers. For example, a study by the National Bureau of Economic Research found that in industries with high levels of concentration, workers earn lower wages and are less likely to receive benefits such as health insurance.<|im_end|>\\n<|im_start|>user\\nWhat can be done at a regulatory level to ensure, in a monopsony, that the power over the employees isn\\'t abused? List a few options and focus on the organs that should act.<|im_end|>\\n<|im_start|>assistant\\nHere are some potential regulatory options to address monopsony power over employees:\\n\\n- Antitrust enforcement agencies like the FTC or DOJ could investigate and take action against dominant employers that are abusing their market power to suppress wages or worsen working conditions. They could force divestitures or other structural remedies.\\n- Labor standards agencies could set industry-specific minimum wage floors or other regulations around compensation and working conditions. This would reduce the ability of dominant employers to push wages/conditions below certain thresholds.\\n- Sector-specific regulators could impose requirements around how companies hire, compensate, and treat workers. For example, banking regulators could prohibit abusive practices by dominant banks with regard to their employees.\\n- Legislatures could pass laws<|im_end|>\\n<|im_start|>assistant\\nRegulatory intervention can be used to address the negative consequences of monopsony power in the labor market. A few options include:\\n\\n1. Antitrust enforcement: Antitrust laws can be used to prevent firms from engaging in practices that limit competition and suppress wages. The antitrust division of the Department of Justice and the Federal Trade Commission (FTC) are responsible for enforcing these laws.\\n\\n2. Labor standards and protections: Governments can set minimum wage standards and other labor protections to ensure that workers are paid a fair wage, even in industries dominated by a single buyer. The U.S. Department of Labor is responsible for enforcing these standards.\\n\\n3. Occupational licensing reform: Occupational licensing requirements can restrict worker mobility and increase the bargaining power of employers. Reforms to licensing requirements can reduce these barriers and increase competition in the labor market. State governments typically regulate occupational licensing.\\n\\n4. Collective bargaining rights: Collective bargaining by workers can increase their bargaining power and lead to higher wages. Governments can protect and promote collective bargaining rights to counteract the effects of monopsony power. The National Labor Relations Board is responsible for enforcing workers\\' rights to engage in collective bargaining in the U.S.\\n\\nThese are just a few examples of regulatory options that can be used to address monopsony power in the labor market. The specific actions taken will depend on the particular circumstances and context of each case.<|im_end|>\\n<|im_start|>assistant\\nYes, that\\'s correct. Keeping the code for the TESR and the registration code in the same file can make it easier to manage and maintain the code. The ExampleMod class acts as a container for the TESR code, providing a convenient and logical grouping. The functionality of the code remains unchanged, and the TESR will still be properly registered and used to render the custom tile entities in the game.<|im_end|>\\n<|im_start|>user\\nI would imagine this is similar or even the same as a \"monopoly\" but I am not sure.\\n\\nAssuming that this some kind of \"final state\" of a particular industry or even an entire economy, give me some larger historical examples of this kind of structure consolidating over time, and describe what circumstances are common prerequisite.<|im_end|>\\n<|im_start|>assistant\\nBouguereau died in 1905, so it is unlikely that any of his direct descendants are still alive. However, his works continue to be popular and are sold at auction and through art dealers. It is possible that some indirect descendants may benefit from the sale of his works.<|im_end|>\\n'}"
1471
+ ]
1472
+ },
1473
+ "execution_count": 51,
1474
+ "metadata": {},
1475
+ "output_type": "execute_result"
1476
+ }
1477
+ ],
1478
+ "source": [
1479
+ "my_dataset[0]"
1480
+ ]
1481
+ },
1482
+ {
1483
+ "cell_type": "code",
1484
+ "execution_count": null,
1485
+ "id": "1ae08369-7a2c-4aca-b14d-c3adcd47fbc6",
1486
+ "metadata": {},
1487
+ "outputs": [],
1488
+ "source": []
1489
+ }
1490
+ ],
1491
+ "metadata": {
1492
+ "kernelspec": {
1493
+ "display_name": "Python 3 (ipykernel)",
1494
+ "language": "python",
1495
+ "name": "python3"
1496
+ },
1497
+ "language_info": {
1498
+ "codemirror_mode": {
1499
+ "name": "ipython",
1500
+ "version": 3
1501
+ },
1502
+ "file_extension": ".py",
1503
+ "mimetype": "text/x-python",
1504
+ "name": "python",
1505
+ "nbconvert_exporter": "python",
1506
+ "pygments_lexer": "ipython3",
1507
+ "version": "3.10.12"
1508
+ }
1509
+ },
1510
+ "nbformat": 4,
1511
+ "nbformat_minor": 5
1512
+ }
Experiments/sft_falcon.ipynb ADDED
@@ -0,0 +1,928 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "085740a4-476b-43d3-8706-17ea6ad73d5b",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stderr",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/huggingface_hub/repocard.py:105: UserWarning: Repo card metadata block was not found. Setting CardData to empty.\n",
14
+ " warnings.warn(\"Repo card metadata block was not found. Setting CardData to empty.\")\n"
15
+ ]
16
+ }
17
+ ],
18
+ "source": [
19
+ "from datasets import load_dataset\n",
20
+ "\n",
21
+ "dataset_name = \"timdettmers/openassistant-guanaco\"\n",
22
+ "dataset = load_dataset(dataset_name, split=\"train\")"
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "code",
27
+ "execution_count": 4,
28
+ "id": "a3d9b409-e0d3-45c8-86f2-7a4209f3c948",
29
+ "metadata": {},
30
+ "outputs": [
31
+ {
32
+ "data": {
33
+ "text/plain": [
34
+ "Dataset({\n",
35
+ " features: ['text'],\n",
36
+ " num_rows: 9846\n",
37
+ "})"
38
+ ]
39
+ },
40
+ "execution_count": 4,
41
+ "metadata": {},
42
+ "output_type": "execute_result"
43
+ }
44
+ ],
45
+ "source": [
46
+ "dataset"
47
+ ]
48
+ },
49
+ {
50
+ "cell_type": "code",
51
+ "execution_count": 4,
52
+ "id": "23952eb2-8e73-4784-a5ca-534bfae44c80",
53
+ "metadata": {},
54
+ "outputs": [
55
+ {
56
+ "data": {
57
+ "text/plain": [
58
+ "{'text': '### Human: ¿CUales son las etapas del desarrollo y en qué consisten según Piaget?### Assistant: Jean Piaget fue un psicólogo suizo que propuso una teoría sobre el desarrollo cognitivo humano que consta de cuatro etapas:\\n\\nEtapa sensoriomotora (0-2 años): Durante esta etapa, el niño aprende a través de sus sentidos y movimientos. Descubre que sus acciones pueden tener un impacto en el entorno y comienza a formarse una idea básica de objetividad y continuidad.\\n\\nEtapa preoperatoria (2-7 años): En esta etapa, el niño comienza a desarrollar un pensamiento simbólico y a comprender que las cosas pueden representar a otras cosas. También comienzan a desarrollar un pensamiento lógico y a comprender conceptos como la causa y el efecto.\\n\\nEtapa de operaciones concretas (7-12 años): Durante esta etapa, el niño desarrolla un pensamiento lógico y comprende las relaciones causales. Empiezan a comprender que las cosas pueden tener múltiples perspectivas y que los conceptos pueden ser más complejos de lo que parecen a simple vista.\\n\\nEtapa de operaciones formales (12 años en adelante): En esta etapa, el individuo desarrolla un pensamiento abstracto y puede comprender conceptos complejos y abstractos. Son capaces de razonar hipotéticamente y tienen la capacidad de reflexionar sobre su propio pensamiento.\\n\\nEstas etapas no son lineales y algunos individuos pueden avanzar en una etapa más rápidamente que en otras. La teoría de Piaget sobre el desarrollo cognitivo ha sido ampliamente utilizada y es una base importante para la investigación y el entendimiento del desarrollo humano.### Human: ¿Hay otras teorías sobre las etapas del desarrollo que reafirmen o contradigan a la teoría de Piaget?'}"
59
+ ]
60
+ },
61
+ "execution_count": 4,
62
+ "metadata": {},
63
+ "output_type": "execute_result"
64
+ }
65
+ ],
66
+ "source": [
67
+ "dataset[1]"
68
+ ]
69
+ },
70
+ {
71
+ "cell_type": "code",
72
+ "execution_count": 5,
73
+ "id": "a855608b-9609-424f-b482-f9a45b592369",
74
+ "metadata": {},
75
+ "outputs": [
76
+ {
77
+ "data": {
78
+ "application/vnd.jupyter.widget-view+json": {
79
+ "model_id": "5ce955c31dd74916b7c4c8b7044a4564",
80
+ "version_major": 2,
81
+ "version_minor": 0
82
+ },
83
+ "text/plain": [
84
+ "config.json: 0%| | 0.00/581 [00:00<?, ?B/s]"
85
+ ]
86
+ },
87
+ "metadata": {},
88
+ "output_type": "display_data"
89
+ },
90
+ {
91
+ "data": {
92
+ "application/vnd.jupyter.widget-view+json": {
93
+ "model_id": "4fab3613650d4fe08c849884fd81db32",
94
+ "version_major": 2,
95
+ "version_minor": 0
96
+ },
97
+ "text/plain": [
98
+ "pytorch_model.bin.index.json: 0%| | 0.00/16.9k [00:00<?, ?B/s]"
99
+ ]
100
+ },
101
+ "metadata": {},
102
+ "output_type": "display_data"
103
+ },
104
+ {
105
+ "data": {
106
+ "application/vnd.jupyter.widget-view+json": {
107
+ "model_id": "b3b253f625eb4b5cbda7166794d9287d",
108
+ "version_major": 2,
109
+ "version_minor": 0
110
+ },
111
+ "text/plain": [
112
+ "Downloading shards: 0%| | 0/8 [00:00<?, ?it/s]"
113
+ ]
114
+ },
115
+ "metadata": {},
116
+ "output_type": "display_data"
117
+ },
118
+ {
119
+ "data": {
120
+ "application/vnd.jupyter.widget-view+json": {
121
+ "model_id": "54493316f83044bcbf17e435e61288bd",
122
+ "version_major": 2,
123
+ "version_minor": 0
124
+ },
125
+ "text/plain": [
126
+ "pytorch_model-00001-of-00008.bin: 0%| | 0.00/1.92G [00:00<?, ?B/s]"
127
+ ]
128
+ },
129
+ "metadata": {},
130
+ "output_type": "display_data"
131
+ },
132
+ {
133
+ "data": {
134
+ "application/vnd.jupyter.widget-view+json": {
135
+ "model_id": "2fcf4eabf2a841b293af52eb6ee2c681",
136
+ "version_major": 2,
137
+ "version_minor": 0
138
+ },
139
+ "text/plain": [
140
+ "pytorch_model-00002-of-00008.bin: 0%| | 0.00/1.99G [00:00<?, ?B/s]"
141
+ ]
142
+ },
143
+ "metadata": {},
144
+ "output_type": "display_data"
145
+ },
146
+ {
147
+ "data": {
148
+ "application/vnd.jupyter.widget-view+json": {
149
+ "model_id": "50624335a579460295b5e7ab39ae11f4",
150
+ "version_major": 2,
151
+ "version_minor": 0
152
+ },
153
+ "text/plain": [
154
+ "pytorch_model-00003-of-00008.bin: 0%| | 0.00/1.91G [00:00<?, ?B/s]"
155
+ ]
156
+ },
157
+ "metadata": {},
158
+ "output_type": "display_data"
159
+ },
160
+ {
161
+ "data": {
162
+ "application/vnd.jupyter.widget-view+json": {
163
+ "model_id": "d8cf3d955aaf4b9ead6bb74d7c927654",
164
+ "version_major": 2,
165
+ "version_minor": 0
166
+ },
167
+ "text/plain": [
168
+ "pytorch_model-00004-of-00008.bin: 0%| | 0.00/1.91G [00:00<?, ?B/s]"
169
+ ]
170
+ },
171
+ "metadata": {},
172
+ "output_type": "display_data"
173
+ },
174
+ {
175
+ "data": {
176
+ "application/vnd.jupyter.widget-view+json": {
177
+ "model_id": "f42b4b4c1f584462850d64560747aeba",
178
+ "version_major": 2,
179
+ "version_minor": 0
180
+ },
181
+ "text/plain": [
182
+ "pytorch_model-00005-of-00008.bin: 0%| | 0.00/1.99G [00:00<?, ?B/s]"
183
+ ]
184
+ },
185
+ "metadata": {},
186
+ "output_type": "display_data"
187
+ },
188
+ {
189
+ "data": {
190
+ "application/vnd.jupyter.widget-view+json": {
191
+ "model_id": "6f7d4b86d3e046909ba321b5d8acd45a",
192
+ "version_major": 2,
193
+ "version_minor": 0
194
+ },
195
+ "text/plain": [
196
+ "pytorch_model-00006-of-00008.bin: 0%| | 0.00/1.91G [00:00<?, ?B/s]"
197
+ ]
198
+ },
199
+ "metadata": {},
200
+ "output_type": "display_data"
201
+ },
202
+ {
203
+ "data": {
204
+ "application/vnd.jupyter.widget-view+json": {
205
+ "model_id": "47c171c788674d2e8dbe8c4bb96a4f2e",
206
+ "version_major": 2,
207
+ "version_minor": 0
208
+ },
209
+ "text/plain": [
210
+ "pytorch_model-00007-of-00008.bin: 0%| | 0.00/1.91G [00:00<?, ?B/s]"
211
+ ]
212
+ },
213
+ "metadata": {},
214
+ "output_type": "display_data"
215
+ },
216
+ {
217
+ "data": {
218
+ "application/vnd.jupyter.widget-view+json": {
219
+ "model_id": "b7eba9bd6d5743faa7377315a447d7f7",
220
+ "version_major": 2,
221
+ "version_minor": 0
222
+ },
223
+ "text/plain": [
224
+ "pytorch_model-00008-of-00008.bin: 0%| | 0.00/921M [00:00<?, ?B/s]"
225
+ ]
226
+ },
227
+ "metadata": {},
228
+ "output_type": "display_data"
229
+ },
230
+ {
231
+ "data": {
232
+ "application/vnd.jupyter.widget-view+json": {
233
+ "model_id": "210346662bbe460cb820dc4693a74bed",
234
+ "version_major": 2,
235
+ "version_minor": 0
236
+ },
237
+ "text/plain": [
238
+ "Loading checkpoint shards: 0%| | 0/8 [00:00<?, ?it/s]"
239
+ ]
240
+ },
241
+ "metadata": {},
242
+ "output_type": "display_data"
243
+ },
244
+ {
245
+ "data": {
246
+ "application/vnd.jupyter.widget-view+json": {
247
+ "model_id": "a4c954c8db594c48b900db6ebb19531e",
248
+ "version_major": 2,
249
+ "version_minor": 0
250
+ },
251
+ "text/plain": [
252
+ "generation_config.json: 0%| | 0.00/116 [00:00<?, ?B/s]"
253
+ ]
254
+ },
255
+ "metadata": {},
256
+ "output_type": "display_data"
257
+ }
258
+ ],
259
+ "source": [
260
+ "import torch\n",
261
+ "from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, AutoTokenizer\n",
262
+ "\n",
263
+ "model_name = \"ybelkada/falcon-7b-sharded-bf16\"\n",
264
+ "\n",
265
+ "bnb_config = BitsAndBytesConfig(\n",
266
+ " load_in_4bit=True,\n",
267
+ " bnb_4bit_quant_type=\"nf4\",\n",
268
+ " bnb_4bit_compute_dtype=torch.float16,\n",
269
+ ")\n",
270
+ "\n",
271
+ "model = AutoModelForCausalLM.from_pretrained(\n",
272
+ " model_name,\n",
273
+ " quantization_config=bnb_config,\n",
274
+ " trust_remote_code=True\n",
275
+ ")\n",
276
+ "model.config.use_cache = False"
277
+ ]
278
+ },
279
+ {
280
+ "cell_type": "code",
281
+ "execution_count": 6,
282
+ "id": "58af3692-0a9a-4bce-ac60-2bb79e900dcc",
283
+ "metadata": {},
284
+ "outputs": [
285
+ {
286
+ "data": {
287
+ "application/vnd.jupyter.widget-view+json": {
288
+ "model_id": "32ef55f0624f4cc49e465f2d1afb866a",
289
+ "version_major": 2,
290
+ "version_minor": 0
291
+ },
292
+ "text/plain": [
293
+ "tokenizer_config.json: 0%| | 0.00/180 [00:00<?, ?B/s]"
294
+ ]
295
+ },
296
+ "metadata": {},
297
+ "output_type": "display_data"
298
+ },
299
+ {
300
+ "data": {
301
+ "application/vnd.jupyter.widget-view+json": {
302
+ "model_id": "bca9b3fb7866469f8070ee008c5f4823",
303
+ "version_major": 2,
304
+ "version_minor": 0
305
+ },
306
+ "text/plain": [
307
+ "tokenizer.json: 0%| | 0.00/2.73M [00:00<?, ?B/s]"
308
+ ]
309
+ },
310
+ "metadata": {},
311
+ "output_type": "display_data"
312
+ },
313
+ {
314
+ "data": {
315
+ "application/vnd.jupyter.widget-view+json": {
316
+ "model_id": "21b8f9c471ac42cab9510ccb734e14f3",
317
+ "version_major": 2,
318
+ "version_minor": 0
319
+ },
320
+ "text/plain": [
321
+ "special_tokens_map.json: 0%| | 0.00/281 [00:00<?, ?B/s]"
322
+ ]
323
+ },
324
+ "metadata": {},
325
+ "output_type": "display_data"
326
+ }
327
+ ],
328
+ "source": [
329
+ "tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)\n",
330
+ "tokenizer.pad_token = tokenizer.eos_token"
331
+ ]
332
+ },
333
+ {
334
+ "cell_type": "code",
335
+ "execution_count": 7,
336
+ "id": "d87ab91d-fe51-4c1c-814a-dbd74d91ab8c",
337
+ "metadata": {},
338
+ "outputs": [
339
+ {
340
+ "data": {
341
+ "text/plain": [
342
+ "'<|endoftext|>'"
343
+ ]
344
+ },
345
+ "execution_count": 7,
346
+ "metadata": {},
347
+ "output_type": "execute_result"
348
+ }
349
+ ],
350
+ "source": [
351
+ "tokenizer.pad_token"
352
+ ]
353
+ },
354
+ {
355
+ "cell_type": "code",
356
+ "execution_count": 8,
357
+ "id": "be54dd49-0cfb-4edd-9dd8-ae16288d9668",
358
+ "metadata": {},
359
+ "outputs": [],
360
+ "source": [
361
+ "tokenizer.unk_token"
362
+ ]
363
+ },
364
+ {
365
+ "cell_type": "code",
366
+ "execution_count": 9,
367
+ "id": "dd346b8a-1f4d-45bf-85ff-facfa9473e99",
368
+ "metadata": {},
369
+ "outputs": [],
370
+ "source": [
371
+ "tokenizer.sep_token"
372
+ ]
373
+ },
374
+ {
375
+ "cell_type": "code",
376
+ "execution_count": 10,
377
+ "id": "bcde26ce-0b19-4a34-a8e6-5ff34b50a964",
378
+ "metadata": {},
379
+ "outputs": [],
380
+ "source": [
381
+ "tokenizer.chat_template"
382
+ ]
383
+ },
384
+ {
385
+ "cell_type": "code",
386
+ "execution_count": 11,
387
+ "id": "2031ebad-fd3c-4b53-824b-a10a57c73762",
388
+ "metadata": {},
389
+ "outputs": [
390
+ {
391
+ "data": {
392
+ "text/plain": [
393
+ "FalconForCausalLM(\n",
394
+ " (transformer): FalconModel(\n",
395
+ " (word_embeddings): Embedding(65024, 4544)\n",
396
+ " (h): ModuleList(\n",
397
+ " (0-31): 32 x FalconDecoderLayer(\n",
398
+ " (self_attention): FalconAttention(\n",
399
+ " (rotary_emb): FalconRotaryEmbedding()\n",
400
+ " (query_key_value): Linear4bit(in_features=4544, out_features=4672, bias=False)\n",
401
+ " (dense): Linear4bit(in_features=4544, out_features=4544, bias=False)\n",
402
+ " (attention_dropout): Dropout(p=0.0, inplace=False)\n",
403
+ " )\n",
404
+ " (mlp): FalconMLP(\n",
405
+ " (dense_h_to_4h): Linear4bit(in_features=4544, out_features=18176, bias=False)\n",
406
+ " (act): GELU(approximate='none')\n",
407
+ " (dense_4h_to_h): Linear4bit(in_features=18176, out_features=4544, bias=False)\n",
408
+ " )\n",
409
+ " (input_layernorm): LayerNorm((4544,), eps=1e-05, elementwise_affine=True)\n",
410
+ " )\n",
411
+ " )\n",
412
+ " (ln_f): LayerNorm((4544,), eps=1e-05, elementwise_affine=True)\n",
413
+ " )\n",
414
+ " (lm_head): Linear(in_features=4544, out_features=65024, bias=False)\n",
415
+ ")"
416
+ ]
417
+ },
418
+ "execution_count": 11,
419
+ "metadata": {},
420
+ "output_type": "execute_result"
421
+ }
422
+ ],
423
+ "source": [
424
+ "model"
425
+ ]
426
+ },
427
+ {
428
+ "cell_type": "code",
429
+ "execution_count": 12,
430
+ "id": "d5c76cc9-5925-4d49-819d-d72a0149bea3",
431
+ "metadata": {},
432
+ "outputs": [],
433
+ "source": [
434
+ "from peft import LoraConfig\n",
435
+ "\n",
436
+ "lora_alpha = 16\n",
437
+ "lora_dropout = 0.1\n",
438
+ "lora_r = 64\n",
439
+ "\n",
440
+ "peft_config = LoraConfig(\n",
441
+ " lora_alpha=lora_alpha,\n",
442
+ " lora_dropout=lora_dropout,\n",
443
+ " r=lora_r,\n",
444
+ " bias=\"none\",\n",
445
+ " task_type=\"CAUSAL_LM\",\n",
446
+ " target_modules=[\n",
447
+ " \"query_key_value\",\n",
448
+ " \"dense\",\n",
449
+ " \"dense_h_to_4h\",\n",
450
+ " \"dense_4h_to_h\",\n",
451
+ " ]\n",
452
+ ")"
453
+ ]
454
+ },
455
+ {
456
+ "cell_type": "code",
457
+ "execution_count": 13,
458
+ "id": "73134583-40da-4e66-ae8f-ecfe798d202a",
459
+ "metadata": {},
460
+ "outputs": [],
461
+ "source": [
462
+ "from transformers import TrainingArguments\n",
463
+ "\n",
464
+ "output_dir = \"./results\"\n",
465
+ "per_device_train_batch_size = 4\n",
466
+ "gradient_accumulation_steps = 4\n",
467
+ "optim = \"paged_adamw_32bit\"\n",
468
+ "save_steps = 10\n",
469
+ "logging_steps = 10\n",
470
+ "learning_rate = 2e-4\n",
471
+ "max_grad_norm = 0.3\n",
472
+ "max_steps = 500\n",
473
+ "warmup_ratio = 0.03\n",
474
+ "lr_scheduler_type = \"constant\"\n",
475
+ "\n",
476
+ "training_arguments = TrainingArguments(\n",
477
+ " output_dir=output_dir,\n",
478
+ " per_device_train_batch_size=per_device_train_batch_size,\n",
479
+ " gradient_accumulation_steps=gradient_accumulation_steps,\n",
480
+ " optim=optim,\n",
481
+ " save_steps=save_steps,\n",
482
+ " logging_steps=logging_steps,\n",
483
+ " learning_rate=learning_rate,\n",
484
+ " fp16=True,\n",
485
+ " max_grad_norm=max_grad_norm,\n",
486
+ " max_steps=max_steps,\n",
487
+ " warmup_ratio=warmup_ratio,\n",
488
+ " group_by_length=True,\n",
489
+ " lr_scheduler_type=lr_scheduler_type,\n",
490
+ " gradient_checkpointing=True,\n",
491
+ ")"
492
+ ]
493
+ },
494
+ {
495
+ "cell_type": "code",
496
+ "execution_count": 14,
497
+ "id": "77305bf4-1e78-4902-8e46-8bad6754946a",
498
+ "metadata": {},
499
+ "outputs": [
500
+ {
501
+ "data": {
502
+ "application/vnd.jupyter.widget-view+json": {
503
+ "model_id": "0fc425435c564dd1bf4baeee15d42691",
504
+ "version_major": 2,
505
+ "version_minor": 0
506
+ },
507
+ "text/plain": [
508
+ "Map: 0%| | 0/9846 [00:00<?, ? examples/s]"
509
+ ]
510
+ },
511
+ "metadata": {},
512
+ "output_type": "display_data"
513
+ }
514
+ ],
515
+ "source": [
516
+ "from trl import SFTTrainer\n",
517
+ "\n",
518
+ "max_seq_length = 512\n",
519
+ "\n",
520
+ "trainer = SFTTrainer(\n",
521
+ " model=model,\n",
522
+ " train_dataset=dataset,\n",
523
+ " peft_config=peft_config,\n",
524
+ " dataset_text_field=\"text\",\n",
525
+ " max_seq_length=max_seq_length,\n",
526
+ " tokenizer=tokenizer,\n",
527
+ " args=training_arguments,\n",
528
+ ")"
529
+ ]
530
+ },
531
+ {
532
+ "cell_type": "code",
533
+ "execution_count": 15,
534
+ "id": "7d110181-e5d6-4d64-9816-5d8059b5168e",
535
+ "metadata": {},
536
+ "outputs": [],
537
+ "source": [
538
+ "for name, module in trainer.model.named_modules():\n",
539
+ " if \"norm\" in name:\n",
540
+ " module = module.to(torch.float32)"
541
+ ]
542
+ },
543
+ {
544
+ "cell_type": "code",
545
+ "execution_count": null,
546
+ "id": "23bf9d6d-59b4-47c0-8461-e6e1ee9abea6",
547
+ "metadata": {},
548
+ "outputs": [
549
+ {
550
+ "name": "stderr",
551
+ "output_type": "stream",
552
+ "text": [
553
+ "You're using a PreTrainedTokenizerFast tokenizer. Please note that with a fast tokenizer, using the `__call__` method is faster than using a method to encode the text followed by a call to the `pad` method to get a padded encoding.\n",
554
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
555
+ " warnings.warn(\n",
556
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
557
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n"
558
+ ]
559
+ },
560
+ {
561
+ "data": {
562
+ "text/html": [
563
+ "\n",
564
+ " <div>\n",
565
+ " \n",
566
+ " <progress value='220' max='500' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
567
+ " [220/500 2:04:17 < 2:39:38, 0.03 it/s, Epoch 0.71/2]\n",
568
+ " </div>\n",
569
+ " <table border=\"1\" class=\"dataframe\">\n",
570
+ " <thead>\n",
571
+ " <tr style=\"text-align: left;\">\n",
572
+ " <th>Step</th>\n",
573
+ " <th>Training Loss</th>\n",
574
+ " </tr>\n",
575
+ " </thead>\n",
576
+ " <tbody>\n",
577
+ " <tr>\n",
578
+ " <td>10</td>\n",
579
+ " <td>1.316300</td>\n",
580
+ " </tr>\n",
581
+ " <tr>\n",
582
+ " <td>20</td>\n",
583
+ " <td>1.266000</td>\n",
584
+ " </tr>\n",
585
+ " <tr>\n",
586
+ " <td>30</td>\n",
587
+ " <td>1.342400</td>\n",
588
+ " </tr>\n",
589
+ " <tr>\n",
590
+ " <td>40</td>\n",
591
+ " <td>1.548100</td>\n",
592
+ " </tr>\n",
593
+ " <tr>\n",
594
+ " <td>50</td>\n",
595
+ " <td>1.771500</td>\n",
596
+ " </tr>\n",
597
+ " <tr>\n",
598
+ " <td>60</td>\n",
599
+ " <td>1.232100</td>\n",
600
+ " </tr>\n",
601
+ " <tr>\n",
602
+ " <td>70</td>\n",
603
+ " <td>1.275000</td>\n",
604
+ " </tr>\n",
605
+ " <tr>\n",
606
+ " <td>80</td>\n",
607
+ " <td>1.318400</td>\n",
608
+ " </tr>\n",
609
+ " <tr>\n",
610
+ " <td>90</td>\n",
611
+ " <td>1.590500</td>\n",
612
+ " </tr>\n",
613
+ " <tr>\n",
614
+ " <td>100</td>\n",
615
+ " <td>1.756100</td>\n",
616
+ " </tr>\n",
617
+ " <tr>\n",
618
+ " <td>110</td>\n",
619
+ " <td>1.189800</td>\n",
620
+ " </tr>\n",
621
+ " <tr>\n",
622
+ " <td>120</td>\n",
623
+ " <td>1.202800</td>\n",
624
+ " </tr>\n",
625
+ " <tr>\n",
626
+ " <td>130</td>\n",
627
+ " <td>1.339000</td>\n",
628
+ " </tr>\n",
629
+ " <tr>\n",
630
+ " <td>140</td>\n",
631
+ " <td>1.559700</td>\n",
632
+ " </tr>\n",
633
+ " <tr>\n",
634
+ " <td>150</td>\n",
635
+ " <td>1.804100</td>\n",
636
+ " </tr>\n",
637
+ " <tr>\n",
638
+ " <td>160</td>\n",
639
+ " <td>1.186700</td>\n",
640
+ " </tr>\n",
641
+ " <tr>\n",
642
+ " <td>170</td>\n",
643
+ " <td>1.242300</td>\n",
644
+ " </tr>\n",
645
+ " <tr>\n",
646
+ " <td>180</td>\n",
647
+ " <td>1.337900</td>\n",
648
+ " </tr>\n",
649
+ " <tr>\n",
650
+ " <td>190</td>\n",
651
+ " <td>1.535100</td>\n",
652
+ " </tr>\n",
653
+ " <tr>\n",
654
+ " <td>200</td>\n",
655
+ " <td>1.791000</td>\n",
656
+ " </tr>\n",
657
+ " <tr>\n",
658
+ " <td>210</td>\n",
659
+ " <td>1.160500</td>\n",
660
+ " </tr>\n",
661
+ " </tbody>\n",
662
+ "</table><p>"
663
+ ],
664
+ "text/plain": [
665
+ "<IPython.core.display.HTML object>"
666
+ ]
667
+ },
668
+ "metadata": {},
669
+ "output_type": "display_data"
670
+ },
671
+ {
672
+ "name": "stderr",
673
+ "output_type": "stream",
674
+ "text": [
675
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
676
+ " warnings.warn(\n",
677
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
678
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
679
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
680
+ " warnings.warn(\n",
681
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
682
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
683
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
684
+ " warnings.warn(\n",
685
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
686
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
687
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
688
+ " warnings.warn(\n",
689
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
690
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
691
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
692
+ " warnings.warn(\n",
693
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
694
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
695
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
696
+ " warnings.warn(\n",
697
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
698
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
699
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
700
+ " warnings.warn(\n",
701
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
702
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
703
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
704
+ " warnings.warn(\n",
705
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
706
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
707
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
708
+ " warnings.warn(\n",
709
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
710
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
711
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
712
+ " warnings.warn(\n",
713
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
714
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
715
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
716
+ " warnings.warn(\n",
717
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
718
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
719
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
720
+ " warnings.warn(\n",
721
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
722
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
723
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
724
+ " warnings.warn(\n",
725
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
726
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
727
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
728
+ " warnings.warn(\n",
729
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
730
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
731
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
732
+ " warnings.warn(\n",
733
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
734
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
735
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
736
+ " warnings.warn(\n",
737
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
738
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
739
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
740
+ " warnings.warn(\n",
741
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
742
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
743
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
744
+ " warnings.warn(\n",
745
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
746
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
747
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
748
+ " warnings.warn(\n",
749
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
750
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
751
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
752
+ " warnings.warn(\n",
753
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
754
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
755
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
756
+ " warnings.warn(\n",
757
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
758
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n"
759
+ ]
760
+ }
761
+ ],
762
+ "source": [
763
+ "trainer.train()"
764
+ ]
765
+ },
766
+ {
767
+ "cell_type": "code",
768
+ "execution_count": 18,
769
+ "id": "cffe2159-f2ad-4af2-8b40-226bb726201c",
770
+ "metadata": {},
771
+ "outputs": [],
772
+ "source": [
773
+ "from transformers import (\n",
774
+ " AutoModelForCausalLM,\n",
775
+ " AutoTokenizer,\n",
776
+ " BitsAndBytesConfig,\n",
777
+ " HfArgumentParser,\n",
778
+ " TrainingArguments,\n",
779
+ " pipeline,\n",
780
+ " logging,\n",
781
+ ")"
782
+ ]
783
+ },
784
+ {
785
+ "cell_type": "code",
786
+ "execution_count": 19,
787
+ "id": "4f6f9cb9-571c-4b8f-b6e5-2b95ea30f4b3",
788
+ "metadata": {},
789
+ "outputs": [
790
+ {
791
+ "name": "stderr",
792
+ "output_type": "stream",
793
+ "text": [
794
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/transformers/generation/utils.py:1518: UserWarning: You have modified the pretrained model configuration to control generation. This is a deprecated strategy to control generation and will be removed soon, in a future version. Please use and modify the model generation configuration (see https://huggingface.co/docs/transformers/generation_strategies#default-text-generation-configuration )\n",
795
+ " warnings.warn(\n",
796
+ "Setting `pad_token_id` to `eos_token_id`:11 for open-end generation.\n",
797
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:429: UserWarning: torch.utils.checkpoint: please pass in use_reentrant=True or use_reentrant=False explicitly. The default value of use_reentrant will be updated to be False in the future. To maintain current behavior, pass use_reentrant=True. It is recommended that you use use_reentrant=False. Refer to docs for more details on the differences between the two variants.\n",
798
+ " warnings.warn(\n",
799
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/utils/checkpoint.py:61: UserWarning: None of the inputs have requires_grad=True. Gradients will be None\n",
800
+ " warnings.warn(\n"
801
+ ]
802
+ },
803
+ {
804
+ "name": "stdout",
805
+ "output_type": "stream",
806
+ "text": [
807
+ "<s>[INST] What is a large language model? [/INST]</s>\n",
808
+ "\n",
809
+ "A large language model (LLM) is a type of machine learning model that is designed to process and understand large amounts of text data. LLMs are typically trained on large datasets of text, such as news articles, social media posts, or chat logs, and can be used for tasks such as natural language processing (NLP), sentiment analysis, and text generation.\n",
810
+ "\n",
811
+ "LLMs are different from traditional machine learning models in that they are designed to process large amounts of text data in a single pass, rather than processing one piece of data at a time. This allows them to learn patterns and relationships between words and phrases, and to generate text that is more natural and coherent than traditional models.\n",
812
+ "\n",
813
+ "LLMs have been shown to be effective in a wide range of applications, including text summarization, question answering, and machine translation. They have also been used to generate\n"
814
+ ]
815
+ }
816
+ ],
817
+ "source": [
818
+ "# Run text generation pipeline with our next model\n",
819
+ "prompt = \"What is a large language model?\"\n",
820
+ "pipe = pipeline(task=\"text-generation\", model=model, tokenizer=tokenizer, max_length=200)\n",
821
+ "result = pipe(f\"<s>[INST] {prompt} [/INST]\")\n",
822
+ "print(result[0]['generated_text'])"
823
+ ]
824
+ },
825
+ {
826
+ "cell_type": "code",
827
+ "execution_count": 20,
828
+ "id": "e61ae4be-eb58-457a-b4b6-f02ec42f0782",
829
+ "metadata": {},
830
+ "outputs": [
831
+ {
832
+ "name": "stderr",
833
+ "output_type": "stream",
834
+ "text": [
835
+ "Setting `pad_token_id` to `eos_token_id`:11 for open-end generation.\n"
836
+ ]
837
+ },
838
+ {
839
+ "name": "stdout",
840
+ "output_type": "stream",
841
+ "text": [
842
+ "What is a large language model?\n",
843
+ "Large language models (LLMs) are a type of artificial intelligence (AI) model that can understand and generate human language. They are designed to mimic the way humans process language, and can be used for tasks such as natural language processing (NLP), machine translation, and chatbots.\n",
844
+ "LLMs are typically large neural networks that are trained on massive amounts of data, such as text corpora or large language models. They are designed to learn patterns and relationships in the data, and can be used to perform tasks such as sentiment analysis, topic modeling, and question answering.\n",
845
+ "LLMs are often used in applications where accuracy and speed are critical, such as in speech recognition, machine translation, and natural language processing. They can also be used to generate text, images, and other forms of media.\n",
846
+ "The size of an LLM can be measured in terms of the number of parameters or weights in the model. The larger the model\n"
847
+ ]
848
+ }
849
+ ],
850
+ "source": [
851
+ "# Run text generation pipeline with our next model\n",
852
+ "prompt = \"What is a large language model?\"\n",
853
+ "pipe = pipeline(task=\"text-generation\", model=model, tokenizer=tokenizer, max_length=200)\n",
854
+ "result = pipe(prompt)\n",
855
+ "print(result[0]['generated_text'])"
856
+ ]
857
+ },
858
+ {
859
+ "cell_type": "code",
860
+ "execution_count": 21,
861
+ "id": "5d0f2d66-e942-4046-a28d-b0b6f5f9c52f",
862
+ "metadata": {},
863
+ "outputs": [
864
+ {
865
+ "name": "stderr",
866
+ "output_type": "stream",
867
+ "text": [
868
+ "Setting `pad_token_id` to `eos_token_id`:11 for open-end generation.\n"
869
+ ]
870
+ },
871
+ {
872
+ "name": "stdout",
873
+ "output_type": "stream",
874
+ "text": [
875
+ "<|im_start|>user\n",
876
+ "What is a large language model?<|im_end|>\n",
877
+ "<|im_start|>assistant\n",
878
+ "Large language models are a type of artificial intelligence (AI) technology that can understand and generate human language. They are designed to mimic the way humans think and communicate, and can perform tasks such as answering questions, writing essays, and translating between languages.\n",
879
+ "<|im_end|>user\n",
880
+ "What are some examples of large language models?<|im_start|>assistant\n",
881
+ "There are many large language models, including:\n",
882
+ "- ChatGPT: A language model developed by OpenAI that can engage in text-based conversations and answer questions.\n",
883
+ "- GPT-3: A language model developed by OpenAI that can generate text, including creative writing and poetry.\n",
884
+ "- GPT-J: A language model developed by OpenAI that can generate text in a variety of languages.\n",
885
+ "- GPT-Neo: A language\n"
886
+ ]
887
+ }
888
+ ],
889
+ "source": [
890
+ "prompt = \"What is a large language model?\"\n",
891
+ "\n",
892
+ "prompt_ct = f\"<|im_start|>user\\n{prompt}<|im_end|>\\n<|im_start|>assistant\"\n",
893
+ "pipe = pipeline(task=\"text-generation\", model=model, tokenizer=tokenizer, max_length=200)\n",
894
+ "result = pipe(prompt_ct)\n",
895
+ "print(result[0]['generated_text'])"
896
+ ]
897
+ },
898
+ {
899
+ "cell_type": "code",
900
+ "execution_count": null,
901
+ "id": "6f6740be-89a8-49a4-8e94-575eb1bdfb18",
902
+ "metadata": {},
903
+ "outputs": [],
904
+ "source": []
905
+ }
906
+ ],
907
+ "metadata": {
908
+ "kernelspec": {
909
+ "display_name": "Python 3 (ipykernel)",
910
+ "language": "python",
911
+ "name": "python3"
912
+ },
913
+ "language_info": {
914
+ "codemirror_mode": {
915
+ "name": "ipython",
916
+ "version": 3
917
+ },
918
+ "file_extension": ".py",
919
+ "mimetype": "text/x-python",
920
+ "name": "python",
921
+ "nbconvert_exporter": "python",
922
+ "pygments_lexer": "ipython3",
923
+ "version": "3.10.12"
924
+ }
925
+ },
926
+ "nbformat": 4,
927
+ "nbformat_minor": 5
928
+ }
Phi2_SFT.ipynb ADDED
@@ -0,0 +1,897 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "id": "8a904d03-8c1a-4eb4-bd77-a26ec985d992",
6
+ "metadata": {},
7
+ "source": [
8
+ "## Load the Dataset"
9
+ ]
10
+ },
11
+ {
12
+ "cell_type": "code",
13
+ "execution_count": 1,
14
+ "id": "f398bea9-d201-43ae-95e8-d4fad1de651c",
15
+ "metadata": {},
16
+ "outputs": [],
17
+ "source": [
18
+ "# Opening modified dataset uploaded to HF\n",
19
+ "from datasets import load_dataset\n",
20
+ "\n",
21
+ "dataset_name = \"RaviNaik/oasst1-chatml\"\n",
22
+ "dataset = load_dataset(dataset_name, split=\"train\")"
23
+ ]
24
+ },
25
+ {
26
+ "cell_type": "markdown",
27
+ "id": "b74449fb-9f01-4c96-8a7e-6661180be1f3",
28
+ "metadata": {},
29
+ "source": [
30
+ "## Load the Model, Tokenizer and configure bnb"
31
+ ]
32
+ },
33
+ {
34
+ "cell_type": "code",
35
+ "execution_count": 2,
36
+ "id": "ab5a26da-b9e0-424f-b482-034c10f049ce",
37
+ "metadata": {},
38
+ "outputs": [],
39
+ "source": [
40
+ "import torch\n",
41
+ "from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig, AutoTokenizer"
42
+ ]
43
+ },
44
+ {
45
+ "cell_type": "code",
46
+ "execution_count": 3,
47
+ "id": "8f5d677d-082a-4d96-9fab-4d66981ecc27",
48
+ "metadata": {},
49
+ "outputs": [
50
+ {
51
+ "data": {
52
+ "application/vnd.jupyter.widget-view+json": {
53
+ "model_id": "88aa19589a2b46f9888c214db3867598",
54
+ "version_major": 2,
55
+ "version_minor": 0
56
+ },
57
+ "text/plain": [
58
+ "Loading checkpoint shards: 0%| | 0/2 [00:00<?, ?it/s]"
59
+ ]
60
+ },
61
+ "metadata": {},
62
+ "output_type": "display_data"
63
+ }
64
+ ],
65
+ "source": [
66
+ "model_name = \"microsoft/phi-2\"\n",
67
+ "\n",
68
+ "bnb_config = BitsAndBytesConfig(\n",
69
+ " load_in_4bit=True,\n",
70
+ " bnb_4bit_quant_type=\"nf4\",\n",
71
+ " bnb_4bit_compute_dtype=torch.float16,\n",
72
+ ")\n",
73
+ "\n",
74
+ "model = AutoModelForCausalLM.from_pretrained(\n",
75
+ " model_name,\n",
76
+ " quantization_config=bnb_config,\n",
77
+ " trust_remote_code=True,\n",
78
+ " device_map=\"cuda:0\"\n",
79
+ ")\n",
80
+ "model.config.use_cache = False"
81
+ ]
82
+ },
83
+ {
84
+ "cell_type": "code",
85
+ "execution_count": 4,
86
+ "id": "0d649bc1-69d0-4683-b3e7-b999f4a52ce7",
87
+ "metadata": {},
88
+ "outputs": [
89
+ {
90
+ "name": "stderr",
91
+ "output_type": "stream",
92
+ "text": [
93
+ "Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n"
94
+ ]
95
+ }
96
+ ],
97
+ "source": [
98
+ "tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, device_map=\"cuda:0\")\n",
99
+ "tokenizer.pad_token = tokenizer.eos_token"
100
+ ]
101
+ },
102
+ {
103
+ "cell_type": "markdown",
104
+ "id": "2304e9e1-fe0a-48c9-8eaa-605af8d93ea1",
105
+ "metadata": {},
106
+ "source": [
107
+ "## Display Model Layers"
108
+ ]
109
+ },
110
+ {
111
+ "cell_type": "code",
112
+ "execution_count": 5,
113
+ "id": "0d572c85-fc5b-407d-bdd9-667c3cdb74bd",
114
+ "metadata": {},
115
+ "outputs": [
116
+ {
117
+ "data": {
118
+ "text/plain": [
119
+ "PhiForCausalLM(\n",
120
+ " (transformer): PhiModel(\n",
121
+ " (embd): Embedding(\n",
122
+ " (wte): Embedding(51200, 2560)\n",
123
+ " (drop): Dropout(p=0.0, inplace=False)\n",
124
+ " )\n",
125
+ " (h): ModuleList(\n",
126
+ " (0-31): 32 x ParallelBlock(\n",
127
+ " (ln): LayerNorm((2560,), eps=1e-05, elementwise_affine=True)\n",
128
+ " (resid_dropout): Dropout(p=0.1, inplace=False)\n",
129
+ " (mixer): MHA(\n",
130
+ " (rotary_emb): RotaryEmbedding()\n",
131
+ " (Wqkv): Linear4bit(in_features=2560, out_features=7680, bias=True)\n",
132
+ " (out_proj): Linear4bit(in_features=2560, out_features=2560, bias=True)\n",
133
+ " (inner_attn): SelfAttention(\n",
134
+ " (drop): Dropout(p=0.0, inplace=False)\n",
135
+ " )\n",
136
+ " (inner_cross_attn): CrossAttention(\n",
137
+ " (drop): Dropout(p=0.0, inplace=False)\n",
138
+ " )\n",
139
+ " )\n",
140
+ " (mlp): MLP(\n",
141
+ " (fc1): Linear4bit(in_features=2560, out_features=10240, bias=True)\n",
142
+ " (fc2): Linear4bit(in_features=10240, out_features=2560, bias=True)\n",
143
+ " (act): NewGELUActivation()\n",
144
+ " )\n",
145
+ " )\n",
146
+ " )\n",
147
+ " )\n",
148
+ " (lm_head): CausalLMHead(\n",
149
+ " (ln): LayerNorm((2560,), eps=1e-05, elementwise_affine=True)\n",
150
+ " (linear): Linear(in_features=2560, out_features=51200, bias=True)\n",
151
+ " )\n",
152
+ " (loss): CausalLMLoss(\n",
153
+ " (loss_fct): CrossEntropyLoss()\n",
154
+ " )\n",
155
+ ")"
156
+ ]
157
+ },
158
+ "execution_count": 5,
159
+ "metadata": {},
160
+ "output_type": "execute_result"
161
+ }
162
+ ],
163
+ "source": [
164
+ "model"
165
+ ]
166
+ },
167
+ {
168
+ "cell_type": "markdown",
169
+ "id": "7d628159-3f0e-43eb-bf7b-12129f54e0df",
170
+ "metadata": {},
171
+ "source": [
172
+ "## Configure LoRA for finetuning"
173
+ ]
174
+ },
175
+ {
176
+ "cell_type": "code",
177
+ "execution_count": 6,
178
+ "id": "45d0e0e8-a8d8-4a05-9c7d-4f6217b57310",
179
+ "metadata": {},
180
+ "outputs": [],
181
+ "source": [
182
+ "from peft import LoraConfig"
183
+ ]
184
+ },
185
+ {
186
+ "cell_type": "code",
187
+ "execution_count": 7,
188
+ "id": "2cb2780d-609d-4fba-902d-a2526863b02c",
189
+ "metadata": {},
190
+ "outputs": [],
191
+ "source": [
192
+ "lora_alpha = 16\n",
193
+ "lora_dropout = 0.1\n",
194
+ "lora_r = 64\n",
195
+ "\n",
196
+ "peft_config = LoraConfig(\n",
197
+ " lora_alpha=lora_alpha,\n",
198
+ " lora_dropout=lora_dropout,\n",
199
+ " r=lora_r,\n",
200
+ " bias=\"none\",\n",
201
+ " task_type=\"CAUSAL_LM\",\n",
202
+ " target_modules=[\n",
203
+ " \"Wqkv\",\n",
204
+ " \"out_proj\",\n",
205
+ " \"fc1\",\n",
206
+ " \"fc2\",\n",
207
+ " ]\n",
208
+ ")"
209
+ ]
210
+ },
211
+ {
212
+ "cell_type": "markdown",
213
+ "id": "f1ed1b63-2263-4574-9497-180acd38ec14",
214
+ "metadata": {},
215
+ "source": [
216
+ "## Configure Training Params"
217
+ ]
218
+ },
219
+ {
220
+ "cell_type": "code",
221
+ "execution_count": 8,
222
+ "id": "f5074cda-91b9-4077-9d9f-b74d34778767",
223
+ "metadata": {},
224
+ "outputs": [],
225
+ "source": [
226
+ "from transformers import TrainingArguments"
227
+ ]
228
+ },
229
+ {
230
+ "cell_type": "code",
231
+ "execution_count": 9,
232
+ "id": "a793135a-a797-42b1-935d-fb969772a91f",
233
+ "metadata": {},
234
+ "outputs": [],
235
+ "source": [
236
+ "output_dir = \"./results\"\n",
237
+ "per_device_train_batch_size = 4\n",
238
+ "gradient_accumulation_steps = 4\n",
239
+ "optim = \"paged_adamw_32bit\"\n",
240
+ "save_steps = 100\n",
241
+ "logging_steps = 10\n",
242
+ "learning_rate = 2e-4\n",
243
+ "max_grad_norm = 0.3\n",
244
+ "max_steps = 500\n",
245
+ "warmup_ratio = 0.03\n",
246
+ "lr_scheduler_type = \"constant\"\n",
247
+ "\n",
248
+ "training_arguments = TrainingArguments(\n",
249
+ " output_dir=output_dir,\n",
250
+ " per_device_train_batch_size=per_device_train_batch_size,\n",
251
+ " gradient_accumulation_steps=gradient_accumulation_steps,\n",
252
+ " optim=optim,\n",
253
+ " save_steps=save_steps,\n",
254
+ " logging_steps=logging_steps,\n",
255
+ " learning_rate=learning_rate,\n",
256
+ " fp16=True,\n",
257
+ " max_grad_norm=max_grad_norm,\n",
258
+ " max_steps=max_steps,\n",
259
+ " warmup_ratio=warmup_ratio,\n",
260
+ " group_by_length=True,\n",
261
+ " lr_scheduler_type=lr_scheduler_type,\n",
262
+ " gradient_checkpointing=False,\n",
263
+ ")"
264
+ ]
265
+ },
266
+ {
267
+ "cell_type": "code",
268
+ "execution_count": 10,
269
+ "id": "606d810a-8eaa-42df-9804-9f6bd421dee6",
270
+ "metadata": {},
271
+ "outputs": [],
272
+ "source": [
273
+ "from trl import SFTTrainer"
274
+ ]
275
+ },
276
+ {
277
+ "cell_type": "code",
278
+ "execution_count": 11,
279
+ "id": "d554e892-5966-4cb3-9ef4-ede9a14a50e6",
280
+ "metadata": {},
281
+ "outputs": [],
282
+ "source": [
283
+ "max_seq_length = 256\n",
284
+ "\n",
285
+ "trainer = SFTTrainer(\n",
286
+ " model=model,\n",
287
+ " train_dataset=dataset,\n",
288
+ " peft_config=peft_config,\n",
289
+ " dataset_text_field=\"text\",\n",
290
+ " max_seq_length=max_seq_length,\n",
291
+ " tokenizer=tokenizer,\n",
292
+ " args=training_arguments,\n",
293
+ ")"
294
+ ]
295
+ },
296
+ {
297
+ "cell_type": "code",
298
+ "execution_count": 12,
299
+ "id": "129c1914-447d-4e95-9346-fe9eb892eb12",
300
+ "metadata": {},
301
+ "outputs": [],
302
+ "source": [
303
+ "for name, module in trainer.model.named_modules():\n",
304
+ " if \"norm\" in name:\n",
305
+ " module = module.to(torch.float32).to(\"cuda:0\")"
306
+ ]
307
+ },
308
+ {
309
+ "cell_type": "markdown",
310
+ "id": "a9f421a1-073d-4042-a092-650d7f6d27ec",
311
+ "metadata": {},
312
+ "source": [
313
+ "## Begin Training"
314
+ ]
315
+ },
316
+ {
317
+ "cell_type": "code",
318
+ "execution_count": 13,
319
+ "id": "ca7336ee-fc7d-479e-a384-24737ab74007",
320
+ "metadata": {},
321
+ "outputs": [
322
+ {
323
+ "name": "stderr",
324
+ "output_type": "stream",
325
+ "text": [
326
+ "You're using a CodeGenTokenizerFast tokenizer. Please note that with a fast tokenizer, using the `__call__` method is faster than using a method to encode the text followed by a call to the `pad` method to get a padded encoding.\n",
327
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
328
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n"
329
+ ]
330
+ },
331
+ {
332
+ "data": {
333
+ "text/html": [
334
+ "\n",
335
+ " <div>\n",
336
+ " \n",
337
+ " <progress value='500' max='500' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
338
+ " [500/500 1:11:36, Epoch 1/2]\n",
339
+ " </div>\n",
340
+ " <table border=\"1\" class=\"dataframe\">\n",
341
+ " <thead>\n",
342
+ " <tr style=\"text-align: left;\">\n",
343
+ " <th>Step</th>\n",
344
+ " <th>Training Loss</th>\n",
345
+ " </tr>\n",
346
+ " </thead>\n",
347
+ " <tbody>\n",
348
+ " <tr>\n",
349
+ " <td>10</td>\n",
350
+ " <td>1.720800</td>\n",
351
+ " </tr>\n",
352
+ " <tr>\n",
353
+ " <td>20</td>\n",
354
+ " <td>1.548300</td>\n",
355
+ " </tr>\n",
356
+ " <tr>\n",
357
+ " <td>30</td>\n",
358
+ " <td>1.550700</td>\n",
359
+ " </tr>\n",
360
+ " <tr>\n",
361
+ " <td>40</td>\n",
362
+ " <td>1.543500</td>\n",
363
+ " </tr>\n",
364
+ " <tr>\n",
365
+ " <td>50</td>\n",
366
+ " <td>1.506600</td>\n",
367
+ " </tr>\n",
368
+ " <tr>\n",
369
+ " <td>60</td>\n",
370
+ " <td>1.501400</td>\n",
371
+ " </tr>\n",
372
+ " <tr>\n",
373
+ " <td>70</td>\n",
374
+ " <td>1.559600</td>\n",
375
+ " </tr>\n",
376
+ " <tr>\n",
377
+ " <td>80</td>\n",
378
+ " <td>1.552900</td>\n",
379
+ " </tr>\n",
380
+ " <tr>\n",
381
+ " <td>90</td>\n",
382
+ " <td>1.506300</td>\n",
383
+ " </tr>\n",
384
+ " <tr>\n",
385
+ " <td>100</td>\n",
386
+ " <td>1.471700</td>\n",
387
+ " </tr>\n",
388
+ " <tr>\n",
389
+ " <td>110</td>\n",
390
+ " <td>1.484100</td>\n",
391
+ " </tr>\n",
392
+ " <tr>\n",
393
+ " <td>120</td>\n",
394
+ " <td>1.498100</td>\n",
395
+ " </tr>\n",
396
+ " <tr>\n",
397
+ " <td>130</td>\n",
398
+ " <td>1.517600</td>\n",
399
+ " </tr>\n",
400
+ " <tr>\n",
401
+ " <td>140</td>\n",
402
+ " <td>1.481100</td>\n",
403
+ " </tr>\n",
404
+ " <tr>\n",
405
+ " <td>150</td>\n",
406
+ " <td>1.485100</td>\n",
407
+ " </tr>\n",
408
+ " <tr>\n",
409
+ " <td>160</td>\n",
410
+ " <td>1.516800</td>\n",
411
+ " </tr>\n",
412
+ " <tr>\n",
413
+ " <td>170</td>\n",
414
+ " <td>1.505000</td>\n",
415
+ " </tr>\n",
416
+ " <tr>\n",
417
+ " <td>180</td>\n",
418
+ " <td>1.484600</td>\n",
419
+ " </tr>\n",
420
+ " <tr>\n",
421
+ " <td>190</td>\n",
422
+ " <td>1.495200</td>\n",
423
+ " </tr>\n",
424
+ " <tr>\n",
425
+ " <td>200</td>\n",
426
+ " <td>1.447100</td>\n",
427
+ " </tr>\n",
428
+ " <tr>\n",
429
+ " <td>210</td>\n",
430
+ " <td>1.520700</td>\n",
431
+ " </tr>\n",
432
+ " <tr>\n",
433
+ " <td>220</td>\n",
434
+ " <td>1.444500</td>\n",
435
+ " </tr>\n",
436
+ " <tr>\n",
437
+ " <td>230</td>\n",
438
+ " <td>1.464800</td>\n",
439
+ " </tr>\n",
440
+ " <tr>\n",
441
+ " <td>240</td>\n",
442
+ " <td>1.480200</td>\n",
443
+ " </tr>\n",
444
+ " <tr>\n",
445
+ " <td>250</td>\n",
446
+ " <td>1.444100</td>\n",
447
+ " </tr>\n",
448
+ " <tr>\n",
449
+ " <td>260</td>\n",
450
+ " <td>1.543900</td>\n",
451
+ " </tr>\n",
452
+ " <tr>\n",
453
+ " <td>270</td>\n",
454
+ " <td>1.512700</td>\n",
455
+ " </tr>\n",
456
+ " <tr>\n",
457
+ " <td>280</td>\n",
458
+ " <td>1.441300</td>\n",
459
+ " </tr>\n",
460
+ " <tr>\n",
461
+ " <td>290</td>\n",
462
+ " <td>1.502200</td>\n",
463
+ " </tr>\n",
464
+ " <tr>\n",
465
+ " <td>300</td>\n",
466
+ " <td>1.476900</td>\n",
467
+ " </tr>\n",
468
+ " <tr>\n",
469
+ " <td>310</td>\n",
470
+ " <td>1.478200</td>\n",
471
+ " </tr>\n",
472
+ " <tr>\n",
473
+ " <td>320</td>\n",
474
+ " <td>1.481000</td>\n",
475
+ " </tr>\n",
476
+ " <tr>\n",
477
+ " <td>330</td>\n",
478
+ " <td>1.433600</td>\n",
479
+ " </tr>\n",
480
+ " <tr>\n",
481
+ " <td>340</td>\n",
482
+ " <td>1.404000</td>\n",
483
+ " </tr>\n",
484
+ " <tr>\n",
485
+ " <td>350</td>\n",
486
+ " <td>1.401000</td>\n",
487
+ " </tr>\n",
488
+ " <tr>\n",
489
+ " <td>360</td>\n",
490
+ " <td>1.424400</td>\n",
491
+ " </tr>\n",
492
+ " <tr>\n",
493
+ " <td>370</td>\n",
494
+ " <td>1.429100</td>\n",
495
+ " </tr>\n",
496
+ " <tr>\n",
497
+ " <td>380</td>\n",
498
+ " <td>1.388700</td>\n",
499
+ " </tr>\n",
500
+ " <tr>\n",
501
+ " <td>390</td>\n",
502
+ " <td>1.402600</td>\n",
503
+ " </tr>\n",
504
+ " <tr>\n",
505
+ " <td>400</td>\n",
506
+ " <td>1.417900</td>\n",
507
+ " </tr>\n",
508
+ " <tr>\n",
509
+ " <td>410</td>\n",
510
+ " <td>1.358200</td>\n",
511
+ " </tr>\n",
512
+ " <tr>\n",
513
+ " <td>420</td>\n",
514
+ " <td>1.460700</td>\n",
515
+ " </tr>\n",
516
+ " <tr>\n",
517
+ " <td>430</td>\n",
518
+ " <td>1.417800</td>\n",
519
+ " </tr>\n",
520
+ " <tr>\n",
521
+ " <td>440</td>\n",
522
+ " <td>1.447300</td>\n",
523
+ " </tr>\n",
524
+ " <tr>\n",
525
+ " <td>450</td>\n",
526
+ " <td>1.429200</td>\n",
527
+ " </tr>\n",
528
+ " <tr>\n",
529
+ " <td>460</td>\n",
530
+ " <td>1.388100</td>\n",
531
+ " </tr>\n",
532
+ " <tr>\n",
533
+ " <td>470</td>\n",
534
+ " <td>1.433200</td>\n",
535
+ " </tr>\n",
536
+ " <tr>\n",
537
+ " <td>480</td>\n",
538
+ " <td>1.431600</td>\n",
539
+ " </tr>\n",
540
+ " <tr>\n",
541
+ " <td>490</td>\n",
542
+ " <td>1.491200</td>\n",
543
+ " </tr>\n",
544
+ " <tr>\n",
545
+ " <td>500</td>\n",
546
+ " <td>1.406600</td>\n",
547
+ " </tr>\n",
548
+ " </tbody>\n",
549
+ "</table><p>"
550
+ ],
551
+ "text/plain": [
552
+ "<IPython.core.display.HTML object>"
553
+ ]
554
+ },
555
+ "metadata": {},
556
+ "output_type": "display_data"
557
+ },
558
+ {
559
+ "name": "stderr",
560
+ "output_type": "stream",
561
+ "text": [
562
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
563
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n"
564
+ ]
565
+ },
566
+ {
567
+ "data": {
568
+ "application/vnd.jupyter.widget-view+json": {
569
+ "model_id": "a595199a17b14a5b99d4c06f5eda00af",
570
+ "version_major": 2,
571
+ "version_minor": 0
572
+ },
573
+ "text/plain": [
574
+ "config.json: 0%| | 0.00/866 [00:00<?, ?B/s]"
575
+ ]
576
+ },
577
+ "metadata": {},
578
+ "output_type": "display_data"
579
+ },
580
+ {
581
+ "name": "stderr",
582
+ "output_type": "stream",
583
+ "text": [
584
+ "You are using a model of type phi to instantiate a model of type phi-msft. This is not supported for all configurations of models and can yield errors.\n",
585
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
586
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
587
+ "You are using a model of type phi to instantiate a model of type phi-msft. This is not supported for all configurations of models and can yield errors.\n",
588
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
589
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
590
+ "You are using a model of type phi to instantiate a model of type phi-msft. This is not supported for all configurations of models and can yield errors.\n",
591
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/torch/nn/parallel/_functions.py:68: UserWarning: Was asked to gather along dimension 0, but all input tensors were scalars; will instead unsqueeze and return a vector.\n",
592
+ " warnings.warn('Was asked to gather along dimension 0, but all '\n",
593
+ "You are using a model of type phi to instantiate a model of type phi-msft. This is not supported for all configurations of models and can yield errors.\n"
594
+ ]
595
+ },
596
+ {
597
+ "data": {
598
+ "text/plain": [
599
+ "TrainOutput(global_step=500, training_loss=1.4746462078094482, metrics={'train_runtime': 4307.6684, 'train_samples_per_second': 3.714, 'train_steps_per_second': 0.116, 'total_flos': 6.667526640623616e+16, 'train_loss': 1.4746462078094482, 'epoch': 1.62})"
600
+ ]
601
+ },
602
+ "execution_count": 13,
603
+ "metadata": {},
604
+ "output_type": "execute_result"
605
+ }
606
+ ],
607
+ "source": [
608
+ "trainer.train()"
609
+ ]
610
+ },
611
+ {
612
+ "cell_type": "markdown",
613
+ "id": "94cbfe9f-3bf4-4f0c-bc7e-8544809d1309",
614
+ "metadata": {},
615
+ "source": [
616
+ "## Inference"
617
+ ]
618
+ },
619
+ {
620
+ "cell_type": "code",
621
+ "execution_count": 15,
622
+ "id": "31262e62-3ca5-41e1-9f69-739d975a0cbb",
623
+ "metadata": {},
624
+ "outputs": [],
625
+ "source": [
626
+ "from transformers import (\n",
627
+ " AutoModelForCausalLM,\n",
628
+ " AutoTokenizer,\n",
629
+ " BitsAndBytesConfig,\n",
630
+ " HfArgumentParser,\n",
631
+ " TrainingArguments,\n",
632
+ " pipeline,\n",
633
+ " logging,\n",
634
+ ")"
635
+ ]
636
+ },
637
+ {
638
+ "cell_type": "code",
639
+ "execution_count": 16,
640
+ "id": "85ab9662-7a84-43a8-ad83-f4a6aed8f515",
641
+ "metadata": {},
642
+ "outputs": [],
643
+ "source": [
644
+ "chat_template = \"\"\"<|im_start|>system\n",
645
+ "You are a helpful assistant who always respond to user queries<|im_end|>\n",
646
+ "<im_start>user\n",
647
+ "{prompt}<|im_end|>\n",
648
+ "<|im_start|>assistant\n",
649
+ "\"\"\""
650
+ ]
651
+ },
652
+ {
653
+ "cell_type": "code",
654
+ "execution_count": 17,
655
+ "id": "e3e26a34-acfc-45f7-8a4a-96157e25d1f5",
656
+ "metadata": {},
657
+ "outputs": [
658
+ {
659
+ "name": "stderr",
660
+ "output_type": "stream",
661
+ "text": [
662
+ "/home/ravi.naik/miniconda3/envs/torchenv/lib/python3.10/site-packages/transformers/generation/utils.py:1518: UserWarning: You have modified the pretrained model configuration to control generation. This is a deprecated strategy to control generation and will be removed soon, in a future version. Please use and modify the model generation configuration (see https://huggingface.co/docs/transformers/generation_strategies#default-text-generation-configuration )\n",
663
+ " warnings.warn(\n"
664
+ ]
665
+ },
666
+ {
667
+ "name": "stdout",
668
+ "output_type": "stream",
669
+ "text": [
670
+ "<|im_start|>system\n",
671
+ "You are a helpful assistant who always respond to user queries<|im_end|>\n",
672
+ "<im_start>user\n",
673
+ "What is a large language model?<|im_end|>\n",
674
+ "<|im_start|>assistant\n",
675
+ "A large language model (LLM) is a type of artificial intelligence model that is designed to understand and generate human language. LLMs are typically trained on large amounts of text data and are capable of performing a wide range of language-related tasks, such as language translation, text summarization, and text generation.\n",
676
+ "\n",
677
+ "LLMs are different from traditional language models, such as recurrent neural networks (RNNs) or transformers, in that they are designed to handle large amounts of text data and are able to learn from this data in a more efficient and effective way. This makes them well-suited for tasks that require a deep understanding of language, such as natural language processing (N\n"
678
+ ]
679
+ }
680
+ ],
681
+ "source": [
682
+ "prompt = \"What is a large language model?\"\n",
683
+ "pipe = pipeline(task=\"text-generation\", model=model, tokenizer=tokenizer, max_length=200)\n",
684
+ "result = pipe(chat_template.format(prompt=prompt))\n",
685
+ "print(result[0]['generated_text'])"
686
+ ]
687
+ },
688
+ {
689
+ "cell_type": "code",
690
+ "execution_count": 18,
691
+ "id": "7af8f545-e76c-4ce3-a02d-864404dd357c",
692
+ "metadata": {},
693
+ "outputs": [
694
+ {
695
+ "name": "stdout",
696
+ "output_type": "stream",
697
+ "text": [
698
+ "<|im_start|>system\n",
699
+ "You are a helpful assistant who always respond to user queries<|im_end|>\n",
700
+ "<im_start>user\n",
701
+ "Write a Python program to print first 50 prime numbers<|im_end|>\n",
702
+ "<|im_start|>assistant\n",
703
+ "Here's a Python program that prints the first 50 prime numbers:\n",
704
+ "\n",
705
+ "```python\n",
706
+ "def is_prime(n):\n",
707
+ " if n < 2:\n",
708
+ " return False\n",
709
+ " for i in range(2, int(n**0.5) + 1):\n",
710
+ " if n % i == 0:\n",
711
+ " return False\n",
712
+ " return True\n",
713
+ "\n",
714
+ "count = 0\n",
715
+ "num = 2\n",
716
+ "while count < 50:\n",
717
+ " if is_prime(num):\n",
718
+ " print(num)\n",
719
+ " count += 1\n",
720
+ " num += 1\n",
721
+ "```\n",
722
+ "\n",
723
+ "This program uses a helper function `is_prime` to check if a number is prime\n"
724
+ ]
725
+ }
726
+ ],
727
+ "source": [
728
+ "prompt = \"Write a Python program to print first 50 prime numbers\"\n",
729
+ "pipe = pipeline(task=\"text-generation\", model=model, tokenizer=tokenizer, max_length=200)\n",
730
+ "result = pipe(chat_template.format(prompt=prompt))\n",
731
+ "print(result[0]['generated_text'])"
732
+ ]
733
+ },
734
+ {
735
+ "cell_type": "code",
736
+ "execution_count": 19,
737
+ "id": "398c483f-d4d6-4532-aecf-e22c2fc001f0",
738
+ "metadata": {},
739
+ "outputs": [
740
+ {
741
+ "name": "stdout",
742
+ "output_type": "stream",
743
+ "text": [
744
+ "<|im_start|>system\n",
745
+ "You are a helpful assistant who always respond to user queries<|im_end|>\n",
746
+ "<im_start>user\n",
747
+ "Can you write a short introduction about the relevance of the term monopsony in economics?<|im_end|>\n",
748
+ "<|im_start|>assistant\n",
749
+ "Sure, I'd be happy to help!\n",
750
+ "\n",
751
+ "Monopsony is a term used in economics to describe a market structure in which there is only one buyer for a particular good or service. This means that the buyer has significant bargaining power and can set the price at which they will purchase the good or service.\n",
752
+ "\n",
753
+ "In a monopsony, the buyer has the ability to influence the price of the good or service, which can have significant implications for the market. For example, if the buyer is a large corporation, they may be able to drive down the price of the good or service, which can have negative effects on the\n"
754
+ ]
755
+ }
756
+ ],
757
+ "source": [
758
+ "prompt = \"Can you write a short introduction about the relevance of the term monopsony in economics?\"\n",
759
+ "pipe = pipeline(task=\"text-generation\", model=model, tokenizer=tokenizer, max_length=200)\n",
760
+ "result = pipe(chat_template.format(prompt=prompt))\n",
761
+ "print(result[0]['generated_text'])"
762
+ ]
763
+ },
764
+ {
765
+ "cell_type": "code",
766
+ "execution_count": 20,
767
+ "id": "23d75586-7177-4c82-9f93-170ee982e319",
768
+ "metadata": {},
769
+ "outputs": [
770
+ {
771
+ "name": "stderr",
772
+ "output_type": "stream",
773
+ "text": [
774
+ "You are using a model of type phi to instantiate a model of type phi-msft. This is not supported for all configurations of models and can yield errors.\n"
775
+ ]
776
+ }
777
+ ],
778
+ "source": [
779
+ "trainer.save_model(\"checkpoints\")"
780
+ ]
781
+ },
782
+ {
783
+ "cell_type": "code",
784
+ "execution_count": 21,
785
+ "id": "7a362585-9064-4961-9160-0e560be70731",
786
+ "metadata": {},
787
+ "outputs": [
788
+ {
789
+ "name": "stderr",
790
+ "output_type": "stream",
791
+ "text": [
792
+ "You are using a model of type phi to instantiate a model of type phi-msft. This is not supported for all configurations of models and can yield errors.\n"
793
+ ]
794
+ },
795
+ {
796
+ "data": {
797
+ "application/vnd.jupyter.widget-view+json": {
798
+ "model_id": "417e9c7948d7488aa6fc1b8c613d1d75",
799
+ "version_major": 2,
800
+ "version_minor": 0
801
+ },
802
+ "text/plain": [
803
+ "Upload 3 LFS files: 0%| | 0/3 [00:00<?, ?it/s]"
804
+ ]
805
+ },
806
+ "metadata": {},
807
+ "output_type": "display_data"
808
+ },
809
+ {
810
+ "data": {
811
+ "application/vnd.jupyter.widget-view+json": {
812
+ "model_id": "0c2a5148f24d40439fb06025b7ae1d9e",
813
+ "version_major": 2,
814
+ "version_minor": 0
815
+ },
816
+ "text/plain": [
817
+ "events.out.tfevents.1704991189.si-aiwork2.2021276.0: 0%| | 0.00/13.1k [00:00<?, ?B/s]"
818
+ ]
819
+ },
820
+ "metadata": {},
821
+ "output_type": "display_data"
822
+ },
823
+ {
824
+ "data": {
825
+ "application/vnd.jupyter.widget-view+json": {
826
+ "model_id": "ea9d618995d740b1a0042aa9a3d8eeb5",
827
+ "version_major": 2,
828
+ "version_minor": 0
829
+ },
830
+ "text/plain": [
831
+ "adapter_model.safetensors: 0%| | 0.00/336M [00:00<?, ?B/s]"
832
+ ]
833
+ },
834
+ "metadata": {},
835
+ "output_type": "display_data"
836
+ },
837
+ {
838
+ "data": {
839
+ "application/vnd.jupyter.widget-view+json": {
840
+ "model_id": "5ac3bafc71614c6e830a9ac6b6b1000e",
841
+ "version_major": 2,
842
+ "version_minor": 0
843
+ },
844
+ "text/plain": [
845
+ "training_args.bin: 0%| | 0.00/4.66k [00:00<?, ?B/s]"
846
+ ]
847
+ },
848
+ "metadata": {},
849
+ "output_type": "display_data"
850
+ },
851
+ {
852
+ "data": {
853
+ "text/plain": [
854
+ "CommitInfo(commit_url='https://huggingface.co/RaviNaik/Phi2-Osst/commit/987f0bdcb557c8cb356eb79452181f2944c21f8b', commit_message='End of training', commit_description='', oid='987f0bdcb557c8cb356eb79452181f2944c21f8b', pr_url=None, pr_revision=None, pr_num=None)"
855
+ ]
856
+ },
857
+ "execution_count": 21,
858
+ "metadata": {},
859
+ "output_type": "execute_result"
860
+ }
861
+ ],
862
+ "source": [
863
+ "trainer.hub_model_id = \"RaviNaik/Phi2-OSST\"\n",
864
+ "trainer.push_to_hub()"
865
+ ]
866
+ },
867
+ {
868
+ "cell_type": "code",
869
+ "execution_count": null,
870
+ "id": "6a5308db-e616-44df-8b1d-387c1ca69282",
871
+ "metadata": {},
872
+ "outputs": [],
873
+ "source": []
874
+ }
875
+ ],
876
+ "metadata": {
877
+ "kernelspec": {
878
+ "display_name": "Python 3 (ipykernel)",
879
+ "language": "python",
880
+ "name": "python3"
881
+ },
882
+ "language_info": {
883
+ "codemirror_mode": {
884
+ "name": "ipython",
885
+ "version": 3
886
+ },
887
+ "file_extension": ".py",
888
+ "mimetype": "text/x-python",
889
+ "name": "python",
890
+ "nbconvert_exporter": "python",
891
+ "pygments_lexer": "ipython3",
892
+ "version": "3.10.12"
893
+ }
894
+ },
895
+ "nbformat": 4,
896
+ "nbformat_minor": 5
897
+ }
README.md CHANGED
@@ -1,8 +1,8 @@
1
  ---
2
- title: ERAV1 SESSION27
3
- emoji: 📈
4
- colorFrom: pink
5
- colorTo: green
6
  sdk: gradio
7
  sdk_version: 4.14.0
8
  app_file: app.py
@@ -10,4 +10,73 @@ pinned: false
10
  license: mit
11
  ---
12
 
13
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: ERA SESSION27 - Phi2 Model Finetuning with QLoRA on OpenAssistant Conversations Dataset (OASST1)
3
+ emoji: 💻
4
+ colorFrom: yellow
5
+ colorTo: blue
6
  sdk: gradio
7
  sdk_version: 4.14.0
8
  app_file: app.py
 
10
  license: mit
11
  ---
12
 
13
+ [**Repository Link**](https://github.com/RaviNaik/ERA-SESSION27)
14
+
15
+ This is an implementation of [Phi2](https://huggingface.co/microsoft/phi-2) model finetuning using QLoRA stratergy on [OpenAssistant Conversations Dataset (OASST1)](https://huggingface.co/datasets/OpenAssistant/oasst1)
16
+
17
+ Dataset used to finetune: [OpenAssistant Conversations Dataset (OASST1)](https://huggingface.co/datasets/OpenAssistant/oasst1)
18
+ ChatML modified OSST Dataset: [RaviNaik/oasst1-chatml](https://huggingface.co/datasets/RaviNaik/oasst1-chatml)
19
+ Finetuned Model: [RaviNaik/Phi2-Osst](https://huggingface.co/RaviNaik/Phi2-Osst)
20
+
21
+ ### Tasks:
22
+ 1. :heavy_check_mark: Use OpenAssistant dataset.
23
+ 2. :heavy_check_mark: Finetune Microsoft Phi2 model.
24
+ 3. :heavy_check_mark: Use QLoRA stratergy.
25
+ 4. :heavy_check_mark: Create an App on HF space using finetuned model.
26
+
27
+ ## Phi2 Model Description:
28
+ ```python
29
+ PhiForCausalLM(
30
+ (transformer): PhiModel(
31
+ (embd): Embedding(
32
+ (wte): Embedding(51200, 2560)
33
+ (drop): Dropout(p=0.0, inplace=False)
34
+ )
35
+ (h): ModuleList(
36
+ (0-31): 32 x ParallelBlock(
37
+ (ln): LayerNorm((2560,), eps=1e-05, elementwise_affine=True)
38
+ (resid_dropout): Dropout(p=0.1, inplace=False)
39
+ (mixer): MHA(
40
+ (rotary_emb): RotaryEmbedding()
41
+ (Wqkv): Linear4bit(in_features=2560, out_features=7680, bias=True)
42
+ (out_proj): Linear4bit(in_features=2560, out_features=2560, bias=True)
43
+ (inner_attn): SelfAttention(
44
+ (drop): Dropout(p=0.0, inplace=False)
45
+ )
46
+ (inner_cross_attn): CrossAttention(
47
+ (drop): Dropout(p=0.0, inplace=False)
48
+ )
49
+ )
50
+ (mlp): MLP(
51
+ (fc1): Linear4bit(in_features=2560, out_features=10240, bias=True)
52
+ (fc2): Linear4bit(in_features=10240, out_features=2560, bias=True)
53
+ (act): NewGELUActivation()
54
+ )
55
+ )
56
+ )
57
+ )
58
+ (lm_head): CausalLMHead(
59
+ (ln): LayerNorm((2560,), eps=1e-05, elementwise_affine=True)
60
+ (linear): Linear(in_features=2560, out_features=51200, bias=True)
61
+ )
62
+ (loss): CausalLMLoss(
63
+ (loss_fct): CrossEntropyLoss()
64
+ )
65
+ )
66
+ ```
67
+ ## Training Loss Curve:
68
+ ![image](https://github.com/RaviNaik/ERA-SESSION27/assets/23289802/b477dd79-acab-48d2-aca7-39baa80dfb5b)
69
+ ### Training Output
70
+ ```python
71
+ TrainOutput(global_step=500, training_loss=1.4746462078094482, metrics={'train_runtime': 4307.6684, 'train_samples_per_second': 3.714, 'train_steps_per_second': 0.116, 'total_flos': 6.667526640623616e+16, 'train_loss': 1.4746462078094482, 'epoch': 1.62})
72
+ ```
73
+ ### Loss vs Steps Logs
74
+ ![image](https://github.com/RaviNaik/ERA-SESSION27/assets/23289802/f305c4e7-c64d-4501-9b60-ae8f9a266349)
75
+
76
+ ## Sample Results:
77
+ ![image](https://github.com/RaviNaik/ERA-SESSION27/assets/23289802/e76a1f9c-24a4-40ac-b62a-291eacf1e3de)
78
+ ![image](https://github.com/RaviNaik/ERA-SESSION27/assets/23289802/72278fa6-6e2e-49ea-8f97-78e3eddff8ae)
79
+
80
+ ## Gradio UI:
81
+ ![image](https://github.com/RaviNaik/ERA-SESSION27/assets/23289802/4fe7e106-7616-408b-8132-644567f8d0bb)
82
+
app.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import (
4
+ AutoModelForCausalLM,
5
+ AutoTokenizer,
6
+ BitsAndBytesConfig,
7
+ pipeline
8
+ )
9
+
10
+ model_name = "RaviNaik/Phi2-Osst"
11
+
12
+ device = "cuda" if torch.cuda.is_available() else "cpu"
13
+ model = AutoModelForCausalLM.from_pretrained(
14
+ model_name,
15
+ trust_remote_code=True,
16
+ device_map=device
17
+ )
18
+ model.config.use_cache = False
19
+ tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, device_map=device)
20
+ tokenizer.pad_token = tokenizer.eos_token
21
+ chat_template = """<|im_start|>system
22
+ You are a helpful assistant who always respond to user queries<|im_end|>
23
+ <im_start>user
24
+ {prompt}<|im_end|>
25
+ <|im_start|>assistant
26
+ """
27
+
28
+ def generate(prompt, max_length, temperature, num_samples):
29
+ prompt = prompt.strip()
30
+ pipe = pipeline(task="text-generation", model=model, tokenizer=tokenizer, max_length=max_length, temperature=temperature, num_return_sequences=num_samples)
31
+ # result = pipe(chat_template.format(prompt=prompt))
32
+ result = pipe(prompt)
33
+ return {output: result}
34
+
35
+
36
+ with gr.Blocks() as app:
37
+ gr.Markdown("## ERA Session27 - Phi2 Model Finetuning with QLoRA on OpenAssistant Conversations Dataset (OASST1)")
38
+ gr.Markdown(
39
+ """This is an implementation of [Phi2](https://huggingface.co/microsoft/phi-2) model finetuning using QLoRA stratergy on [OpenAssistant Conversations Dataset (OASST1)](https://huggingface.co/datasets/OpenAssistant/oasst1)
40
+
41
+ Please find the source code and training details [here](https://github.com/RaviNaik/ERA-SESSION27).
42
+
43
+ Dataset used to finetune: [OpenAssistant Conversations Dataset (OASST1)](https://huggingface.co/datasets/OpenAssistant/oasst1)
44
+ ChatML modified OSST Dataset: [RaviNaik/oasst1-chatml](https://huggingface.co/datasets/RaviNaik/oasst1-chatml)
45
+ Finetuned Model: [RaviNaik/Phi2-Osst](https://huggingface.co/RaviNaik/Phi2-Osst)
46
+ """
47
+ )
48
+ with gr.Row():
49
+ with gr.Column():
50
+ prompt_box = gr.Textbox(label="Initial Prompt", interactive=True)
51
+ max_length = gr.Slider(
52
+ minimum=50,
53
+ maximum=500,
54
+ value=200,
55
+ step=10,
56
+ label="Select Number of Tokens to be Generated",
57
+ interactive=True,
58
+ )
59
+ temperature = gr.Slider(
60
+ minimum=0.1,
61
+ maximum=1,
62
+ value=0.7,
63
+ step=0.1,
64
+ label="Select Temperature",
65
+ interactive=True,
66
+ )
67
+ num_samples = gr.Dropdown(
68
+ choices=[1, 2, 5, 10],
69
+ value=1,
70
+ interactive=True,
71
+ label="Select No. of outputs to be generated",
72
+ )
73
+ submit_btn = gr.Button(value="Generate")
74
+
75
+ with gr.Column():
76
+ output = gr.JSON(label="Generated Text")
77
+
78
+ submit_btn.click(
79
+ generate,
80
+ inputs=[prompt_box, max_length, temperature, num_samples],
81
+ outputs=[output],
82
+ )
83
+
84
+ app.launch()
requirements.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ gradio
2
+ transformers[torch]
3
+ accelerate
4
+ git+https://github.com/huggingface/peft.git
5
+ bitsandbytes
6
+ einops
7
+ trl