@@ -1946,18 +1946,15 @@ def _validate_mm_kwargs(
1946
1946
"model (usually arising from an inconsistency between "
1947
1947
"`_call_hf_processor` and `_get_mm_fields_config`)." )
1948
1948
1949
- def _validate_mm_placeholders (
1949
+ def _validate_mm_updates (
1950
1950
self ,
1951
- mm_placeholders : Mapping [ str , list [ PlaceholderFeaturesInfo ]] ,
1951
+ mm_updates : MultiModalPromptUpdates ,
1952
1952
mm_item_counts : Mapping [str , int ],
1953
1953
) -> None :
1954
1954
for modality , item_count in mm_item_counts .items ():
1955
- placeholders = mm_placeholders .get (modality , [])
1955
+ placeholders = mm_updates .get (modality , [])
1956
1956
1957
1957
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
1961
1958
raise RuntimeError (
1962
1959
f"Expected there to be { item_count } prompt updates "
1963
1960
f"corresponding to { item_count } { modality } items, but "
@@ -1967,6 +1964,22 @@ def _validate_mm_placeholders(
1967
1964
"in the prompt. If the model has a chat template, make "
1968
1965
"sure you have applied it before calling `LLM.generate`." )
1969
1966
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
+
1970
1983
def _maybe_apply_prompt_updates (
1971
1984
self ,
1972
1985
mm_items : MultiModalDataItems ,
@@ -1977,6 +1990,7 @@ def _maybe_apply_prompt_updates(
1977
1990
) -> tuple [list [int ], Mapping [str , list [PlaceholderFeaturesInfo ]]]:
1978
1991
mm_item_counts = mm_items .get_all_counts ()
1979
1992
self ._validate_mm_kwargs (mm_kwargs , mm_item_counts )
1993
+ self ._validate_mm_updates (mm_prompt_updates , mm_item_counts )
1980
1994
1981
1995
if is_update_applied :
1982
1996
mm_placeholders = self ._find_mm_placeholders (
0 commit comments