[MM] Further cleanup _apply_hf_processor_main (#53610)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
@@ -616,29 +616,29 @@ class FunAudioChatMultiModalProcessor(
|
||||
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}
|
||||
mm_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))
|
||||
return self._finalize_hf_mm_data(mm_data, hf_kwargs, passthrough_data)
|
||||
|
||||
prompt_text = self.dummy_inputs.get_dummy_text(mm_items.get_all_counts())
|
||||
|
||||
tokenizer = self.info.get_tokenizer()
|
||||
input_ids = torch.tensor([tokenizer.encode(prompt_text)])
|
||||
|
||||
audios = mm_data.get("audios", [])
|
||||
audios = mm_data.get("audio", [])
|
||||
if not audios:
|
||||
processed_data = BatchFeature({"input_ids": input_ids})
|
||||
processed_data.update(passthrough_data)
|
||||
return processed_data
|
||||
return self._finalize_hf_mm_data(
|
||||
mm_data, hf_kwargs, passthrough_data, processed_data
|
||||
)
|
||||
assert isinstance(audios, Sequence)
|
||||
|
||||
feature_extractor = self.info.get_feature_extractor(**hf_processor_mm_kwargs)
|
||||
feature_extractor = self.info.get_feature_extractor(**hf_kwargs)
|
||||
sr = int(feature_extractor.sampling_rate)
|
||||
min_samples = int(getattr(feature_extractor, "n_fft", 400) or 400)
|
||||
|
||||
@@ -690,8 +690,9 @@ class FunAudioChatMultiModalProcessor(
|
||||
}
|
||||
|
||||
processed_data = BatchFeature({"input_ids": input_ids, **mm_inputs})
|
||||
processed_data.update(passthrough_data)
|
||||
return processed_data
|
||||
return self._finalize_hf_mm_data(
|
||||
mm_data, hf_kwargs, passthrough_data, processed_data
|
||||
)
|
||||
|
||||
def _get_mm_fields_config(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user