Jae-Won Chung commited on
Commit
97b5f1c
2 Parent(s): 9ef9f0b 8533f92

Merge pull request #5 from ml-energy/add_compute_script

Browse files
Files changed (1) hide show
  1. extract.py +69 -0
extract.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import re
2
+ import json
3
+ import numpy as np
4
+ import statistics
5
+ import os
6
+ import csv
7
+
8
+ model = []
9
+ throughput = []
10
+ response_length = []
11
+ latency = []
12
+ energy = []
13
+
14
+ temp_throughput = []
15
+ temp_response_length = []
16
+ temp_latency = []
17
+ temp_energy = []
18
+
19
+ model_name = os.listdir("data/chat")
20
+
21
+ match_name = False
22
+
23
+ for models in model_name:
24
+ with open("data/chat/"+models+"/benchmark.json", 'r') as file:
25
+ json_data = json.load(file)
26
+
27
+ for obj in json_data:
28
+ if not match_name:
29
+ name = str(obj["model"])
30
+ model.append(name.replace('--','/'))
31
+ match_name = True
32
+ temp_throughput.append(float(obj["throughput"]))
33
+ temp_response_length.append(float(obj["response_length"]))
34
+ temp_latency.append(float(obj["latency"]))
35
+ temp_energy.append(float(obj["energy"]))
36
+
37
+ match_name = False
38
+
39
+ throughput.append(temp_throughput.copy())
40
+ response_length.append(temp_response_length.copy())
41
+ latency.append(temp_latency.copy())
42
+ energy.append(temp_energy.copy())
43
+
44
+ temp_throughput.clear()
45
+ temp_response_length.clear()
46
+ temp_latency.clear()
47
+ temp_energy.clear()
48
+
49
+
50
+ avg_throughput = [statistics.mean(row) for row in throughput]
51
+ avg_response_length = [statistics.mean(row) for row in response_length]
52
+ avg_latency = [statistics.mean(row) for row in latency]
53
+ avg_energy = [statistics.mean(row) for row in energy]
54
+
55
+ for i in range(len(model)):
56
+ print(model[i])
57
+ print(len(throughput[i]))
58
+ print(len(response_length[i]))
59
+ print(len(latency[i]))
60
+ print(len(energy[i]))
61
+
62
+ csv_file = "leaderboard.csv"
63
+
64
+ with open(csv_file, "w", newline="") as file:
65
+ writer = csv.writer(file)
66
+ writer.writerow(["model","throughput","response_length","latency","energy"])
67
+ for i in range(len(model)):
68
+ writer.writerow([model[i], avg_throughput[i], avg_response_length[i], avg_latency[i], avg_energy[i]])
69
+