vlm: support video as an input modality (#5888)
This commit is contained in:
@@ -65,6 +65,8 @@ class GenerateReqInput:
|
||||
] = None
|
||||
# The audio input. Like image data, it can be a file name, a url, or base64 encoded string.
|
||||
audio_data: Optional[Union[List[AudioDataItem], AudioDataItem]] = None
|
||||
# The video input. Like image data, it can be a file name, a url, or base64 encoded string.
|
||||
video_data: Optional[Union[List[List[str]], List[str], str]] = None
|
||||
# The sampling_params. See descriptions below.
|
||||
sampling_params: Optional[Union[List[Dict], Dict]] = None
|
||||
# The request id.
|
||||
@@ -110,7 +112,11 @@ class GenerateReqInput:
|
||||
data_parallel_rank: Optional[int] = None
|
||||
|
||||
def contains_mm_input(self) -> bool:
|
||||
return has_valid_data(self.image_data) or has_valid_data(self.audio_data)
|
||||
return (
|
||||
has_valid_data(self.image_data)
|
||||
or has_valid_data(self.video_data)
|
||||
or has_valid_data(self.audio_data)
|
||||
)
|
||||
|
||||
def normalize_batch_and_arguments(self):
|
||||
"""
|
||||
@@ -232,6 +238,7 @@ class GenerateReqInput:
|
||||
self._normalize_rid(num)
|
||||
self._normalize_lora_paths(num)
|
||||
self._normalize_image_data(num)
|
||||
self._normalize_video_data(num)
|
||||
self._normalize_audio_data(num)
|
||||
self._normalize_sampling_params(num)
|
||||
self._normalize_logprob_params(num)
|
||||
@@ -300,6 +307,15 @@ class GenerateReqInput:
|
||||
self.image_data = wrapped_images * self.parallel_sample_num
|
||||
self.modalities = ["image"] * num
|
||||
|
||||
def _normalize_video_data(self, num):
|
||||
"""Normalize video data for batch processing."""
|
||||
if self.video_data is None:
|
||||
self.video_data = [None] * num
|
||||
elif not isinstance(self.video_data, list):
|
||||
self.video_data = [self.video_data] * num
|
||||
elif isinstance(self.video_data, list):
|
||||
self.video_data = self.video_data * self.parallel_sample_num
|
||||
|
||||
def _normalize_audio_data(self, num):
|
||||
"""Normalize audio data for batch processing."""
|
||||
if self.audio_data is None:
|
||||
@@ -408,6 +424,7 @@ class GenerateReqInput:
|
||||
self.input_embeds[i] if self.input_embeds is not None else None
|
||||
),
|
||||
image_data=self.image_data[i],
|
||||
video_data=self.video_data[i],
|
||||
audio_data=self.audio_data[i],
|
||||
sampling_params=self.sampling_params[i],
|
||||
rid=self.rid[i],
|
||||
@@ -507,6 +524,8 @@ class EmbeddingReqInput:
|
||||
image_data: Optional[
|
||||
Union[List[List[Union[Image, str]]], List[Union[Image, str]], Union[Image, str]]
|
||||
] = None
|
||||
# The video input. Like image data, it can be a file name, a url, or base64 encoded string.
|
||||
video_data: Optional[Union[List[str], str]] = None
|
||||
# The audio input. Like image data, it can be a file name, a url, or base64 encoded string.
|
||||
audio_data: Optional[Union[List[str], str]] = None
|
||||
# The token ids for text; one can either specify text or input_ids.
|
||||
@@ -578,7 +597,11 @@ class EmbeddingReqInput:
|
||||
return self.rid
|
||||
|
||||
def contains_mm_input(self) -> bool:
|
||||
return has_valid_data(self.image_data) or has_valid_data(self.audio_data)
|
||||
return (
|
||||
has_valid_data(self.image_data)
|
||||
or has_valid_data(self.video_data)
|
||||
or has_valid_data(self.audio_data)
|
||||
)
|
||||
|
||||
def __getitem__(self, i):
|
||||
if self.is_cross_encoder_request:
|
||||
|
||||
Reference in New Issue
Block a user