-
Notifications
You must be signed in to change notification settings - Fork 233
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
Port VLM functionalities from main branch to the refactor branch #769
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d62df10
port VLM input generation
nv-hwoo dddf4db
add tests
nv-hwoo 7cee8b0
add new tests
nv-hwoo 2e339f4
port output parsing and metrics
nv-hwoo d6d8b23
add one more test
nv-hwoo 1f8c926
Fix PR run
nv-hwoo ed90c85
address feedback
nv-hwoo 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,10 @@ | |
from genai_perf.exceptions import GenAIPerfException | ||
from genai_perf.llm_inputs.dataset_retriever import DatasetRetriever | ||
from genai_perf.llm_inputs.inputs_utils import ( | ||
DEFAULT_IMAGE_HEIGHT_MEAN, | ||
DEFAULT_IMAGE_HEIGHT_STDDEV, | ||
DEFAULT_IMAGE_WIDTH_MEAN, | ||
DEFAULT_IMAGE_WIDTH_STDDEV, | ||
DEFAULT_LENGTH, | ||
DEFAULT_NUM_PROMPTS, | ||
DEFAULT_OUTPUT_TOKENS_MEAN, | ||
|
@@ -40,6 +44,7 @@ | |
DEFAULT_PROMPT_TOKENS_STDDEV, | ||
DEFAULT_RANDOM_SEED, | ||
DEFAULT_STARTING_INDEX, | ||
ImageFormat, | ||
ModelSelectionStrategy, | ||
OutputFormat, | ||
PromptSource, | ||
|
@@ -76,6 +81,11 @@ def create_llm_inputs( | |
output_tokens_deterministic: bool = False, | ||
prompt_tokens_mean: int = DEFAULT_PROMPT_TOKENS_MEAN, | ||
prompt_tokens_stddev: int = DEFAULT_PROMPT_TOKENS_STDDEV, | ||
image_width_mean: int = DEFAULT_IMAGE_WIDTH_MEAN, | ||
image_width_stddev: int = DEFAULT_IMAGE_WIDTH_STDDEV, | ||
image_height_mean: int = DEFAULT_IMAGE_HEIGHT_MEAN, | ||
image_height_stddev: int = DEFAULT_IMAGE_HEIGHT_STDDEV, | ||
image_format: ImageFormat = ImageFormat.PNG, | ||
random_seed: int = DEFAULT_RANDOM_SEED, | ||
num_of_output_prompts: int = DEFAULT_NUM_PROMPTS, | ||
add_model_name: bool = False, | ||
|
@@ -101,14 +111,20 @@ def create_llm_inputs( | |
prompt_tokens_mean, | ||
prompt_tokens_stddev, | ||
num_of_output_prompts, | ||
image_width_mean, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can leave this for now... but same thing here. Maybe we need an image class. Adding all of these args replicates the issues we're trying to get rid of with this refactor. So this will need another refactor after this port. |
||
image_width_stddev, | ||
image_height_mean, | ||
image_height_stddev, | ||
image_format, | ||
output_format, | ||
) | ||
elif input_type == PromptSource.FILE: | ||
input_filename = cast(Path, input_filename) | ||
# TODO: Follow-up ticket to add support for rankings | ||
# if output_format == OutputFormat.RANKINGS: | ||
# dataset = DatasetRetriever.from_directory(input_filename) | ||
# else: | ||
dataset = DatasetRetriever.from_file(input_filename) | ||
dataset = DatasetRetriever.from_file(input_filename, output_format) | ||
else: | ||
raise GenAIPerfException("Input source is not recognized.") | ||
|
||
|
@@ -147,6 +163,7 @@ def validate_args( | |
PromptSource.DATASET, | ||
], | ||
OutputFormat.RANKINGS: [PromptSource.DATASET, PromptSource.SYNTHETIC], | ||
OutputFormat.OPENAI_VISION: [PromptSource.DATASET], | ||
} | ||
|
||
if input_type in unsupported_combinations.get(output_format, []): | ||
|
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
Binary file added
BIN
+147 KB
src/c++/perf_analyzer/genai-perf/genai_perf/llm_inputs/source_images/dlss.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+149 KB
src/c++/perf_analyzer/genai-perf/genai_perf/llm_inputs/source_images/h100.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+99.3 KB
src/c++/perf_analyzer/genai-perf/genai_perf/llm_inputs/source_images/h200.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+107 KB
src/c++/perf_analyzer/genai-perf/genai_perf/llm_inputs/source_images/jensen.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
77 changes: 77 additions & 0 deletions
77
src/c++/perf_analyzer/genai-perf/genai_perf/llm_inputs/synthetic_image_generator.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,77 @@ | ||
# Copyright 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# * Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# * Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# * Neither the name of NVIDIA CORPORATION nor the names of its | ||
# contributors may be used to endorse or promote products derived | ||
# from this software without specific prior written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY | ||
# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR | ||
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
import glob | ||
import random | ||
from pathlib import Path | ||
from typing import Optional | ||
|
||
from genai_perf import utils | ||
from genai_perf.llm_inputs.inputs_utils import ImageFormat | ||
from PIL import Image | ||
|
||
|
||
class SyntheticImageGenerator: | ||
"""A simple synthetic image generator that generates multiple synthetic | ||
images from the source images. | ||
""" | ||
|
||
@classmethod | ||
def create_synthetic_image( | ||
cls, | ||
image_width_mean: int, | ||
image_width_stddev: int, | ||
image_height_mean: int, | ||
image_height_stddev: int, | ||
image_format: Optional[ImageFormat] = None, | ||
) -> str: | ||
"""Generate base64 encoded synthetic image using the source images.""" | ||
if image_format is None: | ||
image_format = random.choice(list(ImageFormat)) | ||
width = cls._sample_random_positive_integer( | ||
image_width_mean, image_width_stddev | ||
) | ||
height = cls._sample_random_positive_integer( | ||
image_height_mean, image_height_stddev | ||
) | ||
|
||
image = cls._sample_source_image() | ||
image = image.resize(size=(width, height)) | ||
|
||
img_base64 = utils.encode_image(image, image_format.name) | ||
return f"data:image/{image_format.name.lower()};base64,{img_base64}" | ||
|
||
@classmethod | ||
def _sample_source_image(cls): | ||
"""Sample one image among the source images.""" | ||
filepath = Path(__file__).parent.resolve() / "source_images" / "*" | ||
filenames = glob.glob(str(filepath)) | ||
return Image.open(random.choice(filenames)) | ||
|
||
@classmethod | ||
def _sample_random_positive_integer(cls, mean: int, stddev: int) -> int: | ||
n = int(abs(random.gauss(mean, stddev))) | ||
return n if n != 0 else 1 # avoid zero |
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 think the Dataset Retriever should have no concept of output format. Otherwise, we're moving back towards where we currently are with everything being interdependent. We might want to discuss the best way to proceed here. Perhaps we can add a separate from_image_file method that can get an image from a file and then use it in the LLM Inputs file to add that image to each input. Or follow another approach.
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.
That's a valid point, and I agree. But I would rather focus on porting the VLM functionalities for this PR as there's already too many changes happening in this PR. I can tag a ticket for decoupling output format from this method. How does that sound?
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 need to think on it. I know that this port was already difficult. At the same time, deferring some parts is going to make other ports harder and make it more likely this gets missed. Introducing clutter to this class seems like a mistake unless we're going to immediately submit another PR to fix this. So then that becomes one more ticket/PR we need to do.