-
Notifications
You must be signed in to change notification settings - Fork 9
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
Improve error visibility when printing metrics #234
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3b78fc9
Clean up classes/typing
dyastremsky f7dd524
Draft console exporter improved error visibility
dyastremsky 7b8bad1
Draft exporter code to improve error visibility
dyastremsky 5c92e32
Add utils class
dyastremsky 74da9a5
Subject (<50 chars)
dyastremsky 09175e1
Merge branch 'main' into dyas-error-visibility
dyastremsky 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,11 +25,16 @@ | |
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
|
||
from genai_perf.export_data import telemetry_data_exporter_util as telem_utils | ||
from genai_perf.export_data.exporter_config import ExporterConfig | ||
import genai_perf.logging as logging | ||
from rich.console import Console | ||
from rich.table import Table | ||
|
||
from . import exporter_utils | ||
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. Switching to relative imports for conciseness. This will also make any future refactors easier, so that we don't need to update the path if files are reorganized. |
||
from . import telemetry_data_exporter_util as telem_utils | ||
from .exporter_config import ExporterConfig | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class ConsoleExporter: | ||
""" | ||
|
@@ -76,32 +81,35 @@ def export(self) -> None: | |
) | ||
|
||
def _construct_table(self, table: Table) -> None: | ||
|
||
for metric in self._metrics.request_metrics: | ||
if self._should_skip(metric.name): | ||
continue | ||
|
||
metric_str = metric.name.replace("_", " ").capitalize() | ||
metric_str += f" ({metric.unit})" if metric.unit != "tokens" else "" | ||
metric_str = exporter_utils.format_metric_name(metric.name, metric.unit) | ||
row_values = [metric_str] | ||
|
||
for stat in self.STAT_COLUMN_KEYS: | ||
value = self._stats[metric.name].get(stat, None) | ||
row_values.append(f"{value:,.2f}" if value else "N/A") | ||
row_values.append( | ||
exporter_utils.fetch_stat(self._stats, metric.name, stat) | ||
) | ||
|
||
table.add_row(*row_values) | ||
|
||
for metric in self._metrics.system_metrics: | ||
metric_str = metric.name.replace("_", " ").capitalize() | ||
if metric.name == "request_goodput": | ||
if not self._args.goodput: | ||
continue | ||
metric_str += f" ({metric.unit})" if metric.unit != "tokens" else "" | ||
metric_str = exporter_utils.format_metric_name(metric.name, metric.unit) | ||
if metric.name == "request_goodput" and not self._args.goodput: | ||
continue | ||
|
||
row_values = [metric_str] | ||
for stat in self.STAT_COLUMN_KEYS: | ||
if stat == "avg": | ||
value = self._stats[metric.name]["avg"] | ||
row_values.append(f"{value:,.2f}") | ||
row_values.append( | ||
exporter_utils.fetch_stat(self._stats, metric.name, "avg") | ||
) | ||
else: | ||
row_values.append("N/A") | ||
|
||
table.add_row(*row_values) | ||
|
||
# (TMA-1976) Refactor this method as the csv exporter shares identical method. | ||
|
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 |
---|---|---|
@@ -0,0 +1,96 @@ | ||
# 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 logging | ||
from typing import Any, Dict, Optional | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def format_metric_name(name: str, unit: Optional[str]) -> str: | ||
""" | ||
Formats a metric name into a human-readable string with an optional unit. | ||
|
||
Args: | ||
name: The raw metric name with underscores. | ||
unit: The unit of the metric (e.g., 'ms'). | ||
|
||
Returns: | ||
The formatted metric name with the unit if provided. | ||
""" | ||
metric_str = name.replace("_", " ").title() | ||
return f"{metric_str} ({unit})" if unit else metric_str | ||
|
||
|
||
def format_stat_value(value: Any) -> str: | ||
""" | ||
Formats a statistic value for human-readable output. | ||
|
||
Args: | ||
value: The value to format. Supports int and float types. | ||
|
||
Returns: | ||
The formatted value as a string. If not a number, returns the string representation. | ||
""" | ||
return f"{value:,.2f}" if isinstance(value, (int, float)) else str(value) | ||
|
||
|
||
def fetch_stat( | ||
stats: Dict[str, Dict[str, float]], | ||
metric_name: str, | ||
stat: str, | ||
) -> str: | ||
""" | ||
Fetches a statistic value for a metric. | ||
Logs warnings for missing metrics or stats and returns 'N/A' if the value is missing. | ||
|
||
Args: | ||
stats: Dictionary containing statistics for metrics. | ||
metric_name: The name of the metric. | ||
stat: The statistic to fetch (e.g., 'avg', 'min', 'max'). | ||
|
||
Returns: | ||
The formatted statistic value or 'N/A' if missing. | ||
""" | ||
if metric_name not in stats: | ||
logger.error(f"Metric '{metric_name}' is missing in the provided statistics.") | ||
return "N/A" | ||
|
||
metric_stats = stats[metric_name] | ||
if not isinstance(metric_stats, dict): | ||
logger.error( | ||
f"Expected statistics for metric '{metric_name}' to be a dictionary. Got: {type(metric_stats).__name__}." | ||
) | ||
return "N/A" | ||
|
||
if stat not in metric_stats: | ||
logger.error( | ||
f"Statistic '{stat}' for metric '{metric_name}' is missing. " | ||
f"Available stats: {list(metric_stats.keys())}." | ||
) | ||
return "N/A" | ||
|
||
return format_stat_value(metric_stats[stat]) |
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
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.
Added aliases. While PA uses request-count, all other GAP args that use counts start with --num (most notably, --num-prompts).
We can decide for GA what arg name to use (if only one), but having this consistency would make it less confusing to be adding args. I often would type out the wrong one, so I imagine some users might too.
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.
This was the previous name right?
An alias is fine, just having deja vu here.