Skip to content

Commit

Permalink
PaliGemma: Make sure to add <eos> to suffix if <image> is present in …
Browse files Browse the repository at this point in the history
…`text` (#35201)

Move suffix processing code to out of if statement
  • Loading branch information
probicheaux authored Dec 19, 2024
1 parent 4592cc9 commit 56ff1e9
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/transformers/models/paligemma/processing_paligemma.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 56ff1e9

Please sign in to comment.