fix: fix mm processor double bos (#26505)
This commit is contained in:
@@ -204,6 +204,12 @@ class BaseMultimodalProcessor(ABC):
|
||||
else:
|
||||
self._tokenizer = self._processor
|
||||
|
||||
# Same guard as in serving_chat.py against double BOS.
|
||||
try:
|
||||
self._tokenizer_auto_adds_specials = len(self._tokenizer.encode("")) > 0
|
||||
except Exception:
|
||||
self._tokenizer_auto_adds_specials = False
|
||||
|
||||
# FIXME: not accurate, model and image specific
|
||||
self.NUM_TOKEN_PER_FRAME = 330
|
||||
|
||||
@@ -467,6 +473,12 @@ class BaseMultimodalProcessor(ABC):
|
||||
npu_apply_glm46v_image_preprocess_patch()
|
||||
kwargs["device"] = "npu"
|
||||
|
||||
# Avoid double BOS when the chat template already wrote one.
|
||||
if self._tokenizer_auto_adds_specials and isinstance(input_text, str):
|
||||
bos = getattr(self._tokenizer, "bos_token", None)
|
||||
if bos and input_text.startswith(bos):
|
||||
kwargs.setdefault("add_special_tokens", False)
|
||||
|
||||
result = processor.__call__(
|
||||
text=[input_text],
|
||||
padding=True,
|
||||
|
||||
Reference in New Issue
Block a user