xu song
commited on
Commit
•
04a7868
1
Parent(s):
98b5498
update
Browse files- models/cpp_qwen2.py +4 -3
models/cpp_qwen2.py
CHANGED
@@ -69,7 +69,7 @@ class Qwen2Simulator(Simulator):
|
|
69 |
"<|im_start|>",
|
70 |
"<|endoftext|>",
|
71 |
]
|
72 |
-
self.stop_tokens = self.tokenize(
|
73 |
self.generation_kwargs = dict(
|
74 |
temperature=config.DEFAULT_TEMPERATURE,
|
75 |
top_p=config.DEFAULT_TOP_P,
|
@@ -91,6 +91,7 @@ class Qwen2Simulator(Simulator):
|
|
91 |
tokens.pop(0)
|
92 |
while tokens and tokens[-1] in self.stop_tokens:
|
93 |
tokens.pop()
|
|
|
94 |
|
95 |
def generate(self, history, stream=True):
|
96 |
if history[-1]['role'] in ["user"]:
|
@@ -102,8 +103,8 @@ class Qwen2Simulator(Simulator):
|
|
102 |
for message in history:
|
103 |
if "tokens" not in message: # tokens
|
104 |
message["tokens"] = self.tokenize(message["content"])
|
105 |
-
input_ids += self.
|
106 |
-
+ message["tokens"] \
|
107 |
+ self.tokenize("<|im_end|>\n")
|
108 |
input_ids += start_tokens
|
109 |
if stream:
|
|
|
69 |
"<|im_start|>",
|
70 |
"<|endoftext|>",
|
71 |
]
|
72 |
+
self.stop_tokens = self.tokenize("".joself.stop_words)
|
73 |
self.generation_kwargs = dict(
|
74 |
temperature=config.DEFAULT_TEMPERATURE,
|
75 |
top_p=config.DEFAULT_TOP_P,
|
|
|
91 |
tokens.pop(0)
|
92 |
while tokens and tokens[-1] in self.stop_tokens:
|
93 |
tokens.pop()
|
94 |
+
return tokens
|
95 |
|
96 |
def generate(self, history, stream=True):
|
97 |
if history[-1]['role'] in ["user"]:
|
|
|
103 |
for message in history:
|
104 |
if "tokens" not in message: # tokens
|
105 |
message["tokens"] = self.tokenize(message["content"])
|
106 |
+
input_ids += self.tokenize(f"<|im_start|>{message['role']}\n") \
|
107 |
+
+ self._strip_stoptokens(message["tokens"]) \
|
108 |
+ self.tokenize("<|im_end|>\n")
|
109 |
input_ids += start_tokens
|
110 |
if stream:
|