-
Notifications
You must be signed in to change notification settings - Fork 0
/
papaya.py
164 lines (126 loc) · 4.08 KB
/
papaya.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
from abc import ABCMeta, abstractmethod
import sys
import torch
class local_sharing():
def __init__(self, func):
self._locals = {}
self.func = func
def __call__(self, *args, **kwargs):
def tracer(frame, event, arg):
if event=='return':
self._locals = frame.f_locals.copy()
sys.setprofile(tracer)
try:
res = self.func(*args, **kwargs)
finally:
sys.setprofile(None)
return res
def clear_locals(self):
self._locals = {}
@property
def locals(self):
return self._locals
class PapayaProfiler:
__metaclass__ = ABCMeta
@local_sharing
def init(self):
pass
@abstractmethod
def create_dataloader(self, batch_size):
pass
def post_create_dataloader():
pass
@abstractmethod
def run_iter(self, batch):
pass
def profile(self):
batch_times = []
self.init()
for batch_size in [4, 8, 12]:
dataloader = self.create_dataloader(batch_size)
self.post_create_dataloader()
for i, batch in enumerate(dataloader):
start = torch.cuda.Event(enable_timing=True)
end = torch.cuda.Event(enable_timing=True)
torch.cuda.synchronize()
start.record()
self.run_iter(batch)
torch.cuda.synchronize()
end.record()
batch_time = start.elapsed_time(end) / 1000.0 # event in ms
def get_p_point(self):
pass
def get_p_score(self):
pass
def predict_max_tpt(self, op, fragmentation_ratio):
pass
def predict_tpt(self, op, batch_size):
pass
def predict_peak_mem(self, op, batch_size):
pass
class Papaya:
def __init__(self) -> None:
pass
def set_optimization(self, op):
pass
def start_iter(self):
pass
def finish_iter(self):
pass
def get_point(self):
pass
def get_score(self, op):
pass
def predict_max_tpt(self, op, fragmentation_ratio):
pass
def predict_tpt(self, op, batch_size):
pass
def predict_peak_mem(self, op, batch_size):
pass
def dump_info():
pass
# ======================= Private Methods Below ===========================
import exp_bert, exp_gpt, exp_swin, argparse, utilizations
algo_dict = {
"swin": exp_swin.Experiment,
"bert": exp_bert.Experiment,
"gpt": exp_gpt.Experiment
}
def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"--machine-tag",
nargs='*',
type=str,
default=["v100"],
help="tag for machine configuration, e.g. v100/t4/4v100",
)
parser.add_argument(
"--run-new", help="run experiment from scratch,\
otherwise using existing data", action='store_true'
)
parser.add_argument(
"--plot-graph", help="plot graph for experiment data", action='store_true'
)
parser.add_argument('--algos', nargs='*', type=str)
parser.add_argument('--network', nargs='*', type=str)
args = parser.parse_args()
if args.algos and len(args.algos): algos = [a.lower() for a in args.algos]
else: algos = list(algo_dict.keys())
if not all(m in algo_dict for m in algos):
print("Framework not covered in experiments.")
return
if "all" in args.machine_tag: args.machine_tag = ["t4","v100","4v100"]
if args.run_new:
# run experiment code to be filled
if not all(mt[-1]==args.machine_tag[0][-1] for mt in args.machine_tag):
print("[ERROR] Please specify a single tag for current machine configurations.")
return
else:
for mt in args.machine_tag:
for m in algos:
print("================={}@{}=================".format(m,mt))
algo_dict[m].run_experiment(mt,args.network)
for tag in args.machine_tag:
for m in algos: algo_dict[m].do_plot(tag,args.plot_graph)
if __name__== "__main__": main()