mirror of
https://git.datalinker.icu/vllm-project/vllm.git
synced 2026-05-16 04:02:18 +08:00
[Bugfix] properly catch PIL-related errors for vision models when incorrect data urls are provided (#19202)
Signed-off-by: Guillaume Calmettes <gcalmettes@scaleway.com>
This commit is contained in:
parent
1aeb925f34
commit
9bc8bb07cf
@ -141,6 +141,19 @@ async def test_fetch_image_local_files(image_url: str):
|
|||||||
f"file://{temp_dir}/../{os.path.basename(image_url)}")
|
f"file://{temp_dir}/../{os.path.basename(image_url)}")
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_fetch_image_error_conversion():
|
||||||
|
connector = MediaConnector()
|
||||||
|
broken_img = "data:image/png;base64,aGVsbG9fdmxsbV9jb21tdW5pdHkK"
|
||||||
|
|
||||||
|
# PIL.UnidentifiedImageError should be converted to ValueError
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
await connector.fetch_image_async(broken_img)
|
||||||
|
|
||||||
|
with pytest.raises(ValueError):
|
||||||
|
connector.fetch_image(broken_img)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.asyncio
|
@pytest.mark.asyncio
|
||||||
@pytest.mark.parametrize("video_url", TEST_VIDEO_URLS)
|
@pytest.mark.parametrize("video_url", TEST_VIDEO_URLS)
|
||||||
@pytest.mark.parametrize("num_frames", [-1, 32, 1800])
|
@pytest.mark.parametrize("num_frames", [-1, 32, 1800])
|
||||||
|
|||||||
@ -9,7 +9,7 @@ from urllib.parse import ParseResult, urlparse
|
|||||||
import numpy as np
|
import numpy as np
|
||||||
import numpy.typing as npt
|
import numpy.typing as npt
|
||||||
import torch
|
import torch
|
||||||
from PIL import Image
|
from PIL import Image, UnidentifiedImageError
|
||||||
|
|
||||||
import vllm.envs as envs
|
import vllm.envs as envs
|
||||||
from vllm.connections import HTTPConnection, global_http_connection
|
from vllm.connections import HTTPConnection, global_http_connection
|
||||||
@ -185,11 +185,15 @@ class MediaConnector:
|
|||||||
"""
|
"""
|
||||||
image_io = ImageMediaIO(image_mode=image_mode)
|
image_io = ImageMediaIO(image_mode=image_mode)
|
||||||
|
|
||||||
return self.load_from_url(
|
try:
|
||||||
image_url,
|
return self.load_from_url(
|
||||||
image_io,
|
image_url,
|
||||||
fetch_timeout=envs.VLLM_IMAGE_FETCH_TIMEOUT,
|
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(
|
async def fetch_image_async(
|
||||||
self,
|
self,
|
||||||
@ -204,11 +208,15 @@ class MediaConnector:
|
|||||||
"""
|
"""
|
||||||
image_io = ImageMediaIO(image_mode=image_mode)
|
image_io = ImageMediaIO(image_mode=image_mode)
|
||||||
|
|
||||||
return await self.load_from_url_async(
|
try:
|
||||||
image_url,
|
return await self.load_from_url_async(
|
||||||
image_io,
|
image_url,
|
||||||
fetch_timeout=envs.VLLM_IMAGE_FETCH_TIMEOUT,
|
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
|
||||||
|
|
||||||
def fetch_video(
|
def fetch_video(
|
||||||
self,
|
self,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user