[Bugfix][Frontend] Truncate pooling prompts before padding them (#54364)

Signed-off-by: hotragn <hotragn.pettugani_2024@woxsen.edu.in>
This commit is contained in:
Hotragn Pettugani
2026-08-30 22:12:03 -07:00
committed by GitHub
parent 44fe2a392b
commit 687db59744
4 changed files with 142 additions and 17 deletions
+5 -1
View File
@@ -462,9 +462,13 @@ class TokenizeParams:
def _validate_tokens(self, tokenizer: TokenizerLike | None, tokens: _S) -> _S:
"""Apply all validators to a token sequence."""
# Truncation runs before padding, matching the Transformers pipeline
# these parameters are named after. Padding first would let a
# subsequent left-side truncation keep only the pad tokens it just
# appended, discarding the prompt entirely.
for validator in (
self._token_padding,
self._token_truncation,
self._token_padding,
self._token_len_check,
):
tokens = validator(tokenizer, tokens)