Skip to content

tokenizer: allow skip_special_tokens=False for mistral tokenizer #1058

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions aphrodite/transformers_utils/tokenizers/mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
from mistral_common.tokens.tokenizers.tekken import (SpecialTokenPolicy,
Tekkenizer)

from aphrodite.common.logger import log_once

if TYPE_CHECKING:
from aphrodite.endpoints.chat_utils import ChatCompletionMessageParam

Expand Down Expand Up @@ -192,16 +190,20 @@ def convert_ids_to_tokens(
ids: List[int],
skip_special_tokens: bool = True,
) -> List[str]:
# TODO(Patrick) - potentially allow special tokens to not be skipped
if not skip_special_tokens:
log_once(
level="ERROR",
message="skip_special_tokens=False is not supported for "
"Mistral tokenizers.")

assert isinstance(self.tokenizer,
(Tekkenizer, SentencePieceTokenizer)), type(
self.tokenizer)
if isinstance(self.tokenizer, Tekkenizer):
original_policy = self.tokenizer.special_token_policy
self.tokenizer.special_token_policy = (
SpecialTokenPolicy.IGNORE if skip_special_tokens else
SpecialTokenPolicy.KEEP
)
try:
tokens = [self.tokenizer.id_to_piece(id) for id in ids]
finally:
if isinstance(self.tokenizer, Tekkenizer):
self.tokenizer.special_token_policy = original_policy

tokens = [self.tokenizer.id_to_piece(id) for id in ids]
return tokens
Loading