[Bugfix][Frontend] Truncate prompt_is_token_ids with the prompt (#54509)

Signed-off-by: hotragn <hotragn.pettugani_2024@woxsen.edu.in>
This commit is contained in:
Hotragn Pettugani
2026-08-31 09:29:01 +00:00
committed by GitHub
parent 399247cc88
commit 28bf75c9a9
2 changed files with 54 additions and 2 deletions
+7 -2
View File
@@ -420,8 +420,8 @@ class TokenizeParams:
"""The slice truncation applies to a sequence of `length` tokens.
`None` means no truncation. Anything parallel to the prompt tokens
(see `prompt_token_offsets`) must be reduced with this same slice to
stay aligned with them.
(see `prompt_token_offsets` and `prompt_is_token_ids`) must be reduced
with this same slice to stay aligned with them.
"""
max_length = self.truncate_prompt_tokens
if max_length is not None and max_length < 0:
@@ -516,5 +516,10 @@ class TokenizeParams:
truncation = self._truncation_slice(tokenizer, len(offsets))
if truncation is not None:
prompt["prompt_token_offsets"] = offsets[truncation] # type: ignore[typeddict-unknown-key]
is_token_ids = cast(EmbedsPrompt, prompt).get("prompt_is_token_ids")
if is_token_ids is not None:
truncation = self._truncation_slice(tokenizer, len(is_token_ids))
if truncation is not None:
prompt["prompt_is_token_ids"] = is_token_ids[truncation] # type: ignore[typeddict-unknown-key]
return prompt