Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support different image sizes in prefill in VLMs #2065

Merged
merged 1 commit into from
Jun 17, 2024

Conversation

danieldk
Copy link
Member

@danieldk danieldk commented Jun 13, 2024

What does this PR do?

When a batch contained images if different sizes during prefill, the server would fail (fixes #2056). Images were processed separately and then concatenated. However, this can fail for images with different sizes.

Fix this by preprocessing all images in the batch together, so that the image processor can ensure that all image tensors have compatible sizes.

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?

Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.

When a batch contained images if different sizes during prefill, the
server would fail (see e.g. #2056). Images were processed separately and
then concatenated. However, this can fail for images with different sizes.

Fix this by preprocessing all images in the batch together, so that the
image processor can ensure that all image tensors have compatible sizes.
@danieldk danieldk force-pushed the bugfix/multiple-images branch from 7d3439f to f5c10d4 Compare June 14, 2024 07:47
Comment on lines +53 to +61
response = await flash_pali_gemma.generate(
f"caption![]({chicken})![]({cow_beach})\n",
max_new_tokens=20,
)
# Is PaliGemma not able to handle two separate images? At least we
# get output showing that both images are used.
assert (
response.generated_text == "image result for chicken on the beach"
), f"{repr(response.generated_text)}"
Copy link
Collaborator

Choose a reason for hiding this comment

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

ha this is interesting!

I wonder if we should identify and throw an error for models that limit the number of images in the future?

Copy link
Member Author

Choose a reason for hiding this comment

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

That sounds like a useful validation. Not sure which models are supposed to handle multiple images in one prompt.

Copy link
Collaborator

@drbh drbh left a comment

Choose a reason for hiding this comment

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

lgtm!

@danieldk danieldk merged commit e903770 into main Jun 17, 2024
6 checks passed
@danieldk danieldk deleted the bugfix/multiple-images branch June 17, 2024 08:49
@tctrautman
Copy link

Thank you for this, @danieldk! Do you have a sense of when this should get published to the ghcr.io/huggingface/text-generation-inference:latest docker image?

@Narsil Narsil mentioned this pull request Jun 24, 2024
5 tasks
yuanwu2017 pushed a commit to yuanwu2017/tgi-gaudi that referenced this pull request Sep 26, 2024
When a batch contained images if different sizes during prefill, the
server would fail (see e.g. huggingface#2056). Images were processed separately and
then concatenated. However, this can fail for images with different sizes.

Fix this by preprocessing all images in the batch together, so that the
image processor can ensure that all image tensors have compatible sizes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants