-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtable2.py
156 lines (128 loc) · 4.3 KB
/
table2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
import os
import json
# Set the paths
json_files_path = "./experiment_results" # Directory where your JSON files are stored
output_md_path = "./README2.md" # Path to the output README.md file
# Initialize lists to store data
results = []
# Read all JSON files and extract data
for filename in os.listdir(json_files_path):
if filename.endswith("_info.json"):
with open(os.path.join(json_files_path, filename), "r") as f:
data = json.load(f)
# Extract model name from filename
model_name = filename.split("-")[0].replace("ckpt@", "")
data["model_name"] = model_name
results.append(data)
# Function to generate markdown table
def generate_markdown_table(headers, rows):
table = "| " + " | ".join(headers) + " |\n"
table += "| " + " | ".join(["---"] * len(headers)) + " |\n"
for row in rows:
table += "| " + " | ".join(str(x) for x in row) + " |\n"
return table
# Function to sort and generate tables
def create_sorted_tables(table_headers, table_rows, sort_by):
sorted_by_memory = sorted(table_rows, key=lambda x: float(x[sort_by["memory"]]))
sorted_by_latency = sorted(table_rows, key=lambda x: float(x[sort_by["latency"]]))
table_memory_md = generate_markdown_table(table_headers, sorted_by_memory)
table_latency_md = generate_markdown_table(table_headers, sorted_by_latency)
return table_memory_md, table_latency_md
# Headers for the tables
table_headers = [
"Model Name",
"Batch Size",
"Quantization",
"Quantize TE",
"Memory (GB)",
"Latency (Seconds)",
]
# Prepare rows for the first table
table_rows = []
for result in results:
table_rows.append(
[
result["model_name"],
result["batch_size"],
result["qtype"].upper(),
"True" if result["qte"] else "False",
result["memory"],
result["time"],
]
)
# Sort and create tables
table_1_memory_md, table_1_latency_md = create_sorted_tables(
table_headers, table_rows, {"memory": 4, "latency": 5}
)
# Prepare rows for the second table
table_2_headers = [
"Model Name",
"Batch Size",
"Quantization",
"Memory (GB)",
"Latency (Seconds)",
]
table_2_rows = []
for result in results:
if result["qte"] == 0: # Only include rows where qte is False
table_2_rows.append(
[
result["model_name"],
result["batch_size"],
result["qtype"].upper(),
result["memory"],
result["time"],
]
)
# Sort and create tables
table_2_memory_md, table_2_latency_md = create_sorted_tables(
table_2_headers, table_2_rows, {"memory": 3, "latency": 4}
)
# Prepare rows for the third table (example with Quantize TE 1, 2, 3 columns)
table_3_headers = [
"Model Name",
"Batch Size",
"Quantization",
"Quantize TE 1",
"Quantize TE 2",
"Quantize TE 3",
"Memory (GB)",
"Latency (Seconds)",
]
table_3_rows = []
for result in results:
# Add dummy Quantize TE 1, 2, 3 values for demonstration
qte_1 = 1 if result["qte"] == 1 else 0
qte_2 = 1 if result["qte"] == 1 else 0
qte_3 = 1 if result["qte"] == 1 else 0
table_3_rows.append(
[
result["model_name"],
result["batch_size"],
result["qtype"].upper(),
qte_1,
qte_2,
qte_3,
result["memory"],
result["time"],
]
)
# Sort and create tables
table_3_memory_md, table_3_latency_md = create_sorted_tables(
table_3_headers, table_3_rows, {"memory": 6, "latency": 7}
)
# Write to README.md
with open(output_md_path, "w") as md_file:
md_file.write("# Experiment Results\n\n")
md_file.write("## Table 1 (Sorted by Memory)\n\n")
md_file.write(table_1_memory_md + "\n")
md_file.write("## Table 1 (Sorted by Latency)\n\n")
md_file.write(table_1_latency_md + "\n")
md_file.write("## Table 2 (Sorted by Memory)\n\n")
md_file.write(table_2_memory_md + "\n")
md_file.write("## Table 2 (Sorted by Latency)\n\n")
md_file.write(table_2_latency_md + "\n")
md_file.write("## Table 3 (Sorted by Memory)\n\n")
md_file.write(table_3_memory_md + "\n")
md_file.write("## Table 3 (Sorted by Latency)\n\n")
md_file.write(table_3_latency_md + "\n")