From dc9427c8c0ddac88cfe09b99a495ea1ea53e5c07 Mon Sep 17 00:00:00 2001 From: braf Date: Thu, 29 Feb 2024 23:07:25 +0000 Subject: [PATCH 01/11] Initial code for LLmInputs methods. All unit tests passing. --- .../genai-pa/genaipa_exceptions.py | 23 ++ .../genai-pa/llm_inputs/__init__.py | 27 ++ .../genai-pa/llm_inputs/llm_inputs.py | 286 ++++++++++++++++++ src/c++/perf_analyzer/genai-pa/pyproject.toml | 1 + .../genai-pa/tests/test_llm_inputs.py | 172 +++++++++++ 5 files changed, 509 insertions(+) create mode 100644 src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py create mode 100644 src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py create mode 100644 src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py create mode 100644 src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py diff --git a/src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py b/src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py new file mode 100644 index 000000000..8b2c3782d --- /dev/null +++ b/src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 + +# Copyright 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +class GenAiPAExceptions(Exception): + """ + A custom exception specific to the GenAI-PA + """ + + pass \ No newline at end of file diff --git a/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py b/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py new file mode 100644 index 000000000..4d50bae64 --- /dev/null +++ b/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py @@ -0,0 +1,27 @@ +# 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. + +__version__ = "0.0.1" diff --git a/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py b/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py new file mode 100644 index 000000000..862cad835 --- /dev/null +++ b/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py @@ -0,0 +1,286 @@ +#!/usr/bin/env python3 + +# Copyright 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json +import requests +import urllib3 + +from copy import deepcopy + +from typing import Dict, List, Tuple + +from genaipa_exceptions import GenAiPAExceptions + +from requests import Response +from datasets import load_dataset + + +class LlmInputs: + """ + A library of methods that control the generation of LLM Inputs + """ + + OUTPUT_FILENAME = "./llm_inputs.json" + + OPEN_ORCA_URL = "https://datasets-server.huggingface.co/rows?dataset=Open-Orca%2FOpenOrca&config=default&split=train" + CNN_DAILYMAIL_URL = "https://datasets-server.huggingface.co/rows?dataset=cnn_dailymail&config=1.0.0&split=train" + + DEFAULT_STARTING_INDEX = 0 + MINIMUM_STARTING_INDEX = 0 + + DEFAULT_LENGTH = 100 + MINIMUM_LENGTH = 1 + + EMPTY_JSON_IN_PA_FORMAT = {"data": [{"payload": []}]} + + @classmethod + def create_openai_llm_inputs( + cls, + url: str = OPEN_ORCA_URL, + starting_index: int = DEFAULT_STARTING_INDEX, + length: int = DEFAULT_LENGTH, + model_name: str = None, + add_streaming: bool = False, + ) -> Dict: + """ + Given a URL and indexing parameters, it will write a string of LLM Inputs + (in a JSON dictionary) to a file + + Parameters + ---------- + url: + URL to gather LLM Inputs from + starting_index: + Offset from within the list to start gathering inputs + length: + Number of entries to gather + model_name: + add_streaming: + """ + + LlmInputs._check_for_valid_args(starting_index, length) + configured_url = LlmInputs._create_configured_url(url, starting_index, length) + dataset = LlmInputs._download_dataset(configured_url, starting_index, length) + dataset_json = LlmInputs._convert_dataset_to_json(dataset) + json_in_pa_format = LlmInputs._convert_json_to_pa_format( + dataset_json, model_name, add_streaming + ) + LlmInputs._write_json_to_file(json_in_pa_format) + + return json_in_pa_format + + @classmethod + def _write_json_to_file(cls, json_in_pa_format: Dict): + f = open(LlmInputs.OUTPUT_FILENAME, "w") + f.write(json.dumps(json_in_pa_format, indent=2)) + f.close() + + @classmethod + def _check_for_valid_args(cls, starting_index: int, length: int) -> None: + try: + LlmInputs._check_for_valid_starting_index(starting_index) + LlmInputs._check_for_valid_length(length) + except Exception as e: + raise GenAiPAExceptions(e) + + @classmethod + def _create_configured_url(cls, url: str, starting_index: int, length: int) -> str: + starting_index_str = str(starting_index) + length_str = str(length) + configured_url = url + f"&offset={starting_index_str}" + f"&length={length_str}" + + return configured_url + + @classmethod + def _download_dataset(cls, configured_url, starting_index, length) -> Response: + + dataset = LlmInputs._query_server(configured_url) + + return dataset + + @classmethod + def _convert_dataset_to_json(cls, dataset: Response) -> Dict: + dataset_json = dataset.json() + try: + LlmInputs._check_for_error_in_json_of_dataset(dataset_json) + except Exception as e: + raise GenAiPAExceptions(e) + + return dataset_json + + @classmethod + def _convert_json_to_pa_format( + cls, dataset_json: Dict, model_name: str, add_streaming: bool + ) -> Dict: + system_role_headers, user_role_headers = LlmInputs._determine_json_pa_roles( + dataset_json + ) + pa_json = LlmInputs._populate_pa_json( + dataset_json, + system_role_headers, + user_role_headers, + model_name, + add_streaming, + ) + + return pa_json + + @classmethod + def _determine_json_pa_roles( + cls, dataset_json: Dict + ) -> Tuple[List[str], List[str]]: + SYSTEM_ROLE_LIST = ["system_prompt"] + USER_ROLE_LIST = ["question", "article"] + + system_role_headers, user_role_headers = [], [] + if "features" in dataset_json.keys(): + for index, feature in enumerate(dataset_json["features"]): + if feature["name"] in SYSTEM_ROLE_LIST: + system_role_headers.append(feature["name"]) + if feature["name"] in USER_ROLE_LIST: + user_role_headers.append(feature["name"]) + + assert system_role_headers is not None or user_role_headers is not None + + return system_role_headers, user_role_headers + + @classmethod + def _populate_pa_json( + cls, + dataset_json: Dict, + system_role_headers: List[str], + user_role_headers: List[str], + model_name: str, + add_streaming: bool, + ) -> Dict: + pa_json = LlmInputs._create_empty_pa_json() + + for entry in dataset_json["rows"]: + pa_json["data"][0]["payload"].append({"messages": []}) + + for header in entry["row"]: + new_message = LlmInputs._create_new_message( + header, system_role_headers, user_role_headers, entry["row"][header] + ) + + pa_json = LlmInputs._add_new_message_to_json( + pa_json, entry["row_idx"], new_message + ) + + pa_json = LlmInputs._add_optional_tags_to_json( + pa_json, entry["row_idx"], model_name, add_streaming + ) + + return pa_json + + @classmethod + def _create_empty_pa_json(cls) -> Dict: + empty_pa_json = deepcopy(LlmInputs.EMPTY_JSON_IN_PA_FORMAT) + + return empty_pa_json + + @classmethod + def _create_new_message( + cls, + header: str, + system_role_headers: List[str], + user_role_headers: List[str], + content: str, + ) -> Dict: + if header in system_role_headers: + new_message = { + "role": "system", + "content": content, + } + elif header in user_role_headers: + new_message = { + "role": "user", + "content": content, + } + else: + new_message = {} + + return new_message + + @classmethod + def _add_new_message_to_json( + cls, pa_json: Dict, index: int, new_message: Dict + ) -> Dict: + if new_message: + pa_json["data"][0]["payload"][index]["messages"].append(new_message) + + return pa_json + + @classmethod + def _add_optional_tags_to_json( + cls, pa_json: Dict, index: int, model_name: str, add_streaming: bool + ) -> Dict: + if model_name: + pa_json["data"][0]["payload"][index]["model"] = model_name + if add_streaming: + pa_json["data"][0]["payload"][index]["streaming"] = "true" + + return pa_json + + @classmethod + def _check_for_valid_starting_index(cls, starting_index: int) -> None: + if not isinstance(starting_index, int): + raise GenAiPAExceptions( + f"starting_index: {starting_index} must be an integer." + ) + + if starting_index < LlmInputs.MINIMUM_STARTING_INDEX: + raise GenAiPAExceptions( + f"starting_index: {starting_index} must be larger than {LlmInputs.MINIMUM_STARTING_INDEX}." + ) + + @classmethod + def _check_for_valid_length(cls, length: int) -> None: + if not isinstance(length, int): + raise GenAiPAExceptions(f"length: {length} must be an integer.") + + if length < LlmInputs.MINIMUM_LENGTH: + raise GenAiPAExceptions( + f"starting_index: {length} must be larger than {LlmInputs.MINIMUM_LENGTH}." + ) + + @classmethod + def _query_server(cls, configured_url: str) -> Response: + try: + response = requests.get(configured_url) + except Exception as e: + error_message = LlmInputs._create_error_message(e) + raise GenAiPAExceptions(error_message) + + return response + + @classmethod + def _create_error_message(cls, exception: Exception) -> str: + url_str = exception.args[0].args[0] + url_start = url_str.find("'") + url_end = url_str.find("'", url_start + 1) + 1 + error_message = f"Invalid URL: {url_str[url_start:url_end]}" + + return error_message + + @classmethod + def _check_for_error_in_json_of_dataset(cls, json_of_dataset: str) -> None: + if "error" in json_of_dataset.keys(): + raise GenAiPAExceptions(json_of_dataset["error"]) + + +if __name__ == "__main__": + main() diff --git a/src/c++/perf_analyzer/genai-pa/pyproject.toml b/src/c++/perf_analyzer/genai-pa/pyproject.toml index 9e707fa1f..5ccf5f2df 100644 --- a/src/c++/perf_analyzer/genai-pa/pyproject.toml +++ b/src/c++/perf_analyzer/genai-pa/pyproject.toml @@ -46,6 +46,7 @@ maintainers = [] keywords = [] requires-python = ">=3.8,<4" dependencies = [ + "datasets", "numpy", "pytest", "rich" diff --git a/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py b/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py new file mode 100644 index 000000000..a2e000064 --- /dev/null +++ b/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py @@ -0,0 +1,172 @@ +#!/usr/bin/env python3 + +# Copyright 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import json +import pytest + +from genai_pa import parser +from genaipa_exceptions import GenAiPAExceptions +from llm_inputs.llm_inputs import LlmInputs + + +class TestLlmInputs: + + @pytest.fixture + def default_configured_url(self): + default_configured_url = LlmInputs._create_configured_url( + LlmInputs.OPEN_ORCA_URL, + LlmInputs.DEFAULT_STARTING_INDEX, + LlmInputs.DEFAULT_LENGTH, + ) + + yield default_configured_url + + def test_illegal_starting_index(self): + """ + Test for exceptions when illegal values are given for starting index + """ + with pytest.raises(GenAiPAExceptions): + _ = LlmInputs._check_for_valid_args( + starting_index="foo", length=LlmInputs.DEFAULT_LENGTH + ) + + with pytest.raises(GenAiPAExceptions): + _ = LlmInputs._check_for_valid_args( + starting_index=-1, length=LlmInputs.DEFAULT_LENGTH + ) + + def test_illegal_length(self): + """ + Test for exceptions when illegal values are given for length + """ + with pytest.raises(GenAiPAExceptions): + _ = LlmInputs._check_for_valid_args( + starting_index=LlmInputs.DEFAULT_STARTING_INDEX, length="foo" + ) + + with pytest.raises(GenAiPAExceptions): + _ = LlmInputs._check_for_valid_args( + starting_index=LlmInputs.DEFAULT_STARTING_INDEX, length=0 + ) + + def test_create_configured_url(self): + """ + Test that we are appending and configuring the URL correctly + """ + expected_configured_url = ( + "http://test-url.com" + + f"&offset={LlmInputs.DEFAULT_STARTING_INDEX}" + + f"&length={LlmInputs.DEFAULT_LENGTH}" + ) + configured_url = LlmInputs._create_configured_url( + "http://test-url.com", + LlmInputs.DEFAULT_STARTING_INDEX, + LlmInputs.DEFAULT_LENGTH, + ) + + assert configured_url == expected_configured_url + + def test_download_dataset_illegal_url(self): + """ + Test for exception when URL is bad + """ + with pytest.raises(GenAiPAExceptions): + _ = LlmInputs._download_dataset( + "https://bad-url.zzz", + LlmInputs.DEFAULT_STARTING_INDEX, + LlmInputs.DEFAULT_LENGTH, + ) + + def test_llm_inputs_error_in_server_response(self): + """ + Test for exception when length is out of range + """ + with pytest.raises(GenAiPAExceptions): + llm_inputs = LlmInputs.create_openai_llm_inputs( + LlmInputs.OPEN_ORCA_URL, + LlmInputs.DEFAULT_STARTING_INDEX, + int(LlmInputs.DEFAULT_LENGTH * 100), + ) + + def test_llm_inputs_with_defaults(self, default_configured_url): + """ + Test that default options work + """ + dataset = LlmInputs._download_dataset( + default_configured_url, + LlmInputs.DEFAULT_STARTING_INDEX, + LlmInputs.DEFAULT_LENGTH, + ) + dataset_json = LlmInputs._convert_dataset_to_json(dataset) + + assert dataset_json is not None + assert len(dataset_json["rows"]) == LlmInputs.DEFAULT_LENGTH + + def test_llm_inputs_with_non_default_length(self): + """ + Test that non-default length works + """ + configured_url = LlmInputs._create_configured_url( + LlmInputs.OPEN_ORCA_URL, + LlmInputs.DEFAULT_STARTING_INDEX, + (int(LlmInputs.DEFAULT_LENGTH / 2)), + ) + dataset = LlmInputs._download_dataset( + configured_url, + LlmInputs.DEFAULT_STARTING_INDEX, + length=(int(LlmInputs.DEFAULT_LENGTH / 2)), + ) + dataset_json = LlmInputs._convert_dataset_to_json(dataset) + + assert dataset_json is not None + assert len(dataset_json["rows"]) == LlmInputs.DEFAULT_LENGTH / 2 + + def test_convert_default_json_to_pa_format(self, default_configured_url): + """ + Test that conversion to PA JSON format is correct + """ + dataset = LlmInputs._download_dataset( + default_configured_url, + LlmInputs.DEFAULT_STARTING_INDEX, + LlmInputs.DEFAULT_LENGTH, + ) + dataset_json = LlmInputs._convert_dataset_to_json(dataset) + pa_json = LlmInputs._convert_json_to_pa_format(dataset_json, "", False) + + assert pa_json is not None + assert len(pa_json["data"][0]["payload"]) == LlmInputs.DEFAULT_LENGTH + + def test_create_openai_llm_inputs_cnn_dailymail(self): + """ + Test CNN_DAILYMAIL can be accessed + """ + pa_json = LlmInputs.create_openai_llm_inputs(LlmInputs.CNN_DAILYMAIL_URL) + + assert pa_json is not None + assert len(pa_json["data"][0]["payload"]) == LlmInputs.DEFAULT_LENGTH + + def test_write_to_file(self): + """ + Test that write to file is working correctly + """ + pa_json = LlmInputs.create_openai_llm_inputs( + model_name="OpenOrca", add_streaming=True + ) + f = open(LlmInputs.OUTPUT_FILENAME, "r") + json_str = f.read() + f.close() + + assert pa_json == json.loads(json_str) From 37cedf75b8c314f8c5c2678e842893e977b62674 Mon Sep 17 00:00:00 2001 From: braf Date: Thu, 29 Feb 2024 23:56:46 +0000 Subject: [PATCH 02/11] Ensure file is deleted and general cleanup --- src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py | 2 +- src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py | 1 - src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py | 6 +++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py b/src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py index 8b2c3782d..0901447a4 100644 --- a/src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py +++ b/src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py @@ -20,4 +20,4 @@ class GenAiPAExceptions(Exception): A custom exception specific to the GenAI-PA """ - pass \ No newline at end of file + pass diff --git a/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py b/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py index 4d50bae64..ec4d7bd7e 100644 --- a/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py +++ b/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py @@ -24,4 +24,3 @@ # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -__version__ = "0.0.1" diff --git a/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py b/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py index a2e000064..16026c745 100644 --- a/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py +++ b/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py @@ -15,6 +15,7 @@ # limitations under the License. import json +import os import pytest from genai_pa import parser @@ -155,6 +156,8 @@ def test_create_openai_llm_inputs_cnn_dailymail(self): """ pa_json = LlmInputs.create_openai_llm_inputs(LlmInputs.CNN_DAILYMAIL_URL) + os.remove(LlmInputs.OUTPUT_FILENAME) + assert pa_json is not None assert len(pa_json["data"][0]["payload"]) == LlmInputs.DEFAULT_LENGTH @@ -168,5 +171,6 @@ def test_write_to_file(self): f = open(LlmInputs.OUTPUT_FILENAME, "r") json_str = f.read() f.close() - + os.remove(LlmInputs.OUTPUT_FILENAME) + assert pa_json == json.loads(json_str) From 2fa39db724527b6a8da469eea4bfec68d256f22e Mon Sep 17 00:00:00 2001 From: braf Date: Fri, 1 Mar 2024 00:10:20 +0000 Subject: [PATCH 03/11] Adding in missing parameter descriptions --- src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py b/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py index 862cad835..b04722990 100644 --- a/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py +++ b/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py @@ -67,8 +67,10 @@ def create_openai_llm_inputs( Offset from within the list to start gathering inputs length: Number of entries to gather - model_name: - add_streaming: + model_name: + If included adds this model name field to each payload + add_streaming: + If true adds a streaming field to each payload """ LlmInputs._check_for_valid_args(starting_index, length) From 8a032f42ebf06b74f047f9a808efe0cf2273958c Mon Sep 17 00:00:00 2001 From: braf Date: Fri, 1 Mar 2024 00:18:08 +0000 Subject: [PATCH 04/11] Removing uneeded import --- src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py b/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py index b04722990..d148033d1 100644 --- a/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py +++ b/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py @@ -16,7 +16,6 @@ import json import requests -import urllib3 from copy import deepcopy From 3d30152cbc8292b2d55528d1eb01879b87687983 Mon Sep 17 00:00:00 2001 From: braf Date: Fri, 1 Mar 2024 00:22:30 +0000 Subject: [PATCH 05/11] Fixing precommit issues --- .../perf_analyzer/genai-pa/genaipa_exceptions.py | 2 -- .../perf_analyzer/genai-pa/llm_inputs/__init__.py | 1 - .../genai-pa/llm_inputs/llm_inputs.py | 14 ++++---------- .../genai-pa/tests/test_llm_inputs.py | 11 ++++------- 4 files changed, 8 insertions(+), 20 deletions(-) diff --git a/src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py b/src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py index 0901447a4..8101b1436 100644 --- a/src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py +++ b/src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python3 - # Copyright 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py b/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py index ec4d7bd7e..dc1c939c6 100644 --- a/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py +++ b/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py @@ -23,4 +23,3 @@ # 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. - diff --git a/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py b/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py index d148033d1..b8190faa6 100644 --- a/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py +++ b/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python3 - # Copyright 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -15,16 +13,13 @@ # limitations under the License. import json -import requests - from copy import deepcopy - from typing import Dict, List, Tuple +import requests +from datasets import load_dataset from genaipa_exceptions import GenAiPAExceptions - from requests import Response -from datasets import load_dataset class LlmInputs: @@ -66,9 +61,9 @@ def create_openai_llm_inputs( Offset from within the list to start gathering inputs length: Number of entries to gather - model_name: + model_name: If included adds this model name field to each payload - add_streaming: + add_streaming: If true adds a streaming field to each payload """ @@ -107,7 +102,6 @@ def _create_configured_url(cls, url: str, starting_index: int, length: int) -> s @classmethod def _download_dataset(cls, configured_url, starting_index, length) -> Response: - dataset = LlmInputs._query_server(configured_url) return dataset diff --git a/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py b/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py index 16026c745..6b84e0a44 100644 --- a/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py +++ b/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python3 - # Copyright 2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); @@ -16,15 +14,14 @@ import json import os -import pytest +import pytest from genai_pa import parser from genaipa_exceptions import GenAiPAExceptions from llm_inputs.llm_inputs import LlmInputs class TestLlmInputs: - @pytest.fixture def default_configured_url(self): default_configured_url = LlmInputs._create_configured_url( @@ -32,7 +29,7 @@ def default_configured_url(self): LlmInputs.DEFAULT_STARTING_INDEX, LlmInputs.DEFAULT_LENGTH, ) - + yield default_configured_url def test_illegal_starting_index(self): @@ -157,7 +154,7 @@ def test_create_openai_llm_inputs_cnn_dailymail(self): pa_json = LlmInputs.create_openai_llm_inputs(LlmInputs.CNN_DAILYMAIL_URL) os.remove(LlmInputs.OUTPUT_FILENAME) - + assert pa_json is not None assert len(pa_json["data"][0]["payload"]) == LlmInputs.DEFAULT_LENGTH @@ -172,5 +169,5 @@ def test_write_to_file(self): json_str = f.read() f.close() os.remove(LlmInputs.OUTPUT_FILENAME) - + assert pa_json == json.loads(json_str) From cb61be83837c96e08ccd3b720abbdd4dbd694f7b Mon Sep 17 00:00:00 2001 From: braf Date: Fri, 1 Mar 2024 00:26:55 +0000 Subject: [PATCH 06/11] Fixing codeQL issue --- .../perf_analyzer/genai-pa/tests/test_llm_inputs.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py b/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py index 6b84e0a44..55109fd32 100644 --- a/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py +++ b/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py @@ -165,9 +165,11 @@ def test_write_to_file(self): pa_json = LlmInputs.create_openai_llm_inputs( model_name="OpenOrca", add_streaming=True ) - f = open(LlmInputs.OUTPUT_FILENAME, "r") - json_str = f.read() - f.close() - os.remove(LlmInputs.OUTPUT_FILENAME) + try: + f = open(LlmInputs.OUTPUT_FILENAME, "r") + json_str = f.read() + finally: + f.close() + os.remove(LlmInputs.OUTPUT_FILENAME) assert pa_json == json.loads(json_str) From 42b78621a61aefbdebb1fcf6dc5635db8c9924e7 Mon Sep 17 00:00:00 2001 From: braf Date: Fri, 1 Mar 2024 00:53:27 +0000 Subject: [PATCH 07/11] Fixing more codeQL issues --- src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py | 9 +++++---- src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py | 3 +-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py b/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py index b8190faa6..dbc556ee6 100644 --- a/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py +++ b/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py @@ -17,7 +17,6 @@ from typing import Dict, List, Tuple import requests -from datasets import load_dataset from genaipa_exceptions import GenAiPAExceptions from requests import Response @@ -80,9 +79,11 @@ def create_openai_llm_inputs( @classmethod def _write_json_to_file(cls, json_in_pa_format: Dict): - f = open(LlmInputs.OUTPUT_FILENAME, "w") - f.write(json.dumps(json_in_pa_format, indent=2)) - f.close() + try: + f = open(LlmInputs.OUTPUT_FILENAME, "w") + f.write(json.dumps(json_in_pa_format, indent=2)) + finally: + f.close() @classmethod def _check_for_valid_args(cls, starting_index: int, length: int) -> None: diff --git a/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py b/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py index 55109fd32..0dedae0d5 100644 --- a/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py +++ b/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py @@ -16,7 +16,6 @@ import os import pytest -from genai_pa import parser from genaipa_exceptions import GenAiPAExceptions from llm_inputs.llm_inputs import LlmInputs @@ -93,7 +92,7 @@ def test_llm_inputs_error_in_server_response(self): Test for exception when length is out of range """ with pytest.raises(GenAiPAExceptions): - llm_inputs = LlmInputs.create_openai_llm_inputs( + _ = LlmInputs.create_openai_llm_inputs( LlmInputs.OPEN_ORCA_URL, LlmInputs.DEFAULT_STARTING_INDEX, int(LlmInputs.DEFAULT_LENGTH * 100), From ab215cd432a27af6a43c27519b4c6ab4deb07fb9 Mon Sep 17 00:00:00 2001 From: braf Date: Fri, 1 Mar 2024 01:13:00 +0000 Subject: [PATCH 08/11] Removing datasets dependency --- src/c++/perf_analyzer/genai-pa/pyproject.toml | 1 - 1 file changed, 1 deletion(-) diff --git a/src/c++/perf_analyzer/genai-pa/pyproject.toml b/src/c++/perf_analyzer/genai-pa/pyproject.toml index 5ccf5f2df..9e707fa1f 100644 --- a/src/c++/perf_analyzer/genai-pa/pyproject.toml +++ b/src/c++/perf_analyzer/genai-pa/pyproject.toml @@ -46,7 +46,6 @@ maintainers = [] keywords = [] requires-python = ">=3.8,<4" dependencies = [ - "datasets", "numpy", "pytest", "rich" From 08847eacfa5a809f714a5ff02d18c7ce3e6fde7f Mon Sep 17 00:00:00 2001 From: braf Date: Fri, 1 Mar 2024 16:30:44 +0000 Subject: [PATCH 09/11] Changes based on Elias' review --- .../genai-pa/genaipa_exceptions.py | 2 +- .../genai-pa/llm_inputs/__init__.py | 32 +++------ .../genai-pa/llm_inputs/llm_inputs.py | 68 +++++++++---------- .../genai-pa/tests/test_llm_inputs.py | 16 ++--- 4 files changed, 51 insertions(+), 67 deletions(-) diff --git a/src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py b/src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py index 8101b1436..970556e7a 100644 --- a/src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py +++ b/src/c++/perf_analyzer/genai-pa/genaipa_exceptions.py @@ -13,7 +13,7 @@ # limitations under the License. -class GenAiPAExceptions(Exception): +class GenAiPAException(Exception): """ A custom exception specific to the GenAI-PA """ diff --git a/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py b/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py index dc1c939c6..fd35ebcb1 100644 --- a/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py +++ b/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py @@ -1,25 +1,13 @@ # 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. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at # -# 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. +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. \ No newline at end of file diff --git a/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py b/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py index dbc556ee6..d4a5422b9 100644 --- a/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py +++ b/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py @@ -14,10 +14,10 @@ import json from copy import deepcopy -from typing import Dict, List, Tuple +from typing import Dict, List, Optional, Tuple import requests -from genaipa_exceptions import GenAiPAExceptions +from genaipa_exceptions import GenAiPAException from requests import Response @@ -46,7 +46,7 @@ def create_openai_llm_inputs( starting_index: int = DEFAULT_STARTING_INDEX, length: int = DEFAULT_LENGTH, model_name: str = None, - add_streaming: bool = False, + add_stream: bool = False, ) -> Dict: """ Given a URL and indexing parameters, it will write a string of LLM Inputs @@ -62,8 +62,8 @@ def create_openai_llm_inputs( Number of entries to gather model_name: If included adds this model name field to each payload - add_streaming: - If true adds a streaming field to each payload + add_stream: + If true adds a steam field to each payload """ LlmInputs._check_for_valid_args(starting_index, length) @@ -71,33 +71,25 @@ def create_openai_llm_inputs( dataset = LlmInputs._download_dataset(configured_url, starting_index, length) dataset_json = LlmInputs._convert_dataset_to_json(dataset) json_in_pa_format = LlmInputs._convert_json_to_pa_format( - dataset_json, model_name, add_streaming + dataset_json, model_name, add_stream ) LlmInputs._write_json_to_file(json_in_pa_format) return json_in_pa_format - @classmethod - def _write_json_to_file(cls, json_in_pa_format: Dict): - try: - f = open(LlmInputs.OUTPUT_FILENAME, "w") - f.write(json.dumps(json_in_pa_format, indent=2)) - finally: - f.close() - @classmethod def _check_for_valid_args(cls, starting_index: int, length: int) -> None: try: LlmInputs._check_for_valid_starting_index(starting_index) LlmInputs._check_for_valid_length(length) except Exception as e: - raise GenAiPAExceptions(e) + raise GenAiPAException(e) @classmethod def _create_configured_url(cls, url: str, starting_index: int, length: int) -> str: starting_index_str = str(starting_index) length_str = str(length) - configured_url = url + f"&offset={starting_index_str}" + f"&length={length_str}" + configured_url = url + f"&offset={starting_index_str}&length={length_str}" return configured_url @@ -113,13 +105,13 @@ def _convert_dataset_to_json(cls, dataset: Response) -> Dict: try: LlmInputs._check_for_error_in_json_of_dataset(dataset_json) except Exception as e: - raise GenAiPAExceptions(e) + raise GenAiPAException(e) return dataset_json @classmethod def _convert_json_to_pa_format( - cls, dataset_json: Dict, model_name: str, add_streaming: bool + cls, dataset_json: Dict, model_name: str, add_stream: bool ) -> Dict: system_role_headers, user_role_headers = LlmInputs._determine_json_pa_roles( dataset_json @@ -129,11 +121,19 @@ def _convert_json_to_pa_format( system_role_headers, user_role_headers, model_name, - add_streaming, + add_stream, ) return pa_json + @classmethod + def _write_json_to_file(cls, json_in_pa_format: Dict): + try: + f = open(LlmInputs.OUTPUT_FILENAME, "w") + f.write(json.dumps(json_in_pa_format, indent=2)) + finally: + f.close() + @classmethod def _determine_json_pa_roles( cls, dataset_json: Dict @@ -160,7 +160,7 @@ def _populate_pa_json( system_role_headers: List[str], user_role_headers: List[str], model_name: str, - add_streaming: bool, + add_stream: bool, ) -> Dict: pa_json = LlmInputs._create_empty_pa_json() @@ -177,7 +177,7 @@ def _populate_pa_json( ) pa_json = LlmInputs._add_optional_tags_to_json( - pa_json, entry["row_idx"], model_name, add_streaming + pa_json, entry["row_idx"], model_name, add_stream ) return pa_json @@ -195,7 +195,7 @@ def _create_new_message( system_role_headers: List[str], user_role_headers: List[str], content: str, - ) -> Dict: + ) -> Optional[Dict]: if header in system_role_headers: new_message = { "role": "system", @@ -213,7 +213,7 @@ def _create_new_message( @classmethod def _add_new_message_to_json( - cls, pa_json: Dict, index: int, new_message: Dict + cls, pa_json: Dict, index: int, new_message: Optional[Dict] ) -> Dict: if new_message: pa_json["data"][0]["payload"][index]["messages"].append(new_message) @@ -222,34 +222,34 @@ def _add_new_message_to_json( @classmethod def _add_optional_tags_to_json( - cls, pa_json: Dict, index: int, model_name: str, add_streaming: bool + cls, pa_json: Dict, index: int, model_name: str, add_stream: bool ) -> Dict: if model_name: pa_json["data"][0]["payload"][index]["model"] = model_name - if add_streaming: - pa_json["data"][0]["payload"][index]["streaming"] = "true" + if add_stream: + pa_json["data"][0]["payload"][index]["steam"] = "true" return pa_json @classmethod def _check_for_valid_starting_index(cls, starting_index: int) -> None: if not isinstance(starting_index, int): - raise GenAiPAExceptions( + raise GenAiPAException( f"starting_index: {starting_index} must be an integer." ) if starting_index < LlmInputs.MINIMUM_STARTING_INDEX: - raise GenAiPAExceptions( + raise GenAiPAException( f"starting_index: {starting_index} must be larger than {LlmInputs.MINIMUM_STARTING_INDEX}." ) @classmethod def _check_for_valid_length(cls, length: int) -> None: if not isinstance(length, int): - raise GenAiPAExceptions(f"length: {length} must be an integer.") + raise GenAiPAException(f"length: {length} must be an integer.") if length < LlmInputs.MINIMUM_LENGTH: - raise GenAiPAExceptions( + raise GenAiPAException( f"starting_index: {length} must be larger than {LlmInputs.MINIMUM_LENGTH}." ) @@ -259,7 +259,7 @@ def _query_server(cls, configured_url: str) -> Response: response = requests.get(configured_url) except Exception as e: error_message = LlmInputs._create_error_message(e) - raise GenAiPAExceptions(error_message) + raise GenAiPAException(error_message) return response @@ -275,8 +275,4 @@ def _create_error_message(cls, exception: Exception) -> str: @classmethod def _check_for_error_in_json_of_dataset(cls, json_of_dataset: str) -> None: if "error" in json_of_dataset.keys(): - raise GenAiPAExceptions(json_of_dataset["error"]) - - -if __name__ == "__main__": - main() + raise GenAiPAException(json_of_dataset["error"]) diff --git a/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py b/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py index 0dedae0d5..7abeb3f53 100644 --- a/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py +++ b/src/c++/perf_analyzer/genai-pa/tests/test_llm_inputs.py @@ -16,7 +16,7 @@ import os import pytest -from genaipa_exceptions import GenAiPAExceptions +from genaipa_exceptions import GenAiPAException from llm_inputs.llm_inputs import LlmInputs @@ -35,12 +35,12 @@ def test_illegal_starting_index(self): """ Test for exceptions when illegal values are given for starting index """ - with pytest.raises(GenAiPAExceptions): + with pytest.raises(GenAiPAException): _ = LlmInputs._check_for_valid_args( starting_index="foo", length=LlmInputs.DEFAULT_LENGTH ) - with pytest.raises(GenAiPAExceptions): + with pytest.raises(GenAiPAException): _ = LlmInputs._check_for_valid_args( starting_index=-1, length=LlmInputs.DEFAULT_LENGTH ) @@ -49,12 +49,12 @@ def test_illegal_length(self): """ Test for exceptions when illegal values are given for length """ - with pytest.raises(GenAiPAExceptions): + with pytest.raises(GenAiPAException): _ = LlmInputs._check_for_valid_args( starting_index=LlmInputs.DEFAULT_STARTING_INDEX, length="foo" ) - with pytest.raises(GenAiPAExceptions): + with pytest.raises(GenAiPAException): _ = LlmInputs._check_for_valid_args( starting_index=LlmInputs.DEFAULT_STARTING_INDEX, length=0 ) @@ -80,7 +80,7 @@ def test_download_dataset_illegal_url(self): """ Test for exception when URL is bad """ - with pytest.raises(GenAiPAExceptions): + with pytest.raises(GenAiPAException): _ = LlmInputs._download_dataset( "https://bad-url.zzz", LlmInputs.DEFAULT_STARTING_INDEX, @@ -91,7 +91,7 @@ def test_llm_inputs_error_in_server_response(self): """ Test for exception when length is out of range """ - with pytest.raises(GenAiPAExceptions): + with pytest.raises(GenAiPAException): _ = LlmInputs.create_openai_llm_inputs( LlmInputs.OPEN_ORCA_URL, LlmInputs.DEFAULT_STARTING_INDEX, @@ -162,7 +162,7 @@ def test_write_to_file(self): Test that write to file is working correctly """ pa_json = LlmInputs.create_openai_llm_inputs( - model_name="OpenOrca", add_streaming=True + model_name="OpenOrca", add_stream=True ) try: f = open(LlmInputs.OUTPUT_FILENAME, "r") From 6794b144ec6c5f80b9b21794e9537ce91c71fecc Mon Sep 17 00:00:00 2001 From: braf Date: Fri, 1 Mar 2024 17:08:35 +0000 Subject: [PATCH 10/11] Fixing precommit error --- src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py b/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py index fd35ebcb1..c6959fce1 100644 --- a/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py +++ b/src/c++/perf_analyzer/genai-pa/llm_inputs/__init__.py @@ -10,4 +10,4 @@ # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and -# limitations under the License. \ No newline at end of file +# limitations under the License. From 3ffea3c2ebc5ce5bf8a0f7adb1ba66ecde7ccdc4 Mon Sep 17 00:00:00 2001 From: braf Date: Fri, 1 Mar 2024 17:55:05 +0000 Subject: [PATCH 11/11] Fixing names --- .../perf_analyzer/genai-pa/llm_inputs/llm_inputs.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py b/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py index d4a5422b9..924c0bdc4 100644 --- a/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py +++ b/src/c++/perf_analyzer/genai-pa/llm_inputs/llm_inputs.py @@ -37,7 +37,7 @@ class LlmInputs: DEFAULT_LENGTH = 100 MINIMUM_LENGTH = 1 - EMPTY_JSON_IN_PA_FORMAT = {"data": [{"payload": []}]} + EMPTY_JSON_IN_OPENAI_PA_FORMAT = {"data": [{"payload": []}]} @classmethod def create_openai_llm_inputs( @@ -116,7 +116,7 @@ def _convert_json_to_pa_format( system_role_headers, user_role_headers = LlmInputs._determine_json_pa_roles( dataset_json ) - pa_json = LlmInputs._populate_pa_json( + pa_json = LlmInputs._populate_openai_pa_json( dataset_json, system_role_headers, user_role_headers, @@ -154,7 +154,7 @@ def _determine_json_pa_roles( return system_role_headers, user_role_headers @classmethod - def _populate_pa_json( + def _populate_openai_pa_json( cls, dataset_json: Dict, system_role_headers: List[str], @@ -162,7 +162,7 @@ def _populate_pa_json( model_name: str, add_stream: bool, ) -> Dict: - pa_json = LlmInputs._create_empty_pa_json() + pa_json = LlmInputs._create_empty_openai_pa_json() for entry in dataset_json["rows"]: pa_json["data"][0]["payload"].append({"messages": []}) @@ -183,8 +183,8 @@ def _populate_pa_json( return pa_json @classmethod - def _create_empty_pa_json(cls) -> Dict: - empty_pa_json = deepcopy(LlmInputs.EMPTY_JSON_IN_PA_FORMAT) + def _create_empty_openai_pa_json(cls) -> Dict: + empty_pa_json = deepcopy(LlmInputs.EMPTY_JSON_IN_OPENAI_PA_FORMAT) return empty_pa_json