@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 9bc8bb07cf
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 15, 07:15 UTC

[Bugfix] properly catch PIL-related errors for vision models when incorrect data urls are provided (#19202)

Signed-off-by: Guillaume Calmettes <gcalmettes@scaleway.com>

Guillaume Calmettes committed Jun 5, 2025 at 14:59 UTC 9bc8bb07cf16c8a9116b8029e63d1015d150cccb
2 files changed +32 -11
tests/multimodal/test_utils.py
+13
@@ -141,6 +141,19 @@ async def test_fetch_image_local_files(image_url: str):
141 f"file://{temp_dir}/../{os.path.basename(image_url)}")
142
143
144 +@pytest.mark.asyncio
145 +async def test_fetch_image_error_conversion():
146 + connector = MediaConnector()
147 + broken_img = "data:image/png;base64,aGVsbG9fdmxsbV9jb21tdW5pdHkK"
148 +
149 + # PIL.UnidentifiedImageError should be converted to ValueError
150 + with pytest.raises(ValueError):
151 + await connector.fetch_image_async(broken_img)
152 +
153 + with pytest.raises(ValueError):
154 + connector.fetch_image(broken_img)
155 +
156 +
157 @pytest.mark.asyncio
158 @pytest.mark.parametrize("video_url", TEST_VIDEO_URLS)
159 @pytest.mark.parametrize("num_frames", [-1, 32, 1800])
vllm/multimodal/utils.py
+19 -11
@@ -9,7 +9,7 @@ from urllib.parse import ParseResult, urlparse
9 import numpy as np
10 import numpy.typing as npt
11 import torch
12 -from PIL import Image
12 +from PIL import Image, UnidentifiedImageError
13
14 import vllm.envs as envs
15 from vllm.connections import HTTPConnection, global_http_connection
@@ -185,11 +185,15 @@ class MediaConnector:
185 """
186 image_io = ImageMediaIO(image_mode=image_mode)
187
188 - return self.load_from_url(
189 - image_url,
190 - image_io,
191 - fetch_timeout=envs.VLLM_IMAGE_FETCH_TIMEOUT,
192 - )
188 + try:
189 + return self.load_from_url(
190 + image_url,
191 + image_io,
192 + fetch_timeout=envs.VLLM_IMAGE_FETCH_TIMEOUT,
193 + )
194 + except UnidentifiedImageError as e:
195 + # convert to ValueError to be properly caught upstream
196 + raise ValueError(str(e)) from e
197
198 async def fetch_image_async(
199 self,
@@ -204,11 +208,15 @@ class MediaConnector:
208 """
209 image_io = ImageMediaIO(image_mode=image_mode)
210
207 - return await self.load_from_url_async(
208 - image_url,
209 - image_io,
210 - fetch_timeout=envs.VLLM_IMAGE_FETCH_TIMEOUT,
211 - )
211 + try:
212 + return await self.load_from_url_async(
213 + image_url,
214 + image_io,
215 + fetch_timeout=envs.VLLM_IMAGE_FETCH_TIMEOUT,
216 + )
217 + except UnidentifiedImageError as e:
218 + # convert to ValueError to be properly caught upstream
219 + raise ValueError(str(e)) from e
220
221 def fetch_video(
222 self,