美文网首页
Pytorch手动求导出现NoneType错误

Pytorch手动求导出现NoneType错误

作者: Kyrielight | 来源:发表于2021-04-07 02:19 被阅读0次

更新权重的表达式形式要注意:

w -= 0.01 * w.grad is an in-place operation, so it performs calculation on existing w and updates the value.

However, w = w - 0.01 * w.grad is not in-place operation, so it creates a new variable w, which does not have requires_grad set and so the error.

You can quickly check this by calling - print(w.requires_grad). In the first case you would get True wheres in the second case it would be False.

相关文章

网友评论

      本文标题:Pytorch手动求导出现NoneType错误

      本文链接:https://www.haomeiwen.com/subject/oprykltx.html