-
-
Notifications
You must be signed in to change notification settings - Fork 8.1k
[Model] Initialize Fuyu-8B support #3924
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 29 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
89f97ba
support persimmon model
Isotr0py f51e0a4
optimize persimmon code
Isotr0py 09d126e
make ruff happy
Isotr0py 07592ae
Add Fuyu support
Isotr0py 3a24825
Merge branch 'vllm-project:main' into fuyu
Isotr0py 28d4707
Merge branch 'main' into fuyu
Isotr0py 9e4f994
Fix model loader
Isotr0py 061e812
Fix several typos
Isotr0py d72810d
fix loader and add example
Isotr0py 222124f
Add fuyu example
Isotr0py 9f190cc
Reformat code
Isotr0py ca8ddc4
Fix a typo in fuyu example
Isotr0py bf4def6
rmove fuyu from vision config loading
Isotr0py ef666cd
Make image_input_shape and image_feature_size
Isotr0py 5815536
format code
Isotr0py 9fce2f0
Fix isort
Isotr0py 65cfc08
expand vision_language_config assertion
Isotr0py 260ab10
Merge branch 'main' into fuyu
Isotr0py 5da3a32
Merge remote-tracking branch 'upstream/main' into fuyu
Isotr0py dd28d7d
Merge branch 'main' into fuyu
Isotr0py 3e55b0a
revert arg_utils mistake change
Isotr0py e5a6418
rebase fuyu
Isotr0py 5454031
fix fuyu dynamic shape
Isotr0py 7b64800
add fuyu test
Isotr0py 1f9c405
Merge branch 'vllm-project:main' into fuyu
Isotr0py de57a56
fix fuyu processor
Isotr0py cefa770
debug persimmon
Isotr0py 867cb36
fix fuyu test
Isotr0py b8e8004
Merge branch 'vllm-project:main' into fuyu
Isotr0py c6e779c
update model flag
Isotr0py 4134084
fix wrong used RowParallelLinear
Isotr0py dc31551
Merge branch 'vllm-project:main' into fuyu
Isotr0py 018336f
refactor fuyu
Isotr0py a006ac1
Merge branch 'main' into fuyu
Isotr0py c788ceb
fix fuyu input processor
Isotr0py 71a38c3
refactor fuyu test
Isotr0py 8a32199
fix fuyu test
Isotr0py b346bf2
reduce image size_factors
Isotr0py 3b6e411
reduce scale factors
Isotr0py b7070c4
reduce size_factors
Isotr0py c55ff87
Merge branch 'vllm-project:main' into fuyu
Isotr0py 71166ee
add monkey-patch for fuyu test
Isotr0py 3a21aab
use shared merge_vision_embeddings and add dim check
Isotr0py 6cff87a
reduce max_model_len
Isotr0py f806004
reduce size_factors
Isotr0py 50e9c2d
add vllm_to_hf_output
Isotr0py bf89017
fix vllm_to_hf_output
Isotr0py 004b0c0
Merge remote-tracking branch 'upstream/main' into fuyu
ywang96 b69ce43
Merge remote-tracking branch 'upstream/main' into fuyu
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import math | ||
import os | ||
import subprocess | ||
|
||
from PIL import Image | ||
|
||
from vllm import LLM, SamplingParams | ||
from vllm.multimodal.image import ImagePixelData | ||
|
||
|
||
def run_fuyu_pixel_values(): | ||
llm = LLM( | ||
model="adept/fuyu-8b", | ||
max_model_len=4096, | ||
image_input_type="pixel_values", | ||
image_token_id=71011, | ||
image_input_shape="1,3,1080,1920", | ||
image_feature_size=2304, | ||
) | ||
|
||
# load and create image prompt | ||
image = Image.open("images/stop_sign.jpg") | ||
W, H = image.size | ||
|
||
nrow = math.ceil(min(H, 1080) / 30) | ||
ncol = math.ceil(min(W, 1920) / 30) | ||
|
||
# single-image prompt | ||
prompt = "<image>\nWhat is the content of this image?\n" | ||
prompt = prompt.replace("<image>", | ||
("|SPEAKER|" * ncol + "|NEWLINE|") * nrow) | ||
|
||
sampling_params = SamplingParams(temperature=0, max_tokens=64) | ||
|
||
outputs = llm.generate( | ||
{ | ||
"prompt": prompt, | ||
"multi_modal_data": ImagePixelData(image), | ||
}, | ||
sampling_params=sampling_params) | ||
for o in outputs: | ||
generated_text = o.outputs[0].text | ||
print(generated_text) | ||
|
||
|
||
if __name__ == "__main__": | ||
# Download from s3 | ||
s3_bucket_path = "s3://air-example-data-2/vllm_opensource_llava/" | ||
local_directory = "images" | ||
|
||
# Make sure the local directory exists or create it | ||
os.makedirs(local_directory, exist_ok=True) | ||
|
||
# Use AWS CLI to sync the directory, assume anonymous access | ||
subprocess.check_call([ | ||
"aws", | ||
"s3", | ||
"sync", | ||
s3_bucket_path, | ||
local_directory, | ||
"--no-sign-request", | ||
]) | ||
run_fuyu_pixel_values() |
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,115 @@ | ||
from typing import List, Tuple | ||
|
||
import pytest | ||
|
||
from vllm.config import VisionLanguageConfig | ||
from vllm.utils import is_cpu | ||
|
||
from ..conftest import IMAGE_ASSETS | ||
|
||
pytestmark = pytest.mark.vlm | ||
|
||
HF_IMAGE_PROMPTS = IMAGE_ASSETS.prompts({ | ||
"stop_sign": | ||
"What color is the stop sign?\n", # noqa: E501 | ||
"cherry_blossom": | ||
"What is the season?\n", # noqa: E501 | ||
}) | ||
|
||
|
||
def iter_fuyu_configs(model_name: str): | ||
image_hw_to_feature_size = { | ||
(420, 660): 308, | ||
} | ||
|
||
for (h, w), f in image_hw_to_feature_size.items(): | ||
for input_type, input_shape in [ | ||
(VisionLanguageConfig.ImageInputType.PIXEL_VALUES, (1, 3, h, w)), | ||
]: | ||
yield (model_name, | ||
VisionLanguageConfig(image_input_type=input_type, | ||
image_feature_size=f, | ||
image_token_id=71011, | ||
image_input_shape=input_shape, | ||
image_processor=model_name, | ||
image_processor_revision=None)) | ||
|
||
|
||
model_and_vl_config = [ | ||
*iter_fuyu_configs("adept/fuyu-8b"), | ||
] | ||
|
||
|
||
def vllm_to_hf_output(vllm_output: Tuple[List[int], str]): | ||
"""Sanitize vllm output to be comparable with hf output. | ||
The function reduces `input_ids` from 1, 32000, 32000, ..., 32000, | ||
x1, x2, x3 ... to 1, 32000, x1, x2, x3 ... | ||
It also reduces `output_str` from "<image><image>bla" to "bla". | ||
""" | ||
input_ids, output_str = vllm_output | ||
|
||
hf_input_ids = input_ids[2:] | ||
hf_output_str = output_str | ||
|
||
return hf_input_ids, hf_output_str | ||
|
||
|
||
target_dtype = "half" | ||
if is_cpu(): | ||
target_dtype = "bfloat16" | ||
|
||
|
||
# TODO: Add test for `tensor_parallel_size` [ref: PR #3883] | ||
@pytest.mark.parametrize("model_and_config", model_and_vl_config) | ||
@pytest.mark.parametrize("dtype", [target_dtype]) | ||
@pytest.mark.parametrize("max_tokens", [128]) | ||
def test_models(hf_runner, vllm_runner, image_assets, model_and_config, | ||
dtype: str, max_tokens: int) -> None: | ||
"""Inference result should be the same between hf and vllm. | ||
|
||
All the image fixtures for the test is under tests/images. | ||
For huggingface runner, we provide the PIL images as input. | ||
For vllm runner, we provide MultiModalData objects and corresponding | ||
vision language config as input. | ||
Note, the text input is also adjusted to abide by vllm contract. | ||
The text output is sanitized to be able to compare with hf. | ||
""" | ||
model_id, vlm_config = model_and_config | ||
_, _, H, W = vlm_config.image_input_shape | ||
|
||
# resize images to the model's input shape | ||
hf_images = [asset.for_hf().resize((W, H)) for asset in image_assets] | ||
vllm_images = [asset.for_vllm(vlm_config) for asset in image_assets] | ||
for i in range(len(image_assets)): | ||
vllm_images[i].image = vllm_images[i].image.resize((W, H)) | ||
|
||
with hf_runner(model_id, dtype=dtype) as hf_model: | ||
hf_outputs = hf_model.generate_greedy( | ||
HF_IMAGE_PROMPTS, | ||
max_tokens, | ||
images=hf_images, | ||
eos_token_id=hf_model.processor.tokenizer.eos_token_id) | ||
|
||
ncol, nrow = W // 30, H // 30 | ||
image_prompts = ("|SPEAKER|" * ncol + "|NEWLINE|") * nrow | ||
vllm_image_prompts = [ | ||
image_prompts + "<s> " + p + "\x04" for p in HF_IMAGE_PROMPTS | ||
] | ||
|
||
with vllm_runner(model_id, | ||
max_model_len=1024, | ||
dtype=dtype, | ||
enforce_eager=True, | ||
**vlm_config.as_cli_args_dict()) as vllm_model: | ||
vllm_outputs = vllm_model.generate_greedy(vllm_image_prompts, | ||
max_tokens, | ||
images=vllm_images) | ||
|
||
for i in range(len(HF_IMAGE_PROMPTS)): | ||
hf_output_ids, hf_output_str = hf_outputs[i] | ||
vllm_output_ids, vllm_output_str = vllm_outputs[i] | ||
vllm_output_ids, vllm_output_str = vllm_to_hf_output(vllm_outputs[i]) | ||
assert hf_output_str == vllm_output_str, ( | ||
f"Test{i}:\nHF: {hf_output_str!r}\nvLLM: {vllm_output_str!r}") | ||
assert hf_output_ids == vllm_output_ids, ( | ||
f"Test{i}:\nHF: {hf_output_ids}\nvLLM: {vllm_output_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
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.
Uh oh!
There was an error while loading. Please reload this page.