From ef8840adc73bfbe3108811cebcd8af7252f9b6f0 Mon Sep 17 00:00:00 2001 From: Andreas Karatzas Date: Fri, 29 May 2026 23:14:37 -0500 Subject: [PATCH] [ROCm][CI] Fix failure in the Phi3V pooling test (#44028) Signed-off-by: Andreas Karatzas --- tests/models/multimodal/pooling/test_phi3v.py | 72 +++++++++++++++---- 1 file changed, 59 insertions(+), 13 deletions(-) diff --git a/tests/models/multimodal/pooling/test_phi3v.py b/tests/models/multimodal/pooling/test_phi3v.py index 2794b0b293..285ded375d 100644 --- a/tests/models/multimodal/pooling/test_phi3v.py +++ b/tests/models/multimodal/pooling/test_phi3v.py @@ -8,6 +8,8 @@ from PIL import Image from vllm.assets.base import get_vllm_public_assets from vllm.assets.image import VLM_IMAGES_DIR +from vllm.config import ModelConfig +from vllm.multimodal import MULTIMODAL_REGISTRY from ....conftest import IMAGE_ASSETS, HfRunner, PromptImageInput, VllmRunner from ....utils import large_gpu_test @@ -37,6 +39,18 @@ HF_IMAGE_PROMPTS = IMAGE_ASSETS.prompts( MODELS = ["TIGER-Lab/VLM2Vec-Full"] +SPECIAL_TOKEN_IMAGE_PROMPT = ( + "\n<|user|>\n <|image_1|>\n\t " + "Represent the given image for classification<|end|>" + "\n<|assistant|>\n" +) + + +def _get_cherry_blossom_image() -> Image.Image: + return Image.open( + get_vllm_public_assets(filename="cherry_blossom.jpg", s3_prefix=VLM_IMAGES_DIR) + ) + def _run_test( hf_runner: type[HfRunner], @@ -123,19 +137,6 @@ def test_models_image( input_texts_images = [ (text, asset.pil_image) for text, asset in zip(HF_IMAGE_PROMPTS, image_assets) ] - # add cases for special_tokens - input_texts_images.append( - ( - "\n<|user|>\n <|image_1|>\n\t " - "Represent the given image for classification<|end|>" - "\n<|assistant|>\n", - Image.open( - get_vllm_public_assets( - filename="cherry_blossom.jpg", s3_prefix=VLM_IMAGES_DIR - ) - ), - ) - ) input_texts = [text for text, _ in input_texts_images] input_images = [image for _, image in input_texts_images] @@ -147,3 +148,48 @@ def test_models_image( model, dtype=dtype, ) + + +@pytest.mark.core_model +@pytest.mark.parametrize("model", MODELS) +@pytest.mark.parametrize("dtype", ["half"]) +def test_models_image_special_tokens_processing( + model: str, + dtype: str, +) -> None: + model_config = ModelConfig( + model, + runner="pooling", + trust_remote_code=True, + dtype=dtype, + max_model_len=1024, + ) + processor = MULTIMODAL_REGISTRY.create_processor(model_config) + image = _get_cherry_blossom_image() + + processed_inputs = processor( + SPECIAL_TOKEN_IMAGE_PROMPT, + mm_items=processor.info.parse_mm_data({"image": image}), + hf_processor_mm_kwargs={}, + ) + + hf_processor = processor.info.get_hf_processor() + hf_inputs = hf_processor( + SPECIAL_TOKEN_IMAGE_PROMPT, + images=image, + return_tensors="pt", + ) + + image_token_id = hf_processor.get_special_image_token_id() + hf_prompt_token_ids = [ + image_token_id if token_id < 0 else token_id + for token_id in hf_inputs["input_ids"][0].tolist() + ] + + prompt_token_ids = processed_inputs["prompt_token_ids"] + + assert prompt_token_ids == hf_prompt_token_ids + assert prompt_token_ids.count(image_token_id) == hf_prompt_token_ids.count( + image_token_id + ) + assert prompt_token_ids.count(image_token_id) > 0