[Bugfix][Frontend] Detokenize echoed prompts after truncation (#61876)
Signed-off-by: Cy <15118312+cycancode@users.noreply.github.com> Co-authored-by: Cy <15118312+cycancode@users.noreply.github.com>
This commit is contained in:
+10
-2
@@ -687,13 +687,17 @@ class BaseRenderer(ABC, Generic[_T]):
|
||||
prompt = self._tokenize_prompt(prompt, params)
|
||||
prompt = self._apply_prompt_char_offset(prompt, prompt_char_offset)
|
||||
|
||||
prompt = params.apply_post_tokenization(self.tokenizer, prompt) # type: ignore[arg-type]
|
||||
|
||||
# Detokenize after truncation so the text matches the tokens sent
|
||||
# to the engine.
|
||||
if params.needs_detokenization and "prompt" not in prompt:
|
||||
if "prompt_token_ids" not in prompt:
|
||||
raise RuntimeError("Cannot run detokenization on embeddings")
|
||||
|
||||
prompt = self._detokenize_prompt(prompt) # type: ignore[arg-type]
|
||||
|
||||
return params.apply_post_tokenization(self.tokenizer, prompt) # type: ignore[arg-type]
|
||||
return prompt
|
||||
|
||||
@overload
|
||||
async def _tokenize_singleton_prompt_async(
|
||||
@@ -727,13 +731,17 @@ class BaseRenderer(ABC, Generic[_T]):
|
||||
prompt = await self._tokenize_prompt_async(prompt, params)
|
||||
prompt = self._apply_prompt_char_offset(prompt, prompt_char_offset)
|
||||
|
||||
prompt = params.apply_post_tokenization(self.tokenizer, prompt) # type: ignore[arg-type]
|
||||
|
||||
# Detokenize after truncation so the text matches the tokens sent
|
||||
# to the engine.
|
||||
if params.needs_detokenization and "prompt" not in prompt:
|
||||
if "prompt_token_ids" not in prompt:
|
||||
raise RuntimeError("Cannot run detokenization on embeddings")
|
||||
|
||||
prompt = await self._detokenize_prompt_async(prompt) # type: ignore[arg-type]
|
||||
|
||||
return params.apply_post_tokenization(self.tokenizer, prompt) # type: ignore[arg-type]
|
||||
return prompt
|
||||
|
||||
def _tokenize_enc_dec_prompt(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user