-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
[VLM] Merged multi-modal processors for LLaVA-NeXT-Video and LLaVA-OneVision #11717
Merged
DarkLight1337
merged 19 commits into
vllm-project:main
from
DarkLight1337:llava-processors
Jan 4, 2025
+1,114
−983
Merged
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
8bb3080
Merged multi-modal processor for llava-next-video
DarkLight1337 d6c4fd5
Merged multi-modal processor for LLaVA-OneVision
DarkLight1337 0f54d72
Fix error when list of floats is passed
DarkLight1337 6590bd5
Move and update tests
DarkLight1337 3a1bf12
Fix lint errors
DarkLight1337 95339d6
Fix failing tests
DarkLight1337 b5020c2
Rename `_find_placeholders`
DarkLight1337 347f718
More precise profiling
DarkLight1337 d0d5078
Fix llava-onevision prompt replacement
DarkLight1337 5e32fa8
Avoid having empty videos
DarkLight1337 814036d
Fix
DarkLight1337 fb5126d
Merge branch 'main' into llava-processors
DarkLight1337 ea6b7b4
Fix processor tests
DarkLight1337 4d651df
Fix video profiling
DarkLight1337 0899dce
Move out validation logic
DarkLight1337 12e5a9a
Rename `_get_dummy_mm_inputs`
DarkLight1337 0d7b328
Avoid error when dummy data is too long
DarkLight1337 8cf61f4
Avoid having zero frames
DarkLight1337 f7c9f2a
Remove test as chunked prefill will be on by default in V1
DarkLight1337 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
58 changes: 58 additions & 0 deletions
58
tests/models/decoder_only/vision_language/processing/test_llava_next.py
This file contains 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,58 @@ | ||
import pytest | ||
from PIL import Image | ||
from transformers import AutoTokenizer | ||
|
||
from vllm.inputs import InputProcessingContext | ||
|
||
from ....utils import build_model_context | ||
|
||
|
||
# Fixtures lazy import to avoid initializing CUDA during test collection | ||
@pytest.fixture() | ||
def processor_for_llava_next(): | ||
from vllm.model_executor.models.llava_next import ( | ||
LlavaNextMultiModalProcessor) | ||
return LlavaNextMultiModalProcessor | ||
|
||
|
||
# FIXME: image_size [(198, 176), (176, 198)] | ||
@pytest.mark.parametrize("model_id", ["llava-hf/llava-v1.6-mistral-7b-hf"]) | ||
@pytest.mark.parametrize("image_size", [(1669, 2560), (2560, 1669), (183, 488), | ||
(488, 183)]) | ||
@pytest.mark.parametrize("num_imgs", [1, 2]) | ||
def test_processor_prompt_replacements( | ||
processor_for_llava_next, | ||
model_id: str, | ||
image_size: tuple[int, int], | ||
num_imgs: int, | ||
): | ||
""" | ||
Ensure LlavaNextMultiModalProcessor handles prompt replacement properly. | ||
""" | ||
ctx = build_model_context( | ||
model_name=model_id, | ||
tokenizer_name=model_id, | ||
mm_processor_kwargs=None, | ||
limit_mm_per_prompt={"image": num_imgs}, | ||
) | ||
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True) | ||
ctx = InputProcessingContext(ctx.model_config, tokenizer) | ||
|
||
# Build the image str / prompt based on the number of images we pass | ||
prompt = "<image>" * num_imgs | ||
mm_data = {"image": [Image.new("RGB", size=image_size)] * num_imgs} | ||
|
||
# The processor will throw an error if there is a mismatch | ||
# in the prompt replacements | ||
processor = processor_for_llava_next(ctx) | ||
processed_inputs = processor.apply(prompt, mm_data, {}) | ||
|
||
image_placeholders = processed_inputs["mm_placeholders"]["image"] | ||
assert len(image_placeholders) == num_imgs | ||
|
||
first_placeholder = image_placeholders[0] | ||
|
||
# NOTE: There is a BOS token | ||
assert first_placeholder["offset"] == 1 | ||
assert first_placeholder["length"] + 1 == len( | ||
processed_inputs["prompt_token_ids"]) // num_imgs |
59 changes: 59 additions & 0 deletions
59
tests/models/decoder_only/vision_language/processing/test_llava_onevision.py
This file contains 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,59 @@ | ||
import pytest | ||
from PIL import Image | ||
from transformers import AutoTokenizer | ||
|
||
from vllm.inputs import InputProcessingContext | ||
|
||
from ....utils import build_model_context | ||
|
||
|
||
# Fixtures lazy import to avoid initializing CUDA during test collection | ||
@pytest.fixture() | ||
def processor_for_llava_onevision(): | ||
from vllm.model_executor.models.llava_onevision import ( | ||
LlavaOnevisionMultiModalProcessor) | ||
return LlavaOnevisionMultiModalProcessor | ||
|
||
|
||
@pytest.mark.parametrize("model_id", | ||
["llava-hf/llava-onevision-qwen2-0.5b-ov-hf"]) | ||
@pytest.mark.parametrize("image_size", [(1669, 2560), (2560, 1669), (183, 488), | ||
(488, 183), (198, 176), (176, 198)]) | ||
@pytest.mark.parametrize("num_imgs", [1, 2]) | ||
def test_processor_prompt_replacements( | ||
processor_for_llava_onevision, | ||
model_id: str, | ||
image_size: tuple[int, int], | ||
num_imgs: int, | ||
): | ||
""" | ||
Ensure LlavaOnevisionMultiModalProcessor handles prompt replacement | ||
properly. | ||
""" | ||
ctx = build_model_context( | ||
model_name=model_id, | ||
tokenizer_name=model_id, | ||
mm_processor_kwargs=None, | ||
limit_mm_per_prompt={"image": num_imgs}, | ||
) | ||
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True) | ||
ctx = InputProcessingContext(ctx.model_config, tokenizer) | ||
|
||
# Build the image str / prompt based on the number of images we pass | ||
prompt = "<image>" * num_imgs | ||
mm_data = {"image": [Image.new("RGB", size=image_size)] * num_imgs} | ||
|
||
# The processor will throw an error if there is a mismatch | ||
# in the prompt replacements | ||
processor = processor_for_llava_onevision(ctx) | ||
processed_inputs = processor.apply(prompt, mm_data, {}) | ||
|
||
image_placeholders = processed_inputs["mm_placeholders"]["image"] | ||
assert len(image_placeholders) == num_imgs | ||
|
||
first_placeholder = image_placeholders[0] | ||
|
||
# NOTE: There is a BOS token | ||
assert first_placeholder["offset"] == 1 | ||
assert first_placeholder["length"] + 1 == len( | ||
processed_inputs["prompt_token_ids"]) // num_imgs |
This file contains 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
File renamed without changes.
This file contains 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 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 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 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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix #11704 in a separate PR