2025-02-02 14:58:18 -05:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
2025-06-03 11:20:17 -07:00
|
|
|
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
2025-02-02 14:58:18 -05:00
|
|
|
|
2024-05-29 04:29:31 +08:00
|
|
|
import pytest
|
|
|
|
|
|
2025-12-07 16:00:22 +08:00
|
|
|
from vllm.config import ModelConfig
|
2024-10-08 08:12:56 -06:00
|
|
|
from vllm.inputs import zip_enc_dec_prompts
|
2025-10-05 18:10:20 +08:00
|
|
|
from vllm.inputs.preprocess import InputPreprocessor
|
2024-05-29 04:29:31 +08:00
|
|
|
|
2025-09-30 09:45:20 -04:00
|
|
|
pytestmark = pytest.mark.cpu_test
|
|
|
|
|
|
2024-10-08 08:12:56 -06:00
|
|
|
|
2025-10-05 17:18:11 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"mm_processor_kwargs,expected_mm_kwargs",
|
|
|
|
|
[
|
|
|
|
|
(None, [{}, {}]),
|
|
|
|
|
({}, [{}, {}]),
|
|
|
|
|
({"foo": 100}, [{"foo": 100}, {"foo": 100}]),
|
|
|
|
|
([{"foo": 100}, {"bar": 200}], [{"foo": 100}, {"bar": 200}]),
|
|
|
|
|
],
|
|
|
|
|
)
|
2024-10-08 08:12:56 -06:00
|
|
|
def test_zip_enc_dec_prompts(mm_processor_kwargs, expected_mm_kwargs):
|
|
|
|
|
"""Test mm_processor_kwargs init for zipping enc/dec prompts."""
|
2025-10-05 17:18:11 +01:00
|
|
|
encoder_prompts = ["An encoder prompt", "Another encoder prompt"]
|
|
|
|
|
decoder_prompts = ["A decoder prompt", "Another decoder prompt"]
|
|
|
|
|
zipped_prompts = zip_enc_dec_prompts(
|
|
|
|
|
encoder_prompts, decoder_prompts, mm_processor_kwargs
|
|
|
|
|
)
|
2024-10-08 08:12:56 -06:00
|
|
|
assert len(zipped_prompts) == len(encoder_prompts) == len(decoder_prompts)
|
2025-10-05 17:18:11 +01:00
|
|
|
for enc, dec, exp_kwargs, zipped in zip(
|
|
|
|
|
encoder_prompts, decoder_prompts, expected_mm_kwargs, zipped_prompts
|
|
|
|
|
):
|
2024-10-08 08:12:56 -06:00
|
|
|
assert isinstance(zipped, dict)
|
|
|
|
|
assert len(zipped.keys()) == 3
|
2025-10-05 17:18:11 +01:00
|
|
|
assert zipped["encoder_prompt"] == enc
|
|
|
|
|
assert zipped["decoder_prompt"] == dec
|
|
|
|
|
assert zipped["mm_processor_kwargs"] == exp_kwargs
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"model_id",
|
|
|
|
|
[
|
|
|
|
|
"facebook/chameleon-7b",
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"prompt",
|
|
|
|
|
[
|
|
|
|
|
"",
|
|
|
|
|
{"prompt_token_ids": []},
|
|
|
|
|
],
|
|
|
|
|
)
|
2025-11-17 06:49:25 -08:00
|
|
|
@pytest.mark.skip(
|
|
|
|
|
reason=(
|
|
|
|
|
"Applying huggingface processor on text inputs results in "
|
|
|
|
|
"significant performance regression for multimodal models. "
|
|
|
|
|
"See https://github.com/vllm-project/vllm/issues/26320"
|
|
|
|
|
)
|
|
|
|
|
)
|
2025-10-05 18:10:20 +08:00
|
|
|
def test_preprocessor_always_mm_code_path(model_id, prompt):
|
|
|
|
|
model_config = ModelConfig(model=model_id)
|
2026-01-22 20:44:22 +08:00
|
|
|
input_preprocessor = InputPreprocessor(model_config)
|
2025-10-05 18:10:20 +08:00
|
|
|
|
|
|
|
|
# HF processor adds sep token
|
2026-01-22 20:44:22 +08:00
|
|
|
tokenizer = input_preprocessor.get_tokenizer()
|
2025-10-05 18:10:20 +08:00
|
|
|
sep_token_id = tokenizer.vocab[tokenizer.sep_token]
|
|
|
|
|
|
|
|
|
|
processed_inputs = input_preprocessor.preprocess(prompt)
|
|
|
|
|
assert sep_token_id in processed_inputs["prompt_token_ids"]
|