test_short_mm_context.py 1.2 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3

4
5
6
7
import pytest

from ..conftest import IMAGE_ASSETS

8
9
10
11
12
13
HF_IMAGE_PROMPTS = IMAGE_ASSETS.prompts(
    {
        "stop_sign": "USER: <image>\nWhat's the content of the image?\nASSISTANT:",
        "cherry_blossom": "USER: <image>\nWhat is the season?\nASSISTANT:",
    }
)
14
15
16
17
18
19
20
21

models = ["llava-hf/llava-1.5-7b-hf"]


@pytest.mark.parametrize("model", models)
def test_context_length_too_short(vllm_runner, image_assets, model):
    images = [asset.pil_image for asset in image_assets]

22
    with pytest.raises(ValueError, match="longer than the maximum model length"):
23
24
        vllm_model = vllm_runner(
            model,
25
26
27
28
29
            # LLaVA has a feature size of 576
            # For the HF processor to execute successfully but still
            # failing the overall context length check, we need the
            # max_model_len to at least contain all image tokens
            max_model_len=579,
30
            enforce_eager=True,
31
            load_format="dummy",
32
33
34
        )

        with vllm_model:
35
36
37
            vllm_model.generate_greedy(
                [HF_IMAGE_PROMPTS[0]], max_tokens=1, images=[images[0]]
            )