-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.py
More file actions
43 lines (38 loc) · 1.15 KB
/
Copy pathanalysis.py
File metadata and controls
43 lines (38 loc) · 1.15 KB
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
import ast
import matplotlib.pyplot as plt
def analyse_line(line):
try:
line = line.decode('utf-8').strip()
data = ast.literal_eval(line)
except (ValueError, SyntaxError, UnicodeDecodeError):
return
if not isinstance(data, dict):
return
return data
def analyse_file(filepath):
series = []
with open(filepath, 'rb') as f:
text = f.readlines()
for line in text:
analysis = analyse_line(line)
if analysis is not None:
series.append(analysis)
return series
def plot_graphs(series):
keys = list(series[0].keys())
episodes = [entry['episode'] for entry in series]
for key in keys:
values = [entry[key] for entry in series]
plt.figure()
plt.plot(episodes, values, label=key)
plt.xlabel('Episode')
plt.ylabel(key)
plt.title(f'{key} over Episodes')
plt.savefig(f'{key.replace("/", ".")}_over_episodes.png')
plt.close()
def main():
filepath = 'result.ppo.meta-llama.Llama-3.1-8B-Instruct.out'
series = analyse_file(filepath)
plot_graphs(series)
if __name__ == "__main__":
main()