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, 23:45 UTC
Migrate GLMVImagePixelInputs to TensorSchema (#21679)
Signed-off-by: Benji Beck <benjibeck@meta.com>
Benji Beck committed
Jul 27, 2025 at 22:36 UTC
304dcdf5758fdbf0252966b6b0791bbba9254feb
1 file changed
+20
-23
vllm/model_executor/models/glm4v.py
+20
-23
@@ -6,7 +6,7 @@
6
"""Inference-only CogAgent model compatible with THUDM weights."""
7
from argparse import Namespace
8
from collections.abc import Mapping, Sequence
9
-from typing import Literal, Optional, TypedDict, Union
9
+from typing import Annotated, Literal, Optional, Union
10
11
import torch
12
from torch import nn
@@ -38,6 +38,7 @@ from vllm.multimodal.processing import (BaseMultiModalProcessor,
38
from vllm.multimodal.profiling import BaseDummyInputsBuilder
39
from vllm.sequence import IntermediateTensors
40
from vllm.transformers_utils.configs import ChatGLMConfig
41
+from vllm.utils.tensor_schema import TensorSchema, TensorShape
42
43
from .chatglm import ChatGLMBaseModel, ChatGLMModel
44
from .interfaces import (MultiModalEmbeddings, SupportsLoRA,
@@ -45,10 +46,16 @@ from .interfaces import (MultiModalEmbeddings, SupportsLoRA,
46
from .utils import flatten_bn, merge_multimodal_embeddings
47
48
48
-class GLMVImagePixelInputs(TypedDict):
49
- type: Literal["pixel_values"]
50
- data: torch.Tensor
51
- """Shape: `(batch_size, num_channels, height, width)`"""
49
+class GLMVImagePixelInputs(TensorSchema):
50
+ """
51
+ Dimensions:
52
+ - b: Batch size
53
+ - c: Number of channels (3)
54
+ - h: Height of image
55
+ - w: Width of image
56
+ """
57
+ type: Literal["pixel_values"] = "pixel_values"
58
+ data: Annotated[torch.Tensor, TensorShape("b", 3, "h", "w")]
59
60
61
class EVA2CLIPPatchEmbedding(nn.Module):
@@ -562,19 +569,6 @@ class GLM4VForCausalLM(ChatGLMBaseModel, SupportsLoRA, SupportsPP,
569
570
self.transformer: GLM4VModel
571
565
- def _validate_pixel_values(self, data: torch.Tensor) -> torch.Tensor:
566
- h = w = self.config.vision_config["image_size"]
567
- expected_dims = (3, h, w)
568
- actual_dims = tuple(data.shape[1:])
569
-
570
- if actual_dims != expected_dims:
571
- expected_expr = ("batch_size", *map(str, expected_dims))
572
- raise ValueError(
573
- f"The expected shape of pixel values is {expected_expr}. "
574
- f"You supplied {tuple(data.shape)}.")
575
-
576
- return data
577
-
572
def _parse_and_validate_image_input(
573
self, **kwargs: object) -> Optional[GLMVImagePixelInputs]:
574
pixel_values = kwargs.pop("pixel_values", None)
@@ -584,11 +578,14 @@ class GLM4VForCausalLM(ChatGLMBaseModel, SupportsLoRA, SupportsPP,
578
raise ValueError("Incorrect type of pixel values. "
579
f"Got type: {type(pixel_values)}")
580
587
- return GLMVImagePixelInputs(
588
- type="pixel_values",
589
- data=self._validate_pixel_values(
590
- flatten_bn(pixel_values, concat=True)),
591
- )
581
+ expected_h = expected_w = self.config.vision_config["image_size"]
582
+ return GLMVImagePixelInputs(type="pixel_values",
583
+ data=flatten_bn(pixel_values,
584
+ concat=True),
585
+ resolve_bindings={
586
+ "h": expected_h,
587
+ "w": expected_w
588
+ })
589
590
return None
591