-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
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.
7d3439f
to
f5c10d4
Compare
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)}" |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
Thank you for this, @danieldk! Do you have a sense of when this should get published to the |
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.
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
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
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.