|
| 1 | +import argparse |
| 2 | +from pathlib import Path |
| 3 | +import pandas as pd |
| 4 | + |
| 5 | + |
| 6 | +def parse_args(): |
| 7 | + parser = argparse.ArgumentParser(description='Aggregate end-to-end test results') |
| 8 | + parser.add_argument('--input-dir', '-i', type=str, required=True, help='Input directory containing test results') |
| 9 | + parser.add_argument('--output-dir', '-o', type=str, required=True, help='Output directory for aggregated results') |
| 10 | + return parser.parse_args() |
| 11 | + |
| 12 | + |
| 13 | +def parse_folder_name(folder_name): |
| 14 | + """ |
| 15 | + Parse folder name to extract suite and dtype. |
| 16 | +
|
| 17 | + Expected format: logs-{suite}-{dtype}-{mode}-accuracy, where mode can contain `-` characters |
| 18 | + Examples: |
| 19 | + - logs-torchbench-float32-inference-accuracy -> suite=torchbench, dtype=float32 |
| 20 | + - logs-huggingface-amp_bf16-training-accuracy -> suite=huggingface, dtype=amp_bf16 |
| 21 | + """ |
| 22 | + parts = folder_name.split('-') |
| 23 | + |
| 24 | + # Check if it follows the expected pattern |
| 25 | + if len(parts) < 4 or parts[0] != 'logs' or parts[-1] != 'accuracy': |
| 26 | + return None, None, None |
| 27 | + |
| 28 | + suite = parts[1] |
| 29 | + dtype = parts[2] |
| 30 | + # Extract mode, can include dashes |
| 31 | + mode = '-'.join(parts[3:-1]) |
| 32 | + |
| 33 | + return suite, dtype, mode |
| 34 | + |
| 35 | + |
| 36 | +def build_suite_report(combined_df, output_path): |
| 37 | + print('=======================================') |
| 38 | + print('= SUMMARY REPORT =') |
| 39 | + print('=======================================') |
| 40 | + assert combined_df.groupby(['suite', 'mode', 'dtype', 'batch_size', |
| 41 | + 'name']).count().max().max() == 1, 'Discovered unexpected duplicates in results!' |
| 42 | + |
| 43 | + def fn(df): |
| 44 | + results = df['accuracy'].value_counts().to_dict() |
| 45 | + errors = df[~df['accuracy'].str.startswith('pass')] |
| 46 | + errors = errors.groupby('accuracy')['name'].apply(';'.join).to_dict() |
| 47 | + |
| 48 | + return results, errors |
| 49 | + |
| 50 | + agg = combined_df.groupby(['suite', 'mode', 'dtype']).apply(fn, include_groups=False) |
| 51 | + |
| 52 | + for index, row in agg.items(): |
| 53 | + n_pass = sum(c for k, c in row[0].items() if k.startswith('pass')) |
| 54 | + n_total = sum(row[0].values()) |
| 55 | + |
| 56 | + join_parts = [] |
| 57 | + for k, v in row[0].items(): |
| 58 | + if 'pass' in k: |
| 59 | + join_parts.append(f'{k}={v}') |
| 60 | + else: |
| 61 | + join_parts.append(f'{k}={v}[{row[1][k]}]') |
| 62 | + |
| 63 | + txt = f'suite={index[0]},mode={index[1]},dtype={index[2]},' + \ |
| 64 | + f'passrate={n_pass / n_total if n_total > 0 else 0:.1%},' + \ |
| 65 | + ','.join(join_parts) |
| 66 | + |
| 67 | + print(txt) |
| 68 | + |
| 69 | + # Unpack errors and failed models into new columns |
| 70 | + agg = agg.apply(lambda x: pd.Series({**x[0], **{k + '_models': v for k, v in x[1].items()}})) |
| 71 | + agg = agg.reset_index().fillna(0) |
| 72 | + |
| 73 | + agg.to_csv(output_path / 'summary_agg.csv', index=False) |
| 74 | + |
| 75 | + |
| 76 | +def drop_duplicates(df, suite, mode): |
| 77 | + """ Some (name, dtype) groups can have duplicates, let's print them """ |
| 78 | + group_counts = df.groupby(['name', 'dtype']).size() |
| 79 | + duplicates = group_counts[group_counts > 1] |
| 80 | + |
| 81 | + if not duplicates.empty: |
| 82 | + print(f'Found {len(duplicates)} duplicate groups for {suite} {mode}:') |
| 83 | + for (name, dtype), _ in duplicates.items(): |
| 84 | + print(df[df['name'].eq(name) & df['dtype'].eq(dtype)]) |
| 85 | + print() |
| 86 | + return df.groupby(['name', 'dtype'], as_index=False).first() |
| 87 | + |
| 88 | + |
| 89 | +def build_pytorch_report(combined_df, output_path): |
| 90 | + print('====================\nBuiling pytorch report\n====================') |
| 91 | + cols = ['name', 'float32', 'bfloat16', 'float16', 'amp_bf16', 'amp_fp16'] |
| 92 | + |
| 93 | + torch_report_dir = output_path / 'torch_format_report' |
| 94 | + torch_report_dir.mkdir(parents=True, exist_ok=True) |
| 95 | + for suite, mode in combined_df[['suite', 'mode']].drop_duplicates().values: |
| 96 | + df_subset = combined_df[combined_df['suite'].eq(suite) |
| 97 | + & combined_df['mode'].eq(mode)][['dtype', 'name', 'accuracy']] |
| 98 | + |
| 99 | + df_subset = drop_duplicates(df_subset, suite, mode) |
| 100 | + pivoted_df = df_subset.pivot(index='name', columns='dtype', values='accuracy') |
| 101 | + |
| 102 | + # Reset index to make 'name' a regular column |
| 103 | + pivoted_df = pivoted_df.reset_index() |
| 104 | + |
| 105 | + # Fill NaN values if some dtype/name combinations don't exist |
| 106 | + pivoted_df = pivoted_df.fillna('') |
| 107 | + |
| 108 | + pivoted_df = pivoted_df[[c for c in cols if c in pivoted_df.columns]] |
| 109 | + |
| 110 | + pivoted_df.to_csv(torch_report_dir / f'inductor_{suite}_{mode}.csv', index=False) |
| 111 | + |
| 112 | + |
| 113 | +def main(input_dir, output_dir): |
| 114 | + """ |
| 115 | + Main function to aggregate end-to-end test results. |
| 116 | +
|
| 117 | + Args: |
| 118 | + input_dir (str): Path to input directory containing test results |
| 119 | + output_dir (str): Path to output directory for aggregated results |
| 120 | + """ |
| 121 | + input_path = Path(input_dir) |
| 122 | + output_path = Path(output_dir) |
| 123 | + |
| 124 | + if not input_path.exists(): |
| 125 | + raise FileNotFoundError(f'Input directory does not exist: {input_path}') |
| 126 | + |
| 127 | + output_path.mkdir(parents=True, exist_ok=True) |
| 128 | + |
| 129 | + print(f'Processing results from: {input_path}') |
| 130 | + print(f'Output will be saved to: {output_path}') |
| 131 | + |
| 132 | + dfs = [] |
| 133 | + for item_path in input_path.iterdir(): |
| 134 | + name = item_path.name |
| 135 | + if not item_path.is_dir(): |
| 136 | + continue |
| 137 | + |
| 138 | + suite, dtype, mode = parse_folder_name(name) |
| 139 | + if suite is None: |
| 140 | + print(f'Folder name \'{name}\' does not match expected pattern, skipping') |
| 141 | + continue |
| 142 | + filepath = item_path / suite / dtype / f'inductor_{suite}_{dtype}_{mode}_xpu_accuracy.csv' |
| 143 | + df = pd.read_csv(filepath) |
| 144 | + df['suite'] = suite |
| 145 | + df['mode'] = mode |
| 146 | + df['dtype'] = dtype |
| 147 | + dfs.append(df) |
| 148 | + |
| 149 | + combined_df = pd.concat(dfs, ignore_index=True) |
| 150 | + combined_df = combined_df.sort_values(['suite', 'mode', 'dtype']) |
| 151 | + |
| 152 | + # Artifacts |
| 153 | + # 1. Simple concat of all with added suite, mode, dtype |
| 154 | + combined_df.to_csv(output_path / 'combined_results.csv', index=False) |
| 155 | + # 2. torch format report, 9 items (suite, mode), dtype stored as column |
| 156 | + build_pytorch_report(combined_df, output_path=output_path) |
| 157 | + # 3. Agg report with 45 rows (suite, mode, dtype, passed, failed_REASON, failed_REASON model list) |
| 158 | + build_suite_report(combined_df, output_path=output_path) |
| 159 | + |
| 160 | + |
| 161 | +if __name__ == '__main__': |
| 162 | + args = parse_args() |
| 163 | + main(args.input_dir, args.output_dir) |
0 commit comments