PyTorch中每步都是异步的,所以在测试速度时,需要使用torch.cuda.synchronize()先完成异步操作,方便计算实际效率。

torch.cuda.synchronize()
s0 = time.time()
with torch.no_grad():
    output = model(data)
torch.cuda.synchronize()
print(time.time()-s0)
最后修改:2021 年 06 月 01 日 02 : 37 PM
如果觉得我的文章对你有用,请随意赞赏