| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | import weakref |
| 4 | |
| 5 | import pytest |
| 6 | |
| 7 | from tests.entrypoints.multimodal.conftest import TEST_IMAGE_ASSETS |
| 8 | |
| 9 | |
| 10 | @pytest.fixture(scope="function") |
| 11 | def vision_llm(vllm_runner): |
| 12 | with vllm_runner( |
| 13 | "microsoft/Phi-3.5-vision-instruct", |
| 14 | max_model_len=4096, |
| 15 | max_num_seqs=5, |
| 16 | enforce_eager=True, |
| 17 | trust_remote_code=True, |
| 18 | limit_mm_per_prompt={"image": 2}, |
| 19 | seed=0, |
| 20 | ) as runner: |
| 21 | # pytest caches yielded fixtures until after teardown, so use a proxy to |
| 22 | # avoid retaining the LLM while VllmRunner.__exit__ releases ROCm memory. |
| 23 | yield weakref.proxy(runner.llm) |
| 24 | |
| 25 | |
| 26 | @pytest.mark.parametrize( |
| 27 | "image_urls", [[TEST_IMAGE_ASSETS[0], TEST_IMAGE_ASSETS[1]]], indirect=True |
| 28 | ) |
| 29 | def test_chat_multi_image(vision_llm, image_urls: list[str]): |
| 30 | messages = [ |
| 31 | { |
| 32 | "role": "user", |
| 33 | "content": [ |
| 34 | *( |
| 35 | {"type": "image_url", "image_url": {"url": image_url}} |
| 36 | for image_url in image_urls |
| 37 | ), |
| 38 | {"type": "text", "text": "What's in this image?"}, |
| 39 | ], |
| 40 | } |
| 41 | ] |
| 42 | outputs = vision_llm.chat(messages) |
| 43 | assert len(outputs) >= 0 |