[MM] Further cleanup _apply_hf_processor_main (#53610)

Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
Cyrus Leung
2026-09-16 10:21:00 -07:00
committed by GitHub
parent 6ca2b23e22
commit 0b9e018fb9
74 changed files with 1048 additions and 1323 deletions
+25 -21
View File
@@ -324,33 +324,36 @@ class LlavaOnevisionMultiModalProcessor(
pixel_values_videos=MultiModalFieldConfig.batched("video"),
)
def _get_hf_mm_text(self, mm_counts: Mapping[str, int]) -> str:
return self.dummy_inputs.get_dummy_text(mm_counts)
def _apply_hf_processor_main(
self,
mm_items: MultiModalDataItems,
hf_processor_mm_kwargs: Mapping[str, object],
hf_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}
hf_data, hf_kwargs, passthrough_data = self._get_hf_mm_inputs(
mm_items, hf_kwargs
)
mm_data, passthrough_data = self._get_hf_mm_data(valid_mm_items)
if not mm_data:
return BatchFeature(dict(passthrough_data))
if not hf_data:
return self._finalize_hf_mm_data(hf_data, hf_kwargs, passthrough_data)
prompt_text = self.dummy_inputs.get_dummy_text(mm_items.get_all_counts())
prompt_text = hf_data.pop("text")
assert isinstance(prompt_text, str)
mm_data = dict(mm_data)
videos = mm_data.pop("videos", [])
videos = hf_data.pop("videos", [])
assert isinstance(videos, list)
if not videos:
processed_data = self.info.ctx.call_hf_processor(
self.info.get_hf_processor(**hf_processor_mm_kwargs),
dict(text=prompt_text, **mm_data),
hf_processor_mm_kwargs,
self.info.get_hf_processor(**hf_kwargs),
dict(text=prompt_text, **hf_data),
hf_kwargs,
)
return self._finalize_hf_mm_data(
hf_data, hf_kwargs, passthrough_data, processed_data
)
processed_data.update(passthrough_data)
return processed_data
# LLaVA-OneVision processor doesn't support multiple videos
# with different sizes when converting back to tensors
@@ -360,13 +363,13 @@ class LlavaOnevisionMultiModalProcessor(
image_token = processor.image_token
video_token = processor.video_token
images = mm_data.pop("images", [])
images = hf_data.pop("images", [])
assert isinstance(images, list)
if images:
processor_outputs = self.info.ctx.call_hf_processor(
self.info.get_hf_processor(**hf_processor_mm_kwargs),
self.info.get_hf_processor(**hf_kwargs),
dict(text=image_token * len(images), **{"images": images}),
hf_processor_mm_kwargs,
hf_kwargs,
)
image_outputs = {
k: v
@@ -379,9 +382,9 @@ class LlavaOnevisionMultiModalProcessor(
pixel_values_videos = []
for video in videos:
item_outputs = self.info.ctx.call_hf_processor(
self.info.get_hf_processor(**hf_processor_mm_kwargs),
self.info.get_hf_processor(**hf_kwargs),
dict(text=video_token, **{"videos": video}),
hf_processor_mm_kwargs,
hf_kwargs,
)
pixel_values_videos.append(item_outputs["pixel_values_videos"][0])
@@ -394,8 +397,9 @@ class LlavaOnevisionMultiModalProcessor(
**video_outputs,
)
processed_data = BatchFeature(combined_outputs)
processed_data.update(passthrough_data)
return processed_data
return self._finalize_hf_mm_data(
hf_data, hf_kwargs, passthrough_data, processed_data
)
def _get_prompt_updates(
self,