Pytorch手动求导出现NoneType错误

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

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.

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容