@@ -1008,6 +1008,36 @@ def get_supported_mm_limits(self) -> Mapping[str, Optional[int]]:
1008
1008
"""
1009
1009
raise NotImplementedError
1010
1010
1011
+ def get_allowed_mm_limits (self ) -> Mapping [str , Optional [int ]]:
1012
+ """
1013
+ Return the maximum allowed number of items for each modality.
1014
+
1015
+ A value of `None` means unlimited number of items.
1016
+
1017
+ Omitting a modality from the returned dictionary means that
1018
+ it is not supported at all.
1019
+ """
1020
+ supported_mm_limits = self .get_supported_mm_limits ()
1021
+
1022
+ if envs .VLLM_USE_V1 :
1023
+ return supported_mm_limits
1024
+
1025
+ mm_config = self .ctx .get_mm_config ()
1026
+ allowed_mm_limits = {
1027
+ modality : mm_config .get_limit_per_prompt (modality )
1028
+ for modality in supported_mm_limits
1029
+ }
1030
+
1031
+ for modality , supported_limit in supported_mm_limits .items ():
1032
+ limit = allowed_mm_limits [modality ]
1033
+ if supported_limit is not None and supported_limit < limit :
1034
+ raise ValueError (
1035
+ f"You set { modality } ={ limit } (or defaulted to 1) in "
1036
+ f"`--limit-mm-per-prompt`, but this model only supports "
1037
+ f"at most { supported_limit } { modality } items." )
1038
+
1039
+ return allowed_mm_limits
1040
+
1011
1041
@abstractmethod
1012
1042
def get_mm_max_tokens_per_item (
1013
1043
self ,
@@ -1082,17 +1112,25 @@ def _to_mm_items(
1082
1112
before passing them to :meth:`_get_hf_mm_data`.
1083
1113
"""
1084
1114
mm_items = self .data_parser .parse_mm_data (mm_data )
1085
-
1086
- if not envs .VLLM_USE_V1 :
1087
- mm_config = self .info .ctx .get_mm_config ()
1088
-
1089
- for modality , items in mm_items .items ():
1090
- limit = mm_config .get_limit_per_prompt (modality )
1091
- if len (items ) > limit :
1092
- raise ValueError (
1093
- f"You set { modality } ={ limit } (or defaulted to 1) in "
1094
- f"`--limit-mm-per-prompt`, but passed { len (items )} "
1095
- f"{ modality } items in the same prompt." )
1115
+ supported_mm_limits = self .info .get_supported_mm_limits ()
1116
+ allowed_mm_limits = self .info .get_allowed_mm_limits ()
1117
+
1118
+ for modality , items in mm_items .items ():
1119
+ supported_limit = supported_mm_limits .get (modality , 0 )
1120
+ allowed_limit = allowed_mm_limits .get (modality , 0 )
1121
+ num_items = len (items )
1122
+
1123
+ if supported_limit is not None and num_items > supported_limit :
1124
+ raise ValueError (
1125
+ f"The model only supports at most { supported_limit } "
1126
+ f"{ modality } items, but you passed { num_items } "
1127
+ f"{ modality } items in the same prompt." )
1128
+
1129
+ if allowed_limit is not None and num_items > allowed_limit :
1130
+ raise ValueError (
1131
+ f"You set { modality } ={ allowed_limit } (or defaulted to 1) "
1132
+ f"`in --limit-mm-per-prompt`, but passed { num_items } "
1133
+ f"{ modality } items in the same prompt." )
1096
1134
1097
1135
return mm_items
1098
1136
0 commit comments