@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / b616f6a53d
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, 03:30 UTC

[Misc] Small: Fix video loader return type annotations. (#20389)

Signed-off-by: Chenheli Hua <huachenheli@outlook.com>

Chenheli Hua committed Jul 2, 2025 at 20:10 UTC b616f6a53dc0caaf1eeb4be785df76415dde8633
3 files changed +14 -11
tests/multimodal/test_utils.py
+4 -3
@@ -172,9 +172,10 @@ async def test_fetch_video_http(video_url: str, num_frames: int):
172 "num_frames": num_frames,
173 }})
174
175 - video_sync = connector.fetch_video(video_url)
176 - video_async = await connector.fetch_video_async(video_url)
177 - assert np.array_equal(video_sync[0], video_async[0])
175 + video_sync, metadata_sync = connector.fetch_video(video_url)
176 + video_async, metadata_async = await connector.fetch_video_async(video_url)
177 + assert np.array_equal(video_sync, video_async)
178 + assert metadata_sync == metadata_async
179
180
181 # Used for the next two tests related to `merge_and_sort_multimodal_metadata`.
vllm/multimodal/utils.py
+2 -2
@@ -228,7 +228,7 @@ class MediaConnector:
228 video_url: str,
229 *,
230 image_mode: str = "RGB",
231 - ) -> npt.NDArray:
231 + ) -> tuple[npt.NDArray, dict[str, Any]]:
232 """
233 Load video from a HTTP or base64 data URL.
234 """
@@ -248,7 +248,7 @@ class MediaConnector:
248 video_url: str,
249 *,
250 image_mode: str = "RGB",
251 - ) -> npt.NDArray:
251 + ) -> tuple[npt.NDArray, dict[str, Any]]:
252 """
253 Asynchronously load video from a HTTP or base64 data URL.
254
vllm/multimodal/video.py
+8 -6
@@ -6,6 +6,7 @@ from abc import abstractmethod
6 from functools import partial
7 from io import BytesIO
8 from pathlib import Path
9 +from typing import Any
10
11 import numpy as np
12 import numpy.typing as npt
@@ -57,7 +58,7 @@ class VideoLoader:
58 def load_bytes(cls,
59 data: bytes,
60 num_frames: int = -1,
60 - **kwargs) -> npt.NDArray:
61 + **kwargs) -> tuple[npt.NDArray, dict[str, Any]]:
62 raise NotImplementedError
63
64
@@ -106,7 +107,7 @@ class OpenCVVideoBackend(VideoLoader):
107 def load_bytes(cls,
108 data: bytes,
109 num_frames: int = -1,
109 - **kwargs) -> npt.NDArray:
110 + **kwargs) -> tuple[npt.NDArray, dict[str, Any]]:
111 import cv2
112
113 backend = cls().get_cv2_video_api()
@@ -179,12 +180,13 @@ class VideoMediaIO(MediaIO[npt.NDArray]):
180 video_loader_backend = envs.VLLM_VIDEO_LOADER_BACKEND
181 self.video_loader = VIDEO_LOADER_REGISTRY.load(video_loader_backend)
182
182 - def load_bytes(self, data: bytes) -> npt.NDArray:
183 + def load_bytes(self, data: bytes) -> tuple[npt.NDArray, dict[str, Any]]:
184 return self.video_loader.load_bytes(data,
185 num_frames=self.num_frames,
186 **self.kwargs)
187
187 - def load_base64(self, media_type: str, data: str) -> npt.NDArray:
188 + def load_base64(self, media_type: str,
189 + data: str) -> tuple[npt.NDArray, dict[str, Any]]:
190 if media_type.lower() == "video/jpeg":
191 load_frame = partial(
192 self.image_io.load_base64,
@@ -194,11 +196,11 @@ class VideoMediaIO(MediaIO[npt.NDArray]):
196 return np.stack([
197 np.asarray(load_frame(frame_data))
198 for frame_data in data.split(",")
197 - ])
199 + ]), {}
200
201 return self.load_bytes(base64.b64decode(data))
202
201 - def load_file(self, filepath: Path) -> npt.NDArray:
203 + def load_file(self, filepath: Path) -> tuple[npt.NDArray, dict[str, Any]]:
204 with filepath.open("rb") as f:
205 data = f.read()
206