-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into visual-abstract+poster
- Loading branch information
Showing
20 changed files
with
1,175 additions
and
200 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ | |
*.txt | ||
*.csv | ||
!requirements.txt | ||
torchviz-output/ | ||
torchview-output/ | ||
|
||
# generated docs | ||
docs_src/_build/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
"""Simple script to make a latex table from best results""" | ||
|
||
import argparse | ||
|
||
import pandas as pd | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument( | ||
"--input", | ||
type=str, | ||
required=True, | ||
help="Path to best_results<params>.csv generated by get_best_results", | ||
) | ||
|
||
|
||
args = parser.parse_args() | ||
|
||
df = pd.read_csv(args.input) | ||
|
||
df = df.set_index("model") | ||
df = df[df["case"] != "Conv"] | ||
df = df[df["case"] != "SurgicalLast"] | ||
|
||
df["memsave"] = df.index.str.startswith("memsave_") | ||
badi = df.index.map( | ||
lambda x: x.split("memsave_", 1)[1] if x.startswith("memsave") else x | ||
) | ||
badi.name = "model_clean" | ||
df2 = df.reset_index().set_index(badi).sort_index() | ||
divs = df2[(df2["case"] == "All") & (~df2["memsave"])] | ||
df2["Scaled M"] = df2["Memory Usage (GB)"] / divs["Memory Usage (GB)"] | ||
df2["Scaled T"] = df2["Time Taken (s)"] / divs["Time Taken (s)"] | ||
|
||
df2["Memory [GiB]"] = df2.apply( | ||
lambda x: f"{x['Memory Usage (GB)']:.2f} ({x['Scaled M']:.2f})", axis=1 | ||
) | ||
df2["Time [s]"] = df2.apply( | ||
lambda x: f"{x['Time Taken (s)']:.2f} ({x['Scaled T']:.2f})", axis=1 | ||
) | ||
|
||
|
||
def _highlight(group, col_sort, col_bold): | ||
for c_s, c_b in zip(col_sort, col_bold): | ||
min_idx = group[c_s].argmin() | ||
group[c_b] = [ | ||
f"\\textbf{{{group.iloc[i][c_b]}}}" if i == min_idx else group.iloc[i][c_b] | ||
for i in range(len(group.index)) | ||
] | ||
return group | ||
|
||
|
||
df2 = df2.groupby(["model_clean", "case"]).apply( | ||
_highlight, ["Memory Usage (GB)"], ["Memory [GiB]"] | ||
) | ||
# .apply(_highlight, ['Memory Usage (GB)', 'Time Taken (s)'], ['Memory [GiB]', 'Time [s]']) | ||
|
||
names = { | ||
"bert": "BERT", | ||
"bart": "BART", | ||
"roberta": "RoBERTa", | ||
"gpt2": "GPT-2", | ||
"t5": "T5 \\cite{JMLR_t5}", | ||
"flan-t5": "FLAN-T5", | ||
"mistral-7b": "Mistral-7B \\cite{jiang2023mistral}", | ||
"transformer": "Transformer \\cite{NIPS2017_3f5ee243_vaswaniattention}", | ||
"llama3-8b": "LLaMa3-8B \\cite{touvron2023llama}", | ||
"phi3-4b": "Phi3-4B \\cite{gunasekar2023textbooksPhi}", | ||
# Conv | ||
"deeplabv3_resnet101": "DeepLabv3 (RN101) \\cite{deeplabv3_chen2017rethinking}", | ||
"efficientnet_v2_l": "EfficientNetv2-L \\cite{efficientnet_TanL19,efficientnetv2_TanL21}", | ||
"fcn_resnet101": "FCN (RN101) \\cite{fcn}", | ||
"mobilenet_v3_large": "MobileNetv3-L \\cite{mobilenetv3}", | ||
"resnext101_64x4d": "ResNeXt101-64x4d \\cite{resnext_cvpr_XieGDTH17}", | ||
"fasterrcnn_resnet50_fpn_v2": "Faster-RCNN (RN101) \\cite{faster_rcnn_RenHGS15}", | ||
"ssdlite320_mobilenet_v3_large": "SSDLite (MobileNetv3-L) \\cite{mobilenetv2_Sandler_2018_CVPR}", | ||
"vgg16": "VGG-16 \\cite{vgg_SimonyanZ14a}", | ||
} | ||
|
||
# import ipdb; ipdb.set_trace() | ||
df2 = df2[df2.index.isin(names.keys(), level=0)] | ||
|
||
|
||
def _format_name(n): | ||
if n.startswith("memsave_"): | ||
mname = n.split("memsave_", 1)[1] | ||
return f"{names[mname]} + MemSave" | ||
return names[n] | ||
|
||
|
||
ni = df2["model"].apply(_format_name) | ||
df2 = df2.set_index(ni).sort_index().drop( | ||
columns=[ | ||
"model", | ||
"memsave", | ||
"Memory Usage (GB)", | ||
"Time Taken (s)", | ||
"Scaled M", | ||
"Scaled T", | ||
] | ||
) # fmt: skip | ||
|
||
df2_p = df2.pivot_table( | ||
index="model", columns="case", values=df2.columns[1:], aggfunc=lambda x: x | ||
) | ||
|
||
short_index = df2_p.index.map(lambda t: "+ MemSave" if "+ MemSave" in t else t) | ||
df2_p = df2_p.set_index(short_index) | ||
|
||
latex_str = df2_p.to_latex(na_rep="-", multicolumn_format="c") | ||
final_str = "" | ||
for line in latex_str.split("\n"): | ||
add_line = line + "\n" | ||
if line.startswith("+ MemSave"): | ||
add_line += "\\midrule\n" | ||
final_str += add_line | ||
print(final_str) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Simple script to make a latex table from resnet results""" | ||
|
||
import pandas as pd | ||
|
||
df = pd.read_csv("results/resnet101_only/best_results-conv-cpu-usage_stats.csv") | ||
df = df.set_index("model") | ||
df = df.drop(columns=["Scaled M", "Scaled T"]) | ||
df = df.drop("memsave_resnet101_conv+relu+bn") | ||
df = df[df["case"] != "SurgicalLast"] | ||
df = df[df["case"] != "Conv"] | ||
|
||
mem_div = df[df["case"] == "All"].loc["resnet101", "Memory Usage (GB)"] | ||
time_div = df[df["case"] == "All"].loc["resnet101", "Time Taken (s)"] | ||
df["Scaled M"] = df["Memory Usage (GB)"] / mem_div | ||
df["Scaled T"] = df["Time Taken (s)"] / time_div | ||
|
||
df["Memory [GiB]"] = df.apply( | ||
lambda x: f"{x['Memory Usage (GB)']:.2f} ({x['Scaled M']:.2f})", axis=1 | ||
) | ||
df["Time [s]"] = df.apply( | ||
lambda x: f"{x['Time Taken (s)']:.2f} ({x['Scaled T']:.2f})", axis=1 | ||
) | ||
|
||
df = df.drop(columns=["Scaled M", "Scaled T", "Memory Usage (GB)", "Time Taken (s)"]) | ||
df_p = df.pivot_table( | ||
index="model", columns="case", values=df.columns[1:], aggfunc=lambda x: x | ||
) | ||
|
||
labels = { | ||
"resnet101": "Default ResNet-101", | ||
"memsave_resnet101_conv": "+ swap Convolution", | ||
"memsave_resnet101_conv_full": "+ swap BatchNorm, ReLU", | ||
} | ||
|
||
df_p = df_p.rename(index=labels) | ||
df_p = df_p.sort_index(ascending=False) | ||
|
||
print(df_p["Memory [GiB]"].to_latex()) | ||
print(df_p["Time [s]"].to_latex()) |
Oops, something went wrong.