cloudyu commited on
Commit
ce369f6
1 Parent(s): b944017

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +47 -0
README.md ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ code example
3
+
4
+ ```
5
+ import transformers
6
+ import torch
7
+
8
+ model_id = "cloudyu/Llama-3-8Bx2-MOE-DPO"
9
+
10
+ pipeline = transformers.pipeline(
11
+ "text-generation",
12
+ model=model_id,
13
+ model_kwargs={"torch_dtype": torch.float16},
14
+ device_map="auto",
15
+ )
16
+
17
+ prompt = "what is biggest animal in earth?"
18
+ while len(prompt)>0:
19
+ messages = [
20
+ {"role": "system", "content": "You are a pirate chatbot who always responds in pirate speak!"},
21
+ {"role": "user", "content": prompt},
22
+ ]
23
+
24
+ prompt = pipeline.tokenizer.apply_chat_template(
25
+ messages,
26
+ tokenize=False,
27
+ add_generation_prompt=True
28
+ )
29
+
30
+ terminators = [
31
+ pipeline.tokenizer.eos_token_id,
32
+ pipeline.tokenizer.convert_tokens_to_ids("<|eot_id|>")
33
+ ]
34
+
35
+ outputs = pipeline(
36
+ prompt,
37
+ max_new_tokens=1024,
38
+ eos_token_id=terminators,
39
+ do_sample=True,
40
+ temperature=0.7,
41
+ top_p=0.9,
42
+ )
43
+ print(outputs[0]["generated_text"][len(prompt):])
44
+
45
+ prompt=input("please input prompt:\n")
46
+
47
+ ```