|
| 1 | +import pandas as pd |
| 2 | +import matplotlib.pyplot as plt |
| 3 | +import numpy as np |
| 4 | +import argparse |
| 5 | + |
| 6 | +parser = argparse.ArgumentParser() |
| 7 | +parser.add_argument('file', nargs='+') |
| 8 | +args = parser.parse_args() |
| 9 | + |
| 10 | +df = None |
| 11 | + |
| 12 | +#for jsonl_file in args.file: |
| 13 | +# # Read JSONL file into DataFrame |
| 14 | +# df_part = pd.read_json(jsonl_file, lines=True) |
| 15 | +# df_part['label'] = jsonl_file |
| 16 | +# if df is None: |
| 17 | +# df = df_part |
| 18 | +# else: |
| 19 | +# df = pd.concat([df, df_part]) |
| 20 | +# |
| 21 | + |
| 22 | + |
| 23 | + |
| 24 | +for md_file in args.file: |
| 25 | + # Read markdown table file into DataFrame |
| 26 | + df_part = pd.read_csv(md_file, sep=r'\s*\|\s*', engine='python', |
| 27 | + header=0, skiprows=[1]) |
| 28 | + |
| 29 | + # Clean up columns (remove empty columns from markdown formatting) |
| 30 | + df_part = df_part.iloc[:, 1:-1] |
| 31 | + df_part.columns = [col.strip() for col in df_part.columns] |
| 32 | + |
| 33 | + # Rename columns to match expected names |
| 34 | + df_part = df_part.rename(columns={ |
| 35 | + 'N_KV': 'n_kv', |
| 36 | + 'S_PP t/s': 'speed_pp', |
| 37 | + 'S_TG t/s': 'speed_tg' |
| 38 | + }) |
| 39 | + |
| 40 | + # Convert to numeric types |
| 41 | + df_part['n_kv'] = pd.to_numeric(df_part['n_kv']) |
| 42 | + df_part['speed_pp'] = pd.to_numeric(df_part['speed_pp']) |
| 43 | + df_part['speed_tg'] = pd.to_numeric(df_part['speed_tg']) |
| 44 | + |
| 45 | + # Add label and append to main DataFrame |
| 46 | + df_part['label'] = md_file |
| 47 | + df = pd.concat([df, df_part]) if df is not None else df_part |
| 48 | + |
| 49 | +# Group by label and n_kv, calculate mean and std for both speed metrics |
| 50 | +df_grouped = df.groupby(['label', 'n_kv']).agg({ |
| 51 | + 'speed_pp': ['mean', 'std'], |
| 52 | + 'speed_tg': ['mean', 'std'] |
| 53 | +}).reset_index() |
| 54 | + |
| 55 | +# Flatten multi-index columns |
| 56 | +df_grouped.columns = ['label', 'n_kv', 'speed_pp_mean', 'speed_pp_std', |
| 57 | + 'speed_tg_mean', 'speed_tg_std'] |
| 58 | + |
| 59 | +# Replace NaN with 0 (std for a single sample is NaN) |
| 60 | +df_grouped['speed_pp_std'] = df_grouped['speed_pp_std'].fillna(0) |
| 61 | +df_grouped['speed_tg_std'] = df_grouped['speed_tg_std'].fillna(0) |
| 62 | + |
| 63 | +# Prepare ticks values for X axis (prune for readability) |
| 64 | +x_ticks = df['n_kv'].unique() |
| 65 | +while len(x_ticks) > 16: |
| 66 | + x_ticks = x_ticks[::2] |
| 67 | + |
| 68 | +# Get unique labels and color map |
| 69 | +labels = df_grouped['label'].unique() |
| 70 | +colors = plt.cm.rainbow(np.linspace(0, 1, len(labels))) |
| 71 | + |
| 72 | +# Create prompt processing plot |
| 73 | +plt.figure(figsize=(10, 6)) |
| 74 | +ax1 = plt.gca() |
| 75 | +plt.grid() |
| 76 | +ax1.set_xticks(x_ticks) |
| 77 | + |
| 78 | +# Plot each label's data |
| 79 | +for label, color in zip(labels, colors): |
| 80 | + label_data = df_grouped[df_grouped['label'] == label].sort_values('n_kv') |
| 81 | + pp = ax1.errorbar(label_data['n_kv'], label_data['speed_pp_mean'], |
| 82 | + yerr=label_data['speed_pp_std'], color=color, |
| 83 | + marker='o', linestyle='-', label=label) |
| 84 | + |
| 85 | +# Add labels and title |
| 86 | +ax1.set_xlabel('Context Length (tokens)') |
| 87 | +ax1.set_ylabel('Prompt Processing Rate (t/s)') |
| 88 | +plt.title('Prompt Processing Performance Comparison') |
| 89 | +ax1.legend(loc='upper right') |
| 90 | + |
| 91 | +# Adjust layout and save |
| 92 | +plt.tight_layout() |
| 93 | +plt.savefig('performance_comparison_pp.png', bbox_inches='tight') |
| 94 | +plt.close() |
| 95 | + |
| 96 | +# Create token generation plot |
| 97 | +plt.figure(figsize=(10, 6)) |
| 98 | +ax1 = plt.gca() |
| 99 | +plt.grid() |
| 100 | +ax1.set_xticks(x_ticks) |
| 101 | + |
| 102 | +# Plot each model's data |
| 103 | +for label, color in zip(labels, colors): |
| 104 | + label_data = df_grouped[df_grouped['label'] == label].sort_values('n_kv') |
| 105 | + tg = ax1.errorbar(label_data['n_kv'], label_data['speed_tg_mean'], |
| 106 | + yerr=label_data['speed_tg_std'], color=color, |
| 107 | + marker='s', linestyle='-', label=label) |
| 108 | + |
| 109 | +# Add labels and title |
| 110 | +ax1.set_xlabel('Context Length (n_kv)') |
| 111 | +ax1.set_ylabel('Token Generation Rate (t/s)') |
| 112 | +plt.title('Token Generation Performance Comparison') |
| 113 | +ax1.legend(loc='upper right') |
| 114 | + |
| 115 | +# Adjust layout and save |
| 116 | +plt.tight_layout() |
| 117 | +plt.savefig('performance_comparison_tg.png', bbox_inches='tight') |
| 118 | +plt.close() |
0 commit comments