A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 14, 05:30 UTC
[Misc] Require `merge_by_field_config` argument (#26214)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
Cyrus Leung committed
Oct 4, 2025 at 16:40 UTC
736fbf4c89ea256ef3c0c17653cec714d765b0e0
2 files changed
+10
-45
vllm/multimodal/utils.py
+9
-33
@@ -15,7 +15,6 @@ import numpy as np
15
import numpy.typing as npt
16
import torch
17
from PIL import Image, UnidentifiedImageError
18
-from typing_extensions import deprecated
18
19
import vllm.envs as envs
20
from vllm.connections import HTTPConnection, global_http_connection
@@ -376,39 +375,12 @@ def argsort_mm_positions(
375
return [(modality, idx) for modality, idx, _ in sorted_flat_items]
376
377
379
-# Temporary back-compatibility for plugins that define model runner
380
-@deprecated("`group_mm_inputs_by_modality` is superseded by "
381
- "`group_mm_kwargs_by_modality` and will be removed in v0.13. "
382
- "Please use `group_mm_kwargs_by_modality` instead.")
383
-def group_mm_inputs_by_modality(
384
- mm_inputs: list[MultiModalKwargsItems]
385
-) -> list[list[MultiModalKwargsItems]]:
386
- if not mm_inputs:
387
- return []
388
-
389
- def modality_group_func(
390
- mm_input: MultiModalKwargsItems) -> Union[str, int]:
391
- # If the input has multiple modalities, return an id as the unique key
392
- # for the mm_input input.
393
- if len(mm_input) > 1:
394
- return id(mm_input)
395
-
396
- elif len(mm_input) == 1:
397
- return next(iter(mm_input.keys()))
398
-
399
- raise AssertionError("This line should be unreachable.")
400
-
401
- return [
402
- list(group) for _, group in groupby(mm_inputs, key=modality_group_func)
403
- ]
404
-
405
-
378
def group_mm_kwargs_by_modality(
379
mm_kwargs: list[MultiModalKwargsItem],
380
*,
381
device: torch.types.Device = None,
382
pin_memory: bool = False,
411
- merge_by_field_config: bool = False,
383
+ merge_by_field_config: Optional[bool] = None,
384
) -> Iterable[tuple[str, int, BatchedTensorInputs]]:
385
"""Group consecutive `MultiModalKwargsItem`s from `mm_kwargs` with the same
386
modality together into the same `MultiModalKwargs` instance.
@@ -421,15 +393,19 @@ def group_mm_kwargs_by_modality(
393
Yields:
394
A tuple `(modality, num_items, grouped_kwargs)`.
395
"""
396
+ if merge_by_field_config is None:
397
+ raise RuntimeError(
398
+ "`group_mm_kwargs_by_modality` now requires "
399
+ "`merge_by_field_config` arg, please update your model runner "
400
+ "according to https://github.com/vllm-project/vllm/pull/25676.")
401
+
402
from vllm.multimodal.inputs import MultiModalKwargs, MultiModalKwargsItems
403
404
for modality, items in groupby(mm_kwargs, key=lambda item: item.modality):
405
items_lst = list(items)
406
429
- # TODO: Enable `merge_by_field_config` for all models
430
- # to avoid creating an extra batch dimension (except for fields
431
- # that are meant to be stacked anyway).
432
- # We will also need to update each model to remove `flatten_bn`.
407
+ # TODO: Deprecate `merge_by_field_config` once
408
+ # we have migrated all in-tree models
409
if merge_by_field_config:
410
mm_kwargs_group: BatchedTensorInputs = dict(
411
MultiModalKwargsItems.from_seq(items_lst).get_data(
vllm/v1/worker/gpu_input_batch.py
+1
-12
@@ -7,10 +7,9 @@ from typing import Optional, cast
7
8
import numpy as np
9
import torch
10
-from typing_extensions import deprecated
10
11
from vllm.lora.request import LoRARequest
13
-from vllm.multimodal.inputs import MultiModalFeatureSpec, MultiModalKwargsItems
12
+from vllm.multimodal.inputs import MultiModalFeatureSpec
13
from vllm.pooling_params import PoolingParams
14
from vllm.sampling_params import SamplingParams, SamplingType
15
from vllm.utils import length_from_prompt_token_ids_or_embeds, swap_dict_values
@@ -53,16 +52,6 @@ class CachedRequestState:
52
def num_tokens(self) -> int:
53
return self.num_prompt_tokens + len(self.output_token_ids)
54
56
- # Temporary back-compatibility for plugins that define model runner
57
- @property
58
- @deprecated("`mm_inputs` is superseded by `mm_kwargs` and will be "
59
- "removed in v0.13. Please use `mm_kwargs` instead.")
60
- def mm_inputs(self) -> list[MultiModalKwargsItems]:
61
- return [
62
- MultiModalKwargsItems.from_seq([f.data]) for f in self.mm_features
63
- if f.data is not None
64
- ]
65
-
55
def get_token_id(self, idx: int) -> int:
56
if idx < self.num_prompt_tokens:
57
if self.prompt_token_ids is None: