From f69426fd77f0a6965d7779f86a9b724fdde22219 Mon Sep 17 00:00:00 2001 From: YetheSamartaka <55753928+YetheSamartaka@users.noreply.github.com> Date: Tue, 7 Oct 2025 14:47:35 +0200 Subject: [PATCH] Fixed: Cannot handle batch sizes > 1 if no padding token is defined Fixes Cannot handle batch sizes > 1 if no padding token is defined For reranker models that do not have this defined in their config by using the eos_token_id if present as pad_token_id. --- backend/open_webui/routers/retrieval.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/backend/open_webui/routers/retrieval.py b/backend/open_webui/routers/retrieval.py index d322addfa6..e34919d672 100644 --- a/backend/open_webui/routers/retrieval.py +++ b/backend/open_webui/routers/retrieval.py @@ -189,6 +189,22 @@ def get_rf( log.error(f"CrossEncoder: {e}") raise Exception(ERROR_MESSAGES.DEFAULT("CrossEncoder error")) + # Safely adjust pad_token_id if missing as some models do not have this in config + try: + model_cfg = getattr(rf, "model", None) + if model_cfg and hasattr(model_cfg, "config"): + cfg = model_cfg.config + if getattr(cfg, "pad_token_id", None) is None: + # Fallback to eos_token_id when available + eos = getattr(cfg, "eos_token_id", None) + if eos is not None: + cfg.pad_token_id = eos + log.debug(f"Missing pad_token_id detected; set to eos_token_id={eos}") + else: + log.warning("Neither pad_token_id nor eos_token_id present in model config") + except Exception as e2: + log.warning(f"Failed to adjust pad_token_id on CrossEncoder: {e2}") + return rf