Skip to content

Commit

Permalink
[Bugfix] Fix Phi-3v crash when input images are of certain sizes (vll…
Browse files Browse the repository at this point in the history
  • Loading branch information
zifeitong authored Aug 25, 2024
1 parent 64343b7 commit 870f91a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
27 changes: 22 additions & 5 deletions tests/models/test_phi3v.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
from typing import List, Optional, Tuple, Type

import pytest
from PIL import Image
from transformers import AutoTokenizer

from vllm.multimodal.utils import rescale_image_size
from vllm.sequence import SampleLogprobs
from vllm.utils import is_cpu, is_hip

from ..conftest import IMAGE_ASSETS, HfRunner, VllmRunner, _ImageAssets
from ..conftest import IMAGE_ASSETS, HfRunner, VllmRunner
from .utils import check_logprobs_close

pytestmark = pytest.mark.vlm
Expand Down Expand Up @@ -58,7 +59,7 @@ def vllm_to_hf_output(vllm_output: Tuple[List[int], str,
def run_test(
hf_runner: Type[HfRunner],
vllm_runner: Type[VllmRunner],
image_assets: _ImageAssets,
images: List[Image.Image],
model: str,
*,
size_factors: List[float],
Expand All @@ -77,8 +78,6 @@ def run_test(
Note, the text input is also adjusted to abide by vllm contract.
The text output is sanitized to be able to compare with hf.
"""
images = [asset.pil_image for asset in image_assets]

inputs_per_image = [(
[prompt for _ in size_factors],
[
Expand Down Expand Up @@ -159,11 +158,29 @@ def test_models(hf_runner, vllm_runner, image_assets, model, size_factors,
run_test(
hf_runner,
vllm_runner,
image_assets,
[asset.pil_image for asset in image_assets],
model,
size_factors=size_factors,
dtype=dtype,
max_tokens=max_tokens,
num_logprobs=num_logprobs,
tensor_parallel_size=1,
)


@pytest.mark.parametrize("model", models)
@pytest.mark.parametrize("dtype", [target_dtype])
def test_regression_7840(hf_runner, vllm_runner, image_assets, model,
dtype) -> None:
# Regression test for #7840.
run_test(
hf_runner,
vllm_runner,
[image_assets[0].pil_image.resize((465, 226))],
model,
size_factors=[1.0],
dtype=dtype,
max_tokens=128,
num_logprobs=10,
tensor_parallel_size=1,
)
2 changes: 0 additions & 2 deletions vllm/model_executor/models/phi3v.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,6 @@ def input_processor_for_phi3v(ctx: InputContext, llm_inputs: LLMInputs):
image_data = multi_modal_data["image"]
if isinstance(image_data, Image.Image):
w, h = image_data.size
w, h = _calc_hd_transform_size(width=w, height=h)

image_feature_size = get_phi3v_image_feature_size(hf_config,
input_width=w,
input_height=h)
Expand Down

0 comments on commit 870f91a

Please sign in to comment.