From 791321451d771e43253673dbef772b5df3b24a78 Mon Sep 17 00:00:00 2001 From: Raushan Turganbay Date: Thu, 18 Apr 2024 19:31:32 +0500 Subject: [PATCH] Fix: remove `pad token id` in pipeline forward arguments (#30285) --- src/transformers/pipelines/base.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/transformers/pipelines/base.py b/src/transformers/pipelines/base.py index 25645fbaae061e..ccda438119cbdb 100644 --- a/src/transformers/pipelines/base.py +++ b/src/transformers/pipelines/base.py @@ -888,11 +888,6 @@ def __init__( if self.model.can_generate(): self.model.generation_config.update(**task_specific_params.get(task)) - self.call_count = 0 - self._batch_size = kwargs.pop("batch_size", None) - self._num_workers = kwargs.pop("num_workers", None) - self._preprocess_params, self._forward_params, self._postprocess_params = self._sanitize_parameters(**kwargs) - # Pipelines calling `generate`: if the tokenizer has a pad token but the model doesn't, set it in the # forward params so that `generate` is aware of the pad token. if ( @@ -901,7 +896,12 @@ def __init__( and self.tokenizer.pad_token_id is not None and self.model.generation_config.pad_token_id is None ): - self._forward_params["pad_token_id"] = self.tokenizer.pad_token_id + kwargs["pad_token_id"] = self.tokenizer.pad_token_id + + self.call_count = 0 + self._batch_size = kwargs.pop("batch_size", None) + self._num_workers = kwargs.pop("num_workers", None) + self._preprocess_params, self._forward_params, self._postprocess_params = self._sanitize_parameters(**kwargs) if self.image_processor is None and self.feature_extractor is not None: if isinstance(self.feature_extractor, BaseImageProcessor):