@@ -894,17 +894,6 @@ def _cached_apply_hf_processor(
894894
895895 mm_kwargs = MultiModalKwargs .from_items (merged_kw_items )
896896
897- if self .enable_sanity_checks :
898- mm_item_counts = mm_data_items .get_all_counts ()
899-
900- for modality , item_count in mm_item_counts .items ():
901- for item_idx in range (item_count ):
902- try :
903- mm_kwargs .get_item (modality , item_idx )
904- except Exception as e :
905- # Make it easy to set a breakpoint in the debugger
906- raise e
907-
908897 return prompt_ids , mm_kwargs
909898
910899 def _bind_and_group_repls (
@@ -999,7 +988,28 @@ def _apply_prompt_replacements(
999988
1000989 return token_ids , text , placeholders
1001990
1002- def _validate_placeholders (
991+ def _validate_mm_kwargs (
992+ self ,
993+ mm_kwargs : MultiModalKwargs ,
994+ mm_item_counts : Mapping [str , int ],
995+ ) -> None :
996+ for modality , item_count in mm_item_counts .items ():
997+ if modality in mm_kwargs .modalities :
998+ items = mm_kwargs .get_items (modality )
999+ else :
1000+ items = []
1001+
1002+ if len (items ) != item_count :
1003+ raise RuntimeError (
1004+ f"Expected there to be { item_count } { modality } items in "
1005+ f"keyword arguments corresponding to { item_count } "
1006+ f"{ modality } data items, but only found { len (items )} ! "
1007+ "There is likely a problem with your "
1008+ "implementation of merged multi-modal processor for this "
1009+ "model (usually arising from an inconsistency between "
1010+ "`_call_hf_processor` and `_get_mm_fields_config`)." )
1011+
1012+ def _validate_mm_placeholders (
10031013 self ,
10041014 mm_placeholders : Mapping [str , list [_PlaceholderInfo ]],
10051015 mm_item_counts : Mapping [str , int ],
@@ -1061,6 +1071,8 @@ def apply(
10611071 mm_prompt_repls = self ._bind_and_group_repls (unbound_prompt_repls )
10621072
10631073 mm_item_counts = mm_items .get_all_counts ()
1074+ self ._validate_mm_kwargs (mm_kwargs , mm_item_counts )
1075+
10641076 hf_mm_placeholders = self ._find_mm_placeholders (
10651077 mm_prompt_repls ,
10661078 prompt_ids ,
@@ -1071,7 +1083,7 @@ def apply(
10711083 mm_missing_repl_counts = mm_item_counts
10721084 mm_missing_repls = dict (mm_prompt_repls )
10731085 else :
1074- mm_missing_repl_counts = self ._validate_placeholders (
1086+ mm_missing_repl_counts = self ._validate_mm_placeholders (
10751087 hf_mm_placeholders ,
10761088 mm_item_counts ,
10771089 allow_missing = True ,
@@ -1106,7 +1118,7 @@ def apply(
11061118
11071119 mm_placeholders = {** hf_mm_placeholders , ** missing_mm_placeholders }
11081120
1109- self ._validate_placeholders (mm_placeholders , mm_item_counts )
1121+ self ._validate_mm_placeholders (mm_placeholders , mm_item_counts )
11101122
11111123 mm_placeholder_ranges = {
11121124 modality : [item .to_range () for item in placeholders ]
0 commit comments