[ROCm][CI] Fix failure in the Phi3V pooling test (#44028)
Signed-off-by: Andreas Karatzas <akaratza@amd.com>
This commit is contained in:
@@ -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<s><|user|>\n <|image_1|>\n\t <s>"
|
||||
"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<s><|user|>\n <|image_1|>\n\t <s>"
|
||||
"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
|
||||
|
||||
Reference in New Issue
Block a user