Files
vllm/vllm/transformers_utils/processors/glm4v.py
Raushan Turganbay 8850738b70 [Bugfix] Fix processor signature (#36630)
Signed-off-by: raushan <raushan@huggingface.co>
Co-authored-by: Harry Mellor <19981378+hmellor@users.noreply.github.com>
2026-03-10 06:20:47 -07:00

39 lines
1.3 KiB
Python

# SPDX-License-Identifier: Apache-2.0
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
from transformers import PreTrainedTokenizer
from transformers.image_processing_utils_fast import BaseImageProcessorFast
from transformers.image_utils import PILImageResampling
from transformers.processing_utils import ProcessorMixin
class GLM4VImageProcessorFast(BaseImageProcessorFast):
"""
Port of https://huggingface.co/zai-org/glm-4v-9b/blob/main/tokenization_chatglm.py#L177
to HF Transformers.
"""
resample = PILImageResampling.BICUBIC
image_mean = [0.48145466, 0.4578275, 0.40821073]
image_std = [0.26862954, 0.26130258, 0.27577711]
size = {"height": 1120, "width": 1120}
do_resize = True
do_rescale = True
do_normalize = True
class GLM4VProcessor(ProcessorMixin):
attributes = ["image_processor", "tokenizer"]
def __init__(
self,
tokenizer: PreTrainedTokenizer,
image_size: int,
image_processor: GLM4VImageProcessorFast | None = None,
) -> None:
self.tokenizer = tokenizer
if image_processor is None:
image_processor = GLM4VImageProcessorFast(
size={"width": image_size, "height": image_size}
)
self.image_processor = image_processor