PyTorch中每步都是异步的,所以在测试速度时,需要使用torch.cuda.synchronize()
先完成异步操作,方便计算实际效率。
torch.cuda.synchronize()
s0 = time.time()
with torch.no_grad():
output = model(data)
torch.cuda.synchronize()
print(time.time()-s0)
PyTorch中每步都是异步的,所以在测试速度时,需要使用torch.cuda.synchronize()
先完成异步操作,方便计算实际效率。
torch.cuda.synchronize()
s0 = time.time()
with torch.no_grad():
output = model(data)
torch.cuda.synchronize()
print(time.time()-s0)