Pytorch手动求导出现NoneType错误

2021-04-07  本文已影响0人  Kyrielight

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

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.

上一篇 下一篇

猜你喜欢

热点阅读