# SPDX-License-Identifier: Apache-2.0 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project import pytest from vllm.assets.image import ImageAsset from vllm.assets.video import VideoAsset from vllm.config import CacheConfig, DeviceConfig, ModelConfig, VllmConfig from vllm.sampling_params import SamplingParams from vllm.v1.engine import processor as processor_mod from vllm.v1.engine.processor import Processor cherry_pil_image = ImageAsset("cherry_blossom").pil_image stop_pil_image = ImageAsset("stop_sign").pil_image baby_reading_np_ndarrays = VideoAsset("baby_reading").np_ndarrays # Mock processor for testing def _mk_processor( monkeypatch, *, mm_cache_gb: float = 4.0, enable_prefix_caching: bool = True ) -> Processor: """ Create a Processor instance with minimal configuration suitable for unit tests without accessing external resources. """ monkeypatch.setattr( ModelConfig, "try_get_generation_config", lambda self: {}, raising=True ) monkeypatch.setattr( ModelConfig, "__post_init__", lambda self, *args: None, raising=True ) monkeypatch.setattr( ModelConfig, "verify_with_parallel_config", lambda self, parallel_config: None, raising=True, ) monkeypatch.setattr( processor_mod, "processor_cache_from_config", lambda vllm_config, mm_registry: None, raising=True, ) monkeypatch.setattr(VllmConfig, "__post_init__", lambda self: None, raising=True) model_config = ModelConfig( skip_tokenizer_init=True, max_model_len=128, mm_processor_cache_gb=mm_cache_gb, generation_config="vllm", tokenizer="dummy", ) # Minimal multimodal_config to satisfy references in # Processor.process_inputs. class _MockMMConfig: def __init__(self, gb: float): self.mm_processor_cache_gb = gb model_config.multimodal_config = _MockMMConfig(mm_cache_gb) # type: ignore[attr-defined] vllm_config = VllmConfig( model_config=model_config, cache_config=CacheConfig(enable_prefix_caching=enable_prefix_caching), device_config=DeviceConfig(device="cpu"), ) return Processor(vllm_config, tokenizer=None) def test_multi_modal_uuids_length_mismatch_raises(monkeypatch): processor = _mk_processor(monkeypatch) prompt = { "prompt": "USER: \nDescribe\nASSISTANT:", "multi_modal_data": {"image": [cherry_pil_image, stop_pil_image]}, # Mismatch: 2 items but only 1 uuid provided "multi_modal_uuids": {"image": ["hash_cherry"]}, } with pytest.raises(ValueError, match="must have same length as data"): processor.process_inputs( request_id="req-1", prompt=prompt, # type: ignore[arg-type] params=SamplingParams(), ) def test_multi_modal_uuids_missing_modality_raises(monkeypatch): processor = _mk_processor(monkeypatch) prompt = { "prompt": "USER: