Paul Rock
commited on
Commit
•
46ecc4e
1
Parent(s):
13cc7c0
Basic info added
Browse files- README.md +112 -0
- chat.json +10 -0
- generation_config.json +13 -0
- test_gguf.py +139 -0
README.md
CHANGED
@@ -1,3 +1,115 @@
|
|
1 |
---
|
2 |
license: mit
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: mit
|
3 |
+
datasets:
|
4 |
+
- d0rj/gsm8k-ru
|
5 |
+
- d0rj/alpaca-cleaned-ru
|
6 |
+
- IlyaGusev/ru_turbo_alpaca
|
7 |
+
- IlyaGusev/ru_turbo_alpaca_evol_instruct
|
8 |
+
language:
|
9 |
+
- ru
|
10 |
+
- en
|
11 |
+
library_name: peft
|
12 |
+
pipeline_tag: text-generation
|
13 |
---
|
14 |
+
|
15 |
+
# PavelGPT 7B 128K (v0.1)
|
16 |
+
|
17 |
+
PavelGPT is a Russian language model based
|
18 |
+
on [NousResearch/Yarn-Mistral-7b-128k](https://huggingface.co/NousResearch/Yarn-Mistral-7b-128k)
|
19 |
+
so it also has 7B parameters and 128k context size.
|
20 |
+
|
21 |
+
- **Developed by:** [EvilFreelancer](https://github.com/EvilFreelancer)
|
22 |
+
- **Model type:** GGUF
|
23 |
+
- **Language(s) (NLP):** Russian, English
|
24 |
+
- **License:** MIT
|
25 |
+
- **Finetuned from model:**
|
26 |
+
[NousResearch/Yarn-Mistral-7b-128k](https://huggingface.co/NousResearch/Yarn-Mistral-7b-128k)
|
27 |
+
|
28 |
+
## Details
|
29 |
+
|
30 |
+
### Description
|
31 |
+
|
32 |
+
The model is able to generate text in Russian, answer questions, solve simple logical puzzles and simple math
|
33 |
+
calculations, it was trained on a medium corpus of Russian instructions, manuals and other texts.
|
34 |
+
|
35 |
+
It optimized for INSTRUCT mode and it works better if you give it system prompt and only one instruction (without
|
36 |
+
history at all).
|
37 |
+
|
38 |
+
### Datasets
|
39 |
+
|
40 |
+
PavelGPT was trained on following datasets:
|
41 |
+
|
42 |
+
- [d0rj/gsm8k-ru](https://huggingface.co/datasets/d0rj/gsm8k-ru) - 7.5k rows of Russian puzzles
|
43 |
+
- [d0rj/alpaca-cleaned-ru](https://huggingface.co/datasets/d0rj/alpaca-cleaned-ru) - 51.8k rows of Russian general
|
44 |
+
instructions
|
45 |
+
- [IlyaGusev/ru_turbo_alpaca](https://huggingface.co/datasets/IlyaGusev/ru_turbo_alpaca) - 29.98k rows of Russian
|
46 |
+
instructions, but was used only instructions with `ok` label (~4.5k)
|
47 |
+
- [IlyaGusev/ru_turbo_alpaca_evol_instruct](https://huggingface.co/datasets/IlyaGusev/ru_turbo_alpaca_evol_instruct) -
|
48 |
+
47.8k rows of Russian instructions
|
49 |
+
|
50 |
+
All datasets was merged with help
|
51 |
+
of [create_instruct_set_v2.py](https://github.com/EvilFreelancer/saiga-custom/blob/main/data_processing/create_instruct_set_v2.py)
|
52 |
+
(hash a1151bf903990b88177d30bd1de67c7b94fdecef).
|
53 |
+
|
54 |
+
After merging and deduplication we got 46.2k rows of training data and 2.4k rows of validation data.
|
55 |
+
|
56 |
+
### Training
|
57 |
+
|
58 |
+
Model was trained on 1x RTX 4090 24GB for 1 epoch (took ~12 hours), it was trained with help of Peft library and in 4bit quantization mode.
|
59 |
+
|
60 |
+
Context size was set to 4096 tokens, batch size was set to 1, gradient accumulation was set to 128.
|
61 |
+
|
62 |
+
Training script: [pavelgpt_7b_128k.ipynb](https://github.com/EvilFreelancer/saiga-custom/blob/main/pavelgpt_7b_128k.ipynb).
|
63 |
+
|
64 |
+
Wandb report: [j6jt6cyd](https://api.wandb.ai/links/evilfreelancer/j6jt6cyd).
|
65 |
+
|
66 |
+
### Tests results
|
67 |
+
|
68 |
+
Tests was performed on following [generation configuration](./generation_config.json):
|
69 |
+
|
70 |
+
```json
|
71 |
+
{
|
72 |
+
"pad_token_id": 0,
|
73 |
+
"unk_token_id": 0,
|
74 |
+
"bos_token_id": 1,
|
75 |
+
"eos_token_id": 2,
|
76 |
+
"temperature": 0.2,
|
77 |
+
"top_p": 0.2,
|
78 |
+
"top_k": 20,
|
79 |
+
"do_sample": true,
|
80 |
+
"max_new_tokens": 4096,
|
81 |
+
"repetition_penalty": 1.2,
|
82 |
+
"no_repeat_ngram_size": 15
|
83 |
+
}
|
84 |
+
```
|
85 |
+
|
86 |
+
Here is the results:
|
87 |
+
|
88 |
+
```text
|
89 |
+
User: Привет! Кто ты?
|
90 |
+
Bot: Я - языковой модель ИИ, называемый PavelGPT. Я способен к естественному языку и обучен отвечать на вопросы по многим темам. Как правило, я использую информацию из Интернета для создания своих ответов.
|
91 |
+
|
92 |
+
User: Ты помнишь как здесь оказался?
|
93 |
+
Bot: Я был создан компанией OpenAI в качестве исследовательского проекта и запущен в декабре 2018 года. С тех пор он продолжает развивать свой алгоритм путем обучения на больших объемах данных и улучшения его функций.
|
94 |
+
|
95 |
+
User: Какой по твоему сейчас год?
|
96 |
+
Bot: В настоящее время это 2023 год.
|
97 |
+
|
98 |
+
User: А какой день?
|
99 |
+
Bot: Сейчас 6 января 2023 г.
|
100 |
+
|
101 |
+
User: Почему трава зелёная?
|
102 |
+
Bot: Зеленый цвет является результатом взаимодействия хлорофилла (пигмента) со светом. Хлорофилл может поглощать красное и синее спектральные излучения, оставляя только зеленое. Эти компоненты вместе образуют зеленый цвет растительной массы.
|
103 |
+
|
104 |
+
User: Я пошёл в магазин и купил 10 яблок. Два яблока я отдал соседу и два ремонтнику. Потом я купил ещё 5 яблок и одно из них съел. Также я отдал три банана моему брату. Сколько яблок у меня осталось?
|
105 |
+
Bot: У вас осталось 10 яблок после того, как вы продали их друзьям и брату.
|
106 |
+
|
107 |
+
User: Твоя задача решить логическую головоломку: У Сер��жи есть мама Татьяна и папа Денис. И ещё у Серёжи есть брат Иван. Кем Ивану приходится Татьяна?
|
108 |
+
Bot: Мамой Ивана должна быть Татьяна.
|
109 |
+
```
|
110 |
+
## Links
|
111 |
+
|
112 |
+
* https://t.me/evilfreelancer
|
113 |
+
* https://dzen.ru/evilfreelancer
|
114 |
+
* https://github.com/EvilFreelancer
|
115 |
+
* https://youtube.com/@pavelzloi
|
chat.json
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"system_prompt": "Ты — PavelGPT, русскоязычный автоматический ассистент. Ты разговариваешь с людьми и помогаешь им.",
|
3 |
+
"system_message_template": "<s>{role}\n{content}</s>\n",
|
4 |
+
"user_message_template": "<s>{role}\n{content}</s>\n",
|
5 |
+
"bot_message_template": "<s>{role}\n{content}</s>\n",
|
6 |
+
"user_role": "user",
|
7 |
+
"bot_role": "bot",
|
8 |
+
"system_role": "system",
|
9 |
+
"suffix": ""
|
10 |
+
}
|
generation_config.json
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"pad_token_id": 0,
|
3 |
+
"unk_token_id": 0,
|
4 |
+
"bos_token_id": 1,
|
5 |
+
"eos_token_id": 2,
|
6 |
+
"temperature": 0.2,
|
7 |
+
"top_p": 0.2,
|
8 |
+
"top_k": 20,
|
9 |
+
"do_sample": true,
|
10 |
+
"max_new_tokens": 4096,
|
11 |
+
"repetition_penalty": 1.2,
|
12 |
+
"no_repeat_ngram_size": 15
|
13 |
+
}
|
test_gguf.py
ADDED
@@ -0,0 +1,139 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import logging
|
2 |
+
|
3 |
+
DEFAULT_MESSAGE_TEMPLATE = "<s>{role}\n{content}</s>\n"
|
4 |
+
DEFAULT_SYSTEM_PROMPT = "Ты — PavelGPT, русскоязычный автоматический ассистент. Ты разговариваешь с людьми и помогаешь им."
|
5 |
+
|
6 |
+
|
7 |
+
class Conversation:
|
8 |
+
def __init__(
|
9 |
+
self,
|
10 |
+
message_template=DEFAULT_MESSAGE_TEMPLATE,
|
11 |
+
system_prompt=DEFAULT_SYSTEM_PROMPT,
|
12 |
+
start_token_id=2,
|
13 |
+
# Bot token may be a list or single int
|
14 |
+
bot_token_id=10093, # yarn_mistral_7b_128k
|
15 |
+
# bot_token_id=46787, # rugpt35_13b
|
16 |
+
# int (amount of questions and answers) or None (unlimited)
|
17 |
+
history_limit=None,
|
18 |
+
):
|
19 |
+
self.logger = logging.getLogger('Conversation')
|
20 |
+
self.message_template = message_template
|
21 |
+
self.start_token_id = start_token_id
|
22 |
+
self.bot_token_id = bot_token_id
|
23 |
+
self.history_limit = history_limit
|
24 |
+
self.messages = [
|
25 |
+
{
|
26 |
+
"role": "system",
|
27 |
+
"content": system_prompt
|
28 |
+
},
|
29 |
+
{
|
30 |
+
"role": "bot",
|
31 |
+
"content": "Здравствуйте! Чем могу помочь?"
|
32 |
+
}
|
33 |
+
]
|
34 |
+
|
35 |
+
def get_start_token_id(self):
|
36 |
+
return self.start_token_id
|
37 |
+
|
38 |
+
def get_bot_token_id(self):
|
39 |
+
return self.bot_token_id
|
40 |
+
|
41 |
+
def add_message(self, role, message):
|
42 |
+
self.messages.append({
|
43 |
+
"role": role,
|
44 |
+
"content": message
|
45 |
+
})
|
46 |
+
self.trim_history()
|
47 |
+
|
48 |
+
def add_user_message(self, message):
|
49 |
+
self.add_message("user", message)
|
50 |
+
|
51 |
+
def add_bot_message(self, message):
|
52 |
+
self.add_message("assistant", message)
|
53 |
+
|
54 |
+
def trim_history(self):
|
55 |
+
if self.history_limit is not None and len(self.messages) > self.history_limit + 2:
|
56 |
+
overflow = len(self.messages) - (self.history_limit + 2)
|
57 |
+
self.messages = [self.messages[0]] + self.messages[overflow + 2:] # remove old messages except system
|
58 |
+
|
59 |
+
def get_prompt(self, tokenizer):
|
60 |
+
final_text = ""
|
61 |
+
# print(self.messages)
|
62 |
+
for message in self.messages:
|
63 |
+
message_text = self.message_template.format(**message)
|
64 |
+
final_text += message_text
|
65 |
+
|
66 |
+
# Bot token id may be an array
|
67 |
+
if isinstance(self.bot_token_id, (list, tuple)):
|
68 |
+
final_text += tokenizer.decode([self.start_token_id] + self.bot_token_id)
|
69 |
+
else:
|
70 |
+
final_text += tokenizer.decode([self.start_token_id, self.bot_token_id])
|
71 |
+
|
72 |
+
return final_text.strip()
|
73 |
+
|
74 |
+
|
75 |
+
def generate(model, prompt, messages, generation_config):
|
76 |
+
output = model(
|
77 |
+
prompt,
|
78 |
+
top_k=generation_config.top_k,
|
79 |
+
top_p=generation_config.top_p,
|
80 |
+
temperature=generation_config.temperature,
|
81 |
+
repeat_penalty=generation_config.repetition_penalty,
|
82 |
+
)['choices'][0]['text']
|
83 |
+
return output.strip()
|
84 |
+
|
85 |
+
|
86 |
+
from llama_cpp import Llama
|
87 |
+
import os
|
88 |
+
from pathlib import Path
|
89 |
+
from huggingface_hub.file_download import http_get
|
90 |
+
from transformers import GenerationConfig
|
91 |
+
|
92 |
+
directory = Path('.').resolve()
|
93 |
+
model_name = "pavelgpt_7b_128k/ggml-model-q8_0.gguf"
|
94 |
+
generation_config = GenerationConfig.from_pretrained("pavelgpt_7b_128k")
|
95 |
+
final_model_path = str(directory / model_name)
|
96 |
+
|
97 |
+
# if not os.path.exists(final_model_path):
|
98 |
+
# with open(final_model_path, "wb") as f:
|
99 |
+
# http_get(model_url, f)
|
100 |
+
# os.chmod(final_model_path, 0o777)
|
101 |
+
# print(f"{final_model_path} files downloaded.")
|
102 |
+
|
103 |
+
model = Llama(
|
104 |
+
model_path=final_model_path,
|
105 |
+
# verbose=True,
|
106 |
+
n_gpu_layers=5,
|
107 |
+
n_ctx=4096,
|
108 |
+
max_length=200,
|
109 |
+
echo=True,
|
110 |
+
)
|
111 |
+
|
112 |
+
conversation = Conversation(bot_token_id=7451)
|
113 |
+
while True:
|
114 |
+
user_message = input("User: ")
|
115 |
+
|
116 |
+
# Reset chat command
|
117 |
+
if user_message.strip() == "/reset":
|
118 |
+
conversation = Conversation(bot_token_id=7451)
|
119 |
+
print("History reset completed!")
|
120 |
+
continue
|
121 |
+
|
122 |
+
# Skip empty messages from user
|
123 |
+
if user_message.strip() == "":
|
124 |
+
continue
|
125 |
+
|
126 |
+
conversation.add_user_message(user_message)
|
127 |
+
prompt = conversation.get_prompt(model.tokenizer())
|
128 |
+
output = generate(
|
129 |
+
model=model,
|
130 |
+
prompt=prompt,
|
131 |
+
generation_config=generation_config,
|
132 |
+
messages=conversation.messages
|
133 |
+
)
|
134 |
+
|
135 |
+
conversation.add_bot_message(output)
|
136 |
+
print("Bot:", output)
|
137 |
+
print()
|
138 |
+
print("==============================")
|
139 |
+
print()
|