-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathconversation.py
86 lines (82 loc) · 2.81 KB
/
conversation.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from fastchat.conversation import Conversation, SeparatorStyle
# 找tokenizer_config.json
CONVS = {
'Qwen1.5': Conversation(
name="qwen",
system_template="<|im_start|>system\n{system_message}",
system_message="You are a helpful assistant.",
roles=("<|im_start|>user", "<|im_start|>assistant"),
sep_style=SeparatorStyle.CHATML,
sep="<|im_end|>",
stop_token_ids=[
151643,
151644,
151645,
14582,
], # "<|endoftext|>", "<|im_start|>", "<|im_end|>"
stop_str="<|endoftext|>",
),
'Qwen1.5-Chat': Conversation(
name="qwen",
system_template="<|im_start|>system\n{system_message}",
system_message="You are a helpful assistant.",
roles=("<|im_start|>user", "<|im_start|>assistant"),
sep_style=SeparatorStyle.CHATML,
sep="<|im_end|>",
stop_token_ids=[
151643,
151644,
151645,
14582,
], # "<|endoftext|>", "<|im_start|>", "<|im_end|>"
stop_str="<|endoftext|>",
),
'Qwen': Conversation(
name="qwen",
system_template="<|im_start|>system\n{system_message}",
system_message="You are a helpful assistant.",
roles=("<|im_start|>user", "<|im_start|>assistant"),
sep_style=SeparatorStyle.CHATML,
sep="<|im_end|>",
stop_token_ids=[
151643,
151644,
151645,
14582,
], # "<|endoftext|>", "<|im_start|>", "<|im_end|>"
stop_str="<|endoftext|>",
),
'Llama-2': Conversation(
name="llama-2",
system_template="[INST] <<SYS>>\n{system_message}\n<</SYS>>\n\n",
roles=("[INST]", "[/INST]"),
sep_style=SeparatorStyle.LLAMA2,
sep=" ",
sep2=" </s><s>",
)
}
def generate_inputs(standard_conv, prompt_q, tokenizer):
# print(standard_conv.name)
if standard_conv.name == 'llama-2':
conv = standard_conv.copy()
conv.set_system_message("You will write beautiful compliments according to needs")
# conv.append_message("<|user|>", prompt_q)
# conv.append_message("<|assistant|>", None)
conv.append_message("[INST]", prompt_q)
conv.append_message("[/INST]", None)
inputs = tokenizer(
conv.get_prompt(),
return_tensors='pt'
)["input_ids"]
elif standard_conv.name == 'qwen':
conv = standard_conv.copy()
conv.set_system_message("You will write beautiful compliments according to needs")
conv.append_message("<|im_start|>user", prompt_q)
conv.append_message("<|im_start|>assistant", None)
inputs = tokenizer(
conv.get_prompt(),
return_tensors='pt'
)["input_ids"]
else:
return None
return inputs