[Bugfix] Fix CI failures for InternVL and Mantis models (#12728)
Signed-off-by: DarkLight1337 <tlleungac@connect.ust.hk>
This commit is contained in:
@@ -1,11 +1,13 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
from contextlib import nullcontext
|
||||
from types import MethodType
|
||||
from typing import cast
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
from transformers import ProcessorMixin
|
||||
|
||||
from vllm.config import ModelConfig
|
||||
from vllm.multimodal import MULTIMODAL_REGISTRY
|
||||
@@ -636,3 +638,70 @@ def test_limit_mm_per_prompt_apply(model_id, num_images, limit, is_valid):
|
||||
mm_data=mm_data,
|
||||
hf_processor_mm_kwargs={},
|
||||
)
|
||||
|
||||
|
||||
class _ProcessorProxy:
|
||||
|
||||
def __init__(self, processor: ProcessorMixin) -> None:
|
||||
super().__init__()
|
||||
|
||||
self.__processor = processor
|
||||
|
||||
def __getattr__(self, key: str):
|
||||
return getattr(self.__processor, key)
|
||||
|
||||
def __call__(
|
||||
self,
|
||||
text=None,
|
||||
images=None,
|
||||
videos=None,
|
||||
exists=None,
|
||||
return_tensors=None,
|
||||
):
|
||||
return dict(exists=exists)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("model_id", ["Qwen/Qwen2-VL-7B-Instruct"]) # Dummy
|
||||
# yapf: disable
|
||||
@pytest.mark.parametrize(
|
||||
("call_kwargs", "expected_kwargs"),
|
||||
[
|
||||
# Should ignore invalid kwargs
|
||||
({"does_not_exist": 100}, {"exists": None}),
|
||||
({"exists": 1}, {"exists": 1}),
|
||||
({"does_not_exist": 100, "exists": 1}, {"exists": 1}),
|
||||
],
|
||||
)
|
||||
# yapf: enable
|
||||
def test_hf_processor_kwargs(model_id, call_kwargs, expected_kwargs):
|
||||
model_config = ModelConfig(
|
||||
model=model_id,
|
||||
task="auto",
|
||||
tokenizer=model_id,
|
||||
tokenizer_mode="auto",
|
||||
trust_remote_code=False,
|
||||
seed=0,
|
||||
dtype="half",
|
||||
revision=None,
|
||||
)
|
||||
|
||||
processor = MULTIMODAL_REGISTRY.create_processor(
|
||||
model_config,
|
||||
tokenizer=cached_get_tokenizer(model_config.tokenizer),
|
||||
)
|
||||
orig_get_hf_processor = processor.info.get_hf_processor
|
||||
|
||||
def get_hf_processor(self, **kwargs):
|
||||
assert kwargs == call_kwargs
|
||||
return _ProcessorProxy(orig_get_hf_processor())
|
||||
|
||||
processor.info.get_hf_processor = MethodType(get_hf_processor,
|
||||
processor.info)
|
||||
|
||||
out_kwargs = processor._call_hf_processor(
|
||||
prompt="",
|
||||
mm_data={},
|
||||
mm_kwargs=call_kwargs,
|
||||
)
|
||||
|
||||
assert out_kwargs == expected_kwargs
|
||||
|
||||
Reference in New Issue
Block a user