Skip to content

Commit

Permalink
rebase and merge
Browse files Browse the repository at this point in the history
Signed-off-by: Keyun Tong <[email protected]>
  • Loading branch information
youngkent committed Jan 29, 2025
1 parent 1b48903 commit ffbd618
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
15 changes: 8 additions & 7 deletions vllm/entrypoints/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1174,27 +1174,28 @@ def ensure_str(prompt: SingletonPrompt):
if isinstance(text_1, (str, dict)):
# Convert a single prompt to a list.
text_1 = [text_1]
text_1 = [ensure_str(t) for t in text_1]
input_text_1: List[str] = [ensure_str(t) for t in text_1]

if isinstance(text_2, (str, dict)):
# Convert a single prompt to a list.
text_2 = [text_2]
text_2 = [ensure_str(t) for t in text_2]
input_text_2: List[str] = [ensure_str(t) for t in text_2]

if len(text_1) > 1 and len(text_1) != len(text_2):
if len(input_text_1) > 1 and len(input_text_1) != len(input_text_2):
raise ValueError("Input lengths must be either 1:1, 1:N or N:N")
if len(text_1) == 0:
if len(input_text_1) == 0:
raise ValueError("At least one text element must be given")
if len(text_2) == 0:
if len(input_text_2) == 0:
raise ValueError("At least one text_pair element must be given")

if self.llm_engine.model_config.is_cross_encoder:
return self._cross_encoding_score(tokenizer, text_1, text_2,
return self._cross_encoding_score(tokenizer, input_text_1,
input_text_2,
truncate_prompt_tokens, use_tqdm,
lora_request,
prompt_adapter_request)
else:
return self._embedding_score(tokenizer, text_1, text_2,
return self._embedding_score(tokenizer, input_text_1, input_text_2,
truncate_prompt_tokens, use_tqdm,
lora_request, prompt_adapter_request)

Expand Down
2 changes: 1 addition & 1 deletion vllm/entrypoints/openai/serving_score.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ async def create_score(

input_pairs = make_pairs(request.text_1, request.text_2)
for q, t in input_pairs:
request_prompt = f"{q}{tokenizer.sep_token}{t}"
request_prompt = f"{q}{tokenizer.sep_token_id}{t}"

tokenization_kwargs: Dict[str, Any] = {}
if truncate_prompt_tokens is not None:
Expand Down
6 changes: 1 addition & 5 deletions vllm/transformers_utils/tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,7 @@ def encode_tokens(
Backend-agnostic equivalent of HF's
:code:`tokenizer.encode(text, add_special_tokens=...)`.
"""
if isinstance(tokenizer, MistralTokenizer):
return tokenizer.tokenizer.encode(text,
bos=add_special_tokens,
eos=add_special_tokens)
elif add_special_tokens is not None:
if add_special_tokens is not None:
return tokenizer.encode(text, add_special_tokens=add_special_tokens)
return tokenizer.encode(text)

Expand Down
9 changes: 7 additions & 2 deletions vllm/transformers_utils/tokenizers/mistral.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ def bos_token_id(self) -> int:
@property
def eos_token_id(self) -> int:
return self.tokenizer.eos_id

@property
def sep_token_id(self) -> int:
raise NotImplementedError()
Expand Down Expand Up @@ -283,7 +283,12 @@ def encode(self,
# `encode` should only be used for prompt completion
# it should never be used for chat_completion.
# For chat completion use `apply_chat_template`
return self.tokenizer.encode(text, bos=True, eos=False)
if add_special_tokens is not None:
return self.tokenizer.encode(text,
bos=add_special_tokens,
eos=add_special_tokens)
else:
return self.tokenizer.encode(text, bos=True, eos=False)

def apply_chat_template(self,
messages: List["ChatCompletionMessageParam"],
Expand Down

0 comments on commit ffbd618

Please sign in to comment.