Spaces:
Running
Running
root
commited on
Commit
•
9197037
1
Parent(s):
9ef9f0b
add compute script
Browse files- extract.py +89 -0
extract.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import subprocess
|
2 |
+
import re
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
import datetime
|
5 |
+
import numpy as np
|
6 |
+
import statistics
|
7 |
+
import pdb
|
8 |
+
import csv
|
9 |
+
|
10 |
+
model = []
|
11 |
+
throughput = []
|
12 |
+
response_length = []
|
13 |
+
latency = []
|
14 |
+
energy = []
|
15 |
+
|
16 |
+
temp_throughput = []
|
17 |
+
temp_response_length = []
|
18 |
+
temp_latency = []
|
19 |
+
temp_energy = []
|
20 |
+
|
21 |
+
model1 = input("model 1: ")
|
22 |
+
model2 = input("model 2: ")
|
23 |
+
model3 = input("model 3: ")
|
24 |
+
model4 = input("model 4: ")
|
25 |
+
|
26 |
+
model_name = []
|
27 |
+
model_name.append(model1)
|
28 |
+
model_name.append(model2)
|
29 |
+
model_name.append(model3)
|
30 |
+
model_name.append(model4)
|
31 |
+
|
32 |
+
match_name = False
|
33 |
+
|
34 |
+
for i in range(len(model_name)):
|
35 |
+
with open(model_name[i], 'r') as file:
|
36 |
+
model_lines = file.readlines()
|
37 |
+
|
38 |
+
for i in range(len(model_lines)):
|
39 |
+
match = re.search(r'"model":\s*"([^"]+)"', model_lines[i])
|
40 |
+
match1 = re.search(r'"throughput":\s*(\d+.\d+)', model_lines[i])
|
41 |
+
match2 = re.search(r'"response_length":\s*([0-9]+)', model_lines[i])
|
42 |
+
match3 = re.search(r'"latency":\s*(\d+.\d+)', model_lines[i])
|
43 |
+
match4 = re.search(r'"energy":\s*(\d+.\d+)', model_lines[i])
|
44 |
+
if match and not match_name:
|
45 |
+
temp_model_name = str(match.group(1))
|
46 |
+
model.append(temp_model_name.replace('--', '/'))
|
47 |
+
match_name = True
|
48 |
+
elif match1:
|
49 |
+
temp_throughput.append(float(match1.group(1)))
|
50 |
+
elif match2:
|
51 |
+
temp_response_length.append(float(match2.group(1)))
|
52 |
+
elif match3:
|
53 |
+
temp_latency.append(float(match3.group(1)))
|
54 |
+
elif match4:
|
55 |
+
temp_energy.append(float(match4.group(1)))
|
56 |
+
|
57 |
+
match_name = False
|
58 |
+
|
59 |
+
throughput.append(temp_throughput.copy())
|
60 |
+
response_length.append(temp_response_length.copy())
|
61 |
+
latency.append(temp_latency.copy())
|
62 |
+
energy.append(temp_energy.copy())
|
63 |
+
|
64 |
+
temp_throughput.clear()
|
65 |
+
temp_response_length.clear()
|
66 |
+
temp_latency.clear()
|
67 |
+
temp_energy.clear()
|
68 |
+
|
69 |
+
|
70 |
+
avg_throughput = [sum(row) / len(row) for row in throughput]
|
71 |
+
avg_response_length = [sum(row) / len(row) for row in response_length]
|
72 |
+
avg_latency = [sum(row) / len(row) for row in latency]
|
73 |
+
avg_energy = [sum(row) / len(row) for row in energy]
|
74 |
+
|
75 |
+
for i in range(len(model)):
|
76 |
+
print(model[i])
|
77 |
+
print(len(throughput[i]))
|
78 |
+
print(len(response_length[i]))
|
79 |
+
print(len(latency[i]))
|
80 |
+
print(len(energy[i]))
|
81 |
+
|
82 |
+
csv_file = "leaderboard.csv"
|
83 |
+
|
84 |
+
with open(csv_file, "w", newline="") as file:
|
85 |
+
writer = csv.writer(file)
|
86 |
+
writer.writerow(["model","throughput","response_length","latency","energy"])
|
87 |
+
for i in range(len(model)):
|
88 |
+
writer.writerow([model[i], avg_throughput[i], avg_response_length[i], avg_latency[i], avg_energy[i]])
|
89 |
+
|