Text Generation
Transformers
Russian
English
gpt2
ruGPT
conversational
Inference Endpoints
text-generation-inference
Paul Rock commited on
Commit
d188338
1 Parent(s): 99bdfc7

Readme updated

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. README.md +191 -1
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ /.idea/
README.md CHANGED
@@ -14,4 +14,194 @@ language:
14
  pipeline_tag: conversational
15
  tags:
16
  - ruGPT
17
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  pipeline_tag: conversational
15
  tags:
16
  - ruGPT
17
+ ---
18
+
19
+ # ruGPT-3.5 13B GGML
20
+
21
+ Welcome to the adapter-only version of ruGPT-3.5 13B GGML. This model is built upon the foundation of [ruGPT-3.5-13B](https://huggingface.co/ai-forever/ruGPT-3.5-13B).
22
+
23
+ 📌 Important: This model was trained using settings identical to [GigaSaiga](https://huggingface.co/IlyaGusev/gigasaiga_lora), but incorporates additional dataset.
24
+
25
+ 🔗 Training code is [here](https://github.com/EvilFreelancer/ruGPT-3.5-13B-lora).
26
+
27
+ ## Code sample
28
+
29
+ ```python
30
+ from llm_rs import AutoModel, GenerationConfig as GConfig
31
+ from transformers import AutoTokenizer, GenerationConfig
32
+
33
+ MODEL_NAME = "evilfreelancer/ruGPT-3.5-13B-ggml"
34
+ DEFAULT_MESSAGE_TEMPLATE = "<s>{role}\n{content}</s>\n"
35
+ DEFAULT_SYSTEM_PROMPT = "Ты — ruGPT-3.5, русскоязычный автоматический ассистент. Ты разговариваешь с людьми и помогаешь им."
36
+
37
+ class Conversation:
38
+ def __init__(
39
+ self,
40
+ message_template=DEFAULT_MESSAGE_TEMPLATE,
41
+ system_prompt=DEFAULT_SYSTEM_PROMPT,
42
+ start_token_id=2,
43
+ bot_token_id=46787
44
+ ):
45
+ self.message_template = message_template
46
+ self.start_token_id = start_token_id
47
+ self.bot_token_id = bot_token_id
48
+ self.messages = [{
49
+ "role": "system",
50
+ "content": system_prompt
51
+ }]
52
+
53
+ def get_start_token_id(self):
54
+ return self.start_token_id
55
+
56
+ def get_bot_token_id(self):
57
+ return self.bot_token_id
58
+
59
+ def add_user_message(self, message):
60
+ self.messages.append({
61
+ "role": "user",
62
+ "content": message
63
+ })
64
+
65
+ def add_bot_message(self, message):
66
+ self.messages.append({
67
+ "role": "bot",
68
+ "content": message
69
+ })
70
+
71
+ def get_prompt(self, tokenizer):
72
+ final_text = ""
73
+ for message in self.messages:
74
+ message_text = self.message_template.format(**message)
75
+ final_text += message_text
76
+ final_text += tokenizer.decode([self.start_token_id, self.bot_token_id])
77
+ return final_text.strip()
78
+
79
+
80
+ def generate(model, tokenizer, prompt, generation_config):
81
+ data = tokenizer(prompt, return_tensors="pt")
82
+ output = model.generate(
83
+ prompt=prompt,
84
+ generation_config=generation_config
85
+ ).text
86
+ # print("output", output)
87
+ output_ids = tokenizer(output, return_tensors="pt")['input_ids'][0]
88
+ # print("output_ids", output_ids)
89
+ # output_ids = output_ids[len(data["input_ids"][0]):]
90
+ # print("output_ids", output_ids)
91
+ output = tokenizer.decode(output_ids, skip_special_tokens=True)
92
+ # print("output_ids", output)
93
+ return output.strip()
94
+
95
+ # Load base model
96
+ model = AutoModel.from_pretrained(
97
+ MODEL_NAME,
98
+ model_file="ruGPT-3.5-13B-lora-q4_0.bin",
99
+ )
100
+
101
+ # Init basic tokenizer
102
+ tokenizer = AutoTokenizer.from_pretrained('ai-forever/ruGPT-3.5-13B', use_fast=False)
103
+ generation_config = GenerationConfig.from_pretrained('ai-forever/ruGPT-3.5-13B')
104
+
105
+ # Instantiate generator config
106
+ g_config = GConfig()
107
+ g_config.top_p = generation_config['top_p']
108
+ g_config.top_k = generation_config['top_k']
109
+ g_config.repetition_penalty = generation_config['repetition_penalty']
110
+ g_config.temperature = generation_config['temperature']
111
+ g_config.max_new_tokens = 200
112
+
113
+ # Start conversation
114
+ conversation = Conversation()
115
+ while True:
116
+ user_message = input("User: ")
117
+
118
+ if user_message.strip() == "/reset":
119
+ conversation = Conversation()
120
+ print("History reset completed!")
121
+ continue
122
+
123
+ if user_message.strip() == "":
124
+ continue
125
+
126
+ conversation.add_user_message(user_message)
127
+ prompt = conversation.get_prompt(tokenizer)
128
+ output = generate(
129
+ model=model,
130
+ tokenizer=tokenizer,
131
+ prompt=prompt,
132
+ generation_config=g_config
133
+ )
134
+ conversation.add_bot_message(output)
135
+ print("ruGPT-3.5:", output)
136
+ print()
137
+ print("==============================")
138
+ print()
139
+ ```
140
+
141
+ ## Examples
142
+
143
+ ```text
144
+ User: Привет! Почему трава зелёная?
145
+ ruGPT-3.5: Трава зелёная благодаря хлорофиллу - пигменту растений, который поглощает световые волны определенной длины и преобразует их в энергию химических связей. Хлорофилл также обеспечивает растения питательными веществами из почвы через фотосинтез.
146
+ ```
147
+
148
+ ```text
149
+ User: Придумай стишок про нейросети.
150
+ ruGPT-3.5: Нейросеть – это чудо науки,
151
+ Она способна решать любые задачи.
152
+ И если ты хочешь стать программистом,
153
+ То лучше всего изучать нейронные сети.
154
+ ```
155
+
156
+ ```text
157
+ User: Высота само�� высокой горы на Земле?
158
+ ruGPT-3.5: Самая высокая гора на Земле находится в Гималаях и называется Эверест (8848 метров).
159
+ ```
160
+
161
+ ```text
162
+ User: Сколько максимум лет может прожить галопогосская черепаха?
163
+ ruGPT-3.5: Галопогосские черепахи могут жить до 100 лет и более. Они являются одними из самых долгоживущих животных на планете.
164
+ ```
165
+
166
+ ## 📚 Training Datasets
167
+
168
+ The datasets utilized for training this model are consistent with those used for [Saiga-2](https://github.com/IlyaGusev/rulm).
169
+
170
+ Here's the comprehensive list:
171
+
172
+ - [ru_turbo_alpaca](https://huggingface.co/datasets/IlyaGusev/ru_turbo_alpaca)
173
+ - [ru_turbo_alpaca_evol_instruct](https://huggingface.co/datasets/IlyaGusev/ru_turbo_alpaca_evol_instruct)
174
+ - [ru_turbo_saiga](https://huggingface.co/datasets/IlyaGusev/ru_turbo_saiga)
175
+ - [ru_sharegpt_cleaned](https://huggingface.co/datasets/IlyaGusev/ru_sharegpt_cleaned)
176
+ - [oasst1_ru_main_branch](https://huggingface.co/datasets/IlyaGusev/oasst1_ru_main_branch)
177
+ - [gpt_roleplay_realm](https://huggingface.co/datasets/IlyaGusev/gpt_roleplay_realm)
178
+ - [ru_instruct_gpt4](https://huggingface.co/datasets/lksy/ru_instruct_gpt4)
179
+
180
+ ## 🛠 Training Procedure
181
+
182
+ The following `bitsandbytes` quantization config was used during training:
183
+
184
+ - quant_method: bitsandbytes
185
+ - load_in_8bit: True
186
+ - load_in_4bit: False
187
+ - llm_int8_threshold: 6.0
188
+ - llm_int8_skip_modules: None
189
+ - llm_int8_enable_fp32_cpu_offload: False
190
+ - llm_int8_has_fp16_weight: False
191
+ - bnb_4bit_quant_type: fp4
192
+ - bnb_4bit_use_double_quant: False
193
+ - bnb_4bit_compute_dtype: float32
194
+
195
+ ## ⚙️ Framework Versions
196
+
197
+ Ensure you have the following framework versions for compatibility:
198
+
199
+ - PyTorch 2.1.0
200
+ - PEFT 0.5.0
201
+ - bitsandbytes 0.41.1
202
+ - transformers 4.34.0
203
+
204
+ ## Links
205
+
206
+ - https://t.me/evilfreelancer
207
+ - https://dzen.ru/evilfreelancer