Skip to content

Conversation

@hiyouga
Copy link
Contributor

@hiyouga hiyouga commented May 20, 2024

What does this PR do?

Fix the paligemma processor raises exception on empty text inputs

Reproduce

from PIL import Image
from transformers import AutoProcessor

image = Image.new("RGB", (100, 100), (255, 255, 255))
processor = AutoProcessor.from_pretrained("google/paligemma-3b-pt-224")
processor(images=image)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/lib/python3.10/site-packages/transformers/models/paligemma/processing_paligemma.py", line 190, in __call__
    pass
TypeError: 'NoneType' object is not iterable

The following lines require text should be a list, we need to convert the Nonetype input to a string or list firstly.

if text is None:
logger.warning_once(
"You are using PaliGemma without a text prefix. It will perform as a picture-captioning model."
)

if _is_str_or_image(text):
text = [text]
elif isinstance(text, list) and _is_str_or_image(text[0]):
pass
input_strings = [
build_string_from_input(
prompt=prompt,
bos_token=self.tokenizer.bos_token,
image_seq_len=self.image_seq_length,
image_token=IMAGE_TOKEN,
)
for prompt in text
]

Before submitting

  • This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
  • Did you read the contributor guideline,
    Pull Request section?
  • Was this discussed/approved via a Github issue or the forum? Please add a link
    to it if that's the case.
  • Did you make sure to update the documentation with your changes? Here are the
    documentation guidelines, and
    here are tips on formatting docstrings.
  • Did you write any new necessary tests?

Who can review?

@amyeroberts

@amyeroberts
Copy link
Contributor

cc @molbap

@molbap
Copy link
Contributor

molbap commented May 21, 2024

Hi @hiyouga , thanks for the fix! LGTM

Copy link
Contributor

@molbap molbap left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing!

@amyeroberts amyeroberts merged commit a755745 into huggingface:main May 21, 2024
@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

ArthurZucker pushed a commit that referenced this pull request May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants