-
Notifications
You must be signed in to change notification settings - Fork 0
/
speed.py
50 lines (45 loc) · 1.88 KB
/
speed.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
import numpy as np
import ast
import scipy.interpolate
import matplotlib.pyplot as plt
import os
import psutil
# from mpl_toolkits.mplot3d import Axes3D
# from matplotlib.ticker import MaxNLocator
def speed_funcs() -> dict:
# fit a speed function for each model
# print(u'当前进程的内存使用:%.4f GB' % (psutil.Process(os.getpid()).memory_info().rss / 1024 / 1024 / 1024))
speed_funcs = dict()
records = []
with open("config_speed.txt", "r") as f:
for line in f:
records.append(ast.literal_eval(line.replace('\n', '')))
speed_maps = dict()
for record in records:
model, sync_mode, tot_batch_size, num_ps, num_worker, speeds, ps_cpu_usages, worker_cpu_usages = record
# acutally ,we just use three column from this.
if model not in speed_maps:
speed_maps[model] = []
speed_maps[model].append((num_ps, num_worker, sum(speeds))) # speeds is sample
for model in speed_maps.keys():
x = []
y = []
z = []
for _num_ps, _num_worker, _speed in speed_maps[model]:
x.append(_num_ps)
y.append(_num_worker)
z.append(_speed)
interp = scipy.interpolate.Rbf(np.array(x), np.array(y), np.array(z), function='linear')
speed_funcs[model] = interp # store function
# ''' you could plot function with following codes '''
# xnew, ynew = np.mgrid[-1:1:100j, -1:1:100j] # 输入输出都是二维
# znew = interp(xnew, ynew)
# ax = plt.subplot(111, projection='3d')
# ax.plot_surface(xnew, ynew, znew, rstride=1, cstride=1, cmap='rainbow')
# ax.scatter(x, y, z, c='r', marker='^')
# plt.title('model {0} fitting speed function'.format(str(model)), size=20)
# plt.show()
return speed_funcs
if __name__ == '__main__':
print("fitting speed function...")
speed_funcs()