test_common.py 52.1 KB
Newer Older
1
# SPDX-License-Identifier: Apache-2.0
2
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4
5
"""Common tests for testing .generate() functionality for single / multiple
image, embedding, and video support for different VLMs in vLLM.
"""
6

7
8
import math
from collections import defaultdict
9
10
from pathlib import PosixPath

zhuwenwen's avatar
zhuwenwen committed
11
import os
12
import pytest
13
from packaging.version import Version
14
15
from transformers import (
    AutoModel,
16
    AutoModelForCausalLM,
17
18
19
    AutoModelForImageTextToText,
    AutoModelForTextToWaveform,
)
20
from transformers import __version__ as TRANSFORMERS_VERSION
21
22

from vllm.platforms import current_platform
23
from vllm.utils.func_utils import identity
24

25
26
27
28
29
30
31
32
33
from ....conftest import (
    IMAGE_ASSETS,
    AudioTestAssets,
    HfRunner,
    ImageTestAssets,
    VideoTestAssets,
    VllmRunner,
)
from ....utils import create_new_process_for_each_test, large_gpu_mark, multi_gpu_marks
34
35
36
from ...utils import check_outputs_equal
from .vlm_utils import custom_inputs, model_utils, runners
from .vlm_utils.case_filtering import get_parametrized_options
37
38
39
40
41
42
from .vlm_utils.types import (
    CustomTestOptions,
    ExpandableVLMTestArgs,
    VLMTestInfo,
    VLMTestType,
)
zhuwenwen's avatar
zhuwenwen committed
43
from ....utils import models_path_prefix
44
45
46
47
48
49

COMMON_BROADCAST_SETTINGS = {
    "test_type": VLMTestType.IMAGE,
    "dtype": "half",
    "max_tokens": 5,
    "tensor_parallel_size": 2,
50
    "hf_model_kwargs": {"device_map": "auto"},
51
    "image_size_factors": [(0.25, 0.5, 1.0)],
52
53
54
    "distributed_executor_backend": (
        "ray",
        "mp",
55
    ),
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
}

### Test configuration for specific models
# NOTE: The convention of the test settings below is to lead each test key
# with the name of the model arch used in the test, using underscores in place
# of hyphens; this makes it more convenient to filter tests for a specific kind
# of model. For example....
#
# To run all test types for a specific key:
#     use the k flag to substring match with a leading square bracket; if the
#     model arch happens to be a substring of another one, you can add a
#     trailing hyphen. E.g.,
#                 - pytest $TEST_FILE -k "[llava-"
#     prevents matching on "[llava_next-" & will match just the enabled cases
#     for llava, i.e., single image, image embedding, and custom input tests.
#
# To run a test for a Test Info for just one of multiple models:
#     use the k flag to substring match the model name, e.g.,
#                 - pytest $TEST_FILE -k OpenGVLab/InternVL2-1B
#     prevents matching on nGVLab/InternVL2-2B.
#
# You can also combine substrings to match more granularly.
#     ex 1:
#        pytest $TEST_FILE -k "test_single_image and OpenGVLab/InternVL2-1B"
#     will run only test_single_image* for OpenGVLab/InternVL2-1B; this would
#     match both wrappers for single image tests, since it also matches
#     test_single_image_heavy (which forks if we have a distributed backend)
#     ex 2:
#        pytest $TEST_FILE -k  "[llava- or [intern_vl-"
#     will run all of the tests for only llava & internvl.
#
# NOTE you can add --collect-only to any of the above commands to see
# which cases would be selected and deselected by pytest. In general,
# this is a good idea for checking your command first, since tests are slow.

VLM_TEST_SETTINGS = {
92
93
    #### Core tests to always run in the CI
    "llava": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
94
        models=[os.path.join(models_path_prefix, "llava-hf/llava-1.5-7b-hf")],
95
        test_type=(VLMTestType.EMBEDDING, VLMTestType.IMAGE, VLMTestType.CUSTOM_INPUTS),
96
97
98
        prompt_formatter=lambda img_prompt: f"USER: {img_prompt}\nASSISTANT:",
        convert_assets_to_embeddings=model_utils.get_llava_embeddings,
        max_model_len=4096,
99
        auto_cls=AutoModelForImageTextToText,
100
        vllm_output_post_proc=model_utils.llava_image_vllm_to_hf_output,
101
102
103
104
105
106
107
108
        custom_test_opts=[
            CustomTestOptions(
                inputs=custom_inputs.multi_image_multi_aspect_ratio_inputs(
                    formatter=lambda img_prompt: f"USER: {img_prompt}\nASSISTANT:"
                ),
                limit_mm_per_prompt={"image": 4},
            )
        ],
109
        vllm_runner_kwargs={"enable_mm_embeds": True},
110
        marks=[pytest.mark.core_model, pytest.mark.cpu_model],
111
112
    ),
    "paligemma": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
113
        models=[os.path.join(models_path_prefix, "google/paligemma-3b-mix-224")],
114
115
        test_type=VLMTestType.IMAGE,
        prompt_formatter=identity,
116
        img_idx_to_prompt=lambda idx: "",
117
        # Paligemma uses its own sample prompts because the default one fails
118
119
120
121
122
123
        single_image_prompts=IMAGE_ASSETS.prompts(
            {
                "stop_sign": "caption es",
                "cherry_blossom": "What is in the picture?",
            }
        ),
124
        auto_cls=AutoModelForImageTextToText,
125
        vllm_output_post_proc=model_utils.paligemma_vllm_to_hf_output,
126
        dtype="bfloat16",
127
128
129
        marks=[
            pytest.mark.skip(reason="vLLM does not support PrefixLM attention mask")
        ],
130
    ),
zhuwenwen's avatar
zhuwenwen committed
131

Roger Wang's avatar
Roger Wang committed
132
    "qwen2_5_vl": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
133
        models=[os.path.join(models_path_prefix, "Qwen/Qwen2.5-VL-3B-Instruct")],
134
135
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE, VLMTestType.VIDEO),
        prompt_formatter=lambda img_prompt: f"<|im_start|>User\n{img_prompt}<|im_end|>\n<|im_start|>assistant\n",  # noqa: E501
136
137
        img_idx_to_prompt=lambda idx: "<|vision_start|><|image_pad|><|vision_end|>",
        video_idx_to_prompt=lambda idx: "<|vision_start|><|video_pad|><|vision_end|>",
138
        enforce_eager=False,
139
140
        max_model_len=4096,
        max_num_seqs=2,
141
        auto_cls=AutoModelForImageTextToText,
142
143
        vllm_output_post_proc=model_utils.qwen2_vllm_to_hf_output,
        image_size_factors=[(), (0.25,), (0.25, 0.25, 0.25), (0.25, 0.2, 0.15)],
144
        marks=[pytest.mark.core_model, pytest.mark.cpu_model],
145
    ),
146
    "qwen2_5_omni": VLMTestInfo(
147
        models=[os.path.join(models_path_prefix, "Qwen/Qwen2.5-Omni-3B")],
148
149
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE, VLMTestType.VIDEO),
        prompt_formatter=lambda img_prompt: f"<|im_start|>User\n{img_prompt}<|im_end|>\n<|im_start|>assistant\n",  # noqa: E501
150
151
        img_idx_to_prompt=lambda idx: "<|vision_bos|><|IMAGE|><|vision_eos|>",
        video_idx_to_prompt=lambda idx: "<|vision_bos|><|VIDEO|><|vision_eos|>",
152
153
        max_model_len=4096,
        max_num_seqs=2,
154
        num_logprobs=6 if current_platform.is_cpu() else 5,
155
        auto_cls=AutoModelForTextToWaveform,
156
        vllm_output_post_proc=model_utils.qwen2_vllm_to_hf_output,
157
        patch_hf_runner=model_utils.qwen2_5_omni_patch_hf_runner,
158
159
160
        image_size_factors=[(), (0.25,), (0.25, 0.25, 0.25), (0.25, 0.2, 0.15)],
        marks=[pytest.mark.core_model, pytest.mark.cpu_model],
    ),
161
    "qwen3_vl": VLMTestInfo(
162
        models=[os.path.join(models_path_prefix, "Qwen/Qwen3-VL-4B-Instruct")],
163
164
165
        test_type=(
            VLMTestType.IMAGE,
            VLMTestType.MULTI_IMAGE,
166
            VLMTestType.VIDEO,
167
        ),
168
        enforce_eager=False,
169
170
171
172
        needs_video_metadata=True,
        prompt_formatter=lambda img_prompt: f"<|im_start|>User\n{img_prompt}<|im_end|>\n<|im_start|>assistant\n",  # noqa: E501
        img_idx_to_prompt=lambda idx: "<|vision_start|><|image_pad|><|vision_end|>",  # noqa: E501
        video_idx_to_prompt=lambda idx: "<|vision_start|><|video_pad|><|vision_end|>",  # noqa: E501
173
174
        max_model_len=4096,
        max_num_seqs=2,
175
176
        num_logprobs=20,
        auto_cls=AutoModelForImageTextToText,
177
        vllm_output_post_proc=model_utils.qwen2_vllm_to_hf_output,
178
        patch_hf_runner=model_utils.qwen3_vl_patch_hf_runner,
179
        image_size_factors=[(), (0.25,), (0.25, 0.25, 0.25), (0.25, 0.2, 0.15)],
180
181
182
        marks=[
            pytest.mark.core_model,
        ],
183
    ),
184
    "ultravox": VLMTestInfo(
185
        models=[os.path.join(models_path_prefix, "fixie-ai/ultravox-v0_5-llama-3_2-1b")],
186
        test_type=VLMTestType.AUDIO,
187
        prompt_formatter=lambda audio_prompt: f"<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\n{audio_prompt}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",  # noqa: E501
188
189
190
191
192
193
194
        audio_idx_to_prompt=lambda idx: "<|audio|>",
        max_model_len=4096,
        max_num_seqs=2,
        auto_cls=AutoModel,
        hf_output_post_proc=model_utils.ultravox_trunc_hf_output,
        marks=[pytest.mark.core_model, pytest.mark.cpu_model],
    ),
195
196
197
198
    #### Transformers fallback to test
    ## To reduce test burden, we only test batching arbitrary image size
    # Dynamic image length and number of patches
    "llava-onevision-transformers": VLMTestInfo(
199
        models=[os.path.join(models_path_prefix, "llava-hf/llava-onevision-qwen2-0.5b-ov-hf")],
200
        test_type=VLMTestType.IMAGE,
201
        prompt_formatter=lambda vid_prompt: f"<|im_start|>user\n{vid_prompt}<|im_end|>\n<|im_start|>assistant\n",  # noqa: E501
202
        max_model_len=16384,
203
        hf_model_kwargs=model_utils.llava_onevision_hf_model_kwargs(
204
            os.path.join(models_path_prefix,"llava-hf/llava-onevision-qwen2-0.5b-ov-hf")
205
        ),
206
207
208
209
210
        auto_cls=AutoModelForImageTextToText,
        vllm_output_post_proc=model_utils.llava_onevision_vllm_to_hf_output,
        image_size_factors=[(0.25, 0.5, 1.0)],
        vllm_runner_kwargs={
            "model_impl": "transformers",
211
            "default_torch_num_threads": 1,
212
        },
213
214
215
        # FIXME: Investigate why the test hangs
        # when processing the 3rd prompt in vLLM
        marks=[pytest.mark.core_model, pytest.mark.skip(reason="Test hangs")],
216
    ),
217
218
    # Gemma3 has bidirectional mask on images
    "gemma3-transformers": VLMTestInfo(
219
        models=[os.path.join(models_path_prefix, "google/gemma-3-4b-it")],
220
221
222
        test_type=VLMTestType.IMAGE,
        prompt_formatter=lambda vid_prompt: f"<'<bos><start_of_turn>user\n{vid_prompt}<start_of_image><end_of_turn>\n<start_of_turn>model\n",  # noqa: E501
        max_model_len=4096,
223
224
225
226
227
228
229
230
        auto_cls=AutoModelForImageTextToText,
        vllm_output_post_proc=model_utils.gemma3_vllm_to_hf_output,
        image_size_factors=[(0.25, 0.5, 1.0)],
        vllm_runner_kwargs={
            "model_impl": "transformers",
        },
        marks=[pytest.mark.core_model],
    ),
231
    "idefics3-transformers": VLMTestInfo(
232
        models=[os.path.join(models_path_prefix, "HuggingFaceTB/SmolVLM-256M-Instruct")],
233
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
234
        prompt_formatter=lambda img_prompt: f"<|begin_of_text|>User:{img_prompt}<end_of_utterance>\nAssistant:",  # noqa: E501
235
236
237
238
239
240
241
242
243
244
245
        img_idx_to_prompt=lambda idx: "<image>",
        max_model_len=8192,
        max_num_seqs=2,
        auto_cls=AutoModelForImageTextToText,
        hf_output_post_proc=model_utils.idefics3_trunc_hf_output,
        image_size_factors=[(0.25, 0.5, 1.0)],
        vllm_runner_kwargs={
            "model_impl": "transformers",
        },
        marks=[pytest.mark.core_model],
    ),
246
247
    # Pixel values from processor are not 4D or 5D arrays
    "qwen2_5_vl-transformers": VLMTestInfo(
248
        models=[os.path.join(models_path_prefix, "Qwen/Qwen2.5-VL-3B-Instruct")],
249
        test_type=VLMTestType.IMAGE,
250
        prompt_formatter=lambda img_prompt: f"<|im_start|>User\n{img_prompt}<|im_end|>\n<|im_start|>assistant\n",  # noqa: E501
251
        img_idx_to_prompt=lambda idx: "<|vision_start|><|image_pad|><|vision_end|>",
252
253
254
255
256
257
258
259
260
261
        max_model_len=4096,
        max_num_seqs=2,
        auto_cls=AutoModelForImageTextToText,
        vllm_output_post_proc=model_utils.qwen2_vllm_to_hf_output,
        image_size_factors=[(0.25, 0.2, 0.15)],
        vllm_runner_kwargs={
            "model_impl": "transformers",
        },
        marks=[large_gpu_mark(min_gb=32)],
    ),
262
    #### Extended model tests
263
    "aria": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
264
        models=[os.path.join(models_path_prefix, "rhymes-ai/Aria")],
265
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
266
        prompt_formatter=lambda img_prompt: f"<|im_start|>user\n{img_prompt}<|im_end|>\n<|im_start|>assistant\n ",  # noqa: E501
267
        img_idx_to_prompt=lambda idx: "<fim_prefix><|img|><fim_suffix>\n",
Roger Wang's avatar
Roger Wang committed
268
269
        max_model_len=4096,
        max_num_seqs=2,
270
        auto_cls=AutoModelForImageTextToText,
271
272
273
        single_image_prompts=IMAGE_ASSETS.prompts(
            {
                "stop_sign": "<vlm_image>Please describe the image shortly.",
274
                "cherry_blossom": "<vlm_image>Please infer the season with reason.",
275
276
            }
        ),
277
        multi_image_prompt="<vlm_image><vlm_image>Describe the two images shortly.",
278
279
280
281
282
        stop_str=["<|im_end|>"],
        image_size_factors=[(0.10, 0.15)],
        max_tokens=64,
        marks=[large_gpu_mark(min_gb=64)],
    ),
Jennifer Zhao's avatar
Jennifer Zhao committed
283
    "aya_vision": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
284
        models=[os.path.join(models_path_prefix, "CohereForAI/aya-vision-8b")],
285
        test_type=(VLMTestType.IMAGE),
286
287
288
        prompt_formatter=lambda img_prompt: f"<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{img_prompt}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>",  # noqa: E501
        single_image_prompts=IMAGE_ASSETS.prompts(
            {
289
290
                "stop_sign": "<image>What's the content in the center of the image?",
                "cherry_blossom": "<image>What is the season?",
291
292
            }
        ),
293
        multi_image_prompt="<image><image>Describe the two images in detail.",
294
295
296
297
298
299
300
301
        max_model_len=4096,
        max_num_seqs=2,
        auto_cls=AutoModelForImageTextToText,
        vllm_runner_kwargs={"mm_processor_kwargs": {"crop_to_patches": True}},
    ),
    "aya_vision-multi_image": VLMTestInfo(
        models=["CohereForAI/aya-vision-8b"],
        test_type=(VLMTestType.MULTI_IMAGE),
302
303
304
        prompt_formatter=lambda img_prompt: f"<|START_OF_TURN_TOKEN|><|USER_TOKEN|>{img_prompt}<|END_OF_TURN_TOKEN|><|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>",  # noqa: E501
        single_image_prompts=IMAGE_ASSETS.prompts(
            {
305
306
                "stop_sign": "<image>What's the content in the center of the image?",
                "cherry_blossom": "<image>What is the season?",
307
308
            }
        ),
309
        multi_image_prompt="<image><image>Describe the two images in detail.",
310
        max_model_len=4096,
Jennifer Zhao's avatar
Jennifer Zhao committed
311
312
        max_num_seqs=2,
        auto_cls=AutoModelForImageTextToText,
313
314
        vllm_runner_kwargs={"mm_processor_kwargs": {"crop_to_patches": True}},
        marks=[large_gpu_mark(min_gb=32)],
Roger Wang's avatar
Roger Wang committed
315
    ),
316
    "blip2": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
317
        models=[os.path.join(models_path_prefix,"Salesforce/blip2-opt-2.7b")],
318
319
320
        test_type=VLMTestType.IMAGE,
        prompt_formatter=lambda img_prompt: f"Question: {img_prompt} Answer:",
        img_idx_to_prompt=lambda idx: "",
321
        auto_cls=AutoModelForImageTextToText,
322
        vllm_output_post_proc=model_utils.blip2_vllm_to_hf_output,
323
324
        # FIXME: https://github.com/huggingface/transformers/pull/38510
        marks=[pytest.mark.skip("Model is broken")],
325
326
    ),
    "chameleon": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
327
        models=[os.path.join(models_path_prefix, "facebook/chameleon-7b")],
328
329
330
        test_type=VLMTestType.IMAGE,
        prompt_formatter=lambda img_prompt: f"USER: {img_prompt}\nASSISTANT:",
        max_model_len=4096,
331
        max_num_seqs=2,
332
        auto_cls=AutoModelForImageTextToText,
333
        # For chameleon, we only compare the sequences
334
335
        vllm_output_post_proc=lambda vllm_output, model: vllm_output[:2],
        hf_output_post_proc=lambda hf_output, model: hf_output[:2],
336
337
338
339
        comparator=check_outputs_equal,
        max_tokens=8,
        dtype="bfloat16",
    ),
340
    "deepseek_vl_v2": VLMTestInfo(
341
        models=["Isotr0py/deepseek-vl2-tiny"],  # model repo using dynamic module
342
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
343
        prompt_formatter=lambda img_prompt: f"<|User|>: {img_prompt}\n\n<|Assistant|>: ",  # noqa: E501
344
345
        max_model_len=4096,
        max_num_seqs=2,
346
347
        single_image_prompts=IMAGE_ASSETS.prompts(
            {
348
                "stop_sign": "<image>\nWhat's the content in the center of the image?",
349
350
351
352
                "cherry_blossom": "<image>\nPlease infer the season with reason in details.",  # noqa: E501
            }
        ),
        multi_image_prompt="image_1:<image>\nimage_2:<image>\nWhich image can we see the car and the tower?",  # noqa: E501
353
354
        patch_hf_runner=model_utils.deepseekvl2_patch_hf_runner,
        hf_output_post_proc=model_utils.deepseekvl2_trunc_hf_output,
355
        stop_str=["<|end▁of▁sentence|>", "<|begin▁of▁sentence|>"],
356
        image_size_factors=[(), (1.0,), (1.0, 1.0, 1.0), (0.1, 0.5, 1.0)],
357
    ),
358
    "fuyu": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
359
        models=[os.path.join(models_path_prefix, "adept/fuyu-8b")],
360
361
362
363
364
        test_type=VLMTestType.IMAGE,
        prompt_formatter=lambda img_prompt: f"{img_prompt}\n",
        img_idx_to_prompt=lambda idx: "",
        max_model_len=2048,
        max_num_seqs=2,
365
        auto_cls=AutoModelForImageTextToText,
366
367
368
369
        use_tokenizer_eos=True,
        vllm_output_post_proc=model_utils.fuyu_vllm_to_hf_output,
        num_logprobs=10,
        image_size_factors=[(), (0.25,), (0.25, 0.25, 0.25), (0.25, 0.2, 0.15)],
370
        marks=[large_gpu_mark(min_gb=32)],
371
    ),
372
    "gemma3": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
373
        models=[os.path.join(models_path_prefix, "google/gemma-3-4b-it")],
374
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
375
376
377
378
379
380
381
        prompt_formatter=lambda img_prompt: f"<bos><start_of_turn>user\n{img_prompt}<end_of_turn>\n<start_of_turn>model\n",  # noqa: E501
        single_image_prompts=IMAGE_ASSETS.prompts(
            {
                "stop_sign": "<start_of_image>What's the content in the center of the image?",  # noqa: E501
                "cherry_blossom": "<start_of_image>What is the season?",
            }
        ),
382
383
384
        multi_image_prompt="<start_of_image><start_of_image>Describe the two images in detail.",  # noqa: E501
        max_model_len=4096,
        max_num_seqs=2,
385
        auto_cls=AutoModelForImageTextToText,
386
387
        vllm_runner_kwargs={"mm_processor_kwargs": {"do_pan_and_scan": True}},
        patch_hf_runner=model_utils.gemma3_patch_hf_runner,
388
        num_logprobs=10,
389
    ),
390
    "glm4v": VLMTestInfo(
391
        models=[os.path.join(models_path_prefix, "zai-org/glm-4v-9b")],
392
        test_type=VLMTestType.IMAGE,
393
        prompt_formatter=lambda img_prompt: f"<|user|>\n{img_prompt}<|assistant|>",
394
395
396
397
398
399
        single_image_prompts=IMAGE_ASSETS.prompts(
            {
                "stop_sign": "<|begin_of_image|><|endoftext|><|end_of_image|>What's the content in the center of the image?",  # noqa: E501
                "cherry_blossom": "<|begin_of_image|><|endoftext|><|end_of_image|>What is the season?",  # noqa: E501
            }
        ),
400
401
402
        max_model_len=2048,
        max_num_seqs=2,
        get_stop_token_ids=lambda tok: [151329, 151336, 151338],
403
404
405
406
407
408
        patch_hf_runner=model_utils.glm4v_patch_hf_runner,
        # The image embeddings match with HF but the outputs of the language
        # decoder are only consistent up to 2 decimal places.
        # So, we need to reduce the number of tokens for the test to pass.
        max_tokens=8,
        num_logprobs=10,
409
        marks=[large_gpu_mark(min_gb=32)],
410
    ),
411
    "glm4_1v": VLMTestInfo(
412
        models=["zai-org/GLM-4.1V-9B-Thinking"],
413
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
414
415
416
        prompt_formatter=lambda img_prompt: f"<|user|>\n{img_prompt}<|assistant|>",
        img_idx_to_prompt=lambda idx: "<|begin_of_image|><|image|><|end_of_image|>",
        video_idx_to_prompt=lambda idx: "<|begin_of_video|><|video|><|end_of_video|>",
417
418
419
420
421
422
        max_model_len=2048,
        max_num_seqs=2,
        get_stop_token_ids=lambda tok: [151329, 151336, 151338],
        num_logprobs=10,
        image_size_factors=[(), (0.25,), (0.25, 0.25, 0.25), (0.25, 0.2, 0.15)],
        auto_cls=AutoModelForImageTextToText,
423
        marks=[large_gpu_mark(min_gb=32)],
424
425
    ),
    "glm4_1v-video": VLMTestInfo(
426
        models=["zai-org/GLM-4.1V-9B-Thinking"],
427
428
429
430
431
432
        # GLM4.1V require include video metadata for input
        test_type=VLMTestType.CUSTOM_INPUTS,
        max_model_len=4096,
        max_num_seqs=2,
        auto_cls=AutoModelForImageTextToText,
        patch_hf_runner=model_utils.glm4_1v_patch_hf_runner,
433
434
435
436
437
438
        custom_test_opts=[
            CustomTestOptions(
                inputs=custom_inputs.video_with_metadata_glm4_1v(),
                limit_mm_per_prompt={"video": 1},
            )
        ],
439
        marks=[large_gpu_mark(min_gb=32)],
440
    ),
441
    "h2ovl": VLMTestInfo(
442
        models=[
443
444
            os.path.join(models_path_prefix,"h2oai/h2ovl-mississippi-800m"),
            os.path.join(models_path_prefix,"h2oai/h2ovl-mississippi-2b"),
445
446
        ],
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
447
        prompt_formatter=lambda img_prompt: f"<|prompt|>{img_prompt}<|end|><|answer|>",
448
449
        single_image_prompts=IMAGE_ASSETS.prompts(
            {
450
                "stop_sign": "<image>\nWhat's the content in the center of the image?",
451
452
453
                "cherry_blossom": "<image>\nWhat is the season?",
            }
        ),
454
455
456
        multi_image_prompt="Image-1: <image>\nImage-2: <image>\nDescribe the two images in short.",  # noqa: E501
        max_model_len=8192,
        use_tokenizer_eos=True,
457
        num_logprobs=10,
458
        patch_hf_runner=model_utils.h2ovl_patch_hf_runner,
459
    ),
460
    "idefics3": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
461
        models=[os.path.join(models_path_prefix, "HuggingFaceTB/SmolVLM-256M-Instruct")],
462
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
463
        prompt_formatter=lambda img_prompt: f"<|begin_of_text|>User:{img_prompt}<end_of_utterance>\nAssistant:",  # noqa: E501
464
465
466
        img_idx_to_prompt=lambda idx: "<image>",
        max_model_len=8192,
        max_num_seqs=2,
467
        auto_cls=AutoModelForImageTextToText,
468
        hf_output_post_proc=model_utils.idefics3_trunc_hf_output,
469
    ),
470
471
    "intern_vl": VLMTestInfo(
        models=[
zhuwenwen's avatar
zhuwenwen committed
472
473
            os.path.join(models_path_prefix, "OpenGVLab/InternVL2-1B"),
            os.path.join(models_path_prefix, "OpenGVLab/InternVL2-2B"),
474
475
            # FIXME: Config cannot be loaded in transformers 4.52
            # "OpenGVLab/Mono-InternVL-2B",
476
477
        ],
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
478
479
480
        prompt_formatter=lambda img_prompt: f"<|im_start|>User\n{img_prompt}<|im_end|>\n<|im_start|>Assistant\n",  # noqa: E501
        single_image_prompts=IMAGE_ASSETS.prompts(
            {
481
                "stop_sign": "<image>\nWhat's the content in the center of the image?",
482
483
484
                "cherry_blossom": "<image>\nWhat is the season?",
            }
        ),
485
486
487
488
489
        multi_image_prompt="Image-1: <image>\nImage-2: <image>\nDescribe the two images in short.",  # noqa: E501
        max_model_len=4096,
        use_tokenizer_eos=True,
        patch_hf_runner=model_utils.internvl_patch_hf_runner,
    ),
490
491
492
493
494
    "intern_vl-video": VLMTestInfo(
        models=[
            "OpenGVLab/InternVL3-1B",
        ],
        test_type=VLMTestType.VIDEO,
495
        prompt_formatter=lambda img_prompt: f"<|im_start|>User\n{img_prompt}<|im_end|>\n<|im_start|>Assistant\n",  # noqa: E501
496
497
498
499
500
        video_idx_to_prompt=lambda idx: "<video>",
        max_model_len=8192,
        use_tokenizer_eos=True,
        patch_hf_runner=model_utils.internvl_patch_hf_runner,
    ),
501
502
503
504
505
506
507
    "intern_vl-hf": VLMTestInfo(
        models=["OpenGVLab/InternVL3-1B-hf"],
        test_type=(
            VLMTestType.IMAGE,
            VLMTestType.MULTI_IMAGE,
            VLMTestType.VIDEO,
        ),
508
        prompt_formatter=lambda img_prompt: f"<|im_start|>User\n{img_prompt}<|im_end|>\n<|im_start|>Assistant\n",  # noqa: E501
509
510
511
512
513
514
        img_idx_to_prompt=lambda idx: "<IMG_CONTEXT>",
        video_idx_to_prompt=lambda idx: "<video>",
        max_model_len=8192,
        use_tokenizer_eos=True,
        auto_cls=AutoModelForImageTextToText,
    ),
515
516
517
    "kimi_vl": VLMTestInfo(
        models=["moonshotai/Kimi-VL-A3B-Instruct"],
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
518
        prompt_formatter=lambda img_prompt: f"<|im_user|>user<|im_middle|>{img_prompt}<|im_end|><|im_assistant|>assistant<|im_middle|>",  # noqa: E501
519
520
521
522
523
524
525
526
        img_idx_to_prompt=lambda _: "<|media_start|>image<|media_content|><|media_pad|><|media_end|>",  # noqa: E501
        max_model_len=8192,
        max_num_seqs=2,
        dtype="bfloat16",
        tensor_parallel_size=1,
        vllm_output_post_proc=model_utils.kimiv_vl_vllm_to_hf_output,
        marks=[large_gpu_mark(min_gb=48)],
    ),
527
528
    "llama4": VLMTestInfo(
        models=["meta-llama/Llama-4-Scout-17B-16E-Instruct"],
529
        prompt_formatter=lambda img_prompt: f"<|begin_of_text|><|header_start|>user<|header_end|>\n\n{img_prompt}<|eot|><|header_start|>assistant<|header_end|>\n\n",  # noqa: E501
530
531
532
        img_idx_to_prompt=lambda _: "<|image|>",
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
        distributed_executor_backend="mp",
533
        image_size_factors=[(0.25, 0.5, 1.0)],
534
535
536
537
538
        hf_model_kwargs={"device_map": "auto"},
        max_model_len=8192,
        max_num_seqs=4,
        dtype="bfloat16",
        auto_cls=AutoModelForImageTextToText,
539
540
        tensor_parallel_size=4,
        marks=multi_gpu_marks(num_gpus=4),
541
    ),
542
    "llava_next": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
543
        models=[os.path.join(models_path_prefix, "llava-hf/llava-v1.6-mistral-7b-hf")],
544
545
546
        test_type=(VLMTestType.IMAGE, VLMTestType.CUSTOM_INPUTS),
        prompt_formatter=lambda img_prompt: f"[INST] {img_prompt} [/INST]",
        max_model_len=10240,
547
        auto_cls=AutoModelForImageTextToText,
548
        vllm_output_post_proc=model_utils.llava_image_vllm_to_hf_output,
549
550
551
552
553
554
555
556
        custom_test_opts=[
            CustomTestOptions(
                inputs=custom_inputs.multi_image_multi_aspect_ratio_inputs(
                    formatter=lambda img_prompt: f"[INST] {img_prompt} [/INST]"
                ),
                limit_mm_per_prompt={"image": 4},
            )
        ],
557
    ),
558
    "llava_onevision": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
559
        models=[os.path.join(models_path_prefix, "llava-hf/llava-onevision-qwen2-0.5b-ov-hf")],
560
        test_type=VLMTestType.CUSTOM_INPUTS,
561
        prompt_formatter=lambda vid_prompt: f"<|im_start|>user\n{vid_prompt}<|im_end|>\n<|im_start|>assistant\n",  # noqa: E501
562
563
        num_video_frames=16,
        max_model_len=16384,
564
565
        hf_model_kwargs=model_utils.llava_onevision_hf_model_kwargs(
            "llava-hf/llava-onevision-qwen2-0.5b-ov-hf"
566
        ),
567
        auto_cls=AutoModelForImageTextToText,
568
        vllm_output_post_proc=model_utils.llava_onevision_vllm_to_hf_output,
569
570
571
572
573
574
575
576
        custom_test_opts=[
            CustomTestOptions(
                inputs=custom_inputs.multi_video_multi_aspect_ratio_inputs(
                    formatter=lambda vid_prompt: f"<|im_start|>user\n{vid_prompt}<|im_end|>\n<|im_start|>assistant\n",  # noqa: E501
                ),
                limit_mm_per_prompt={"video": 4},
            )
        ],
577
578
    ),
    "llava_next_video": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
579
        models=[os.path.join(models_path_prefix, "llava-hf/LLaVA-NeXT-Video-7B-hf")],
580
581
582
583
        test_type=VLMTestType.VIDEO,
        prompt_formatter=lambda vid_prompt: f"USER: {vid_prompt} ASSISTANT:",
        num_video_frames=16,
        max_model_len=4096,
584
        max_num_seqs=2,
585
        auto_cls=AutoModelForImageTextToText,
586
587
        vllm_output_post_proc=model_utils.llava_video_vllm_to_hf_output,
    ),
588
    "mantis": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
589
        models=[os.path.join(models_path_prefix, "TIGER-Lab/Mantis-8B-siglip-llama3")],
590
591
592
593
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
        prompt_formatter=lambda img_prompt: f"<|start_header_id|>user<|end_header_id|>\n\n{img_prompt}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",  # noqa: E501
        max_model_len=4096,
        get_stop_token_ids=lambda tok: [128009],
594
        auto_cls=AutoModelForImageTextToText,
595
596
597
        vllm_output_post_proc=model_utils.mantis_vllm_to_hf_output,
        patch_hf_runner=model_utils.mantis_patch_hf_runner,
    ),
598
    "minicpmv_25": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
599
        models=[os.path.join(models_path_prefix, "openbmb/MiniCPM-Llama3-V-2_5")],
600
        test_type=VLMTestType.IMAGE,
601
602
603
604
605
        prompt_formatter=lambda img_prompt: f"<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\n{img_prompt}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",  # noqa: E501
        img_idx_to_prompt=lambda idx: "(<image>./</image>)\n",
        max_model_len=4096,
        max_num_seqs=2,
        get_stop_token_ids=lambda tok: [tok.eos_id, tok.eot_id],
606
        hf_output_post_proc=model_utils.minicpmv_trunc_hf_output,
607
        patch_hf_runner=model_utils.minicpmv_25_patch_hf_runner,
608
609
        # FIXME: https://huggingface.co/openbmb/MiniCPM-V-2_6/discussions/55
        marks=[pytest.mark.skip("HF import fails")],
610
    ),
611
612
613
614
615
616
617
    "minicpmo_26": VLMTestInfo(
        models=["openbmb/MiniCPM-o-2_6"],
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
        prompt_formatter=lambda img_prompt: f"<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\n{img_prompt}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",  # noqa: E501
        img_idx_to_prompt=lambda idx: "(<image>./</image>)\n",
        max_model_len=4096,
        max_num_seqs=2,
618
619
        get_stop_token_ids=lambda tok: tok.convert_tokens_to_ids(
            ["<|im_end|>", "<|endoftext|>"]
620
        ),
621
        hf_output_post_proc=model_utils.minicpmv_trunc_hf_output,
622
        patch_hf_runner=model_utils.minicpmo_26_patch_hf_runner,
623
        # FIXME: https://huggingface.co/openbmb/MiniCPM-o-2_6/discussions/49
624
        marks=[pytest.mark.skip("HF import fails")],
625
    ),
626
    "minicpmv_26": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
627
        models=[os.path.join(models_path_prefix, "openbmb/MiniCPM-V-2_6")],
628
629
630
631
632
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
        prompt_formatter=lambda img_prompt: f"<|begin_of_text|><|start_header_id|>user<|end_header_id|>\n\n{img_prompt}<|eot_id|><|start_header_id|>assistant<|end_header_id|>\n\n",  # noqa: E501
        img_idx_to_prompt=lambda idx: "(<image>./</image>)\n",
        max_model_len=4096,
        max_num_seqs=2,
633
634
        get_stop_token_ids=lambda tok: tok.convert_tokens_to_ids(
            ["<|im_end|>", "<|endoftext|>"]
635
        ),
636
        hf_output_post_proc=model_utils.minicpmv_trunc_hf_output,
637
        patch_hf_runner=model_utils.minicpmv_26_patch_hf_runner,
638
    ),
639
640
    "minimax_vl_01": VLMTestInfo(
        models=["MiniMaxAI/MiniMax-VL-01"],
641
        prompt_formatter=lambda img_prompt: f"<beginning_of_sentence>user: {img_prompt} assistant:<end_of_sentence>",  # noqa: E501
642
643
644
645
646
647
648
649
650
        img_idx_to_prompt=lambda _: "<image>",
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
        max_model_len=8192,
        max_num_seqs=4,
        dtype="bfloat16",
        hf_output_post_proc=model_utils.minimax_vl_01_hf_output,
        patch_hf_runner=model_utils.minimax_vl_01_patch_hf_runner,
        auto_cls=AutoModelForImageTextToText,
        marks=[large_gpu_mark(min_gb=80)],
651
    ),
652
653
    "molmo": VLMTestInfo(
        models=["allenai/Molmo-7B-D-0924"],
654
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
655
        prompt_formatter=identity,
656
657
        max_model_len=4096,
        max_num_seqs=2,
658
        patch_hf_runner=model_utils.molmo_patch_hf_runner,
659
    ),
660
661
662
    "ovis1_6-gemma2": VLMTestInfo(
        models=["AIDC-AI/Ovis1.6-Gemma2-9B"],
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
663
        prompt_formatter=lambda img_prompt: f"<bos><start_of_turn>user\n{img_prompt}<end_of_turn>\n<start_of_turn>model\n",  # noqa: E501
664
        img_idx_to_prompt=lambda idx: "<image>\n",
665
666
667
668
669
670
671
672
        max_model_len=4096,
        max_num_seqs=2,
        dtype="half",
        # use sdpa mode for hf runner since ovis2 didn't work with flash_attn
        hf_model_kwargs={"llm_attn_implementation": "sdpa"},
        patch_hf_runner=model_utils.ovis_patch_hf_runner,
        marks=[large_gpu_mark(min_gb=32)],
    ),
673
674
675
    "ovis2": VLMTestInfo(
        models=["AIDC-AI/Ovis2-1B"],
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
676
        prompt_formatter=lambda img_prompt: f"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n{img_prompt}<|im_end|>\n<|im_start|>assistant\n",  # noqa: E501
677
        img_idx_to_prompt=lambda idx: "<image>\n",
678
679
680
681
682
        max_model_len=4096,
        max_num_seqs=2,
        dtype="half",
        # use sdpa mode for hf runner since ovis2 didn't work with flash_attn
        hf_model_kwargs={"llm_attn_implementation": "sdpa"},
683
        patch_hf_runner=model_utils.ovis_patch_hf_runner,
684
    ),
685
686
    "ovis2_5": VLMTestInfo(
        models=["AIDC-AI/Ovis2.5-2B"],
687
688
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE, VLMTestType.VIDEO),
        prompt_formatter=lambda img_prompt: f"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n{img_prompt}<|im_end|>\n<|im_start|>assistant\n",  # noqa: E501
689
        img_idx_to_prompt=lambda idx: "<image>\n",
690
691
692
693
694
695
        video_idx_to_prompt=lambda idx: "<video>\n",
        max_model_len=4096,
        max_num_seqs=2,
        dtype="half",
        num_logprobs=10,
        patch_hf_runner=model_utils.ovis2_5_patch_hf_runner,
696
        hf_model_kwargs={"revision": "refs/pr/5"},
697
    ),
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
    "paddleocr_vl": VLMTestInfo(
        models=["PaddlePaddle/PaddleOCR-VL"],
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
        prompt_formatter=lambda img_prompt: f"USER: {img_prompt}\nASSISTANT:",
        img_idx_to_prompt=lambda idx: (
            "<|IMAGE_START|><|IMAGE_PLACEHOLDER|><|IMAGE_END|>"
        ),
        multi_image_prompt=(
            "Image-1: <|IMAGE_START|><|IMAGE_PLACEHOLDER|><|IMAGE_END|>\n"
            "Image-2: <|IMAGE_START|><|IMAGE_PLACEHOLDER|><|IMAGE_END|>\n"
            "Describe these two images separately."
        ),
        max_model_len=8192,
        max_num_seqs=2,
        auto_cls=AutoModelForCausalLM,
        image_size_factors=[(), (0.25,)],
714
715
716
717
718
719
        marks=[
            pytest.mark.skipif(
                Version(TRANSFORMERS_VERSION) == Version("4.57.3"),
                reason="This model is broken in Transformers v4.57.3",
            )
        ],
720
    ),
721
722
723
    "phi3v": VLMTestInfo(
        models=["microsoft/Phi-3.5-vision-instruct"],
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
724
        prompt_formatter=lambda img_prompt: f"<|user|>\n{img_prompt}<|end|>\n<|assistant|>\n",  # noqa: E501
725
726
727
        img_idx_to_prompt=lambda idx: f"<|image_{idx}|>\n",
        max_model_len=4096,
        max_num_seqs=2,
728
        runner="generate",
729
730
        # use sdpa mode for hf runner since phi3v didn't work with flash_attn
        hf_model_kwargs={"_attn_implementation": "sdpa"},
731
732
733
734
        use_tokenizer_eos=True,
        vllm_output_post_proc=model_utils.phi3v_vllm_to_hf_output,
        num_logprobs=10,
    ),
735
    "pixtral_hf": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
736
        models=[os.path.join(models_path_prefix, "nm-testing/pixtral-12b-FP8-dynamic")],
737
738
739
740
741
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
        prompt_formatter=lambda img_prompt: f"<s>[INST]{img_prompt}[/INST]",
        img_idx_to_prompt=lambda idx: "[IMG]",
        max_model_len=8192,
        max_num_seqs=2,
742
        auto_cls=AutoModelForImageTextToText,
743
        marks=[large_gpu_mark(min_gb=48)],
744
    ),
745
    "qwen_vl": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
746
        models=[os.path.join(models_path_prefix, "Qwen/Qwen-VL")],
747
748
749
750
751
752
753
754
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
        prompt_formatter=identity,
        img_idx_to_prompt=lambda idx: f"Picture {idx}: <img></img>\n",
        max_model_len=1024,
        max_num_seqs=2,
        vllm_output_post_proc=model_utils.qwen_vllm_to_hf_output,
        prompt_path_encoder=model_utils.qwen_prompt_path_encoder,
    ),
755
756
    "qwen2_vl": VLMTestInfo(
        models=["Qwen/Qwen2-VL-2B-Instruct"],
757
758
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE, VLMTestType.VIDEO),
        prompt_formatter=lambda img_prompt: f"<|im_start|>User\n{img_prompt}<|im_end|>\n<|im_start|>assistant\n",  # noqa: E501
759
760
        img_idx_to_prompt=lambda idx: "<|vision_start|><|image_pad|><|vision_end|>",
        video_idx_to_prompt=lambda idx: "<|vision_start|><|video_pad|><|vision_end|>",
761
        multi_image_prompt="Picture 1: <vlm_image>\nPicture 2: <vlm_image>\nDescribe these two images with one paragraph respectively.",  # noqa: E501
762
763
        max_model_len=4096,
        max_num_seqs=2,
764
        auto_cls=AutoModelForImageTextToText,
765
766
767
768
        vllm_output_post_proc=model_utils.qwen2_vllm_to_hf_output,
        image_size_factors=[(), (0.25,), (0.25, 0.25, 0.25), (0.25, 0.2, 0.15)],
        marks=[pytest.mark.cpu_model],
    ),
769
770
771
    "skywork_r1v": VLMTestInfo(
        models=["Skywork/Skywork-R1V-38B"],
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
772
773
774
        prompt_formatter=lambda img_prompt: f"<|begin▁of▁sentence|><|User|>\n{img_prompt}<|Assistant|><think>\n",  # noqa: E501
        single_image_prompts=IMAGE_ASSETS.prompts(
            {
775
                "stop_sign": "<image>\nWhat's the content in the center of the image?",
776
777
778
                "cherry_blossom": "<image>\nWhat is the season?",
            }
        ),
779
        multi_image_prompt="<image>\n<image>\nDescribe the two images in short.",
780
781
782
783
784
        max_model_len=4096,
        use_tokenizer_eos=True,
        patch_hf_runner=model_utils.skyworkr1v_patch_hf_runner,
        marks=[large_gpu_mark(min_gb=80)],
    ),
785
786
787
    "smolvlm": VLMTestInfo(
        models=["HuggingFaceTB/SmolVLM2-2.2B-Instruct"],
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
788
        prompt_formatter=lambda img_prompt: f"<|im_start|>User:{img_prompt}<end_of_utterance>\nAssistant:",  # noqa: E501
789
790
791
792
793
        img_idx_to_prompt=lambda idx: "<image>",
        max_model_len=8192,
        max_num_seqs=2,
        auto_cls=AutoModelForImageTextToText,
        hf_output_post_proc=model_utils.smolvlm_trunc_hf_output,
794
        num_logprobs=10,
795
    ),
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
    "tarsier": VLMTestInfo(
        models=["omni-research/Tarsier-7b"],
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
        prompt_formatter=lambda img_prompt: f"USER: {img_prompt} ASSISTANT:",
        max_model_len=4096,
        max_num_seqs=2,
        auto_cls=AutoModelForImageTextToText,
        patch_hf_runner=model_utils.tarsier_patch_hf_runner,
    ),
    "tarsier2": VLMTestInfo(
        models=["omni-research/Tarsier2-Recap-7b"],
        test_type=(
            VLMTestType.IMAGE,
            VLMTestType.MULTI_IMAGE,
            VLMTestType.VIDEO,
        ),
812
        prompt_formatter=lambda img_prompt: f"<|im_start|>system\nYou are a helpful assistant.<|im_end|>\n<|im_start|>user\n{img_prompt}<|im_end|>\n<|im_start|>assistant\n",  # noqa: E501
813
814
        img_idx_to_prompt=lambda idx: "<|vision_start|><|image_pad|><|vision_end|>",
        video_idx_to_prompt=lambda idx: "<|vision_start|><|video_pad|><|vision_end|>",
815
816
817
818
819
820
        max_model_len=4096,
        max_num_seqs=2,
        auto_cls=AutoModelForImageTextToText,
        image_size_factors=[(), (0.25,), (0.25, 0.25, 0.25), (0.25, 0.2, 0.15)],
        marks=[pytest.mark.skip("Model initialization hangs")],
    ),
821
    ### Tensor parallel / multi-gpu broadcast tests
822
    "chameleon-broadcast": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
823
        models=[os.path.join(models_path_prefix, "facebook/chameleon-7b")],
824
825
        prompt_formatter=lambda img_prompt: f"USER: {img_prompt}\nASSISTANT:",
        max_model_len=4096,
826
        auto_cls=AutoModelForImageTextToText,
827
828
        vllm_output_post_proc=lambda vllm_output, model: vllm_output[:2],
        hf_output_post_proc=lambda hf_output, model: hf_output[:2],
829
        comparator=check_outputs_equal,
830
        marks=multi_gpu_marks(num_gpus=2),
831
        **COMMON_BROADCAST_SETTINGS,  # type: ignore
832
    ),
833
    "llava-broadcast": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
834
        models=[os.path.join(models_path_prefix, "llava-hf/llava-1.5-7b-hf")],
835
836
        prompt_formatter=lambda img_prompt: f"USER: {img_prompt}\nASSISTANT:",
        max_model_len=4096,
837
        auto_cls=AutoModelForImageTextToText,
838
        vllm_output_post_proc=model_utils.llava_image_vllm_to_hf_output,
839
        marks=multi_gpu_marks(num_gpus=2),
840
        **COMMON_BROADCAST_SETTINGS,  # type: ignore
841
    ),
842
    "llava_next-broadcast": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
843
        models=[os.path.join(models_path_prefix, "llava-hf/llava-v1.6-mistral-7b-hf")],
844
845
        prompt_formatter=lambda img_prompt: f"[INST] {img_prompt} [/INST]",
        max_model_len=10240,
846
        auto_cls=AutoModelForImageTextToText,
847
        vllm_output_post_proc=model_utils.llava_image_vllm_to_hf_output,
848
        marks=multi_gpu_marks(num_gpus=2),
849
        **COMMON_BROADCAST_SETTINGS,  # type: ignore
850
851
852
    ),
    ### Custom input edge-cases for specific models
    "intern_vl-diff-patches": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
853
        models=[os.path.join(models_path_prefix, "OpenGVLab/InternVL2-2B")],
854
        prompt_formatter=lambda img_prompt: f"<|im_start|>User\n{img_prompt}<|im_end|>\n<|im_start|>Assistant\n",  # noqa: E501
855
856
857
858
859
860
861
862
        test_type=VLMTestType.CUSTOM_INPUTS,
        max_model_len=4096,
        use_tokenizer_eos=True,
        patch_hf_runner=model_utils.internvl_patch_hf_runner,
        custom_test_opts=[
            CustomTestOptions(
                inputs=inp,
                limit_mm_per_prompt={"image": 2},
863
864
            )
            for inp in custom_inputs.different_patch_input_cases_internvl()
865
866
        ],
    ),
867
    "llava_onevision-multiple-images": VLMTestInfo(
zhuwenwen's avatar
zhuwenwen committed
868
        models=[os.path.join(models_path_prefix, "llava-hf/llava-onevision-qwen2-0.5b-ov-hf")],
869
870
871
        test_type=VLMTestType.CUSTOM_INPUTS,
        max_model_len=16384,
        max_num_seqs=2,
872
        auto_cls=AutoModelForImageTextToText,
873
874
        hf_model_kwargs=model_utils.llava_onevision_hf_model_kwargs(
            "llava-hf/llava-onevision-qwen2-0.5b-ov-hf"
875
        ),
876
        vllm_output_post_proc=model_utils.llava_onevision_vllm_to_hf_output,
877
878
879
880
881
882
883
884
        custom_test_opts=[
            CustomTestOptions(
                inputs=custom_inputs.multi_image_multi_aspect_ratio_inputs(
                    formatter=lambda vid_prompt: f"<|im_start|>user\n{vid_prompt}<|im_end|>\n<|im_start|>assistant\n",  # noqa: E501
                ),
                limit_mm_per_prompt={"image": 4},
            )
        ],
885
886
887
888
889
890
        marks=[
            pytest.mark.skipif(
                Version(TRANSFORMERS_VERSION) == Version("4.57.1"),
                reason="This model is broken in Transformers v4.57.1",
            )
        ],
891
    ),
892
893
894
895
896
897
    # regression test for https://github.com/vllm-project/vllm/issues/15122
    "qwen2_5_vl-windows-attention": VLMTestInfo(
        models=["Qwen/Qwen2.5-VL-3B-Instruct"],
        test_type=VLMTestType.CUSTOM_INPUTS,
        max_model_len=4096,
        max_num_seqs=2,
898
        auto_cls=AutoModelForImageTextToText,
899
        vllm_output_post_proc=model_utils.qwen2_vllm_to_hf_output,
900
901
902
903
904
905
        custom_test_opts=[
            CustomTestOptions(
                inputs=custom_inputs.windows_attention_image_qwen2_5_vl(),
                limit_mm_per_prompt={"image": 1},
            )
        ],
906
    ),
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
    "llama4": VLMTestInfo(
        models=["meta-llama/Llama-4-Scout-17B-16E-Instruct"],
        prompt_formatter=lambda img_prompt: f"<|begin_of_text|><|header_start|>user<|header_end|>\n\n{img_prompt}<|eot|><|header_start|>assistant<|header_end|>\n\n", # noqa: E501
        img_idx_to_prompt=lambda _: "<|image|>",
        test_type=(VLMTestType.IMAGE, VLMTestType.MULTI_IMAGE),
        distributed_executor_backend="mp",
        image_size_factors=[(.25, 0.5, 1.0)],
        hf_model_kwargs={"device_map": "auto"},
        max_model_len=8192,
        max_num_seqs=4,
        dtype="bfloat16",
        auto_cls=AutoModelForImageTextToText,
        tensor_parallel_size=8,
        vllm_runner_kwargs={"gpu_memory_utilization": 0.8},
        marks=[large_gpu_mark(min_gb=80), multi_gpu_marks(num_gpus=8)],
    ),
923
924
925
}


926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
def _mark_splits(
    test_settings: dict[str, VLMTestInfo],
    *,
    num_groups: int,
) -> dict[str, VLMTestInfo]:
    name_by_test_info_id = {id(v): k for k, v in test_settings.items()}
    test_infos_by_model = defaultdict[str, list[VLMTestInfo]](list)

    for info in test_settings.values():
        for model in info.models:
            test_infos_by_model[model].append(info)

    models = sorted(test_infos_by_model.keys())
    split_size = math.ceil(len(models) / num_groups)

    new_test_settings = dict[str, VLMTestInfo]()

    for i in range(num_groups):
944
        models_in_group = models[i * split_size : (i + 1) * split_size]
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960

        for model in models_in_group:
            for info in test_infos_by_model[model]:
                new_marks = (info.marks or []) + [pytest.mark.split(group=i)]
                new_info = info._replace(marks=new_marks)
                new_test_settings[name_by_test_info_id[id(info)]] = new_info

    missing_keys = test_settings.keys() - new_test_settings.keys()
    assert not missing_keys, f"Missing keys: {missing_keys}"

    return new_test_settings


VLM_TEST_SETTINGS = _mark_splits(VLM_TEST_SETTINGS, num_groups=2)


961
962
963
964
965
966
### Test wrappers
# Wrappers around the core test running func for:
# - single image
# - multi-image
# - image embeddings
# - video
967
# - audio
968
# - custom inputs
969
970
971
972
973
@pytest.mark.parametrize(
    "model_type,test_case",
    get_parametrized_options(
        VLM_TEST_SETTINGS,
        test_type=VLMTestType.IMAGE,
974
        create_new_process_for_each_test=False,
975
976
    ),
)
977
978
979
980
981
982
983
984
def test_single_image_models(
    tmp_path: PosixPath,
    model_type: str,
    test_case: ExpandableVLMTestArgs,
    hf_runner: type[HfRunner],
    vllm_runner: type[VllmRunner],
    image_assets: ImageTestAssets,
):
985
986
987
988
989
990
991
992
993
994
995
    model_test_info = VLM_TEST_SETTINGS[model_type]
    runners.run_single_image_test(
        tmp_path=tmp_path,
        model_test_info=model_test_info,
        test_case=test_case,
        hf_runner=hf_runner,
        vllm_runner=vllm_runner,
        image_assets=image_assets,
    )


996
997
998
999
1000
@pytest.mark.parametrize(
    "model_type,test_case",
    get_parametrized_options(
        VLM_TEST_SETTINGS,
        test_type=VLMTestType.MULTI_IMAGE,
1001
        create_new_process_for_each_test=False,
1002
1003
    ),
)
1004
1005
1006
1007
1008
1009
1010
1011
def test_multi_image_models(
    tmp_path: PosixPath,
    model_type: str,
    test_case: ExpandableVLMTestArgs,
    hf_runner: type[HfRunner],
    vllm_runner: type[VllmRunner],
    image_assets: ImageTestAssets,
):
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
    model_test_info = VLM_TEST_SETTINGS[model_type]
    runners.run_multi_image_test(
        tmp_path=tmp_path,
        model_test_info=model_test_info,
        test_case=test_case,
        hf_runner=hf_runner,
        vllm_runner=vllm_runner,
        image_assets=image_assets,
    )


1023
1024
1025
1026
1027
@pytest.mark.parametrize(
    "model_type,test_case",
    get_parametrized_options(
        VLM_TEST_SETTINGS,
        test_type=VLMTestType.EMBEDDING,
1028
        create_new_process_for_each_test=False,
1029
1030
    ),
)
1031
1032
1033
1034
1035
1036
1037
def test_image_embedding_models(
    model_type: str,
    test_case: ExpandableVLMTestArgs,
    hf_runner: type[HfRunner],
    vllm_runner: type[VllmRunner],
    image_assets: ImageTestAssets,
):
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
    model_test_info = VLM_TEST_SETTINGS[model_type]
    runners.run_embedding_test(
        model_test_info=model_test_info,
        test_case=test_case,
        hf_runner=hf_runner,
        vllm_runner=vllm_runner,
        image_assets=image_assets,
    )


1048
1049
1050
1051
1052
@pytest.mark.parametrize(
    "model_type,test_case",
    get_parametrized_options(
        VLM_TEST_SETTINGS,
        test_type=VLMTestType.VIDEO,
1053
        create_new_process_for_each_test=False,
1054
1055
    ),
)
1056
1057
1058
1059
1060
1061
1062
def test_video_models(
    model_type: str,
    test_case: ExpandableVLMTestArgs,
    hf_runner: type[HfRunner],
    vllm_runner: type[VllmRunner],
    video_assets: VideoTestAssets,
):
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
    model_test_info = VLM_TEST_SETTINGS[model_type]
    runners.run_video_test(
        model_test_info=model_test_info,
        test_case=test_case,
        hf_runner=hf_runner,
        vllm_runner=vllm_runner,
        video_assets=video_assets,
    )


1073
1074
1075
1076
1077
1078
@pytest.mark.parametrize(
    "model_type,test_case",
    get_parametrized_options(
        VLM_TEST_SETTINGS,
        test_type=VLMTestType.AUDIO,
        create_new_process_for_each_test=False,
1079
1080
    ),
)
1081
1082
1083
1084
1085
1086
1087
def test_audio_models(
    model_type: str,
    test_case: ExpandableVLMTestArgs,
    hf_runner: type[HfRunner],
    vllm_runner: type[VllmRunner],
    audio_assets: AudioTestAssets,
):
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
    model_test_info = VLM_TEST_SETTINGS[model_type]
    runners.run_audio_test(
        model_test_info=model_test_info,
        test_case=test_case,
        hf_runner=hf_runner,
        vllm_runner=vllm_runner,
        audio_assets=audio_assets,
    )


1098
1099
1100
1101
1102
@pytest.mark.parametrize(
    "model_type,test_case",
    get_parametrized_options(
        VLM_TEST_SETTINGS,
        test_type=VLMTestType.CUSTOM_INPUTS,
1103
        create_new_process_for_each_test=False,
1104
1105
    ),
)
1106
1107
1108
def test_custom_inputs_models(
    model_type: str,
    test_case: ExpandableVLMTestArgs,
1109
1110
    hf_runner: type[HfRunner],
    vllm_runner: type[VllmRunner],
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
):
    model_test_info = VLM_TEST_SETTINGS[model_type]
    runners.run_custom_inputs_test(
        model_test_info=model_test_info,
        test_case=test_case,
        hf_runner=hf_runner,
        vllm_runner=vllm_runner,
    )


#### Tests filtering for things running each test as a new process
1122
1123
1124
1125
1126
@pytest.mark.parametrize(
    "model_type,test_case",
    get_parametrized_options(
        VLM_TEST_SETTINGS,
        test_type=VLMTestType.IMAGE,
1127
        create_new_process_for_each_test=True,
1128
1129
    ),
)
1130
@create_new_process_for_each_test()
1131
1132
1133
1134
1135
1136
1137
1138
def test_single_image_models_heavy(
    tmp_path: PosixPath,
    model_type: str,
    test_case: ExpandableVLMTestArgs,
    hf_runner: type[HfRunner],
    vllm_runner: type[VllmRunner],
    image_assets: ImageTestAssets,
):
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
    model_test_info = VLM_TEST_SETTINGS[model_type]
    runners.run_single_image_test(
        tmp_path=tmp_path,
        model_test_info=model_test_info,
        test_case=test_case,
        hf_runner=hf_runner,
        vllm_runner=vllm_runner,
        image_assets=image_assets,
    )


1150
1151
1152
1153
1154
@pytest.mark.parametrize(
    "model_type,test_case",
    get_parametrized_options(
        VLM_TEST_SETTINGS,
        test_type=VLMTestType.MULTI_IMAGE,
1155
        create_new_process_for_each_test=True,
1156
1157
    ),
)
1158
@create_new_process_for_each_test()
1159
1160
1161
1162
1163
1164
1165
1166
def test_multi_image_models_heavy(
    tmp_path: PosixPath,
    model_type: str,
    test_case: ExpandableVLMTestArgs,
    hf_runner: type[HfRunner],
    vllm_runner: type[VllmRunner],
    image_assets: ImageTestAssets,
):
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
    model_test_info = VLM_TEST_SETTINGS[model_type]
    runners.run_multi_image_test(
        tmp_path=tmp_path,
        model_test_info=model_test_info,
        test_case=test_case,
        hf_runner=hf_runner,
        vllm_runner=vllm_runner,
        image_assets=image_assets,
    )


1178
1179
1180
1181
1182
@pytest.mark.parametrize(
    "model_type,test_case",
    get_parametrized_options(
        VLM_TEST_SETTINGS,
        test_type=VLMTestType.EMBEDDING,
1183
        create_new_process_for_each_test=True,
1184
1185
    ),
)
1186
@create_new_process_for_each_test()
1187
1188
1189
1190
1191
1192
1193
def test_image_embedding_models_heavy(
    model_type: str,
    test_case: ExpandableVLMTestArgs,
    hf_runner: type[HfRunner],
    vllm_runner: type[VllmRunner],
    image_assets: ImageTestAssets,
):
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
    model_test_info = VLM_TEST_SETTINGS[model_type]
    runners.run_embedding_test(
        model_test_info=model_test_info,
        test_case=test_case,
        hf_runner=hf_runner,
        vllm_runner=vllm_runner,
        image_assets=image_assets,
    )


1204
1205
1206
1207
1208
@pytest.mark.parametrize(
    "model_type,test_case",
    get_parametrized_options(
        VLM_TEST_SETTINGS,
        test_type=VLMTestType.VIDEO,
1209
        create_new_process_for_each_test=True,
1210
1211
    ),
)
1212
1213
1214
1215
1216
1217
1218
def test_video_models_heavy(
    model_type: str,
    test_case: ExpandableVLMTestArgs,
    hf_runner: type[HfRunner],
    vllm_runner: type[VllmRunner],
    video_assets: VideoTestAssets,
):
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
    model_test_info = VLM_TEST_SETTINGS[model_type]
    runners.run_video_test(
        model_test_info=model_test_info,
        test_case=test_case,
        hf_runner=hf_runner,
        vllm_runner=vllm_runner,
        video_assets=video_assets,
    )


1229
1230
1231
1232
1233
1234
@pytest.mark.parametrize(
    "model_type,test_case",
    get_parametrized_options(
        VLM_TEST_SETTINGS,
        test_type=VLMTestType.AUDIO,
        create_new_process_for_each_test=True,
1235
1236
    ),
)
1237
1238
1239
1240
1241
1242
1243
def test_audio_models_heavy(
    model_type: str,
    test_case: ExpandableVLMTestArgs,
    hf_runner: type[HfRunner],
    vllm_runner: type[VllmRunner],
    audio_assets: AudioTestAssets,
):
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
    model_test_info = VLM_TEST_SETTINGS[model_type]
    runners.run_audio_test(
        model_test_info=model_test_info,
        test_case=test_case,
        hf_runner=hf_runner,
        vllm_runner=vllm_runner,
        audio_assets=audio_assets,
    )


1254
1255
1256
1257
1258
@pytest.mark.parametrize(
    "model_type,test_case",
    get_parametrized_options(
        VLM_TEST_SETTINGS,
        test_type=VLMTestType.CUSTOM_INPUTS,
1259
        create_new_process_for_each_test=True,
1260
1261
    ),
)
1262
@create_new_process_for_each_test()
1263
1264
1265
def test_custom_inputs_models_heavy(
    model_type: str,
    test_case: ExpandableVLMTestArgs,
1266
1267
    hf_runner: type[HfRunner],
    vllm_runner: type[VllmRunner],
1268
1269
1270
1271
1272
1273
1274
1275
):
    model_test_info = VLM_TEST_SETTINGS[model_type]
    runners.run_custom_inputs_test(
        model_test_info=model_test_info,
        test_case=test_case,
        hf_runner=hf_runner,
        vllm_runner=vllm_runner,
    )