diff --git a/src/c++/perf_analyzer/genai-pa/genai_pa/main.py b/src/c++/perf_analyzer/genai-pa/genai_pa/main.py index be4353937..9fc66f365 100755 --- a/src/c++/perf_analyzer/genai-pa/genai_pa/main.py +++ b/src/c++/perf_analyzer/genai-pa/genai_pa/main.py @@ -25,6 +25,8 @@ # (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 contextlib +import io import logging import sys @@ -33,6 +35,17 @@ from genai_pa.exceptions import GenAiPAException from genai_pa.llm_inputs.llm_inputs import LlmInputs +# Silence tokenizer warning on import +with contextlib.redirect_stdout(io.StringIO()) as stdout, contextlib.redirect_stderr( + io.StringIO() +) as stderr: + from genai_pa.metrics import LLMProfileData + from transformers import AutoTokenizer as tokenizer + from transformers import logging as token_logger + + token_logger.set_verbosity_error() + + logging.basicConfig(level=logging.INFO, format="%(name)s - %(levelname)s - %(message)s") logger = logging.getLogger(LOGGER_NAME) @@ -47,6 +60,15 @@ def generate_inputs(args): ) +def calculate_metrics(file: str) -> LLMProfileData: + t = tokenizer.from_pretrained("gpt2") + return LLMProfileData(file, t) + + +def report_output(metrics: LLMProfileData): + print(metrics.get_statistics("concurrency", 1)) + + # Separate function that can raise exceptions used for testing # to assert correct errors and messages. # Optional argv used for testing - will default to sys.argv if None. @@ -55,6 +77,8 @@ def run(argv=None): args = parser.parse_args(argv) generate_inputs(args) args.func(args) + metrics = calculate_metrics(args.profile_export_file) + report_output(metrics) except Exception as e: raise GenAiPAException(e) diff --git a/src/c++/perf_analyzer/genai-pa/genai_pa/llm_profile.py b/src/c++/perf_analyzer/genai-pa/genai_pa/metrics.py similarity index 97% rename from src/c++/perf_analyzer/genai-pa/genai_pa/llm_profile.py rename to src/c++/perf_analyzer/genai-pa/genai_pa/metrics.py index b57a7f372..2716a799f 100755 --- a/src/c++/perf_analyzer/genai-pa/genai_pa/llm_profile.py +++ b/src/c++/perf_analyzer/genai-pa/genai_pa/metrics.py @@ -26,12 +26,18 @@ # (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 contextlib +import io from dataclasses import dataclass from itertools import pairwise import numpy as np from genai_pa.utils import load_json -from transformers import AutoTokenizer + +with contextlib.redirect_stdout(io.StringIO()) as stdout, contextlib.redirect_stderr( + io.StringIO() +) as stderr: + from transformers import AutoTokenizer @dataclass diff --git a/src/c++/perf_analyzer/genai-pa/pyproject.toml b/src/c++/perf_analyzer/genai-pa/pyproject.toml index 9e707fa1f..018d035e3 100644 --- a/src/c++/perf_analyzer/genai-pa/pyproject.toml +++ b/src/c++/perf_analyzer/genai-pa/pyproject.toml @@ -48,7 +48,8 @@ requires-python = ">=3.8,<4" dependencies = [ "numpy", "pytest", - "rich" + "rich", + "transformers" ] # CLI Entrypoint