def benchmark_all() -> pd.DataFrame: save_path = Path("./benchmark.csv") df = pd.DataFrame() if save_path.exists(): df = pd.read_csv(str(save_path), index_col=0) index = [] records = [] bar = tqdm(models) try: for key in bar: if key not in df.index: try: model = AutoModel.from_pretrained(key) tr = AutoTransform.from_name(key) batch_size = 64 if key in batch_sizes: batch_size = batch_sizes[key] bar.set_description( f"{key}, size={tr.transforms[0].size}, batch_size={batch_size}" ) top1, top5, time = benchmark(model.to(device), tr, batch_size) index.append(key) data = { "top1": top1, "top5": top5, "time": time, "batch_size": batch_size, } pprint(data) records.append(data) except KeyError: continue except Exception as e: print(e) pass if len(records) > 0: new_df = pd.DataFrame.from_records(records, index=index) if df is not None: df = pd.concat([df, new_df]) else: df = new_df df.to_csv("./benchmark.csv") mk = df.sort_values("top1", ascending=False).to_markdown() with open("./benchmark.md", "w") as f: f.write(mk) return df
def benchmark_all() -> pd.DataFrame: save_path = Path('./benchmark.csv') df = pd.DataFrame() if save_path.exists(): df = pd.read_csv(str(save_path), index_col=0) index = [] records = [] bar = tqdm(models) try: for key in bar: if key not in df.index: try: model = AutoModel.from_pretrained(key) cfg = AutoConfig.from_name(key) tr = cfg.transform batch_size = 64 # if key in batch_sizes: # batch_size = batch_sizes[key] bar.set_description( f'{key}, size={cfg.input_size}, batch_size={batch_size}' ) top1, top5, time = benchmark(model.to(device), tr, batch_size) index.append(key) data = { 'top1': top1, 'top5': top5, 'time': time, 'batch_size': batch_size } pprint(data) records.append(data) except KeyError: continue except Exception as e: print(e) pass new_df = pd.DataFrame.from_records(records, index=index) if df is not None: df = pd.concat([df, new_df]) else: df = new_df df.to_csv('./benchmark.csv') print(df)