CoolFace
Apppublic

zcahjl3/figmirror-code-aug10

sourceHugging Facemitupdated 4mo agoView on Hugging Face
0likes
1import matplotlib.pyplot as plt2import numpy as np3 4warmup = [5, 10, 15, 20, 25, 30, 35, 40]5latency = [7, 8.5, 10, 10, 10.5, 11, 11.5, 12]6lat_err = [0.2, 0.4, 0.6, 0.6, 0.5, 0.6, 0.7, 0.8]7psnr    = [24, 26, 29, 31, 33, 34, 38, 42]8 9x = np.arange(len(warmup))10 11fig, ax = plt.subplots(figsize=(14, 8))12 13ax.set_xlim(-0.5, len(x) - 0.5)14 15min_latency_idx = np.argmin(latency)16colors = ['#1f77b4'] * len(latency)17colors[min_latency_idx] = 'orange'18 19bars = ax.bar(20    x, latency, yerr=lat_err, capsize=10,21    error_kw={'ecolor':'red', 'elinewidth':3, 'capthick':3},22    color=colors, zorder=2, width=0.623)24 25baseline = 1226xmin, xmax = ax.get_xlim()27ax.hlines(baseline, xmin, xmax,28          colors='#1f77b4', linestyles='--', linewidth=2)29ax.text(30    xmin, baseline + 0.2, 'Baseline Latency',31    fontsize=28, va='bottom', ha='left'32)33 34for i, bar in enumerate(bars):35    height = bar.get_height()36    improvement = (baseline - height) / baseline * 10037    if improvement > 0:38        ax.text(39            bar.get_x() + bar.get_width() / 2,40            height + lat_err[i] + 0.1,41            f'↓{improvement:.1f}%',42            ha='center', va='bottom',43            fontsize=12, color='green', weight='bold'44        )45 46ax.set_xticks(x)47ax.set_xticklabels([f'{w}%' for w in warmup], fontsize=24)48ax.set_xlabel('Warmup ($W$)', fontsize=30)49ax.set_ylabel('Latency (s)', fontsize=30)50ax.set_ylim(0, 13)51ax.grid(axis='y', linestyle='--', color='grey', alpha=0.5)52for label in ax.get_yticklabels():53    label.set_fontsize(24)54 55ax2 = ax.twinx()56ax2.plot(57    x, psnr, color='black', linewidth=3,58    marker='o', markersize=15, markeredgewidth=2,59    label='PSNR'60)61 62max_psnr_idx = np.argmax(psnr)63max_psnr_val = psnr[max_psnr_idx]64ax2.annotate(65    f'Highest PSNR: {max_psnr_val}',66    xy=(x[max_psnr_idx], max_psnr_val),67    xytext=(1.15, 0.9),68    textcoords='axes fraction',69    arrowprops=dict(70        arrowstyle='->',71        color='yellow',72        lw=2,73        connectionstyle="arc3,rad=-0.2"74    ),75    fontsize=16,76    bbox=dict(boxstyle="round,pad=0.3", fc="yellow", ec="black", lw=1, alpha=0.7)77)78 79ax2.set_ylabel('PSNR', fontsize=30)80ax2.set_ylim(20, 45)81ax2.set_yticks([25, 30, 35, 40])82for label in ax2.get_yticklabels():83    label.set_fontsize(24)84 85plt.title('Open-Sora Performance Analysis', fontsize=40)86plt.tight_layout(rect=[0, 0, 0.95, 1])87plt.show()