UserWarning: volatile 已被移除,现在没有 essfet使用 'with torch.no_grad():' 插入

问题描述

PyTorch 版本:1.4.0+cu100 运行时

val_L= Variable(torch.from_numpy(val_L.copy()),volatile=True).cuda()

发生:

UserWarning: volatile was removed and Now has no essfet. Use 'with torch.no_grad():' insted.

那么,我应该如何修改代码? 非常感谢!!!

解决方法

这就是它所指的

with torch.no_grad():
    val_L= Variable(torch.from_numpy(val_L.copy()))