ariG23498's picture
ariG23498 HF Staff
Create plot.py
49d3710 verified
import matplotlib.pyplot as plt
import numpy as np
# -----------------------------
# Data
# -----------------------------
batch_sizes = [32, 64, 128]
time_kernels = [11.9, 12.6, 16.6]
time_no_kernels = [58.2, 113.5, 224.0]
x = np.arange(len(batch_sizes))
width = 0.35
# -----------------------------
# Plot
# -----------------------------
plt.figure(figsize=(10, 6))
bars1 = plt.bar(
x - width / 2,
time_kernels,
width,
label="Use kernels",
color="#4C72B0"
)
bars2 = plt.bar(
x + width / 2,
time_no_kernels,
width,
label="No kernels",
color="#DD8452"
)
# -----------------------------
# Labels & title
# -----------------------------
plt.title(
"Generation Time Comparison for openai/gpt-oss-20b\n(256 tokens generated)",
fontsize=14,
weight="bold"
)
plt.xlabel("Batch size", fontsize=12)
plt.ylabel("Time (seconds)", fontsize=12)
plt.xticks(x, batch_sizes)
plt.legend(fontsize=11)
# -----------------------------
# Grid styling
# -----------------------------
plt.grid(
axis="y",
linestyle="--",
linewidth=0.8,
alpha=0.6
)
# -----------------------------
# Annotate bars
# -----------------------------
def annotate_bars(bars):
for bar in bars:
height = bar.get_height()
plt.annotate(
f"{height:.1f}s",
xy=(bar.get_x() + bar.get_width() / 2, height),
xytext=(0, 3),
textcoords="offset points",
ha="center",
va="bottom",
fontsize=10
)
annotate_bars(bars1)
annotate_bars(bars2)
# -----------------------------
# Layout
# -----------------------------
plt.tight_layout()
plt.savefig("kernels.png")