Page MenuHomePhabricator
Paste P88921

LLM inference latency visualization script for 2026 MAD results CSV format
ActivePublic

Authored by kevinbazira on Feb 20 2026, 12:40 PM.
"""
This script analyzes an LLM latency benchmarking report produced by the ROCm MAD framework
(2026 results CSV format) and generates a bar chart (latency_bar_chart.png) that shows the
relationship between latency (in ms) and token sizes (both input_len and output_len)for
batch size = 1.
"""
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import os
# Load the CSV into a DataFrame.
csv_filename = "perf_8a11e17b25c973a24099d4016bf2e17dd7ec1574.csv"
df = pd.read_csv(csv_filename)
# Ensure output directory exists
output_dir = "charts"
os.makedirs(output_dir, exist_ok=True)
# Filter relevant rows
df_filtered = df[
(df["benchmark"] == "latency")
& (df["metric"] == "latency")
& (df["unit"] == "ms")
& (df["bs"] == 1)
].copy()
# Rename columns for clarity
df_filtered = df_filtered.rename(
columns={
"inp": "input_len",
"out": "output_len",
"performance": "latency_ms",
}
)
# Convert seconds to milliseconds (MAD currently mislabels unit)
df_filtered["latency_ms"] = pd.to_numeric(df_filtered["latency_ms"]) * 1000
# Create a label that combines input_len and output_len.
df_filtered["scenario"] = df_filtered.apply(
lambda row: f"{row['input_len']} / {row['output_len']}", axis=1
)
# Sort for nicer plots
df_filtered = df_filtered.sort_values(
by=["input_len", "output_len"]
)
# Color handling
num_scenarios = df_filtered["scenario"].nunique()
cmap = plt.colormaps["YlGnBu"]
# Avoid division by zero
denom = max(num_scenarios - 1, 1)
colors = [cmap(i / denom) for i in range(num_scenarios)]
# Bar Plot
fig, ax = plt.subplots(figsize=(10, 6))
sns.barplot(
x="scenario",
y="latency_ms",
data=df_filtered,
hue="scenario",
dodge=False,
palette=colors,
legend=False,
ax=ax,
)
plt.xlabel("Input / Output Length")
plt.ylabel("Latency (ms)")
plt.title(
"LLM Inference Latency vs Input/Output Length",
fontsize=12,
fontweight="bold",
pad=20,
)
# Optional subtitle. Edit as needed
fig.text(
0.55,
0.93,
"(model: gpt-oss-safeguard-20b, batch: 1, dtype: auto, unquantized, gpu: mi210 x 1)",
fontsize=10,
ha="center",
va="center",
)
plt.grid(axis="y", linestyle="--", alpha=0.7)
plt.xticks(rotation=90, ha="center")
# Y-axis padding
max_latency = df_filtered["latency_ms"].max()
plt.ylim(0, max_latency * 1.2)
# Annotate bars
for bar in ax.patches:
height = bar.get_height()
ax.annotate(
f"{height:.2f}",
xy=(bar.get_x() + bar.get_width() / 2, height),
xytext=(0, 3),
textcoords="offset points",
ha="center",
va="bottom",
fontsize=8,
rotation=90,
)
plt.tight_layout()
plt.savefig(f"{output_dir}/latency_bar_chart.png", dpi=300)
print(f"Saved chart: {output_dir}/latency_bar_chart.png")
plt.close()