Skip to content

Commit

Permalink
Connect metrics module and silence transformer import warning
Browse files Browse the repository at this point in the history
  • Loading branch information
debermudez committed Mar 5, 2024
1 parent cd9e588 commit 47e10fe
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
24 changes: 24 additions & 0 deletions src/c++/perf_analyzer/genai-pa/genai_pa/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

Expand All @@ -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.
Expand All @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/c++/perf_analyzer/genai-pa/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ requires-python = ">=3.8,<4"
dependencies = [
"numpy",
"pytest",
"rich"
"rich",
"transformers"
]

# CLI Entrypoint
Expand Down

0 comments on commit 47e10fe

Please sign in to comment.