@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / 57f94e88ea
Fork 0

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

[Models] Optimise and simplify `_validate_and_reshape_mm_tensor` (#24742)

Signed-off-by: Lukas Geiger <lukas.geiger94@gmail.com>

Lukas Geiger committed Sep 12, 2025 at 16:37 UTC 57f94e88ea1ed2e48ea8ea9b01e9591f0d79557b
9 files changed +12 -10
vllm/model_executor/models/ernie45_vl.py
+1 -1
@@ -1338,7 +1338,7 @@ class Ernie4_5_VLMoeForConditionalGeneration(nn.Module, SupportsMultiModal,
1338 raise ValueError(f"{name} should be 2D or batched 3D tensor. "
1339 f"Got ndim: {mm_input.ndim} "
1340 f"(shape={mm_input.shape})")
1341 - return torch.concat(list(mm_input))
1341 + return mm_input.reshape(-1, mm_input.shape[-1])
1342 else:
1343 return torch.concat(mm_input)
1344
vllm/model_executor/models/glm4_1v.py
+1 -1
@@ -1378,7 +1378,7 @@ class Glm4vForConditionalGeneration(nn.Module, SupportsMultiModal,
1378 raise ValueError(f"{name} should be 2D or batched 3D tensor. "
1379 f"Got ndim: {mm_input.ndim} "
1380 f"(shape={mm_input.shape})")
1381 - return torch.concat(list(mm_input))
1381 + return mm_input.reshape(-1, mm_input.shape[-1])
1382 else:
1383 return torch.concat(mm_input)
1384
vllm/model_executor/models/keye.py
+2 -2
@@ -1611,12 +1611,12 @@ class KeyeForConditionalGeneration(BaseKeyeModule, SupportsMultiModal,
1611 raise ValueError(f"{name} should be 2D or batched 3D tensor. "
1612 f"Got ndim: {mm_input.ndim} "
1613 f"(shape={mm_input.shape})")
1614 - return torch.concat(list(mm_input))
1614 + return mm_input.reshape(-1, mm_input.shape[-1])
1615 elif is_list_of(mm_input, torch.Tensor):
1616 if all(p.dim() == 4 for p in mm_input) or all(p.dim() == 2
1617 for p in mm_input):
1618 return mm_input
1619 - return torch.concat(list(mm_input))
1619 + return torch.concat(mm_input)
1620
1621 def _parse_and_validate_image_input(
1622 self, **kwargs: object) -> Optional[KeyeImageInputs]:
vllm/model_executor/models/keye_vl1_5.py
+2 -2
@@ -491,14 +491,14 @@ class KeyeVL1_5ForConditionalGeneration(BaseKeyeModule, SupportsMultiModal,
491 if mm_input.ndim == expected_dim:
492 return mm_input
493 elif mm_input.ndim == expected_dim + 1:
494 - return torch.concat(list(mm_input))
494 + return mm_input.reshape(-1, *mm_input.shape[2:])
495 else:
496 raise ValueError(
497 f"{name} should be {expected_dim}D or "
498 f"batched {expected_dim}D tensor."
499 f"Got ndim: {mm_input.ndim} (shape={mm_input.shape})")
500 else:
501 - return torch.concat(list(mm_input))
501 + return torch.concat(mm_input)
502
503 def _parse_and_validate_image_input(
504 self, **kwargs: object) -> Optional[KeyeVL1_5ImageInputs]:
vllm/model_executor/models/midashenglm.py
+1 -1
@@ -669,7 +669,7 @@ class MiDashengLMModel(nn.Module, SupportsMultiModal, SupportsPP):
669 raise ValueError(f"Incorrect type of {name}. "
670 f"Got type: {type(mm_input)}")
671 if isinstance(mm_input, torch.Tensor):
672 - return torch.concat(list(mm_input))
672 + return mm_input.reshape(-1, *mm_input.shape[2:])
673 else:
674 return torch.concat(mm_input)
675
vllm/model_executor/models/qwen2_5_omni_thinker.py
+2
@@ -551,6 +551,8 @@ class Qwen2_5OmniConditionalGenerationMixin:
551 raise ValueError(f"Incorrect type of {name}. "
552 f"Got type: {type(mm_input)}")
553 if isinstance(mm_input, torch.Tensor):
554 + if dim == 0:
555 + return mm_input.reshape(-1, *mm_input.shape[2:])
556 return torch.concat(list(mm_input), dim=dim)
557 else:
558 return torch.concat(mm_input, dim=dim)
vllm/model_executor/models/qwen2_5_vl.py
+1 -1
@@ -986,7 +986,7 @@ class Qwen2_5_VLForConditionalGeneration(nn.Module, SupportsMultiModal,
986 raise ValueError(f"{name} should be 2D or batched 3D tensor. "
987 f"Got ndim: {mm_input.ndim} "
988 f"(shape={mm_input.shape})")
989 - return torch.concat(list(mm_input))
989 + return mm_input.reshape(-1, mm_input.shape[-1])
990 else:
991 return torch.concat(mm_input)
992
vllm/model_executor/models/qwen2_audio.py
+1 -1
@@ -342,7 +342,7 @@ class Qwen2AudioForConditionalGeneration(nn.Module, SupportsMultiModal,
342 raise ValueError(f"Incorrect type of {name}. "
343 f"Got type: {type(mm_input)}")
344 if isinstance(mm_input, torch.Tensor):
345 - return torch.concat(list(mm_input))
345 + return mm_input.reshape(-1, *mm_input.shape[2:])
346 else:
347 return torch.concat(mm_input)
348
vllm/model_executor/models/qwen2_vl.py
+1 -1
@@ -1167,7 +1167,7 @@ class Qwen2VLForConditionalGeneration(nn.Module, SupportsMultiModal,
1167 raise ValueError(f"{name} should be 2D or batched 3D tensor. "
1168 f"Got ndim: {mm_input.ndim} "
1169 f"(shape={mm_input.shape})")
1170 - return torch.concat(list(mm_input))
1170 + return mm_input.reshape(-1, mm_input.shape[-1])
1171 else:
1172 return torch.concat(mm_input)
1173