Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bugfix][Core] Fix tekken edge case for mistral tokenizer #8640

Merged
merged 12 commits into from
Sep 20, 2024
Prev Previous commit
Next Next commit
last format
  • Loading branch information
patrickvonplaten committed Sep 19, 2024
commit c4e3d3131feb356cf08e1a4067a5be7847496ab2
15 changes: 12 additions & 3 deletions vllm/transformers_utils/tokenizers/mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,22 @@ def apply_chat_template(self,

def convert_tokens_to_string(self, tokens: List[str]) -> str:
if isinstance(self.tokenizer, Tekkenizer):
tokens = [t for t in tokens if t not in self.tokenizer._all_special_tokens]
tokens = [
t for t in tokens
if t not in self.tokenizer._all_special_tokens
]

if any(isinstance(t, bytes) for t in tokens):
# we need to encode and decode all tokens again
shift = self.tokenizer.num_special_tokens
byte_tokens = [t.encode("utf-8") if not isinstance(t, bytes) else t for t in tokens]
ids = [self.tokenizer._tekken_token2id_nospecial[t] + shift for t in byte_tokens]
byte_tokens = [
t.encode("utf-8") if not isinstance(t, bytes) else t
for t in tokens
]
ids = [
self.tokenizer._tekken_token2id_nospecial[t] + shift
for t in byte_tokens
]
decoded = self.tokenizer.decode(ids)
else:
decoded = "".join(tokens)
Expand Down
Loading