[V1] Extend beyond image modality and support mixed-modality inference with Llava-OneVision (#11685)
Signed-off-by: Roger Wang <ywang@roblox.com> Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk> Co-authored-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
co-authored by
DarkLight1337
parent
e20c92bb61
commit
91b361ae89
@@ -1,10 +1,6 @@
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
import PIL
|
||||
from blake3 import blake3
|
||||
|
||||
from vllm.config import ModelConfig
|
||||
from vllm.inputs import PromptType
|
||||
from vllm.logger import init_logger
|
||||
from vllm.multimodal import (MULTIMODAL_REGISTRY, MultiModalDataDict,
|
||||
MultiModalKwargs, MultiModalRegistry)
|
||||
@@ -144,66 +140,3 @@ class MMInputMapperServer:
|
||||
full_mm_inputs.append(mm_input)
|
||||
|
||||
return full_mm_inputs
|
||||
|
||||
|
||||
class MMHasher:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def hash_dummy_mm_data(
|
||||
self,
|
||||
mm_data: Optional[MultiModalDataDict]) -> Optional[List[str]]:
|
||||
"""Hash user-defined dummy multimodal data used for profiling."""
|
||||
|
||||
if mm_data is None:
|
||||
return None
|
||||
|
||||
image_inputs = mm_data['image']
|
||||
|
||||
# This is a temporary workaround for models (e.g, Molmo) that
|
||||
# process multimodal data in the input processor (therefore
|
||||
# image_inputs is MultiModalKwargs instead of raw input format).
|
||||
# `raw_mm_data` with the original input format is expected
|
||||
# in this case.
|
||||
if isinstance(image_inputs, dict):
|
||||
assert "raw_mm_data" in image_inputs and isinstance(
|
||||
image_inputs["raw_mm_data"], PIL.Image.Image)
|
||||
image_inputs = image_inputs.pop("raw_mm_data")
|
||||
|
||||
return self.hash_images(image_inputs)
|
||||
|
||||
def hash_prompt_mm_data(self, prompt: PromptType) -> Optional[List[str]]:
|
||||
"""Hash multimodal data in the user input prompt if they exist."""
|
||||
|
||||
if "multi_modal_data" not in prompt:
|
||||
return None
|
||||
|
||||
mm_data = prompt["multi_modal_data"]
|
||||
if not mm_data:
|
||||
# mm_data can be None or an empty dict.
|
||||
return None
|
||||
|
||||
image_inputs = mm_data["image"]
|
||||
|
||||
return self.hash_images(image_inputs)
|
||||
|
||||
def hash_images(self, image_inputs) -> Optional[List[str]]:
|
||||
"""Hash PIL image objects to strings."""
|
||||
if not isinstance(image_inputs, list):
|
||||
image_inputs = [image_inputs]
|
||||
assert len(image_inputs) > 0
|
||||
|
||||
ret = []
|
||||
for image in image_inputs:
|
||||
assert isinstance(image, PIL.Image.Image)
|
||||
|
||||
# Convert image to bytes
|
||||
bytes = image.tobytes()
|
||||
|
||||
# Hash image bytes
|
||||
hasher = blake3()
|
||||
hasher.update(bytes)
|
||||
ret.append(hasher.hexdigest())
|
||||
|
||||
return ret
|
||||
|
||||
Reference in New Issue
Block a user