-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_tb.py
173 lines (127 loc) · 6.07 KB
/
parse_tb.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
from pathlib import Path
import json
import pandas as pd
from tensorboard.backend.event_processing import event_accumulator
import pandas as pd
from tqdm.notebook import tqdm
TGT_COLS = ['task_name', 'from_pretrained', 'model_cfg', 'model_cls', 'model_type', 'lr', 'batch_size', 'HVD_SIZE', 'lr_scheduler', 'input_seq_len', 'max_n_segments', 'input_size', 'num_mem_tokens','segment_ordering','padding_side', 'model_path', 'sum_loss', 'inter_layer_memory', 'memory_layers', 'share_memory_layers','reconstruction_loss_coef', 'num_steps']
SILENT = True
def parse_tensorboard(path, scalars, silent=SILENT):
"""returns a dictionary of pandas dataframes for each requested scalar"""
ea = event_accumulator.EventAccumulator(
path,
size_guidance={event_accumulator.SCALARS: 0},
)
_absorb_print = ea.Reload()
# make sure the scalars are in the event accumulator tags
# assert all(
# s in ea.Tags()["scalars"] for s in scalars
# ),"" if silent else "some scalars were not found in the event accumulator"
# return {k: pd.DataFrame(ea.Scalars(k)) for k in scalars}
found_scalars = [s for s in scalars if s in ea.Tags()['scalars']]
return {k: pd.DataFrame(ea.Scalars(k)) for k in found_scalars}
def parse_to_df(path, target_cols, metric_names, silent=SILENT):
path = Path(path)
logs = list(path.glob('**/*tfevents*'))
experiments = []
for p in tqdm(logs):
expr = json.load(open(p.parent / 'config.json', 'r'))
metrics = {}
try:
metrics = parse_tensorboard(str(p), [f'{m}/iterations/valid' for m in metric_names])
except Exception as e:
if not silent:
print(f'error: {e}\n\tskip: {p}')
try:
metrics_test = parse_tensorboard(str(p), [f'{m}/iterations/test' for m in metric_names])
except Exception as e:
metrics_test = {}
if not silent:
print(f'error: {e}\n\t no test metrics in: {p}')
metrics.update(metrics_test)
if len(metrics) == 0:
continue
for m in metric_names:
if f'{m}/iterations/test' in metrics:
expr[m] = metrics[f'{m}/iterations/test']['value'].item()
expr[f'best_valid_{m}'] = metrics[f'{m}/iterations/valid']['value'].max()
# print(parse_tensorboard(str(p), ['loss/iterations/train'])['loss/iterations/train'].step)
parsed = parse_tensorboard(str(p), ['loss/iterations/train'])
if 'loss/iterations/train' in parsed:
expr['num_steps'] = parsed['loss/iterations/train'].step.max()
experiments += [expr]
experiments = pd.DataFrame(experiments)
# print('\n\ncolumns: ', experiments.columns)
not_found_cols = [col for col in target_cols if col not in experiments.columns]
if not_found_cols:
if not silent:
print(f'{not_found_cols} not found in columns!!\ncolumns:{experiments.columns}')
found_cols = [col for col in target_cols if col in experiments.columns]
experiments = experiments[found_cols]
return experiments
# print('\n\ncolumns: ', experiments.columns)
# # # HYP
# path = Path('/home/bulatov/bulatov/runs/finetune/debug/hyperpartisan_news_detection')
# metric_names = ['f1', 'precision', 'recall', 'accuracy']
# target_cols = ['f1', 'best_valid_f1', 'precision', 'best_valid_precision', 'recall', 'best_valid_recall', 'accuracy', 'best_valid_accuracy']
# out_path = 'results/hyp_new.csv'
# parse_to_csv(path, out_path, target_cols, metric_names)
# # CNLI
# path = Path('/home/bulatov/bulatov/RMT_light/runs/debug/contract_nli')
# metric_names = ['exact_match']
# target_cols = TGT_COLS + ['best_valid_exact_match']
# out_path = 'results/contract_nli_old.csv'
# df = parse_to_csv(path, out_path, target_cols, metric_names)
# df.to_csv(out_path, index=False)
paths = ['/home/bulatov/bulatov/RMT_light/runs/framework/contract_nli',
'/home/bulatov/bulatov/RMT_light/runs/test/contract_nli'
]
paths = [Path(p) for p in paths]
metric_names = ['exact_match']
target_cols = TGT_COLS + ['best_valid_exact_match']
out_path = 'results/contract_nli.csv'
dfs = [parse_to_df(p, target_cols, metric_names) for p in paths]
df = pd.concat(dfs)
df.to_csv(out_path, index=False)
# path = Path()
# metric_names = ['exact_match']
# target_cols = TGT_COLS + ['best_valid_exact_match']
# out_path = 'results/contract_nli-2.csv'
# df = parse_to_csv(path, out_path, target_cols, metric_names)
# df.to_csv(out_path, index=False)
# # QAsper
path = Path('/home/bulatov/bulatov/RMT_light/runs/framework/qasper')
metric_names = ['f1']
target_cols = TGT_COLS + ['best_valid_f1']
out_path = 'results/qasper.csv'
df = parse_to_df(path, target_cols, metric_names)
df.to_csv(out_path, index=False)
# Babi-long
paths = ['/home/bulatov/bulatov/RMT_light/runs/framework/babilong',
'/home/bulatov/bulatov/RMT_light/runs/curriculum_task/babilong',
'/home/bulatov/bulatov/RMT_light/runs/curriculum/babilong'
]
# path = Path('/home/bulatov/bulatov/RMT_light/runs/')
paths = [Path(p) for p in paths]
metric_names = ['exact_match']
target_cols = TGT_COLS + ['best_valid_exact_match']
out_path = 'results/babilong.csv'
dfs = [parse_to_df(p, target_cols, metric_names) for p in paths]
df = pd.concat(dfs)
df.to_csv(out_path, index=False)
# path = Path('/home/bulatov/bulatov/runs_hyp_good_cnli_ok_080822/finetune/debug/contract_nli')
# metric_names = ['exact_match']
# target_cols = TGT_COLS + ['best_valid_exact_match']
# out_path = 'results/debug_cnli.csv'
# parse_to_csv(path, out_path, target_cols, metric_names)
# path = Path('/home/bulatov/bulatov/runs/finetune/debug/qmsum')
# metric_names = ['rouge/geometric_mean']
# target_cols = TGT_COLS + ['best_valid_rouge/geometric_mean']
# out_path = 'results/qmsum.csv'
# parse_to_csv(path, out_path, target_cols, metric_names)
# # quality
# path = Path('/home/bulatov/bulatov/runs/finetune/debug/quality')
# metric_names = ['exact_match']
# target_cols = TGT_COLS + ['best_valid_exact_match']
# out_path = 'results/quality_new.csv'
# parse_to_csv(path, out_path, target_cols, metric_names)