starter, ender = torch.cuda.Event(enable_timing=True), torch.cuda.Event(enable_timing=True)
t = []
for i in enumerate(dataset):
timings = []
with torch.no_grad():
starter.record()
out = model(inputs)
ender.record()
torch.cuda.synchronize()
curr_time = starter.elapsed_time(ender)
timings.append(curr_time)
print('timings mean:', np.mean(timings))
t.append(curr_time)
print('timings min:', np.min(t))
与参考的博客里不同的地方是这里取了最小值,不太确定应该取平均还是最小。