From 05183dd7df13e18852d671dae64965360448397d Mon Sep 17 00:00:00 2001 From: isotr0py <2037008807@qq.com> Date: Fri, 14 Feb 2025 19:23:24 +0800 Subject: [PATCH 1/3] fix qwen2.5-vl image processor Signed-off-by: isotr0py <2037008807@qq.com> --- vllm/model_executor/models/qwen2_5_vl.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/vllm/model_executor/models/qwen2_5_vl.py b/vllm/model_executor/models/qwen2_5_vl.py index 6aec99b3f964..0664e4853ba8 100644 --- a/vllm/model_executor/models/qwen2_5_vl.py +++ b/vllm/model_executor/models/qwen2_5_vl.py @@ -33,10 +33,10 @@ import torch.nn.functional as F from einops import rearrange from transformers import BatchFeature -from transformers.models.qwen2_5_vl import (Qwen2_5_VLImageProcessor, - Qwen2_5_VLProcessor) +from transformers.models.qwen2_5_vl import Qwen2_5_VLProcessor from transformers.models.qwen2_5_vl.configuration_qwen2_5_vl import ( Qwen2_5_VLConfig, Qwen2_5_VLVisionConfig) +from transformers.models.qwen2_vl import Qwen2VLImageProcessor from vllm.attention import AttentionMetadata from vllm.config import VllmConfig @@ -693,7 +693,7 @@ def get_hf_processor( ) -> Qwen2_5_VLProcessor: hf_processor = self.ctx.get_hf_processor(Qwen2_5_VLProcessor) image_processor = hf_processor.image_processor # type: ignore - assert isinstance(image_processor, Qwen2_5_VLImageProcessor) + assert isinstance(image_processor, Qwen2VLImageProcessor) if min_pixels: image_processor.min_pixels = min_pixels @@ -713,14 +713,14 @@ def get_image_processor( min_pixels: Optional[int] = None, max_pixels: Optional[int] = None, fps: Optional[float] = 2.0, - ) -> Qwen2_5_VLImageProcessor: + ) -> Qwen2VLImageProcessor: hf_processor = self.get_hf_processor( min_pixels=min_pixels, max_pixels=max_pixels, fps=fps, ) image_processor = hf_processor.image_processor # type: ignore - assert isinstance(image_processor, Qwen2_5_VLImageProcessor) + assert isinstance(image_processor, Qwen2VLImageProcessor) return image_processor From 83194235a9c6a06e60f2b8c2a8dce37876a065a0 Mon Sep 17 00:00:00 2001 From: isotr0py <2037008807@qq.com> Date: Fri, 14 Feb 2025 20:47:31 +0800 Subject: [PATCH 2/3] check fast version Signed-off-by: isotr0py <2037008807@qq.com> --- vllm/model_executor/models/qwen2_5_vl.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/vllm/model_executor/models/qwen2_5_vl.py b/vllm/model_executor/models/qwen2_5_vl.py index 0664e4853ba8..632ecaf65f2f 100644 --- a/vllm/model_executor/models/qwen2_5_vl.py +++ b/vllm/model_executor/models/qwen2_5_vl.py @@ -36,7 +36,8 @@ from transformers.models.qwen2_5_vl import Qwen2_5_VLProcessor from transformers.models.qwen2_5_vl.configuration_qwen2_5_vl import ( Qwen2_5_VLConfig, Qwen2_5_VLVisionConfig) -from transformers.models.qwen2_vl import Qwen2VLImageProcessor +from transformers.models.qwen2_vl import (Qwen2VLImageProcessor, + Qwen2VLImageProcessorFast) from vllm.attention import AttentionMetadata from vllm.config import VllmConfig @@ -693,7 +694,8 @@ def get_hf_processor( ) -> Qwen2_5_VLProcessor: hf_processor = self.ctx.get_hf_processor(Qwen2_5_VLProcessor) image_processor = hf_processor.image_processor # type: ignore - assert isinstance(image_processor, Qwen2VLImageProcessor) + assert isinstance(image_processor, + (Qwen2VLImageProcessor, Qwen2VLImageProcessorFast)) if min_pixels: image_processor.min_pixels = min_pixels @@ -713,14 +715,15 @@ def get_image_processor( min_pixels: Optional[int] = None, max_pixels: Optional[int] = None, fps: Optional[float] = 2.0, - ) -> Qwen2VLImageProcessor: + ) -> Union[Qwen2VLImageProcessor, Qwen2VLImageProcessorFast]: hf_processor = self.get_hf_processor( min_pixels=min_pixels, max_pixels=max_pixels, fps=fps, ) image_processor = hf_processor.image_processor # type: ignore - assert isinstance(image_processor, Qwen2VLImageProcessor) + assert isinstance(image_processor, + (Qwen2VLImageProcessor, Qwen2VLImageProcessorFast)) return image_processor From 43c24d83462a5f4e76a7554a88ca19a911aa81da Mon Sep 17 00:00:00 2001 From: isotr0py <2037008807@qq.com> Date: Fri, 14 Feb 2025 20:59:05 +0800 Subject: [PATCH 3/3] handle slow and fast processor for qwen2vl Signed-off-by: isotr0py <2037008807@qq.com> --- vllm/model_executor/models/qwen2_vl.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/vllm/model_executor/models/qwen2_vl.py b/vllm/model_executor/models/qwen2_vl.py index 961f53cef137..b50f35c08b11 100644 --- a/vllm/model_executor/models/qwen2_vl.py +++ b/vllm/model_executor/models/qwen2_vl.py @@ -31,7 +31,9 @@ import torch.nn as nn import torch.nn.functional as F from einops import rearrange, repeat +from packaging.version import Version from transformers import BatchFeature +from transformers import __version__ as TRANSFORMERS_VERSION from transformers.models.qwen2_vl import (Qwen2VLImageProcessor, Qwen2VLProcessor) from transformers.models.qwen2_vl.configuration_qwen2_vl import ( @@ -759,7 +761,13 @@ def get_image_processor( hf_processor = self.get_hf_processor(min_pixels=min_pixels, max_pixels=max_pixels) image_processor = hf_processor.image_processor # type: ignore - assert isinstance(image_processor, Qwen2VLImageProcessor) + if Version(TRANSFORMERS_VERSION) >= Version("4.49"): + from transformers.models.qwen2_vl import Qwen2VLImageProcessorFast + assert isinstance( + image_processor, + (Qwen2VLImageProcessor, Qwen2VLImageProcessorFast)) + else: + assert isinstance(image_processor, Qwen2VLImageProcessor) return image_processor def get_supported_mm_limits(self) -> Mapping[str, Optional[int]]: