@@ -1946,18 +1946,15 @@ def _validate_mm_kwargs(
19461946 "model (usually arising from an inconsistency between "
19471947 "`_call_hf_processor` and `_get_mm_fields_config`)." )
19481948
1949- def _validate_mm_placeholders (
1949+ def _validate_mm_updates (
19501950 self ,
1951- mm_placeholders : Mapping [ str , list [ PlaceholderFeaturesInfo ]] ,
1951+ mm_updates : MultiModalPromptUpdates ,
19521952 mm_item_counts : Mapping [str , int ],
19531953 ) -> None :
19541954 for modality , item_count in mm_item_counts .items ():
1955- placeholders = mm_placeholders .get (modality , [])
1955+ placeholders = mm_updates .get (modality , [])
19561956
19571957 if len (placeholders ) != item_count :
1958- # NOTE: If you are a model developer, this can also arise from
1959- # an inconsistency between `_call_hf_processor` and
1960- # `_get_mm_fields_config` implementations
19611958 raise RuntimeError (
19621959 f"Expected there to be { item_count } prompt updates "
19631960 f"corresponding to { item_count } { modality } items, but "
@@ -1967,6 +1964,22 @@ def _validate_mm_placeholders(
19671964 "in the prompt. If the model has a chat template, make "
19681965 "sure you have applied it before calling `LLM.generate`." )
19691966
1967+ def _validate_mm_placeholders (
1968+ self ,
1969+ mm_placeholders : Mapping [str , list [PlaceholderFeaturesInfo ]],
1970+ mm_item_counts : Mapping [str , int ],
1971+ ) -> None :
1972+ for modality , item_count in mm_item_counts .items ():
1973+ placeholders = mm_placeholders .get (modality , [])
1974+
1975+ if len (placeholders ) != item_count :
1976+ raise RuntimeError (
1977+ f"Expected there to be { item_count } prompt placeholders "
1978+ f"corresponding to { item_count } { modality } items, but "
1979+ f"instead found { len (placeholders )} prompt placeholders! "
1980+ "Make sure the implementation of `_call_hf_processor` and "
1981+ "`_get_mm_fields_config` are consistent with each other." )
1982+
19701983 def _maybe_apply_prompt_updates (
19711984 self ,
19721985 mm_items : MultiModalDataItems ,
@@ -1977,6 +1990,7 @@ def _maybe_apply_prompt_updates(
19771990 ) -> tuple [list [int ], Mapping [str , list [PlaceholderFeaturesInfo ]]]:
19781991 mm_item_counts = mm_items .get_all_counts ()
19791992 self ._validate_mm_kwargs (mm_kwargs , mm_item_counts )
1993+ self ._validate_mm_updates (mm_prompt_updates , mm_item_counts )
19801994
19811995 if is_update_applied :
19821996 mm_placeholders = self ._find_mm_placeholders (
0 commit comments