Create plot.py
Browse files
plot.py
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import matplotlib.pyplot as plt
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
# -----------------------------
|
| 5 |
+
# Data
|
| 6 |
+
# -----------------------------
|
| 7 |
+
batch_sizes = [32, 64, 128]
|
| 8 |
+
time_kernels = [11.9, 12.6, 16.6]
|
| 9 |
+
time_no_kernels = [58.2, 113.5, 224.0]
|
| 10 |
+
|
| 11 |
+
x = np.arange(len(batch_sizes))
|
| 12 |
+
width = 0.35
|
| 13 |
+
|
| 14 |
+
# -----------------------------
|
| 15 |
+
# Plot
|
| 16 |
+
# -----------------------------
|
| 17 |
+
plt.figure(figsize=(10, 6))
|
| 18 |
+
|
| 19 |
+
bars1 = plt.bar(
|
| 20 |
+
x - width / 2,
|
| 21 |
+
time_kernels,
|
| 22 |
+
width,
|
| 23 |
+
label="Use kernels",
|
| 24 |
+
color="#4C72B0"
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
bars2 = plt.bar(
|
| 28 |
+
x + width / 2,
|
| 29 |
+
time_no_kernels,
|
| 30 |
+
width,
|
| 31 |
+
label="No kernels",
|
| 32 |
+
color="#DD8452"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# -----------------------------
|
| 36 |
+
# Labels & title
|
| 37 |
+
# -----------------------------
|
| 38 |
+
plt.title(
|
| 39 |
+
"Generation Time Comparison for openai/gpt-oss-20b\n(256 tokens generated)",
|
| 40 |
+
fontsize=14,
|
| 41 |
+
weight="bold"
|
| 42 |
+
)
|
| 43 |
+
plt.xlabel("Batch size", fontsize=12)
|
| 44 |
+
plt.ylabel("Time (seconds)", fontsize=12)
|
| 45 |
+
|
| 46 |
+
plt.xticks(x, batch_sizes)
|
| 47 |
+
plt.legend(fontsize=11)
|
| 48 |
+
|
| 49 |
+
# -----------------------------
|
| 50 |
+
# Grid styling
|
| 51 |
+
# -----------------------------
|
| 52 |
+
plt.grid(
|
| 53 |
+
axis="y",
|
| 54 |
+
linestyle="--",
|
| 55 |
+
linewidth=0.8,
|
| 56 |
+
alpha=0.6
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
# -----------------------------
|
| 60 |
+
# Annotate bars
|
| 61 |
+
# -----------------------------
|
| 62 |
+
def annotate_bars(bars):
|
| 63 |
+
for bar in bars:
|
| 64 |
+
height = bar.get_height()
|
| 65 |
+
plt.annotate(
|
| 66 |
+
f"{height:.1f}s",
|
| 67 |
+
xy=(bar.get_x() + bar.get_width() / 2, height),
|
| 68 |
+
xytext=(0, 3),
|
| 69 |
+
textcoords="offset points",
|
| 70 |
+
ha="center",
|
| 71 |
+
va="bottom",
|
| 72 |
+
fontsize=10
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
annotate_bars(bars1)
|
| 76 |
+
annotate_bars(bars2)
|
| 77 |
+
|
| 78 |
+
# -----------------------------
|
| 79 |
+
# Layout
|
| 80 |
+
# -----------------------------
|
| 81 |
+
plt.tight_layout()
|
| 82 |
+
plt.savefig("kernels.png")
|