-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathparse_logs.py
273 lines (255 loc) · 10.1 KB
/
parse_logs.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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
import os
import glob
import argparse
import numpy as np
import pandas as pd
class InstanceType:
def __init__(
self,
cost_per_hour=None,
cpu_count=None,
cpu_model=None,
ram=None,
gpu_count=None,
gpu_model=None,
instance_class=None):
self.cost_per_hour = cost_per_hour
self.cpu_count = cpu_count
self.cpu_model = cpu_model
self.ram = ram
self.gpu_count = gpu_count
self.gpu_model = gpu_model
self.instance_class = instance_class
class LogType:
def __init__(self):
self.images = []
self.model = []
self.instance = []
self.instance_class = []
self.epoch_num = []
self.time_per_epoch = []
self.cost_per_hour = []
self.cpu_count = []
self.cpu_model = []
self.ram = []
self.gpu_count = []
self.gpu_model = []
self.cost_per_epoch = []
self.total_time = []
self.total_cost = []
self.batch_size = []
self.model_size = []
self.gpu_mem_allocated = []
self.percent_gpu_util = []
instances = {
"g4dn-xl": InstanceType(
cost_per_hour=0.526,
cpu_count=4,
cpu_model="Cascade Lake P-8259L",
ram=16,
gpu_count=1,
gpu_model="t4",
instance_class="g4"),
"g4dn-2xl": InstanceType(
cost_per_hour=0.752,
cpu_count=8,
cpu_model="Cascade Lake P-8259L",
ram=32,
gpu_count=1,
gpu_model="t4",
instance_class="g4"),
"g4dn-4xl": InstanceType(
cost_per_hour=1.204,
cpu_count=16,
cpu_model="Cascade Lake P-8259L",
ram=64,
gpu_count=1,
gpu_model="t4",
instance_class="g4"),
"g4dn-8xl": InstanceType(
cost_per_hour=2.176,
cpu_count=32,
cpu_model="Cascade Lake P-8259L",
ram=128,
gpu_count=1,
gpu_model="t4",
instance_class="g4"),
"g4dn-12xl": InstanceType(
cost_per_hour=3.912,
cpu_count=48,
cpu_model="Cascade Lake P-8259L",
ram=192,
gpu_count=4,
gpu_model="t4",
instance_class="g4"),
"g4dn-16xl": InstanceType(
cost_per_hour=4.352,
cpu_count=64,
cpu_model="Cascade Lake P-8259L",
ram=256,
gpu_count=1,
gpu_model="t4",
instance_class="g4"),
"p2-xl": InstanceType(
cost_per_hour=0.900,
cpu_count=4,
cpu_model="Broadwell E5-2686 v4",
ram=61,
gpu_count=1,
gpu_model="k80",
instance_class="p2"),
"p2-8xl": InstanceType(
cost_per_hour=7.200,
cpu_count=32,
cpu_model="Broadwell E5-2686 v4",
ram=488,
gpu_count=8,
gpu_model="k80",
instance_class="p2"),
"p3-2xl": InstanceType(
cost_per_hour=3.060,
cpu_count=8,
cpu_model="Broadwell E5-2686 v4",
ram=61,
gpu_count=1,
gpu_model="v100",
instance_class="p3"),
"p3-8xl": InstanceType(
cost_per_hour=12.240,
cpu_count=32,
cpu_model="Broadwell E5-2686 v4",
ram=244,
gpu_count=4,
gpu_model="v100",
instance_class="p3"),
"p3-16xl": InstanceType(
cost_per_hour=24.480,
cpu_count=64,
cpu_model="Broadwell E5-2686 v4",
ram=488,
gpu_count=8,
gpu_model="v100",
instance_class="p3"),
"p3dn-24xl": InstanceType(
cost_per_hour=31.212,
cpu_count=96,
cpu_model="Skylake 8175",
ram=768,
gpu_count=8,
gpu_model="v100",
instance_class="p3"),
}
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("-d", "--dir", required=True, help="Log directory")
args = parser.parse_args()
epoch_df = pd.DataFrame()
total_df = pd.DataFrame()
epochs = LogType()
totals = LogType()
log_list = glob.glob(os.path.join(args.dir, "*.txt"))
for log in log_list:
log_split = log.split("/")[-1].split("_")
images = int(log_split[1].replace("k", "000"))
model = log_split[2]
instance = f"{log_split[3]}-{log_split[4]}"
instance_class = log_split[3]
batch_size = None
with open(log, "rt") as file:
for line in file:
if line.startswith("GPU memory allocated"):
gpu_mem_allocated = int(line[22:])
if line.startswith("Model size"):
model_size = int(line[12:])
if line.startswith("Batch size"):
batch_size = int(line[12:])
if line.startswith("Epoch"):
epoch = line[6]
time_vals = [float(val) for val in line[9:].split(":")]
time = sum([a * b for a, b in zip(time_vals, [3600, 60, 1])])
epochs.images.append(images)
epochs.model.append(model)
epochs.instance.append(instance)
epochs.instance_class.append(instances[instance].instance_class)
epochs.epoch_num.append(epoch)
epochs.time_per_epoch.append(time)
epochs.cost_per_hour.append(instances[instance].cost_per_hour)
epochs.cpu_count.append(instances[instance].cpu_count)
epochs.cpu_model.append(instances[instance].cpu_model)
epochs.ram.append(instances[instance].ram)
epochs.gpu_count.append(instances[instance].gpu_count)
epochs.gpu_model.append(instances[instance].gpu_model)
epochs.cost_per_epoch.append(instances[instance].cost_per_hour/(3600) * time)
epochs.batch_size.append(batch_size)
epochs.model_size.append(model_size)
epochs.gpu_mem_allocated.append(gpu_mem_allocated)
epochs.percent_gpu_util.append((batch_size * model_size)/gpu_mem_allocated)
if line.startswith("Total elapsed"):
time_vals = [float(val) for val in line.split()[-1].split(":")]
if "day" in line:
days = int(line.split()[2])
time_vals[0] += days * 24
time = sum([a * b for a, b in zip(time_vals, [3600, 60, 1])])
totals.images.append(images)
totals.model.append(model)
totals.instance.append(instance)
totals.instance_class.append(instances[instance].instance_class)
totals.total_time.append(time)
totals.cost_per_hour.append(instances[instance].cost_per_hour)
totals.cpu_count.append(instances[instance].cpu_count)
totals.cpu_model.append(instances[instance].cpu_model)
totals.ram.append(instances[instance].ram)
totals.gpu_count.append(instances[instance].gpu_count)
totals.gpu_model.append(instances[instance].gpu_model)
totals.total_cost.append(instances[instance].cost_per_hour/(3600) * time)
totals.batch_size.append(batch_size)
totals.model_size.append(model_size)
totals.gpu_mem_allocated.append(gpu_mem_allocated)
totals.percent_gpu_util.append((batch_size * model_size)/gpu_mem_allocated)
total_df["images"] = totals.images
total_df["model"] = totals.model
total_df["instance"] = totals.instance
total_df["instance_class"] = totals.instance_class
total_df["total_time"] = totals.total_time
total_df["cost_per_hour"] = totals.cost_per_hour
total_df["cpu_count"] = totals.cpu_count
total_df["cpu_model"] = totals.cpu_model
total_df["ram"] = totals.ram
total_df["gpu_count"] = totals.gpu_count
total_df["gpu_model"] = totals.gpu_model
total_df["cost_per_run"] = totals.total_cost
total_df["batch_size"] = totals.batch_size
total_df["model_size"] = totals.model_size
total_df["gpu_mem_allocated"] = totals.gpu_mem_allocated
total_df["percent_gpu_util"] = totals.percent_gpu_util
epoch_df["images"] = epochs.images
epoch_df["model"] = epochs.model
epoch_df["instance"] = epochs.instance
epoch_df["instance_class"] = epochs.instance_class
epoch_df["epoch"] = epochs.epoch_num
epoch_df["time_per_epoch"] = epochs.time_per_epoch
epoch_df["cost_per_hour"] = epochs.cost_per_hour
epoch_df["cpu_count"] = epochs.cpu_count
epoch_df["cpu_model"] = epochs.cpu_model
epoch_df["ram"] = epochs.ram
epoch_df["gpu_count"] = epochs.gpu_count
epoch_df["gpu_model"] = epochs.gpu_model
epoch_df["cost_per_epoch"] = epochs.cost_per_epoch
epoch_df["batch_size"] = epochs.batch_size
epoch_df["model_size"] = epochs.model_size
epoch_df["gpu_mem_allocated"] = epochs.gpu_mem_allocated
epoch_df["percent_gpu_util"] = epochs.percent_gpu_util
for image in epoch_df["images"].unique():
for instance in epoch_df["instance"].unique():
costs = epoch_df.loc[(epoch_df["images"] == image) & (epoch_df["instance"] == instance), "cost_per_epoch"]
times = epoch_df.loc[(epoch_df["images"] == image) & (epoch_df["instance"] == instance), "time_per_epoch"]
total_df.loc[(total_df["images"] == image) & (total_df["instance"] == instance), "mean_epoch_time"] = times.mean()
total_df.loc[(total_df["images"] == image) & (total_df["instance"] == instance), "std_epoch_time"] = times.std()
total_df.loc[(total_df["images"] == image) & (total_df["instance"] == instance), "mean_epoch_cost"] = costs.mean()
total_df.loc[(total_df["images"] == image) & (total_df["instance"] == instance), "std_epoch_cost"] = costs.std()
total_df = total_df.sort_values(by=["instance", "images"])
total_df = total_df.reset_index(drop=True)
epoch_df = epoch_df.sort_values(by=["instance", "images"])
epoch_df = epoch_df.reset_index(drop=True)
epoch_df.to_csv("epoch_times.csv", index=False)
total_df.to_csv("total_times.csv", index=False)