Russian
English
zjkarina commited on
Commit
1dd607a
·
verified ·
1 Parent(s): 92d1f19

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +24 -11
README.md CHANGED
@@ -6,24 +6,19 @@ datasets:
6
  - zjkarina/Vikhr_instruct
7
  ---
8
  ```python
 
9
  from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
 
10
 
11
  MODEL_NAME = "Vikhrmodels/Vikhr-7B-instruct"
12
- TEMPLATE = "<s>{role}\n{content}</s>\n"
13
- SYSTEM_PROMPT = "Ты полезный помощник по имени Вихрь. Ты разговариваешь с людьми и помогаешь им."
14
-
15
- model = AutoModelForCausalLM.from_pretrained(MODEL_NAME)
16
- model.to('cuda')
17
- model.eval()
18
-
19
- tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_fast=False)
20
- generation_config = GenerationConfig.from_pretrained(MODEL_NAME)
21
 
22
  class Conversation:
23
  def __init__(
24
  self,
25
- message_template=TEMPLATE,
26
- system_prompt=SYSTEM_PROMPT,
27
  ):
28
  self.message_template = message_template
29
  self.messages = [{
@@ -56,6 +51,24 @@ def generate(model, tokenizer, prompt, generation_config):
56
  output_ids = output_ids[len(data["input_ids"][0]):]
57
  output = tokenizer.decode(output_ids, skip_special_tokens=True)
58
  return output.strip()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
59
 
60
  inputs = ["Как тебя зовут?", "Кто такой Колмогоров?"]
61
 
 
6
  - zjkarina/Vikhr_instruct
7
  ---
8
  ```python
9
+ from peft import PeftModel, PeftConfig
10
  from transformers import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
11
+ import torch
12
 
13
  MODEL_NAME = "Vikhrmodels/Vikhr-7B-instruct"
14
+ DEFAULT_MESSAGE_TEMPLATE = "<s>{role}\n{content}</s>\n"
15
+ DEFAULT_SYSTEM_PROMPT = "Ты Вихрь, русскоязычный автоматический ассистент. Ты разговариваешь с людьми и помогаешь им."
 
 
 
 
 
 
 
16
 
17
  class Conversation:
18
  def __init__(
19
  self,
20
+ message_template=DEFAULT_MESSAGE_TEMPLATE,
21
+ system_prompt=DEFAULT_SYSTEM_PROMPT,
22
  ):
23
  self.message_template = message_template
24
  self.messages = [{
 
51
  output_ids = output_ids[len(data["input_ids"][0]):]
52
  output = tokenizer.decode(output_ids, skip_special_tokens=True)
53
  return output.strip()
54
+
55
+ config = PeftConfig.from_pretrained(MODEL_NAME)
56
+ model = AutoModelForCausalLM.from_pretrained(
57
+ config.base_model_name_or_path,
58
+ load_in_8bit=True,
59
+ torch_dtype=torch.float16,
60
+ device_map="auto"
61
+ )
62
+ model = PeftModel.from_pretrained(
63
+ model,
64
+ MODEL_NAME,
65
+ torch_dtype=torch.float16
66
+ )
67
+ model.eval()
68
+
69
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME, use_fast=False)
70
+ generation_config = GenerationConfig.from_pretrained(MODEL_NAME)
71
+ print(generation_config)
72
 
73
  inputs = ["Как тебя зовут?", "Кто такой Колмогоров?"]
74