main
py 35 lines 1.1 KB
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 # Adapted from
5 # https://github.com/zai-org/CogAgent
6 from transformers import PythonBackend
7 from transformers.image_processing_backends import TorchvisionBackend
8 from transformers.image_utils import PILImageResampling
9 from transformers.processing_utils import ProcessorMixin
10
11
12 class GLM4VImageProcessorFast(TorchvisionBackend):
13 """Port of https://huggingface.co/zai-org/glm-4v-9b/blob/main/tokenization_chatglm.py#L177
14 to HF Transformers.
15 """
16
17 resample = PILImageResampling.BICUBIC
18 image_mean = [0.48145466, 0.4578275, 0.40821073]
19 image_std = [0.26862954, 0.26130258, 0.27577711]
20 size = {"height": 1120, "width": 1120}
21 do_resize = True
22 do_rescale = True
23 do_normalize = True
24
25
26 class GLM4VProcessor(ProcessorMixin):
27 attributes = ["image_processor", "tokenizer"]
28
29 def __init__(
30 self,
31 image_processor: GLM4VImageProcessorFast,
32 tokenizer: PythonBackend,
33 ) -> None:
34 self.image_processor = image_processor
35 self.tokenizer = tokenizer