-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_tester.py
53 lines (44 loc) · 1.7 KB
/
resource_tester.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
from argparse import ArgumentParser
from time import perf_counter
import numpy as np
import torch
from joblib import load
from model import EarthQuakeModel
from pypapi import events, papi_high
def main(deep: bool, time: bool, flops: bool, model: str):
if deep:
model = load_model(model)
sample = torch.empty(1, 2, 512, 512, dtype=torch.float32)
if time:
t0 = perf_counter()
model(sample)
print("Inference Time: ", perf_counter() - t0)
if flops:
papi_high.start_counters([events.PAPI_SP_OPS])
model(sample)
print("MFLOPs: ", papi_high.stop_counters()[0] / 1e6)
else:
model = load_classical_model(model)
sample = np.zeros((1, 2, 512, 512), dtype=np.float32).reshape(1, -1)
if time:
t0 = perf_counter()
model.predict(sample)
print("Inference Time: ", perf_counter() - t0)
if flops:
papi_high.start_counters([events.PAPI_SP_OPS])
model.predict(sample)
print("MFLOPs: ", papi_high.stop_counters()[0] / 1e6)
def load_model(checkpoint):
return EarthQuakeModel.load_from_checkpoint(
checkpoint, strict=False, map_location="cpu"
)
def load_classical_model(checkpoint):
return load(checkpoint)
if __name__ == "__main__":
parser = ArgumentParser()
parser.add_argument("--deep", action="store_true", default=False)
parser.add_argument("--time", action="store_true", default=False)
parser.add_argument("--flops", action="store_true", default=False)
parser.add_argument("--model", type=str, required=True)
args = parser.parse_args()
main(args.deep, args.time, args.flops, args.model)