您的位置:首页 > 其它

[Pytorch]: 错误汇总

2017-07-26 11:18 92 查看

关于自定义后向传播错误

Traceback (most recent call last):
File "/xxx/xxx/xxx.py", line 217, in <module>
output = L.forward(x, label)
File "/xxx/xxx/xxx.py", line 201, in forward
return xxx()(input, target, self.weight)
RuntimeError: save_for_backward can only save input or output tensors, but argument 2 doesn't satisfy this condition


分析:出现这个错误是我在forward中改变了weight这个变量,
weight=weight.div(scalar)
,这导致参数不符合
save_for_backward
的要求。

解决:在forward中要改变weight的值可以使用就地运算
weight.div_(scalar)
。这样即改变也weight的值,又不改变原本的指向。

遇到其它问题会更行,待续…
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: