[MM] Further cleanup _apply_hf_processor_main (#53610)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
@@ -52,6 +52,7 @@ from vllm.multimodal.processing import (
|
||||
PromptUpdateDetails,
|
||||
cached_encode,
|
||||
)
|
||||
from vllm.multimodal.processing.processor import HFMultiModalInputs
|
||||
from vllm.sequence import IntermediateTensors
|
||||
from vllm.utils.gpu_sync_debug import gpu_sync_allowed
|
||||
from vllm.utils.tensor_schema import TensorSchema, TensorShape
|
||||
@@ -240,31 +241,32 @@ class Idefics3DummyInputsBuilder(BaseDummyInputsBuilder[Idefics3ProcessingInfo])
|
||||
|
||||
|
||||
class Idefics3MultiModalProcessor(BaseMultiModalProcessor[Idefics3ProcessingInfo]):
|
||||
def _apply_hf_processor_main(
|
||||
def _get_hf_mm_inputs(
|
||||
self,
|
||||
mm_items: MultiModalDataItems,
|
||||
hf_processor_mm_kwargs: Mapping[str, object],
|
||||
) -> BatchFeature:
|
||||
valid_mm_items = mm_items.select(
|
||||
{k for k, c in mm_items.get_all_counts().items() if c > 0}
|
||||
)
|
||||
mm_data, passthrough_data = self._get_hf_mm_data(valid_mm_items)
|
||||
|
||||
if not mm_data:
|
||||
return BatchFeature(dict(passthrough_data))
|
||||
hf_kwargs: Mapping[str, object],
|
||||
) -> HFMultiModalInputs:
|
||||
hf_inputs = super()._get_hf_mm_inputs(mm_items, hf_kwargs)
|
||||
|
||||
image_processor = self.info.get_hf_processor().image_processor
|
||||
if getattr(image_processor, "backend", "pil") == "pil":
|
||||
hf_processor_mm_kwargs = {
|
||||
"input_data_format": "channels_last",
|
||||
**hf_processor_mm_kwargs,
|
||||
}
|
||||
hf_inputs = hf_inputs._replace(
|
||||
hf_kwargs={
|
||||
"input_data_format": "channels_last",
|
||||
**hf_inputs.hf_kwargs,
|
||||
}
|
||||
)
|
||||
|
||||
processed_data = self.info.ctx.call_hf_processor(
|
||||
self.info.get_hf_processor(**hf_processor_mm_kwargs),
|
||||
mm_data,
|
||||
hf_processor_mm_kwargs,
|
||||
)
|
||||
return hf_inputs
|
||||
|
||||
def _postprocess_hf_mm_data(
|
||||
self,
|
||||
mm_data: Mapping[str, object],
|
||||
hf_processor_mm_kwargs: Mapping[str, object],
|
||||
processed_data: BatchFeature,
|
||||
) -> BatchFeature:
|
||||
if not mm_data:
|
||||
return processed_data
|
||||
|
||||
images = mm_data.get("images", [])
|
||||
mm_items = self.info.parse_mm_data({"image": images}, validate=False)
|
||||
@@ -289,8 +291,6 @@ class Idefics3MultiModalProcessor(BaseMultiModalProcessor[Idefics3ProcessingInfo
|
||||
processed_data["pixel_values"].squeeze_(0)
|
||||
processed_data["pixel_attention_mask"].squeeze_(0)
|
||||
|
||||
processed_data.update(passthrough_data)
|
||||
|
||||
return processed_data
|
||||
|
||||
def _get_mm_fields_config(
|
||||
|
||||
Reference in New Issue
Block a user