Skip to content

Commit 90c6830

Browse files
committed
Fixes
Signed-off-by: DarkLight1337 <[email protected]>
1 parent 657d1b8 commit 90c6830

File tree

2 files changed

+55
-29
lines changed

2 files changed

+55
-29
lines changed

vllm/multimodal/processing.py

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,6 +1008,36 @@ def get_supported_mm_limits(self) -> Mapping[str, Optional[int]]:
10081008
"""
10091009
raise NotImplementedError
10101010

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+
10111041
@abstractmethod
10121042
def get_mm_max_tokens_per_item(
10131043
self,
@@ -1082,17 +1112,25 @@ def _to_mm_items(
10821112
before passing them to :meth:`_get_hf_mm_data`.
10831113
"""
10841114
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.")
10961134

10971135
return mm_items
10981136

vllm/multimodal/profiling.py

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -124,24 +124,12 @@ def dummy_inputs(self) -> BaseDummyInputsBuilder[_I]:
124124
return self.processor.dummy_inputs
125125

126126
def get_mm_limits(self) -> Mapping[str, int]:
127-
mm_config = self.processing_info.ctx.get_mm_config()
128-
supported_mm_limits = self.processing_info.get_supported_mm_limits()
129-
130-
if not envs.VLLM_USE_V1:
131-
mm_limits = {
132-
modality: mm_config.get_limit_per_prompt(modality)
133-
for modality in supported_mm_limits
134-
}
135-
136-
for modality, supported_limit in supported_mm_limits.items():
137-
limit = mm_limits[modality]
138-
if supported_limit is not None and supported_limit < limit:
139-
raise ValueError(
140-
f"You set {modality}={limit} (or defaulted to 1) in "
141-
f"`--limit-mm-per-prompt`, but this model only supports "
142-
f"at most {supported_limit} {modality} items.")
143-
144-
return mm_limits
127+
allowed_mm_limits = self.processing_info.get_allowed_mm_limits()
128+
129+
return {
130+
modality: 999 if limit is None else limit
131+
for modality, limit in allowed_mm_limits.items()
132+
}
145133

146134
def _get_dummy_mm_inputs(
147135
self,

0 commit comments

Comments
 (0)