"vllm/entrypoints/openai/serving_rerank.py" did not exist on "eeec9e339005d887e0064f7b3e7771295ecd68e7"
test_qwen2_vl.py 2.18 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3

4
5
import pytest

6
from vllm.multimodal import MULTIMODAL_REGISTRY
7

8
from ....conftest import ImageTestAssets
9
from ...utils import build_model_context
10
11


12
13
@pytest.mark.parametrize("model_id", ["Qwen/Qwen2-VL-2B-Instruct"])
# yapf: disable
14
@pytest.mark.parametrize(
15
    ("mm_processor_kwargs", "expected_toks_per_img", "expected_pixels_shape"), [
16
        ({}, 1426, (5704, 1176)),
17
        ({"min_pixels": 64**2, "max_pixels": 512**2}, 330, (1320, 1176)),
18
    ])
19
# yapf: enable
20
@pytest.mark.parametrize("num_imgs", [1, 2])
21
@pytest.mark.parametrize("kwargs_on_init", [True, False])
22
def test_processor_override(
23
    image_assets: ImageTestAssets,
24
25
    model_id: str,
    mm_processor_kwargs: dict[str, object],
26
    expected_toks_per_img: int,
27
    expected_pixels_shape: tuple[int, int],
28
    num_imgs: int,
29
    kwargs_on_init: bool,
30
31
32
):
    """Ensure Qwen2VLMultiModalProcessor handles min/max pixels properly."""
    ctx = build_model_context(
33
        model_id,
34
        mm_processor_kwargs=mm_processor_kwargs if kwargs_on_init else None,
35
        limit_mm_per_prompt={"image": num_imgs},
36
    )
37
38
    processor = MULTIMODAL_REGISTRY.create_processor(ctx.model_config)
    tokenizer = processor.info.get_tokenizer()
39
    hf_processor_mm_kwargs = {} if kwargs_on_init else mm_processor_kwargs
40

41
42
    # Build the image str / prompt based on the number of images we pass
    prompt = "<|vision_start|><|image_pad|><|vision_end|>" * num_imgs
43
    mm_data = {"image": [image_assets[0].pil_image] * num_imgs}
44

45
    processed_inputs = processor.apply(prompt, mm_data, hf_processor_mm_kwargs)
46
47

    # Ensure we have the right number of placeholders per num_crops size
48
    hf_processor = processor.info.get_hf_processor(**hf_processor_mm_kwargs)
49
50
51
52
53
54
55
    image_token_id = tokenizer.convert_tokens_to_ids(hf_processor.image_token)
    img_tok_count = processed_inputs["prompt_token_ids"].count(image_token_id)
    pixel_shape = processed_inputs["mm_kwargs"]["pixel_values"].shape

    assert img_tok_count == expected_toks_per_img * num_imgs
    assert pixel_shape[0] == expected_pixels_shape[0] * num_imgs
    assert pixel_shape[1] == expected_pixels_shape[1]