TokenBender
commited on
Commit
•
9a906d6
1
Parent(s):
1e21175
Upload 3 files
Browse files- notebooks/DPO_fine_tuning.ipynb +791 -0
- notebooks/SFTTrainer TRL.ipynb +0 -0
- notebooks/chatml_inference.ipynb +320 -0
notebooks/DPO_fine_tuning.ipynb
ADDED
@@ -0,0 +1,791 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "ebcf3daa-78ce-4baa-846a-ea5e298c9de5",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [
|
9 |
+
{
|
10 |
+
"name": "stdout",
|
11 |
+
"output_type": "stream",
|
12 |
+
"text": [
|
13 |
+
"\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
|
14 |
+
"\u001b[0mNote: you may need to restart the kernel to use updated packages.\n"
|
15 |
+
]
|
16 |
+
}
|
17 |
+
],
|
18 |
+
"source": [
|
19 |
+
"pip install -q datasets trl peft bitsandbytes sentencepiece wandb huggingface_hub"
|
20 |
+
]
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"cell_type": "code",
|
24 |
+
"execution_count": 1,
|
25 |
+
"id": "4d54dddd-dfda-481a-95d4-79d1525524c4",
|
26 |
+
"metadata": {},
|
27 |
+
"outputs": [
|
28 |
+
{
|
29 |
+
"data": {
|
30 |
+
"application/vnd.jupyter.widget-view+json": {
|
31 |
+
"model_id": "a9bddf0a36c64d3f9c6d4a58c3d59282",
|
32 |
+
"version_major": 2,
|
33 |
+
"version_minor": 0
|
34 |
+
},
|
35 |
+
"text/plain": [
|
36 |
+
"VBox(children=(HTML(value='<center> <img\\nsrc=https://huggingface.co/front/assets/huggingface_logo-noborder.sv…"
|
37 |
+
]
|
38 |
+
},
|
39 |
+
"metadata": {},
|
40 |
+
"output_type": "display_data"
|
41 |
+
}
|
42 |
+
],
|
43 |
+
"source": [
|
44 |
+
"from huggingface_hub import notebook_login\n",
|
45 |
+
"notebook_login()"
|
46 |
+
]
|
47 |
+
},
|
48 |
+
{
|
49 |
+
"cell_type": "code",
|
50 |
+
"execution_count": 1,
|
51 |
+
"id": "d137e202-a20e-4c46-9285-3c755e5c3955",
|
52 |
+
"metadata": {},
|
53 |
+
"outputs": [
|
54 |
+
{
|
55 |
+
"name": "stderr",
|
56 |
+
"output_type": "stream",
|
57 |
+
"text": [
|
58 |
+
"Failed to detect the name of this notebook, you can set it manually with the WANDB_NOTEBOOK_NAME environment variable to enable code saving.\n",
|
59 |
+
"\u001b[34m\u001b[1mwandb\u001b[0m: Currently logged in as: \u001b[33mahm-rimer\u001b[0m. Use \u001b[1m`wandb login --relogin`\u001b[0m to force relogin\n"
|
60 |
+
]
|
61 |
+
},
|
62 |
+
{
|
63 |
+
"name": "stdout",
|
64 |
+
"output_type": "stream",
|
65 |
+
"text": [
|
66 |
+
"env: WANDB_PROJECT=hindi_dpo_test\n"
|
67 |
+
]
|
68 |
+
}
|
69 |
+
],
|
70 |
+
"source": [
|
71 |
+
"import os\n",
|
72 |
+
"import gc\n",
|
73 |
+
"import torch\n",
|
74 |
+
"\n",
|
75 |
+
"import transformers\n",
|
76 |
+
"from transformers import AutoModelForCausalLM, AutoTokenizer, TrainingArguments, BitsAndBytesConfig\n",
|
77 |
+
"from datasets import load_dataset\n",
|
78 |
+
"from peft import LoraConfig, PeftModel, get_peft_model, prepare_model_for_kbit_training\n",
|
79 |
+
"from trl import DPOTrainer\n",
|
80 |
+
"import bitsandbytes as bnb\n",
|
81 |
+
"import wandb\n",
|
82 |
+
"wandb.login()\n",
|
83 |
+
"%env WANDB_PROJECT=hindi_dpo_test\n",
|
84 |
+
"\n",
|
85 |
+
"model_name = \"TinyLlama/TinyLlama-1.1B-Chat-v1.0\"\n",
|
86 |
+
"new_model = \"Hindi-SentenceRetrieval-Tinyllama-1.1B\""
|
87 |
+
]
|
88 |
+
},
|
89 |
+
{
|
90 |
+
"cell_type": "code",
|
91 |
+
"execution_count": 2,
|
92 |
+
"id": "f0ac7684-68cd-4891-9979-6d1e22bb229b",
|
93 |
+
"metadata": {},
|
94 |
+
"outputs": [],
|
95 |
+
"source": [
|
96 |
+
"def chatml_format(example):\n",
|
97 |
+
" # Format system\n",
|
98 |
+
" if len(example['task']) > 0:\n",
|
99 |
+
" message = {\"role\": \"system\", \"content\": example['task']}\n",
|
100 |
+
" system = tokenizer.apply_chat_template([message], tokenize=False)\n",
|
101 |
+
" else:\n",
|
102 |
+
" system = \"\"\n",
|
103 |
+
"\n",
|
104 |
+
" # Format instruction\n",
|
105 |
+
" message = {\"role\": \"user\", \"content\": example['query']}\n",
|
106 |
+
" prompt = tokenizer.apply_chat_template([message], tokenize=False, add_generation_prompt=True)\n",
|
107 |
+
"\n",
|
108 |
+
" # Format chosen answer\n",
|
109 |
+
" chosen = example['pos'] + \"<|im_end|>\\n\"\n",
|
110 |
+
"\n",
|
111 |
+
" # Format rejected answer\n",
|
112 |
+
" rejected = example['neg'] + \"<|im_end|>\\n\"\n",
|
113 |
+
"\n",
|
114 |
+
" return {\n",
|
115 |
+
" \"prompt\": system + prompt,\n",
|
116 |
+
" \"chosen\": chosen,\n",
|
117 |
+
" \"rejected\": rejected,\n",
|
118 |
+
" }\n",
|
119 |
+
"\n",
|
120 |
+
"# Load dataset\n",
|
121 |
+
"dataset = load_dataset(\"TokenBender/e5_FT_sentence_retrieval_task_Hindi_mini\")['train']\n",
|
122 |
+
"\n",
|
123 |
+
"# Save columns\n",
|
124 |
+
"original_columns = dataset.column_names\n",
|
125 |
+
"\n",
|
126 |
+
"# Tokenizer\n",
|
127 |
+
"tokenizer = AutoTokenizer.from_pretrained(model_name)\n",
|
128 |
+
"tokenizer.pad_token = tokenizer.eos_token\n",
|
129 |
+
"tokenizer.padding_side = \"left\"\n",
|
130 |
+
"\n",
|
131 |
+
"# Format dataset\n",
|
132 |
+
"dataset = dataset.map(\n",
|
133 |
+
" chatml_format,\n",
|
134 |
+
" remove_columns=original_columns\n",
|
135 |
+
")"
|
136 |
+
]
|
137 |
+
},
|
138 |
+
{
|
139 |
+
"cell_type": "code",
|
140 |
+
"execution_count": 10,
|
141 |
+
"id": "fb9be1e7-9677-4dbd-8a75-946f39e232dd",
|
142 |
+
"metadata": {},
|
143 |
+
"outputs": [
|
144 |
+
{
|
145 |
+
"data": {
|
146 |
+
"text/plain": [
|
147 |
+
"Dataset({\n",
|
148 |
+
" features: ['prompt', 'chosen', 'rejected'],\n",
|
149 |
+
" num_rows: 6633\n",
|
150 |
+
"})"
|
151 |
+
]
|
152 |
+
},
|
153 |
+
"execution_count": 10,
|
154 |
+
"metadata": {},
|
155 |
+
"output_type": "execute_result"
|
156 |
+
}
|
157 |
+
],
|
158 |
+
"source": [
|
159 |
+
"dataset"
|
160 |
+
]
|
161 |
+
},
|
162 |
+
{
|
163 |
+
"cell_type": "code",
|
164 |
+
"execution_count": 13,
|
165 |
+
"id": "7282026e-3a22-4d57-b39b-761b3f9cf7b3",
|
166 |
+
"metadata": {},
|
167 |
+
"outputs": [
|
168 |
+
{
|
169 |
+
"name": "stdout",
|
170 |
+
"output_type": "stream",
|
171 |
+
"text": [
|
172 |
+
"{'prompt': '<|system|>\\nप्रश्न के रूप में एक सेलिब्रिटी का नाम दिए जाने पर, साक्षात्कार और जीवनी पुनर्प्राप्त करें।</s>\\n<|user|>\\nलियोनार्डो डिकैप्रियो एक अमेरिकी अभिनेता, फिल्म निर्माता और पर्यावरण कार्यकर्ता हैं। उन्हें छह अकादमी पुरस्कारों, चार ब्रिटिश अकादमी फिल्म पुरस्कारों और नौ स्क्रीन एक्टर्स गिल्ड पुरस्कारों के लिए नामांकित किया गया है, जिनमें से प्रत्येक पुरस्कार में से एक और ग्यारह नामांकनों में से तीन गोल्डन ग्लोब पुरस्कार जीते हैं। डिकैप्रियो ने 1980 के दशक के अंत में टेलीविजन विज्ञापनों में दिखाई देकर अपने करियर की शुरुआत की। इसके बाद उन्होंने विभिन्न टेलीविजन श्रृंखलाओं में आवर्ती भूमिकाएँ निभाईं, जैसे कि सोप ओपेरा सांता बारबरा और सिटकॉम ग्रोइंग पेन्स। उन्होंने रॉबर्ट डी नीरो के साथ संस्मरण दिस बॉयज़ लाइफ के फिल्म रूपांतरण में अभिनय करने से पहले क्रिटर्स 3 में जोश के रूप में अभिनय करके अपने फिल्म करियर की शुरुआत की। डिकैप्रियो को नाटक वॉट्स ईटिंग गिल्बर्ट ग्रेप (1993) में उनकी सहायक भूमिका के लिए सराहा गया था, और जेम्स कैमरून के महाकाव्य रोमांस टाइटैनिक (1997) के साथ अंतर्राष्ट्रीय प्रसिद्धि प्राप्त करने से पहले, द बास्केटबॉल डायरीज़ (1995) और रोमांटिक ड्रामा रोमियो + जूलियट (1996) नाटक में प्रमुख भूमिकाओं के साथ सार्वजनिक पहचान प्राप्त की, जो उस समय तक की सबसे अधिक कमाई करने वाली फिल्म बन गई। 2000 के दशक से, डिकैप्रियो को फिल्म शैलियों की एक विस्तृत श्रृंखला में उनके काम के लिए आलोचनात्मक प्रशंसा मिली है। उनकी बाद की फिल्मों में द मैन इन द आयरन मास्क (1998), जीवनी अपराध नाटक कैच मी इफ यू कैन (2002) और महाकाव्य ऐतिहासिक नाटक गैंग्स ऑफ न्यूयॉर्क (2002) शामिल हैं, जो निर्देशक मार्टिन स्कॉर्सेज़ के साथ उनके कई सहयोगों में से पहली थी। डिकैप्रियो को राजनीतिक युद्ध थ्रिलर ब्लड डायमंड (2006), नियो-नॉयर क्राइम ड्रामा द डिपार्टेड (2006), जासूसी थ्रिलर बॉडी ऑफ लाइज़ (2008), ड्रामा रिवोल्यूशनरी रोड (2008), मनोवैज्ञानिक थ्रिलर शटर आइलैंड (2010), विज्ञान कथा थ्रिलर इंसेप्शन (2010), जीवनी फिल्म जे. एडगर (2011), पश्चिमी जांगो अनचेन्ड (2012) और पीरियड ड्रामा द ग्रेट गैट्सबी (2013) में उनके प्रदर्शन के लिए सराहा गया था। द एविएटर (2004) में हॉवर्ड ह्यूजेस और द रेवनेंट (2015) में ह्यूग ग्लास के डिकैप्रियो के चित्रण ने उन्हें सर्वश्रेष्ठ अभिनेता-मोशन पिक्चर ड्रामा के लिए गोल्डन ग्लोब पुरस्कार दिलाया। द वुल्फ ऑफ वॉल स्ट्रीट (2013) में जॉर्डन बेल्फोर्ट के रूप में उनके प्रदर्शन ने उन्हें सर्वश्रेष्ठ अभिनेता-मोशन पिक्चर म्यूजिकल या कॉमेडी के लिए गोल्डन ग्लोब पुरस्कार दिलाया। उन्होंने द रेवनेंट के लिए सर्वश्रेष्ठ अभिनेता का अपना पहला अकादमी पुरस्कार भी जीता। डिकैप्रियो एपियन वे प्रोडक्शंस के संस्थापक हैं-एक निर्माण कंपनी जिसने उनकी कुछ फिल्मों और वृत्तचित्र श्रृंखला ग्रीन्सबर्ग (2008-2010) का निर्माण किया है-और पर्यावरण जागरूकता को बढ़ावा देने के लिए समर्पित एक गैर-लाभकारी संगठन लियोनार्डो डिकैप्रियो फाउंडेशन। वह एक प्रतिबद्ध पर्यावरण कार्यकर्ता भी हैं। 2016 में, उन्हें जलवायु परिवर्तन के लिए संयुक्त राष्ट्र शांति दूत नामित किया गया था और जलवायु परिवर्तन से निपटने के लिए उनके काम के लिए विश्व आर्थिक मंच में क्रिस्टल पुरस्कार प्राप्त हुआ था। 2018 में, जल भृंग की एक प्रजाति का नाम उनकी पर्यावरणीय सक्रियता की मान्यता में उनके नाम पर रखा गया था, ग्रौवेलिनस लियोनार्डोडिकाप्रियोई। डिकैप्रियो के पास लॉस फेलिज़, लॉस एंजिल्स में एक घर और बैटरी पार्क सिटी, लोअर मैनहट्टन में एक अपार्टमेंट है। वह जलवायु परिवर्तन पर कार्रवाई के लिए एक मुखर अधिवक्ता रहे हैं और उन्हें पर्यावरण समूहों से प्रशंसा मिली है। जलवायु परिवर्तन के खतरों के बारे में जागरूकता बढ़ाने के उनके प्रयासों और अक्षय ऊर्जा में उनके निवेश के लिए उनकी विशेष रूप से प्रशंसा की गई है। डिकैप्रियो 1992 से शाकाहारी रहे हैं और पर्यावरणवाद और मानवीय कारणों के प्रति अपने समर्पण के लिए जाने जाते हैं। वह पर्यावरण के मुद्दों के बारे में जागरूकता बढ़ाने के अभियानों में शामिल रहे हैं और टीएजी ह्यूअर के ब्रांड एंबेसडर के रूप में कार्य किया है। वह द 11थ आवर जैसे वृत्तचित्रों के निर्माण में भी शामिल रहे हैं। 2010 में, उन्होंने भूकंप के बाद हैती में राहत प्रयासों के लिए $1 मिलियन का दान दिया। 2017 में, उन्होंने तूफान हार्वे के पीड़ितों को $1 मिलियन का दान दिया। 2018 में, उन्होंने गंभीर रूप से लुप्तप्राय सुमात्रा हाथी के संरक्षण और संरक्षण का समर्थन करने के लिए लियोनार्डो डिकैप्रियो फाउंडेशन को $30 लाख का दान दिया। 2020 में, उन्होंने गंभीर रूप से लुप्तप्राय सुमात्रा हाथी के संरक्षण और संरक्षण का समर्थन करने के लिए लियोनार्डो डिकैप्रियो फाउंडेशन को $30 लाख का दान दिया। 2021 में, उन्होंने गंभीर रूप से लुप्तप्राय सुमात्रा हाथी के संरक्षण और संरक्षण का समर्थन करने के लिए लियोनार्डो डिकैप्रियो फाउंडेशन को $43 मिलियन का दान दिया।</s>\\n<|assistant|>\\n', 'chosen': 'लियोनार्डो डिकैप्रियो एक प्रतिभाशाली अभिनेता हैं जिन्हें टाइटैनिक और द रेवनेंट जैसी फिल्मों में उनकी भूमिकाओं के लिए जाना जाता है। ओ पर्यावरण सक्रियतामे सेहो शामिल रहल छथि आ अपन प्रदर्शनक लेल कतेको पुरस्कार प्राप्त कयने छथि। डिकैप्रियो जलवायु परिवर्तन पर कार्रवाई के लिए एक मुखर अधिवक्ता रहे हैं और उन्हें पर्यावरण समूहों से प्रशंसा मिली है। जलवायु परिवर्तन के खतरों के बारे में जागरूकता बढ़ाने के उनके प्रयासों और अक्षय ऊर्जा में उनके निवेश के लिए उनकी विशेष रूप से प्रशंसा की गई है। डिकैप्रियो 1992 से शाकाहारी रहे हैं और पर्यावरणवाद और मानवीय कारणों के प्रति अपने समर्पण के लिए जाने जाते हैं। वह पर्यावरण के मुद्दों के बारे में जागरूकता बढ़ाने के अभियानों में शामिल रहे हैं और टीएजी ह्यूअर के ब्रांड एंबेसडर के रूप में कार्य किया है। वह द 11थ आवर जैसे वृत्तचित्रों के निर्माण में भी शामिल रहे हैं। 2010 में, उन्होंने भूकंप के बाद हैती में राहत प्रयासों के लिए $1 मिलियन का दान दिया। 2017 में, उन्होंने तूफान हार्वे के पीड़ितों को $1 मिलियन का दान दिया। 2018 में, उन्होंने गंभीर रूप से लुप्तप्राय सुमात्रा हाथी के संरक्षण और संरक्षण का समर्थन करने के लिए लियोनार्डो डिकैप्रियो फाउंडेशन को $30 लाख का दान दिया। 2020 में, उन्होंने गंभीर रूप से लुप्तप्राय सुमात्रा हाथी के संरक्षण और संरक्षण का समर्थन करने के लिए लियोनार्डो डिकैप्रियो फाउंडेशन को $30 लाख का दान दिया। 2021 में, उन्होंने गंभीर रूप से लुप्तप्राय सुमात्रा हाथी के संरक्षण और संरक्षण का समर्थन करने के लिए लियोनार्डो डिकैप्रियो फाउंडेशन को $43 मिलियन का दान दिया।<|im_end|>\\n', 'rejected': 'प्रसिद्ध अभिनेता और परोपकारी, लियोनार्डो डिकैप्रियो के साक्षात्कार और जीवनी खोजें, जो अपनी पर्यावरणीय सक्रियता और टाइटैनिक और द रेवनेंट जैसी फिल्मों में पुरस्कार विजेता प्रदर्शन के लिए जाने जाते हैं।<|im_end|>\\n'}\n"
|
173 |
+
]
|
174 |
+
}
|
175 |
+
],
|
176 |
+
"source": [
|
177 |
+
"print(dataset[0])"
|
178 |
+
]
|
179 |
+
},
|
180 |
+
{
|
181 |
+
"cell_type": "code",
|
182 |
+
"execution_count": 3,
|
183 |
+
"id": "2c17bae2-a6a3-4f6c-b842-bc32847def79",
|
184 |
+
"metadata": {},
|
185 |
+
"outputs": [],
|
186 |
+
"source": [
|
187 |
+
"# LoRA configuration\n",
|
188 |
+
"peft_config = LoraConfig(\n",
|
189 |
+
" r=16,\n",
|
190 |
+
" lora_alpha=16,\n",
|
191 |
+
" lora_dropout=0.05,\n",
|
192 |
+
" bias=\"none\",\n",
|
193 |
+
" task_type=\"CAUSAL_LM\",\n",
|
194 |
+
" target_modules=['k_proj', 'gate_proj', 'v_proj', 'up_proj', 'q_proj', 'o_proj', 'down_proj']\n",
|
195 |
+
")"
|
196 |
+
]
|
197 |
+
},
|
198 |
+
{
|
199 |
+
"cell_type": "code",
|
200 |
+
"execution_count": 4,
|
201 |
+
"id": "c8003e61-ae44-400f-8b5c-668c5499bf78",
|
202 |
+
"metadata": {},
|
203 |
+
"outputs": [],
|
204 |
+
"source": [
|
205 |
+
"# Model to fine-tune\n",
|
206 |
+
"model = AutoModelForCausalLM.from_pretrained(\n",
|
207 |
+
" model_name,\n",
|
208 |
+
" torch_dtype=torch.float16,\n",
|
209 |
+
" load_in_4bit=True\n",
|
210 |
+
")\n",
|
211 |
+
"model.config.use_cache = False\n",
|
212 |
+
"\n",
|
213 |
+
"# Reference model\n",
|
214 |
+
"ref_model = AutoModelForCausalLM.from_pretrained(\n",
|
215 |
+
" model_name,\n",
|
216 |
+
" torch_dtype=torch.float16,\n",
|
217 |
+
" load_in_4bit=True\n",
|
218 |
+
")"
|
219 |
+
]
|
220 |
+
},
|
221 |
+
{
|
222 |
+
"cell_type": "code",
|
223 |
+
"execution_count": null,
|
224 |
+
"id": "af86df74-040d-4253-bc41-56c8b0d760f4",
|
225 |
+
"metadata": {},
|
226 |
+
"outputs": [
|
227 |
+
{
|
228 |
+
"name": "stderr",
|
229 |
+
"output_type": "stream",
|
230 |
+
"text": [
|
231 |
+
"/opt/conda/lib/python3.10/site-packages/trl/trainer/dpo_trainer.py:314: UserWarning: When using DPODataCollatorWithPadding, you should set `remove_unused_columns=False` in your TrainingArguments we have set it for you, but you should do it yourself in the future.\n",
|
232 |
+
" warnings.warn(\n"
|
233 |
+
]
|
234 |
+
},
|
235 |
+
{
|
236 |
+
"data": {
|
237 |
+
"application/vnd.jupyter.widget-view+json": {
|
238 |
+
"model_id": "0d6384bdbfec4041a50bc55c3567eabf",
|
239 |
+
"version_major": 2,
|
240 |
+
"version_minor": 0
|
241 |
+
},
|
242 |
+
"text/plain": [
|
243 |
+
"Map: 0%| | 0/6633 [00:00<?, ? examples/s]"
|
244 |
+
]
|
245 |
+
},
|
246 |
+
"metadata": {},
|
247 |
+
"output_type": "display_data"
|
248 |
+
},
|
249 |
+
{
|
250 |
+
"name": "stderr",
|
251 |
+
"output_type": "stream",
|
252 |
+
"text": [
|
253 |
+
"Token indices sequence length is longer than the specified maximum sequence length for this model (4632 > 2048). Running this sequence through the model will result in indexing errors\n",
|
254 |
+
"Detected kernel version 5.4.0, which is below the recommended minimum of 5.5.0; this can cause the process to hang. It is recommended to upgrade the kernel to the minimum version or higher.\n"
|
255 |
+
]
|
256 |
+
},
|
257 |
+
{
|
258 |
+
"data": {
|
259 |
+
"text/html": [
|
260 |
+
"Changes to your `wandb` environment variables will be ignored because your `wandb` session has already started. For more information on how to modify your settings with `wandb.init()` arguments, please refer to <a href='https://wandb.me/wandb-init' target=\"_blank\">the W&B docs</a>."
|
261 |
+
],
|
262 |
+
"text/plain": [
|
263 |
+
"<IPython.core.display.HTML object>"
|
264 |
+
]
|
265 |
+
},
|
266 |
+
"metadata": {},
|
267 |
+
"output_type": "display_data"
|
268 |
+
},
|
269 |
+
{
|
270 |
+
"data": {
|
271 |
+
"text/html": [
|
272 |
+
"Tracking run with wandb version 0.16.2"
|
273 |
+
],
|
274 |
+
"text/plain": [
|
275 |
+
"<IPython.core.display.HTML object>"
|
276 |
+
]
|
277 |
+
},
|
278 |
+
"metadata": {},
|
279 |
+
"output_type": "display_data"
|
280 |
+
},
|
281 |
+
{
|
282 |
+
"data": {
|
283 |
+
"text/html": [
|
284 |
+
"Run data is saved locally in <code>/workspace/wandb/run-20240128_065712-os8qoadz</code>"
|
285 |
+
],
|
286 |
+
"text/plain": [
|
287 |
+
"<IPython.core.display.HTML object>"
|
288 |
+
]
|
289 |
+
},
|
290 |
+
"metadata": {},
|
291 |
+
"output_type": "display_data"
|
292 |
+
},
|
293 |
+
{
|
294 |
+
"data": {
|
295 |
+
"text/html": [
|
296 |
+
"Syncing run <strong><a href='https://wandb.ai/ahm-rimer/hindi_dpo_test/runs/os8qoadz' target=\"_blank\">logical-monkey-4</a></strong> to <a href='https://wandb.ai/ahm-rimer/hindi_dpo_test' target=\"_blank\">Weights & Biases</a> (<a href='https://wandb.me/run' target=\"_blank\">docs</a>)<br/>"
|
297 |
+
],
|
298 |
+
"text/plain": [
|
299 |
+
"<IPython.core.display.HTML object>"
|
300 |
+
]
|
301 |
+
},
|
302 |
+
"metadata": {},
|
303 |
+
"output_type": "display_data"
|
304 |
+
},
|
305 |
+
{
|
306 |
+
"data": {
|
307 |
+
"text/html": [
|
308 |
+
" View project at <a href='https://wandb.ai/ahm-rimer/hindi_dpo_test' target=\"_blank\">https://wandb.ai/ahm-rimer/hindi_dpo_test</a>"
|
309 |
+
],
|
310 |
+
"text/plain": [
|
311 |
+
"<IPython.core.display.HTML object>"
|
312 |
+
]
|
313 |
+
},
|
314 |
+
"metadata": {},
|
315 |
+
"output_type": "display_data"
|
316 |
+
},
|
317 |
+
{
|
318 |
+
"data": {
|
319 |
+
"text/html": [
|
320 |
+
" View run at <a href='https://wandb.ai/ahm-rimer/hindi_dpo_test/runs/os8qoadz' target=\"_blank\">https://wandb.ai/ahm-rimer/hindi_dpo_test/runs/os8qoadz</a>"
|
321 |
+
],
|
322 |
+
"text/plain": [
|
323 |
+
"<IPython.core.display.HTML object>"
|
324 |
+
]
|
325 |
+
},
|
326 |
+
"metadata": {},
|
327 |
+
"output_type": "display_data"
|
328 |
+
},
|
329 |
+
{
|
330 |
+
"name": "stderr",
|
331 |
+
"output_type": "stream",
|
332 |
+
"text": [
|
333 |
+
"/opt/conda/lib/python3.10/site-packages/bitsandbytes/nn/modules.py:226: UserWarning: Input type into Linear4bit is torch.float16, but bnb_4bit_compute_dtype=torch.float32 (default). This will lead to slow inference or training speed.\n",
|
334 |
+
" warnings.warn(f'Input type into Linear4bit is torch.float16, but bnb_4bit_compute_dtype=torch.float32 (default). This will lead to slow inference or training speed.')\n",
|
335 |
+
"Could not estimate the number of tokens of the input, floating-point operations will not be computed\n"
|
336 |
+
]
|
337 |
+
},
|
338 |
+
{
|
339 |
+
"data": {
|
340 |
+
"text/html": [
|
341 |
+
"\n",
|
342 |
+
" <div>\n",
|
343 |
+
" \n",
|
344 |
+
" <progress value='92' max='621' style='width:300px; height:20px; vertical-align: middle;'></progress>\n",
|
345 |
+
" [ 92/621 1:09:37 < 6:49:13, 0.02 it/s, Epoch 0.44/3]\n",
|
346 |
+
" </div>\n",
|
347 |
+
" <table border=\"1\" class=\"dataframe\">\n",
|
348 |
+
" <thead>\n",
|
349 |
+
" <tr style=\"text-align: left;\">\n",
|
350 |
+
" <th>Step</th>\n",
|
351 |
+
" <th>Training Loss</th>\n",
|
352 |
+
" </tr>\n",
|
353 |
+
" </thead>\n",
|
354 |
+
" <tbody>\n",
|
355 |
+
" <tr>\n",
|
356 |
+
" <td>1</td>\n",
|
357 |
+
" <td>0.703000</td>\n",
|
358 |
+
" </tr>\n",
|
359 |
+
" <tr>\n",
|
360 |
+
" <td>2</td>\n",
|
361 |
+
" <td>0.698300</td>\n",
|
362 |
+
" </tr>\n",
|
363 |
+
" <tr>\n",
|
364 |
+
" <td>3</td>\n",
|
365 |
+
" <td>0.703000</td>\n",
|
366 |
+
" </tr>\n",
|
367 |
+
" <tr>\n",
|
368 |
+
" <td>4</td>\n",
|
369 |
+
" <td>0.675100</td>\n",
|
370 |
+
" </tr>\n",
|
371 |
+
" <tr>\n",
|
372 |
+
" <td>5</td>\n",
|
373 |
+
" <td>0.694200</td>\n",
|
374 |
+
" </tr>\n",
|
375 |
+
" <tr>\n",
|
376 |
+
" <td>6</td>\n",
|
377 |
+
" <td>0.675100</td>\n",
|
378 |
+
" </tr>\n",
|
379 |
+
" <tr>\n",
|
380 |
+
" <td>7</td>\n",
|
381 |
+
" <td>0.675300</td>\n",
|
382 |
+
" </tr>\n",
|
383 |
+
" <tr>\n",
|
384 |
+
" <td>8</td>\n",
|
385 |
+
" <td>0.658600</td>\n",
|
386 |
+
" </tr>\n",
|
387 |
+
" <tr>\n",
|
388 |
+
" <td>9</td>\n",
|
389 |
+
" <td>0.641100</td>\n",
|
390 |
+
" </tr>\n",
|
391 |
+
" <tr>\n",
|
392 |
+
" <td>10</td>\n",
|
393 |
+
" <td>0.634400</td>\n",
|
394 |
+
" </tr>\n",
|
395 |
+
" <tr>\n",
|
396 |
+
" <td>11</td>\n",
|
397 |
+
" <td>0.609300</td>\n",
|
398 |
+
" </tr>\n",
|
399 |
+
" <tr>\n",
|
400 |
+
" <td>12</td>\n",
|
401 |
+
" <td>0.606500</td>\n",
|
402 |
+
" </tr>\n",
|
403 |
+
" <tr>\n",
|
404 |
+
" <td>13</td>\n",
|
405 |
+
" <td>0.607200</td>\n",
|
406 |
+
" </tr>\n",
|
407 |
+
" <tr>\n",
|
408 |
+
" <td>14</td>\n",
|
409 |
+
" <td>0.560900</td>\n",
|
410 |
+
" </tr>\n",
|
411 |
+
" <tr>\n",
|
412 |
+
" <td>15</td>\n",
|
413 |
+
" <td>0.563000</td>\n",
|
414 |
+
" </tr>\n",
|
415 |
+
" <tr>\n",
|
416 |
+
" <td>16</td>\n",
|
417 |
+
" <td>0.527200</td>\n",
|
418 |
+
" </tr>\n",
|
419 |
+
" <tr>\n",
|
420 |
+
" <td>17</td>\n",
|
421 |
+
" <td>0.473300</td>\n",
|
422 |
+
" </tr>\n",
|
423 |
+
" <tr>\n",
|
424 |
+
" <td>18</td>\n",
|
425 |
+
" <td>0.486900</td>\n",
|
426 |
+
" </tr>\n",
|
427 |
+
" <tr>\n",
|
428 |
+
" <td>19</td>\n",
|
429 |
+
" <td>0.454200</td>\n",
|
430 |
+
" </tr>\n",
|
431 |
+
" <tr>\n",
|
432 |
+
" <td>20</td>\n",
|
433 |
+
" <td>0.426300</td>\n",
|
434 |
+
" </tr>\n",
|
435 |
+
" <tr>\n",
|
436 |
+
" <td>21</td>\n",
|
437 |
+
" <td>0.381000</td>\n",
|
438 |
+
" </tr>\n",
|
439 |
+
" <tr>\n",
|
440 |
+
" <td>22</td>\n",
|
441 |
+
" <td>0.361900</td>\n",
|
442 |
+
" </tr>\n",
|
443 |
+
" <tr>\n",
|
444 |
+
" <td>23</td>\n",
|
445 |
+
" <td>0.344100</td>\n",
|
446 |
+
" </tr>\n",
|
447 |
+
" <tr>\n",
|
448 |
+
" <td>24</td>\n",
|
449 |
+
" <td>0.298400</td>\n",
|
450 |
+
" </tr>\n",
|
451 |
+
" <tr>\n",
|
452 |
+
" <td>25</td>\n",
|
453 |
+
" <td>0.298100</td>\n",
|
454 |
+
" </tr>\n",
|
455 |
+
" <tr>\n",
|
456 |
+
" <td>26</td>\n",
|
457 |
+
" <td>0.256600</td>\n",
|
458 |
+
" </tr>\n",
|
459 |
+
" <tr>\n",
|
460 |
+
" <td>27</td>\n",
|
461 |
+
" <td>0.245600</td>\n",
|
462 |
+
" </tr>\n",
|
463 |
+
" <tr>\n",
|
464 |
+
" <td>28</td>\n",
|
465 |
+
" <td>0.214800</td>\n",
|
466 |
+
" </tr>\n",
|
467 |
+
" <tr>\n",
|
468 |
+
" <td>29</td>\n",
|
469 |
+
" <td>0.190200</td>\n",
|
470 |
+
" </tr>\n",
|
471 |
+
" <tr>\n",
|
472 |
+
" <td>30</td>\n",
|
473 |
+
" <td>0.163100</td>\n",
|
474 |
+
" </tr>\n",
|
475 |
+
" <tr>\n",
|
476 |
+
" <td>31</td>\n",
|
477 |
+
" <td>0.148100</td>\n",
|
478 |
+
" </tr>\n",
|
479 |
+
" <tr>\n",
|
480 |
+
" <td>32</td>\n",
|
481 |
+
" <td>0.136700</td>\n",
|
482 |
+
" </tr>\n",
|
483 |
+
" <tr>\n",
|
484 |
+
" <td>33</td>\n",
|
485 |
+
" <td>0.117100</td>\n",
|
486 |
+
" </tr>\n",
|
487 |
+
" <tr>\n",
|
488 |
+
" <td>34</td>\n",
|
489 |
+
" <td>0.097800</td>\n",
|
490 |
+
" </tr>\n",
|
491 |
+
" <tr>\n",
|
492 |
+
" <td>35</td>\n",
|
493 |
+
" <td>0.105300</td>\n",
|
494 |
+
" </tr>\n",
|
495 |
+
" <tr>\n",
|
496 |
+
" <td>36</td>\n",
|
497 |
+
" <td>0.072300</td>\n",
|
498 |
+
" </tr>\n",
|
499 |
+
" <tr>\n",
|
500 |
+
" <td>37</td>\n",
|
501 |
+
" <td>0.077200</td>\n",
|
502 |
+
" </tr>\n",
|
503 |
+
" <tr>\n",
|
504 |
+
" <td>38</td>\n",
|
505 |
+
" <td>0.056100</td>\n",
|
506 |
+
" </tr>\n",
|
507 |
+
" <tr>\n",
|
508 |
+
" <td>39</td>\n",
|
509 |
+
" <td>0.051000</td>\n",
|
510 |
+
" </tr>\n",
|
511 |
+
" <tr>\n",
|
512 |
+
" <td>40</td>\n",
|
513 |
+
" <td>0.041900</td>\n",
|
514 |
+
" </tr>\n",
|
515 |
+
" <tr>\n",
|
516 |
+
" <td>41</td>\n",
|
517 |
+
" <td>0.035800</td>\n",
|
518 |
+
" </tr>\n",
|
519 |
+
" <tr>\n",
|
520 |
+
" <td>42</td>\n",
|
521 |
+
" <td>0.031700</td>\n",
|
522 |
+
" </tr>\n",
|
523 |
+
" <tr>\n",
|
524 |
+
" <td>43</td>\n",
|
525 |
+
" <td>0.013200</td>\n",
|
526 |
+
" </tr>\n",
|
527 |
+
" <tr>\n",
|
528 |
+
" <td>44</td>\n",
|
529 |
+
" <td>0.014600</td>\n",
|
530 |
+
" </tr>\n",
|
531 |
+
" <tr>\n",
|
532 |
+
" <td>45</td>\n",
|
533 |
+
" <td>0.036300</td>\n",
|
534 |
+
" </tr>\n",
|
535 |
+
" <tr>\n",
|
536 |
+
" <td>46</td>\n",
|
537 |
+
" <td>0.012200</td>\n",
|
538 |
+
" </tr>\n",
|
539 |
+
" <tr>\n",
|
540 |
+
" <td>47</td>\n",
|
541 |
+
" <td>0.012500</td>\n",
|
542 |
+
" </tr>\n",
|
543 |
+
" <tr>\n",
|
544 |
+
" <td>48</td>\n",
|
545 |
+
" <td>0.011200</td>\n",
|
546 |
+
" </tr>\n",
|
547 |
+
" <tr>\n",
|
548 |
+
" <td>49</td>\n",
|
549 |
+
" <td>0.013500</td>\n",
|
550 |
+
" </tr>\n",
|
551 |
+
" <tr>\n",
|
552 |
+
" <td>50</td>\n",
|
553 |
+
" <td>0.008400</td>\n",
|
554 |
+
" </tr>\n",
|
555 |
+
" <tr>\n",
|
556 |
+
" <td>51</td>\n",
|
557 |
+
" <td>0.004900</td>\n",
|
558 |
+
" </tr>\n",
|
559 |
+
" <tr>\n",
|
560 |
+
" <td>52</td>\n",
|
561 |
+
" <td>0.006900</td>\n",
|
562 |
+
" </tr>\n",
|
563 |
+
" <tr>\n",
|
564 |
+
" <td>53</td>\n",
|
565 |
+
" <td>0.010800</td>\n",
|
566 |
+
" </tr>\n",
|
567 |
+
" <tr>\n",
|
568 |
+
" <td>54</td>\n",
|
569 |
+
" <td>0.006800</td>\n",
|
570 |
+
" </tr>\n",
|
571 |
+
" <tr>\n",
|
572 |
+
" <td>55</td>\n",
|
573 |
+
" <td>0.003900</td>\n",
|
574 |
+
" </tr>\n",
|
575 |
+
" <tr>\n",
|
576 |
+
" <td>56</td>\n",
|
577 |
+
" <td>0.005600</td>\n",
|
578 |
+
" </tr>\n",
|
579 |
+
" <tr>\n",
|
580 |
+
" <td>57</td>\n",
|
581 |
+
" <td>0.002100</td>\n",
|
582 |
+
" </tr>\n",
|
583 |
+
" <tr>\n",
|
584 |
+
" <td>58</td>\n",
|
585 |
+
" <td>0.001800</td>\n",
|
586 |
+
" </tr>\n",
|
587 |
+
" <tr>\n",
|
588 |
+
" <td>59</td>\n",
|
589 |
+
" <td>0.004600</td>\n",
|
590 |
+
" </tr>\n",
|
591 |
+
" <tr>\n",
|
592 |
+
" <td>60</td>\n",
|
593 |
+
" <td>0.001600</td>\n",
|
594 |
+
" </tr>\n",
|
595 |
+
" <tr>\n",
|
596 |
+
" <td>61</td>\n",
|
597 |
+
" <td>0.002000</td>\n",
|
598 |
+
" </tr>\n",
|
599 |
+
" <tr>\n",
|
600 |
+
" <td>62</td>\n",
|
601 |
+
" <td>0.001400</td>\n",
|
602 |
+
" </tr>\n",
|
603 |
+
" <tr>\n",
|
604 |
+
" <td>63</td>\n",
|
605 |
+
" <td>0.001000</td>\n",
|
606 |
+
" </tr>\n",
|
607 |
+
" <tr>\n",
|
608 |
+
" <td>64</td>\n",
|
609 |
+
" <td>0.002900</td>\n",
|
610 |
+
" </tr>\n",
|
611 |
+
" <tr>\n",
|
612 |
+
" <td>65</td>\n",
|
613 |
+
" <td>0.000800</td>\n",
|
614 |
+
" </tr>\n",
|
615 |
+
" <tr>\n",
|
616 |
+
" <td>66</td>\n",
|
617 |
+
" <td>0.004300</td>\n",
|
618 |
+
" </tr>\n",
|
619 |
+
" <tr>\n",
|
620 |
+
" <td>67</td>\n",
|
621 |
+
" <td>0.000700</td>\n",
|
622 |
+
" </tr>\n",
|
623 |
+
" <tr>\n",
|
624 |
+
" <td>68</td>\n",
|
625 |
+
" <td>0.002700</td>\n",
|
626 |
+
" </tr>\n",
|
627 |
+
" <tr>\n",
|
628 |
+
" <td>69</td>\n",
|
629 |
+
" <td>0.000500</td>\n",
|
630 |
+
" </tr>\n",
|
631 |
+
" <tr>\n",
|
632 |
+
" <td>70</td>\n",
|
633 |
+
" <td>0.002600</td>\n",
|
634 |
+
" </tr>\n",
|
635 |
+
" <tr>\n",
|
636 |
+
" <td>71</td>\n",
|
637 |
+
" <td>0.000600</td>\n",
|
638 |
+
" </tr>\n",
|
639 |
+
" <tr>\n",
|
640 |
+
" <td>72</td>\n",
|
641 |
+
" <td>0.000400</td>\n",
|
642 |
+
" </tr>\n",
|
643 |
+
" <tr>\n",
|
644 |
+
" <td>73</td>\n",
|
645 |
+
" <td>0.000800</td>\n",
|
646 |
+
" </tr>\n",
|
647 |
+
" <tr>\n",
|
648 |
+
" <td>74</td>\n",
|
649 |
+
" <td>0.000700</td>\n",
|
650 |
+
" </tr>\n",
|
651 |
+
" <tr>\n",
|
652 |
+
" <td>75</td>\n",
|
653 |
+
" <td>0.000400</td>\n",
|
654 |
+
" </tr>\n",
|
655 |
+
" <tr>\n",
|
656 |
+
" <td>76</td>\n",
|
657 |
+
" <td>0.000600</td>\n",
|
658 |
+
" </tr>\n",
|
659 |
+
" <tr>\n",
|
660 |
+
" <td>77</td>\n",
|
661 |
+
" <td>0.000900</td>\n",
|
662 |
+
" </tr>\n",
|
663 |
+
" <tr>\n",
|
664 |
+
" <td>78</td>\n",
|
665 |
+
" <td>0.000300</td>\n",
|
666 |
+
" </tr>\n",
|
667 |
+
" <tr>\n",
|
668 |
+
" <td>79</td>\n",
|
669 |
+
" <td>0.001000</td>\n",
|
670 |
+
" </tr>\n",
|
671 |
+
" <tr>\n",
|
672 |
+
" <td>80</td>\n",
|
673 |
+
" <td>0.000300</td>\n",
|
674 |
+
" </tr>\n",
|
675 |
+
" <tr>\n",
|
676 |
+
" <td>81</td>\n",
|
677 |
+
" <td>0.002800</td>\n",
|
678 |
+
" </tr>\n",
|
679 |
+
" <tr>\n",
|
680 |
+
" <td>82</td>\n",
|
681 |
+
" <td>0.000900</td>\n",
|
682 |
+
" </tr>\n",
|
683 |
+
" <tr>\n",
|
684 |
+
" <td>83</td>\n",
|
685 |
+
" <td>0.000300</td>\n",
|
686 |
+
" </tr>\n",
|
687 |
+
" <tr>\n",
|
688 |
+
" <td>84</td>\n",
|
689 |
+
" <td>0.000200</td>\n",
|
690 |
+
" </tr>\n",
|
691 |
+
" <tr>\n",
|
692 |
+
" <td>85</td>\n",
|
693 |
+
" <td>0.000300</td>\n",
|
694 |
+
" </tr>\n",
|
695 |
+
" <tr>\n",
|
696 |
+
" <td>86</td>\n",
|
697 |
+
" <td>0.010300</td>\n",
|
698 |
+
" </tr>\n",
|
699 |
+
" <tr>\n",
|
700 |
+
" <td>87</td>\n",
|
701 |
+
" <td>0.001800</td>\n",
|
702 |
+
" </tr>\n",
|
703 |
+
" <tr>\n",
|
704 |
+
" <td>88</td>\n",
|
705 |
+
" <td>0.000400</td>\n",
|
706 |
+
" </tr>\n",
|
707 |
+
" <tr>\n",
|
708 |
+
" <td>89</td>\n",
|
709 |
+
" <td>0.000300</td>\n",
|
710 |
+
" </tr>\n",
|
711 |
+
" <tr>\n",
|
712 |
+
" <td>90</td>\n",
|
713 |
+
" <td>0.000200</td>\n",
|
714 |
+
" </tr>\n",
|
715 |
+
" </tbody>\n",
|
716 |
+
"</table><p>"
|
717 |
+
],
|
718 |
+
"text/plain": [
|
719 |
+
"<IPython.core.display.HTML object>"
|
720 |
+
]
|
721 |
+
},
|
722 |
+
"metadata": {},
|
723 |
+
"output_type": "display_data"
|
724 |
+
}
|
725 |
+
],
|
726 |
+
"source": [
|
727 |
+
"# Training arguments\n",
|
728 |
+
"training_args = TrainingArguments(\n",
|
729 |
+
" per_device_train_batch_size=,\n",
|
730 |
+
" gradient_accumulation_steps=4,\n",
|
731 |
+
" gradient_checkpointing=True,\n",
|
732 |
+
" learning_rate=5e-5,\n",
|
733 |
+
" lr_scheduler_type=\"cosine\",\n",
|
734 |
+
" num_train_epochs=3,\n",
|
735 |
+
" save_strategy=\"no\",\n",
|
736 |
+
" logging_steps=1,\n",
|
737 |
+
" output_dir=new_model,\n",
|
738 |
+
" optim=\"paged_adamw_32bit\",\n",
|
739 |
+
" warmup_steps=100,\n",
|
740 |
+
" bf16=True,\n",
|
741 |
+
" report_to=\"wandb\",\n",
|
742 |
+
")\n",
|
743 |
+
"\n",
|
744 |
+
"# Create DPO trainer\n",
|
745 |
+
"dpo_trainer = DPOTrainer(\n",
|
746 |
+
" model,\n",
|
747 |
+
" ref_model,\n",
|
748 |
+
" args=training_args,\n",
|
749 |
+
" train_dataset=dataset,\n",
|
750 |
+
" tokenizer=tokenizer,\n",
|
751 |
+
" peft_config=peft_config,\n",
|
752 |
+
" beta=0.1,\n",
|
753 |
+
" max_prompt_length=1024,\n",
|
754 |
+
" max_length=1536,\n",
|
755 |
+
")\n",
|
756 |
+
"\n",
|
757 |
+
"# Fine-tune model with DPO\n",
|
758 |
+
"dpo_trainer.train()"
|
759 |
+
]
|
760 |
+
},
|
761 |
+
{
|
762 |
+
"cell_type": "code",
|
763 |
+
"execution_count": null,
|
764 |
+
"id": "4383edf2-f7e9-4502-b375-8918a9712f80",
|
765 |
+
"metadata": {},
|
766 |
+
"outputs": [],
|
767 |
+
"source": []
|
768 |
+
}
|
769 |
+
],
|
770 |
+
"metadata": {
|
771 |
+
"kernelspec": {
|
772 |
+
"display_name": "Python 3 (ipykernel)",
|
773 |
+
"language": "python",
|
774 |
+
"name": "python3"
|
775 |
+
},
|
776 |
+
"language_info": {
|
777 |
+
"codemirror_mode": {
|
778 |
+
"name": "ipython",
|
779 |
+
"version": 3
|
780 |
+
},
|
781 |
+
"file_extension": ".py",
|
782 |
+
"mimetype": "text/x-python",
|
783 |
+
"name": "python",
|
784 |
+
"nbconvert_exporter": "python",
|
785 |
+
"pygments_lexer": "ipython3",
|
786 |
+
"version": "3.10.11"
|
787 |
+
}
|
788 |
+
},
|
789 |
+
"nbformat": 4,
|
790 |
+
"nbformat_minor": 5
|
791 |
+
}
|
notebooks/SFTTrainer TRL.ipynb
ADDED
The diff for this file is too large to render.
See raw diff
|
|
notebooks/chatml_inference.ipynb
ADDED
@@ -0,0 +1,320 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cells": [
|
3 |
+
{
|
4 |
+
"cell_type": "code",
|
5 |
+
"execution_count": 1,
|
6 |
+
"id": "4753f60c-1021-420d-a4e3-1b0c7d610892",
|
7 |
+
"metadata": {},
|
8 |
+
"outputs": [
|
9 |
+
{
|
10 |
+
"name": "stdout",
|
11 |
+
"output_type": "stream",
|
12 |
+
"text": [
|
13 |
+
"\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n",
|
14 |
+
"\u001b[0m"
|
15 |
+
]
|
16 |
+
}
|
17 |
+
],
|
18 |
+
"source": [
|
19 |
+
"!pip install -qU transformers accelerate"
|
20 |
+
]
|
21 |
+
},
|
22 |
+
{
|
23 |
+
"cell_type": "code",
|
24 |
+
"execution_count": 2,
|
25 |
+
"id": "2486c68b-07eb-4c8a-8471-09d81d5cecb6",
|
26 |
+
"metadata": {},
|
27 |
+
"outputs": [
|
28 |
+
{
|
29 |
+
"data": {
|
30 |
+
"application/vnd.jupyter.widget-view+json": {
|
31 |
+
"model_id": "71f0ea022d114a86a4d233b827d5cd4a",
|
32 |
+
"version_major": 2,
|
33 |
+
"version_minor": 0
|
34 |
+
},
|
35 |
+
"text/plain": [
|
36 |
+
"tokenizer_config.json: 0%| | 0.00/1.60k [00:00<?, ?B/s]"
|
37 |
+
]
|
38 |
+
},
|
39 |
+
"metadata": {},
|
40 |
+
"output_type": "display_data"
|
41 |
+
},
|
42 |
+
{
|
43 |
+
"data": {
|
44 |
+
"application/vnd.jupyter.widget-view+json": {
|
45 |
+
"model_id": "d2a49c19bfac4bc1b6e4270d5961b08d",
|
46 |
+
"version_major": 2,
|
47 |
+
"version_minor": 0
|
48 |
+
},
|
49 |
+
"text/plain": [
|
50 |
+
"tokenizer.model: 0%| | 0.00/493k [00:00<?, ?B/s]"
|
51 |
+
]
|
52 |
+
},
|
53 |
+
"metadata": {},
|
54 |
+
"output_type": "display_data"
|
55 |
+
},
|
56 |
+
{
|
57 |
+
"data": {
|
58 |
+
"application/vnd.jupyter.widget-view+json": {
|
59 |
+
"model_id": "f69f402344c1405183181ff9815eaed9",
|
60 |
+
"version_major": 2,
|
61 |
+
"version_minor": 0
|
62 |
+
},
|
63 |
+
"text/plain": [
|
64 |
+
"tokenizer.json: 0%| | 0.00/1.80M [00:00<?, ?B/s]"
|
65 |
+
]
|
66 |
+
},
|
67 |
+
"metadata": {},
|
68 |
+
"output_type": "display_data"
|
69 |
+
},
|
70 |
+
{
|
71 |
+
"data": {
|
72 |
+
"application/vnd.jupyter.widget-view+json": {
|
73 |
+
"model_id": "5716e24a6b2c41969733d713a943f905",
|
74 |
+
"version_major": 2,
|
75 |
+
"version_minor": 0
|
76 |
+
},
|
77 |
+
"text/plain": [
|
78 |
+
"added_tokens.json: 0%| | 0.00/51.0 [00:00<?, ?B/s]"
|
79 |
+
]
|
80 |
+
},
|
81 |
+
"metadata": {},
|
82 |
+
"output_type": "display_data"
|
83 |
+
},
|
84 |
+
{
|
85 |
+
"data": {
|
86 |
+
"application/vnd.jupyter.widget-view+json": {
|
87 |
+
"model_id": "0a20293820654941b97c8c3fd79a5daa",
|
88 |
+
"version_major": 2,
|
89 |
+
"version_minor": 0
|
90 |
+
},
|
91 |
+
"text/plain": [
|
92 |
+
"special_tokens_map.json: 0%| | 0.00/420 [00:00<?, ?B/s]"
|
93 |
+
]
|
94 |
+
},
|
95 |
+
"metadata": {},
|
96 |
+
"output_type": "display_data"
|
97 |
+
},
|
98 |
+
{
|
99 |
+
"name": "stderr",
|
100 |
+
"output_type": "stream",
|
101 |
+
"text": [
|
102 |
+
"Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n"
|
103 |
+
]
|
104 |
+
},
|
105 |
+
{
|
106 |
+
"data": {
|
107 |
+
"application/vnd.jupyter.widget-view+json": {
|
108 |
+
"model_id": "4e2fd0b42c5547468b58d8242084d448",
|
109 |
+
"version_major": 2,
|
110 |
+
"version_minor": 0
|
111 |
+
},
|
112 |
+
"text/plain": [
|
113 |
+
"config.json: 0%| | 0.00/653 [00:00<?, ?B/s]"
|
114 |
+
]
|
115 |
+
},
|
116 |
+
"metadata": {},
|
117 |
+
"output_type": "display_data"
|
118 |
+
},
|
119 |
+
{
|
120 |
+
"data": {
|
121 |
+
"application/vnd.jupyter.widget-view+json": {
|
122 |
+
"model_id": "803d00873cd942baaea2828c30fac2e4",
|
123 |
+
"version_major": 2,
|
124 |
+
"version_minor": 0
|
125 |
+
},
|
126 |
+
"text/plain": [
|
127 |
+
"model.safetensors.index.json: 0%| | 0.00/23.9k [00:00<?, ?B/s]"
|
128 |
+
]
|
129 |
+
},
|
130 |
+
"metadata": {},
|
131 |
+
"output_type": "display_data"
|
132 |
+
},
|
133 |
+
{
|
134 |
+
"data": {
|
135 |
+
"application/vnd.jupyter.widget-view+json": {
|
136 |
+
"model_id": "897afa2a1bcd49bd987fbf74fb9bcd7d",
|
137 |
+
"version_major": 2,
|
138 |
+
"version_minor": 0
|
139 |
+
},
|
140 |
+
"text/plain": [
|
141 |
+
"Downloading shards: 0%| | 0/3 [00:00<?, ?it/s]"
|
142 |
+
]
|
143 |
+
},
|
144 |
+
"metadata": {},
|
145 |
+
"output_type": "display_data"
|
146 |
+
},
|
147 |
+
{
|
148 |
+
"data": {
|
149 |
+
"application/vnd.jupyter.widget-view+json": {
|
150 |
+
"model_id": "0161186a95a141d0839fd5035de42cfb",
|
151 |
+
"version_major": 2,
|
152 |
+
"version_minor": 0
|
153 |
+
},
|
154 |
+
"text/plain": [
|
155 |
+
"model-00001-of-00003.safetensors: 0%| | 0.00/4.94G [00:00<?, ?B/s]"
|
156 |
+
]
|
157 |
+
},
|
158 |
+
"metadata": {},
|
159 |
+
"output_type": "display_data"
|
160 |
+
},
|
161 |
+
{
|
162 |
+
"data": {
|
163 |
+
"application/vnd.jupyter.widget-view+json": {
|
164 |
+
"model_id": "2974a698420745a897c5b1d8058b8811",
|
165 |
+
"version_major": 2,
|
166 |
+
"version_minor": 0
|
167 |
+
},
|
168 |
+
"text/plain": [
|
169 |
+
"model-00002-of-00003.safetensors: 0%| | 0.00/5.00G [00:00<?, ?B/s]"
|
170 |
+
]
|
171 |
+
},
|
172 |
+
"metadata": {},
|
173 |
+
"output_type": "display_data"
|
174 |
+
},
|
175 |
+
{
|
176 |
+
"data": {
|
177 |
+
"application/vnd.jupyter.widget-view+json": {
|
178 |
+
"model_id": "a0bbb291ef6c4fe3b807c3612ec7fa72",
|
179 |
+
"version_major": 2,
|
180 |
+
"version_minor": 0
|
181 |
+
},
|
182 |
+
"text/plain": [
|
183 |
+
"model-00003-of-00003.safetensors: 0%| | 0.00/4.54G [00:00<?, ?B/s]"
|
184 |
+
]
|
185 |
+
},
|
186 |
+
"metadata": {},
|
187 |
+
"output_type": "display_data"
|
188 |
+
},
|
189 |
+
{
|
190 |
+
"data": {
|
191 |
+
"application/vnd.jupyter.widget-view+json": {
|
192 |
+
"model_id": "38d7b091f5d74f3a98530f8237ee3e78",
|
193 |
+
"version_major": 2,
|
194 |
+
"version_minor": 0
|
195 |
+
},
|
196 |
+
"text/plain": [
|
197 |
+
"Loading checkpoint shards: 0%| | 0/3 [00:00<?, ?it/s]"
|
198 |
+
]
|
199 |
+
},
|
200 |
+
"metadata": {},
|
201 |
+
"output_type": "display_data"
|
202 |
+
},
|
203 |
+
{
|
204 |
+
"data": {
|
205 |
+
"application/vnd.jupyter.widget-view+json": {
|
206 |
+
"model_id": "0c1887e25f0b4e60aa20e3637201d054",
|
207 |
+
"version_major": 2,
|
208 |
+
"version_minor": 0
|
209 |
+
},
|
210 |
+
"text/plain": [
|
211 |
+
"generation_config.json: 0%| | 0.00/115 [00:00<?, ?B/s]"
|
212 |
+
]
|
213 |
+
},
|
214 |
+
"metadata": {},
|
215 |
+
"output_type": "display_data"
|
216 |
+
},
|
217 |
+
{
|
218 |
+
"name": "stderr",
|
219 |
+
"output_type": "stream",
|
220 |
+
"text": [
|
221 |
+
"Special tokens have been added in the vocabulary, make sure the associated word embeddings are fine-tuned or trained.\n",
|
222 |
+
"Setting `pad_token_id` to `eos_token_id`:32000 for open-end generation.\n"
|
223 |
+
]
|
224 |
+
},
|
225 |
+
{
|
226 |
+
"name": "stdout",
|
227 |
+
"output_type": "stream",
|
228 |
+
"text": [
|
229 |
+
"<|im_start|>user\n",
|
230 |
+
"What is a large language model?<|im_end|>\n",
|
231 |
+
"<|im_start|>assistant\n",
|
232 |
+
"A large language model is a type of artificial intelligence algorithm 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 within language. Large language models are used in various applications, such as natural language processing, machine translation, and chatbots. They can understand and generate text in a way that is similar to how humans do, making them a powerful tool for language understanding and generation.\n"
|
233 |
+
]
|
234 |
+
}
|
235 |
+
],
|
236 |
+
"source": [
|
237 |
+
"from transformers import AutoTokenizer\n",
|
238 |
+
"import transformers\n",
|
239 |
+
"import torch\n",
|
240 |
+
"\n",
|
241 |
+
"model = \"TokenBender/navaran_hindi_dpo_merged\"\n",
|
242 |
+
"messages = [{\"role\": \"user\", \"content\": \"What is a large language model?\"}]\n",
|
243 |
+
"\n",
|
244 |
+
"tokenizer = AutoTokenizer.from_pretrained(model)\n",
|
245 |
+
"prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)\n",
|
246 |
+
"pipeline = transformers.pipeline(\n",
|
247 |
+
" \"text-generation\",\n",
|
248 |
+
" model=model,\n",
|
249 |
+
" torch_dtype=torch.float16,\n",
|
250 |
+
" device_map=\"auto\",\n",
|
251 |
+
")\n",
|
252 |
+
"\n",
|
253 |
+
"outputs = pipeline(prompt, max_new_tokens=256, do_sample=True, temperature=0.7, top_k=50, top_p=0.95)\n",
|
254 |
+
"print(outputs[0][\"generated_text\"])"
|
255 |
+
]
|
256 |
+
},
|
257 |
+
{
|
258 |
+
"cell_type": "code",
|
259 |
+
"execution_count": 15,
|
260 |
+
"id": "d2f57274-06e8-4e7c-b7a4-c6f22d8bb477",
|
261 |
+
"metadata": {},
|
262 |
+
"outputs": [
|
263 |
+
{
|
264 |
+
"name": "stderr",
|
265 |
+
"output_type": "stream",
|
266 |
+
"text": [
|
267 |
+
"/opt/conda/lib/python3.10/site-packages/transformers/pipelines/base.py:1123: UserWarning: You seem to be using the pipelines sequentially on GPU. In order to maximize efficiency please use a dataset\n",
|
268 |
+
" warnings.warn(\n",
|
269 |
+
"Setting `pad_token_id` to `eos_token_id`:32000 for open-end generation.\n"
|
270 |
+
]
|
271 |
+
},
|
272 |
+
{
|
273 |
+
"name": "stdout",
|
274 |
+
"output_type": "stream",
|
275 |
+
"text": [
|
276 |
+
"<|im_start|>user\n",
|
277 |
+
"वर्चुअल रियलिटी और ऑगमेंटेड रियलिटी में क्या अंतर है?<|im_end|>\n",
|
278 |
+
"<|im_start|>assistant\n",
|
279 |
+
"उत्तर: वीडियो गेम विकास का इतिहास और वीडियो गेम उद्योग पर इसका प्रभाव। यह लेख वीडियो गेम विकास के विकास और वीडियो गेम उद्योग पर इसके प्रभाव की पड़ताल करता है। यह वीडियो गेम विकास के विभिन्न चरणों और विभिन्न प्लेटफार्मों पर इसके प्रभाव पर चर्चा करता है। जबकि यह वीडियो गेम विकास के बारे में मूल्यवान जानकारी प्रदान करता है, यह विशेष रूप से वीडियो गेम विकास के लिए उपयोग किए जाने वाले उन्नत प्रोग्रामिंग भाषाओं पर ध्यान केंद्रित नहीं करता है।\n"
|
280 |
+
]
|
281 |
+
}
|
282 |
+
],
|
283 |
+
"source": [
|
284 |
+
"messages = [{\"role\": \"user\", \"content\": \"वर्चुअल रियलिटी और ऑगमेंटेड रियलिटी में क्या अंतर है?\"}]\n",
|
285 |
+
"prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)\n",
|
286 |
+
"outputs = pipeline(prompt, max_new_tokens=1024, do_sample=True, temperature=0.1, top_k=50, top_p=0.95)\n",
|
287 |
+
"print(outputs[0][\"generated_text\"])"
|
288 |
+
]
|
289 |
+
},
|
290 |
+
{
|
291 |
+
"cell_type": "code",
|
292 |
+
"execution_count": null,
|
293 |
+
"id": "3d143124-be47-400e-b7ee-5315c3e11673",
|
294 |
+
"metadata": {},
|
295 |
+
"outputs": [],
|
296 |
+
"source": []
|
297 |
+
}
|
298 |
+
],
|
299 |
+
"metadata": {
|
300 |
+
"kernelspec": {
|
301 |
+
"display_name": "Python 3 (ipykernel)",
|
302 |
+
"language": "python",
|
303 |
+
"name": "python3"
|
304 |
+
},
|
305 |
+
"language_info": {
|
306 |
+
"codemirror_mode": {
|
307 |
+
"name": "ipython",
|
308 |
+
"version": 3
|
309 |
+
},
|
310 |
+
"file_extension": ".py",
|
311 |
+
"mimetype": "text/x-python",
|
312 |
+
"name": "python",
|
313 |
+
"nbconvert_exporter": "python",
|
314 |
+
"pygments_lexer": "ipython3",
|
315 |
+
"version": "3.10.11"
|
316 |
+
}
|
317 |
+
},
|
318 |
+
"nbformat": 4,
|
319 |
+
"nbformat_minor": 5
|
320 |
+
}
|