Skip to content

[Bugfix] Mistral tokenizer encode accept list of str #12149

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

Merged
merged 6 commits into from
Jan 17, 2025
Merged
Changes from 2 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: 18 additions & 2 deletions vllm/transformers_utils/tokenizers/mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
Tekkenizer)

from vllm.logger import init_logger
from vllm.utils import is_list_of

if TYPE_CHECKING:
from vllm.entrypoints.chat_utils import ChatCompletionMessageParam
Expand All @@ -27,7 +28,7 @@

@dataclass
class Encoding:
input_ids: List[int]
input_ids: Union[List[int], List[List[int]]]


def maybe_serialize_tool_calls(request: ChatCompletionRequest):
Expand Down Expand Up @@ -223,12 +224,27 @@ def __len__(self) -> int:

def __call__(
self,
prompt: str,
prompt: Union[str, List[str], List[int]],
add_special_tokens: bool = False,
truncation: bool = False,
max_length: Optional[int] = None,
):
# For List[str], original prompt text
if is_list_of(prompt, str):
all_input_ids = []
for p in prompt:
input_ids = self.encode(p)
if truncation:
input_ids = input_ids[:max_length]
all_input_ids.append(input_ids)
return Encoding(input_ids=all_input_ids)

# For List[int], apply chat template output
if is_list_of(prompt, int):
return Encoding(input_ids=prompt)

# Mistral Tokenizers should not add special tokens
assert isinstance(prompt, str), f"Invalid prompt: {prompt}"
input_ids = self.encode(prompt)

if truncation:
Expand Down
Loading