"tests/kernels/quantization/untest_cutlass_scaled_mm.py" did not exist on "0e9164b40abdb30f1929edb44b56894c9e26c31d"
test_qwen2_vl.py 2.02 KB
Newer Older
1
2
import pytest

3
4
from vllm.multimodal import MULTIMODAL_REGISTRY
from vllm.multimodal.utils import cached_get_tokenizer
5

6
7
from ....conftest import _ImageAssets
from ...utils import build_model_context
8
9


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

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

    processed_inputs = processor.apply(prompt, mm_data, mm_processor_kwargs)

    # Ensure we have the right number of placeholders per num_crops size
47
    hf_processor = processor.info.get_hf_processor(**mm_processor_kwargs)
48
49
50
51
52
53
54
    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]