UserWarning: This overload of add_ is deprecated

运行别人的代码碰到了两个 warning,虽然不影响使用,但是看着不舒服。

UserWarning: This overload of add_ is deprecated: add_(Number alpha, Tensor other) Consider using one of the following signatures instead: add_(Tensor other, *, Number alpha)

UserWarning: This overload of addcmul_ is deprecated: addcmul_(Number value, Tensor tensor1, Tensor tensor2) Consider using one of the following signatures instead: addcmul_(Tensor tensor1, Tensor tensor2, *, Number value)

原因:PyTorch 1.5 改变了方法的默认参数。

很容易解决,照着提示修改即可。

# 改之前
# next_m.mul_(beta1).add_(1 - beta1, grad)
# next_v.mul_(beta2).addcmul_(1 - beta2, grad, grad)

# 改之后
next_m.mul_(beta1).add_(grad, alpha=1 - beta1)
next_v.mul_(beta2).addcmul_(grad, grad, value=1 - beta2)

你可能感兴趣的:(python,疑难杂症,pytorch,python)