-
-
Notifications
You must be signed in to change notification settings - Fork 12.6k
[Model] Add multi-image input support for LLaVA-Next offline inference #7230
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
DarkLight1337
merged 16 commits into
vllm-project:main
from
zifeitong:multple_images_vlm
Aug 27, 2024
Merged
Changes from 9 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
9ec22d7
Initial commit:
zifeitong f63a1e6
Add tests
zifeitong 1b9d254
Update tests
zifeitong b08fb52
Images with variable sizes
zifeitong 970e9fd
Revert offline_inference_vision_language.py
zifeitong 1c2412c
format
zifeitong 0ba0d94
fix variable number of image patches
zifeitong 97c1069
test passed
zifeitong b4a0bcc
fix tests
zifeitong 723d727
Update vllm/multimodal/image.py
zifeitong 8e0a568
Merge branch 'main' of github.com:zifeitong/vllm into multple_images_vlm
zifeitong a518db7
Fix merge conflicts
zifeitong 95275b1
Test passed again
zifeitong 9a0a557
format
zifeitong e9263a6
reduce model length to fit in CI
zifeitong f889237
Merge branch 'main' of github.com:zifeitong/vllm into multple_images_vlm
zifeitong 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
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,35 @@ | ||
| import pytest | ||
| from transformers import AutoConfig, AutoTokenizer | ||
|
|
||
| from vllm.multimodal.image import repeat_and_pad_image_tokens | ||
|
|
||
|
|
||
| @pytest.mark.parametrize("model", ["llava-hf/llava-v1.6-mistral-7b-hf"]) | ||
| def test_repeat_and_pad_image_tokens(model): | ||
|
||
| config = AutoConfig.from_pretrained(model) | ||
| image_token_id = config.image_token_index | ||
|
|
||
| tokenizer = AutoTokenizer.from_pretrained(model) | ||
|
|
||
| test_cases = [ | ||
| ("<image>", 2, "<image><image>", [32000, 32000]), | ||
| ("<image><image>", 2, "<image><image><image>", [32000, 32000, 32000]), | ||
| ("<image><image>", [3, 2], "<image><image><image><image><image>", | ||
| [32000, 32000, 32000, 32000, 32000]), | ||
| ("Image:<image>Image:<image>!", [3, 2], | ||
| "Image:<image><image><image>Image:<image><image>!", | ||
| [9833, 28747, 32000, 32000, 32000, 9833, 28747, 32000, 32000, 918]), | ||
| ("<image>", [3, 2], "<image><image><image>", [32000, 32000, 32000]), | ||
| ] | ||
|
|
||
| for prompt, repeat_count, expected_prompt, expected_token_ids in test_cases: | ||
| new_prompt, new_token_ids = repeat_and_pad_image_tokens( | ||
| tokenizer=tokenizer, | ||
| prompt=prompt, | ||
| prompt_token_ids=tokenizer.encode(prompt, | ||
| add_special_tokens=False), | ||
| image_token_id=image_token_id, | ||
| repeat_count=repeat_count, | ||
| ) | ||
| assert new_prompt == expected_prompt | ||
| assert new_token_ids == expected_token_ids | ||
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
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.