[LLM] fix chatglm native int4 emoji output (#8739)

This commit is contained in:
Yishuo Wang 2023-08-11 15:38:41 +08:00 committed by GitHub
parent 77efcf7b1d
commit f91035c298

View file

@ -235,6 +235,7 @@ class ChatGLM(GenerationMixin):
text = self.detokenize(output_tokens)
split_text = text[len(prompt):]
split_text.rstrip('<EFBFBD>') # remove partial emoji
if stop != []:
for stop_word in stop:
split_text = split_text.split(stop_word)[0]
@ -309,6 +310,11 @@ class ChatGLM(GenerationMixin):
print('\n')
break
text = self.detokenize(output_tokens)
if text.endswith('<EFBFBD>'):
# generated new token is part of an emoji
# (some emoji consists of multiple tokens)
# continue to generate more tokens to decode this emoji
continue
text = text[len(history_text):]
history_text += text
yield {