Skip to content

Conversation

abdokaseb
Copy link
Contributor

@abdokaseb abdokaseb commented Sep 2, 2025

What does this PR do?

This PR #36682 introduced the batch size for images, everything is working correctly but the check for image existence don't support the PPIL images. The len() function could work with path or other things. So I converted it to check is not None it works for both PIL images and paths or URLs

Note: I made the same fix for videos also

Fixes #40603

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.

@zucchini-nlp

Copy link
Member

@zucchini-nlp zucchini-nlp left a comment

Choose a reason for hiding this comment

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

It will not work unfortunately, because each image can be either an empty list or an ImageInput. We will never get any None inputs at this point

The idea is to not pass images if it is an empty list of empty lists. If it has at least one ImageInput, then we pass it further

@abdokaseb
Copy link
Contributor Author

abdokaseb commented Sep 3, 2025

@zucchini-nlp Thanks for reply.
However the empty list will generate False. See the last example please

In [5]: batch_images = [[], [], ["test.png"]]
   ...: any((im is not None) for im_list in batch_images for im in im_list)
Out[5]: True

In [6]: batch_images = [[], [], [Image.new("RGB", (100, 100), (0, 0, 0))]]
   ...: any((im is not None) for im_list in batch_images for im in im_list)
Out[6]: True

In [7]: batch_images = [[], [], ["http://test.com"]]
   ...: any((im is not None) for im_list in batch_images for im in im_list)
Out[7]: True

In [8]: batch_images = [[], [], []]
   ...: any((im is not None) for im_list in batch_images for im in im_list)
Out[8]: False

@zucchini-nlp
Copy link
Member

Oh yeah, my bad, didn't notice we are iterating per single image and not batched sublist.

Copy link
Member

@zucchini-nlp zucchini-nlp left a comment

Choose a reason for hiding this comment

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

Will merge when CI turns green, it has been a bit flaky lately

@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.

@zucchini-nlp zucchini-nlp merged commit 2bbf98a into huggingface:main Sep 3, 2025
24 checks passed
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.

Processing utils bug in apply_chat_template when image content is PIL image
3 participants