| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | import pytest |
| 5 | |
| 6 | from vllm.exceptions import VLLMValidationError |
| 7 | |
| 8 | from ..conftest import IMAGE_ASSETS |
| 9 | |
| 10 | HF_IMAGE_PROMPTS = IMAGE_ASSETS.prompts( |
| 11 | { |
| 12 | "stop_sign": "USER: <image>\nWhat's the content of the image?\nASSISTANT:", |
| 13 | "cherry_blossom": "USER: <image>\nWhat is the season?\nASSISTANT:", |
| 14 | } |
| 15 | ) |
| 16 | |
| 17 | models = ["llava-hf/llava-1.5-7b-hf"] |
| 18 | |
| 19 | |
| 20 | @pytest.mark.parametrize("model", models) |
| 21 | def test_context_length_too_short(vllm_runner, image_assets, model): |
| 22 | images = [asset.pil_image for asset in image_assets] |
| 23 | |
| 24 | with pytest.raises( |
| 25 | VLLMValidationError, match="longer than the maximum model length" |
| 26 | ): |
| 27 | vllm_model = vllm_runner( |
| 28 | model, |
| 29 | # LLaVA has a feature size of 576 |
| 30 | # For the HF processor to execute successfully but still |
| 31 | # failing the overall context length check, we need the |
| 32 | # max_model_len to at least contain all image tokens |
| 33 | max_model_len=579, |
| 34 | enforce_eager=True, |
| 35 | load_format="dummy", |
| 36 | ) |
| 37 | |
| 38 | with vllm_model: |
| 39 | vllm_model.generate_greedy( |
| 40 | [HF_IMAGE_PROMPTS[0]], max_tokens=1, images=[images[0]] |
| 41 | ) |