root commited on
Commit
8533f92
1 Parent(s): 9197037

use json built in module and os.listdir

Browse files
Files changed (1) hide show
  1. extract.py +18 -38
extract.py CHANGED
@@ -1,10 +1,8 @@
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 = []
@@ -18,41 +16,23 @@ 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
 
@@ -67,10 +47,10 @@ for i in range(len(model_name)):
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])
 
 
1
  import re
2
+ import json
 
3
  import numpy as np
4
  import statistics
5
+ import os
6
  import csv
7
 
8
  model = []
 
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
 
 
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])