From 56ff1e92fd3cb808c82f3fa8e79e236dbbea34d5 Mon Sep 17 00:00:00 2001 From: Peter Date: Thu, 19 Dec 2024 00:53:48 -0800 Subject: [PATCH] PaliGemma: Make sure to add to suffix if is present in `text` (#35201) Move suffix processing code to out of if statement --- .../models/paligemma/processing_paligemma.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/transformers/models/paligemma/processing_paligemma.py b/src/transformers/models/paligemma/processing_paligemma.py index cb35aab66cba..5783308f8315 100644 --- a/src/transformers/models/paligemma/processing_paligemma.py +++ b/src/transformers/models/paligemma/processing_paligemma.py @@ -287,11 +287,6 @@ def __call__( elif not (isinstance(images, list) and isinstance(images[0], list) and is_valid_image(images[0][0])): raise ValueError("images must be an image, list of images or list of list of images") - if suffix is not None and _is_str_or_image(suffix): - suffix = [suffix] - if suffix is not None: - suffix = [sfx + self.tokenizer.eos_token for sfx in suffix] - input_strings = [ build_string_from_input( prompt=prompt, @@ -314,6 +309,11 @@ def __call__( ) expanded_samples.append(expanded_sample) input_strings = [f"{sample}\n" for sample in expanded_samples] + + if suffix is not None and _is_str_or_image(suffix): + suffix = [suffix] + if suffix is not None: + suffix = [sfx + self.tokenizer.eos_token for sfx in suffix] pixel_values = self.image_processor(images, **output_kwargs["images_kwargs"])["pixel_values"] # max_length has to account for the image tokens