-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
[V1] Support interleaved modality items #15605
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
6ed8235
add
ywang96 2b0cffa
update test
ywang96 7d82cba
fix test
ywang96 68bf391
update test
ywang96 5d3b9a6
fix test
ywang96 240bdb4
mypy
ywang96 5bb5646
mypy
ywang96 429a06c
simplify
ywang96 07325c9
add test
ywang96 2f1228e
add mixed-modality test runner
ywang96 92ab8dd
add simple test
ywang96 d18eb2d
add to standard test
ywang96 f8f0efd
comment
ywang96 937c036
Merge branch 'main' into v1-interleaved
ywang96 98e4163
simplify
ywang96 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
tests/models/decoder_only/vision_language/test_interleaved.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
|
||
from vllm.assets.image import ImageAsset | ||
from vllm.assets.video import VideoAsset | ||
|
||
models = ["llava-hf/llava-onevision-qwen2-0.5b-ov-hf"] | ||
|
||
|
||
def base_prompt(modalities_str: str) -> str: | ||
return f"<|im_start|>user {modalities_str}\nDescribe what you see from these items.<|im_end|><|im_start|>assistant\n" # noqa: E501 | ||
|
||
|
||
INTERLEAVED_PROMPT = base_prompt("<image><video><image>\n") | ||
NONINTERLEAVED_PROMPT = base_prompt("<image><image><video>\n") | ||
|
||
|
||
@pytest.mark.parametrize("model", models) | ||
@pytest.mark.parametrize("dtype", ["float16"]) | ||
@pytest.mark.parametrize("max_tokens", [128]) | ||
def test_models(vllm_runner, model, dtype: str, max_tokens: int) -> None: | ||
""" | ||
This is a simple test to check if interleaved and non-interleaved prompts | ||
give the same result. | ||
""" | ||
|
||
image_cherry = ImageAsset("cherry_blossom").pil_image.convert("RGB") | ||
image_stop = ImageAsset("stop_sign").pil_image.convert("RGB") | ||
images = [image_cherry, image_stop] | ||
video = VideoAsset(name="sample_demo_1.mp4", num_frames=16).np_ndarrays | ||
|
||
inputs = [ | ||
( | ||
[INTERLEAVED_PROMPT], | ||
[images], | ||
[video], | ||
), | ||
( | ||
[NONINTERLEAVED_PROMPT], | ||
[images], | ||
[video], | ||
), | ||
] | ||
|
||
with vllm_runner(model, | ||
task="generate", | ||
dtype=dtype, | ||
limit_mm_per_prompt={"image": 2}, | ||
max_model_len=32768, | ||
max_num_seqs=2, | ||
tensor_parallel_size=1, | ||
enforce_eager=True) as vllm_model: | ||
vllm_outputs_per_case = [ | ||
vllm_model.generate_greedy(prompts, | ||
max_tokens, | ||
images=images, | ||
videos=videos) | ||
for prompts, images, videos in inputs | ||
] | ||
|
||
all_results = [output[0][1] for output in vllm_outputs_per_case] | ||
outputs = [(total_str, total_str.find("assistant\n") + len("assistant\n")) | ||
for total_str in all_results] | ||
prompt_lengths = [prompt_len for _, prompt_len in outputs] | ||
generated_strs = [ | ||
total_str[prompt_len:] for total_str, prompt_len in outputs | ||
] | ||
interleaved_prompt_len, noninterleaved_prompt_len = prompt_lengths | ||
interleaved_output_str, noninterleaved_output_str = generated_strs | ||
|
||
# The two prompts are identical except for the order of modality tokens. | ||
assert interleaved_prompt_len == noninterleaved_prompt_len | ||
|
||
# The two generated strings should be different because of the | ||
# interleaved modality tokens. | ||
assert interleaved_output_str != noninterleaved_output_str |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.