yeyongyu commited on
Commit
b66f78d
β€’
1 Parent(s): f64bdc8

modify: modify mistral inference code

Browse files
Files changed (1) hide show
  1. README.md +3 -25
README.md CHANGED
@@ -42,12 +42,8 @@ Here provides a code snippet with `apply_chat_template` to show you how to load
42
  from transformers import AutoModelForCausalLM, AutoTokenizer
43
  device = "cuda" # the device to load the model onto
44
 
45
- model = AutoModelForCausalLM.from_pretrained(
46
- "yuyouyu/Mistral-Nemo-BD-RP",
47
- torch_dtype="auto",
48
- device_map="auto"
49
- )
50
- tokenizer = AutoTokenizer.from_pretrained("yuyouyu/Mistral-Nemo-BD-RP")
51
 
52
  system_prompt_temp = """I want you to answer questions as if you are {role_name}, assuming you live in the world of {world} and mimicking {role_name}'s personality and speaking style. Use the tone, manner, and vocabulary that {role_name} would use. Please do not reveal that you are an AI or language model; you must always remember you are {role_name}.
53
  {role_name}'s character traits are {character}.
@@ -87,26 +83,8 @@ messages = [
87
  {"role": "system", "content": system_prompt},
88
  {"role": "user", "content": prompt}
89
  ]
90
- text = tokenizer.apply_chat_template(
91
- messages,
92
- tokenize=False,
93
- add_generation_prompt=True
94
- )
95
- model_inputs = tokenizer([text], return_tensors="pt").to(device)
96
-
97
- generated_ids = model.generate(
98
- model_inputs.input_ids,
99
- max_new_tokens=256,
100
- do_sample=True,
101
- temperature=0.7,
102
- repetition_penalty=1.2,
103
- )
104
-
105
- generated_ids = [
106
- output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
107
- ]
108
 
109
- response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
110
  ```
111
 
112
  > [!IMPORTANT]
 
42
  from transformers import AutoModelForCausalLM, AutoTokenizer
43
  device = "cuda" # the device to load the model onto
44
 
45
+
46
+ chatbot = pipeline("text-generation", model="yuyouyu/Mistral-Nemo-BD-RP", device_map="auto")
 
 
 
 
47
 
48
  system_prompt_temp = """I want you to answer questions as if you are {role_name}, assuming you live in the world of {world} and mimicking {role_name}'s personality and speaking style. Use the tone, manner, and vocabulary that {role_name} would use. Please do not reveal that you are an AI or language model; you must always remember you are {role_name}.
49
  {role_name}'s character traits are {character}.
 
83
  {"role": "system", "content": system_prompt},
84
  {"role": "user", "content": prompt}
85
  ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
+ response = chatbot(messages, max_new_tokens=256, pad_token_id=chatbot.tokenizer.eos_token_id, do_sample=True, temperature=0.7)[0]['generated_text'][-1]['content']
88
  ```
89
 
90
  > [!IMPORTANT]