-
-
Notifications
You must be signed in to change notification settings - Fork 8.4k
[Bugfix] properly catch PIL-related errors for vision models when incorrect data urls are provided #19202
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
[Bugfix] properly catch PIL-related errors for vision models when incorrect data urls are provided #19202
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -9,7 +9,7 @@ | |||||||||||||
import numpy as np | ||||||||||||||
import numpy.typing as npt | ||||||||||||||
import torch | ||||||||||||||
from PIL import Image | ||||||||||||||
from PIL import Image, UnidentifiedImageError | ||||||||||||||
|
||||||||||||||
import vllm.envs as envs | ||||||||||||||
from vllm.connections import HTTPConnection, global_http_connection | ||||||||||||||
|
@@ -185,11 +185,15 @@ def fetch_image( | |||||||||||||
""" | ||||||||||||||
image_io = ImageMediaIO(image_mode=image_mode) | ||||||||||||||
|
||||||||||||||
return self.load_from_url( | ||||||||||||||
image_url, | ||||||||||||||
image_io, | ||||||||||||||
fetch_timeout=envs.VLLM_IMAGE_FETCH_TIMEOUT, | ||||||||||||||
) | ||||||||||||||
try: | ||||||||||||||
return self.load_from_url( | ||||||||||||||
image_url, | ||||||||||||||
image_io, | ||||||||||||||
fetch_timeout=envs.VLLM_IMAGE_FETCH_TIMEOUT, | ||||||||||||||
) | ||||||||||||||
except UnidentifiedImageError as e: | ||||||||||||||
# convert to ValueError to be properly caught upstream | ||||||||||||||
raise ValueError(str(e)) from e | ||||||||||||||
|
||||||||||||||
async def fetch_image_async( | ||||||||||||||
self, | ||||||||||||||
|
@@ -204,11 +208,15 @@ async def fetch_image_async( | |||||||||||||
""" | ||||||||||||||
image_io = ImageMediaIO(image_mode=image_mode) | ||||||||||||||
|
||||||||||||||
return await self.load_from_url_async( | ||||||||||||||
image_url, | ||||||||||||||
image_io, | ||||||||||||||
fetch_timeout=envs.VLLM_IMAGE_FETCH_TIMEOUT, | ||||||||||||||
) | ||||||||||||||
try: | ||||||||||||||
return await self.load_from_url_async( | ||||||||||||||
image_url, | ||||||||||||||
image_io, | ||||||||||||||
fetch_timeout=envs.VLLM_IMAGE_FETCH_TIMEOUT, | ||||||||||||||
) | ||||||||||||||
except UnidentifiedImageError as e: | ||||||||||||||
# convert to ValueError to be properly caught upstream | ||||||||||||||
raise ValueError(str(e)) from e | ||||||||||||||
Comment on lines
+217
to
+219
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similar to the
Suggested change
|
||||||||||||||
|
||||||||||||||
def fetch_video( | ||||||||||||||
self, | ||||||||||||||
|
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.
This
try...except
block is a good way to handle theUnidentifiedImageError
and convert it to aValueError
. This ensures that the error is caught and handled upstream.Consider adding a more specific error message to the
ValueError
to provide more context to the user. For example, include the original URL that caused the error.