forked from gc-fu/FastChat-bench
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcalc_token_time.py
31 lines (25 loc) · 1.05 KB
/
calc_token_time.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
import json
import numpy as np
log_file = "./wrk.log"
first_token_times = []
rest_token_times = []
with open(log_file, "r") as file:
for line in file:
try:
if line.startswith('{"id":'):
data = json.loads(line)
choices = data.get("choices", [])
for choice in choices:
first_token_time = choice.get("first_token_time")
rest_token_time = choice.get("rest_token_time")
if first_token_time is not None:
first_token_times.append(first_token_time)
if rest_token_time is not None:
rest_token_times.append(rest_token_time)
except Exception:
pass
#print(f"Error parsing JSON at line : {line}")
average_first_token_time = np.mean(first_token_times)
average_rest_token_time = np.mean(rest_token_times)
print("Average first_token_time:", average_first_token_time * 1000)
print("Average rest_token_time:", average_rest_token_time * 1000)