赞
踩
在训练时,检测 “out of memory” 的error并通过torch.cuda.empty_cache()处理
如:
try:
outputs = net(inputs)
except RuntimeError as exception:
if "out of memory" in str(exception):
print('WARNING: out of memory, will pass this')
torch.cuda.empty_cache()
continue
else:
raise exception
在测试时,避免忘记设置 torch.no_grad()
如:
with torch.no_grad():
inputs = None
outputs = model(inputs)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。