Skip to content

Update csv output format #540

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

Merged
merged 4 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 19 additions & 10 deletions src/c++/perf_analyzer/genai-perf/genai_perf/llm_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ def pretty_print(self):
def export_to_csv(self, csv_filename: str):
"""Exports the statistics to a CSV file."""

header = [
"Statistic",
multiple_metric_header = [
"Metric",
"avg",
"min",
"max",
Expand All @@ -268,40 +268,47 @@ def export_to_csv(self, csv_filename: str):
"p25",
]

single_metric_header = [
"Metric",
"Value",
]

with open(csv_filename, mode="w", newline="") as csvfile:
singular_metric_rows = []

csv_writer = csv.writer(csvfile)
csv_writer.writerow(header)
csv_writer.writerow(multiple_metric_header)

for metric in Metrics.metric_labels:
formatted_metric = metric
formatted_metric = metric.replace("_", " ").title()

is_throughput_field = self._is_throughput_field(metric)
is_time_field = self._is_time_field(metric)

if is_time_field:
formatted_metric += "(ns)"
formatted_metric += " (ns)"
elif is_throughput_field:
formatted_metric += "(per sec)"
formatted_metric += " (per sec)"
# TODO (TMA-1712): need to decide if we need this metric. Do not
# include in the csv for now.
# TODO (TMA-1678): output_token_throughput_per_request is treated
# separately since the current code treats all throughput metrics
# to be displayed outside of the statistics table.
elif metric == "output_token_throughput_per_request":
formatted_metric += "(per sec)"
formatted_metric += " (per sec)"
continue

row_values = [formatted_metric]

if is_throughput_field:
value = self.__dict__.get(f"{header[1]}_{metric}", -1)
value = self.__dict__.get(
f"{multiple_metric_header[1]}_{metric}", -1
)
row_values.append(f"{value:.2f}")
singular_metric_rows.append(row_values)
continue

for stat in header[1:]:
for stat in multiple_metric_header[1:]:
value = self.__dict__.get(f"{stat}_{metric}", -1)
row_values.append(f"{value:.0f}")

Expand All @@ -312,7 +319,7 @@ def export_to_csv(self, csv_filename: str):
# Without streaming, TTFT and request latency are the same, so do not print TTFT.
elif metric == "time_to_first_token":
unique_values = False
for stat in header[1:]:
for stat in multiple_metric_header[1:]:
value_ttft = self.__dict__.get(f"{stat}_{metric}", -1)
value_req_latency = self.__dict__.get(
f"{stat}_request_latency", -1
Expand All @@ -325,6 +332,8 @@ def export_to_csv(self, csv_filename: str):

csv_writer.writerow(row_values)

csv_writer.writerow([])
csv_writer.writerow(single_metric_header)
for row in singular_metric_rows:
csv_writer.writerow(row)

Expand Down
Loading
Loading