ljsabc commited on
Commit
06f42ff
·
verified ·
1 Parent(s): 02f4512

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +39 -0
README.md CHANGED
@@ -1,3 +1,42 @@
1
  ---
2
  license: mit
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
  ---
4
+
5
+ Similarly as [Qwen-1.5-14B-Chat](https://huggingface.co/Qwen/Qwen1.5-14B-Chat), you can always call this model from the `AutoModel` class.
6
+
7
+ ```python
8
+ from transformers import AutoModelForCausalLM, AutoTokenizer
9
+ device = "cuda" # the device to load the model onto
10
+
11
+ model = AutoModelForCausalLM.from_pretrained(
12
+ "ljsabc/Qwen-1.5-14B-Chat-Fujisaki",
13
+ torch_dtype="auto",
14
+ device_map="auto",
15
+ #load_in_4bit=True
16
+ )
17
+ tokenizer = AutoTokenizer.from_pretrained("ljsabc/Qwen-1.5-14B-Chat-Fujisaki")
18
+
19
+ prompt = "请撰写一条新的推文。"
20
+ messages = [
21
+ {"role": "system", "content": "你将扮演推特用户@ljsabc,你需要撰写你的原创推文或回复别人的推文。所有你的回复都应该使用简体中文书写。"},
22
+ {"role": "user", "content": prompt}
23
+ ]
24
+ text = tokenizer.apply_chat_template(
25
+ messages,
26
+ tokenize=False,
27
+ add_generation_prompt=True
28
+ )
29
+ model_inputs = tokenizer([text], return_tensors="pt").to(device)
30
+
31
+ generated_ids = model.generate(
32
+ model_inputs.input_ids,
33
+ max_new_tokens=512,
34
+ temperature=0.95,
35
+ top_p=0.99
36
+ )
37
+ generated_ids = [
38
+ output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
39
+ ]
40
+
41
+ response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
42
+ ```