[Pytorch]: 错误汇总

关于自定义后向传播错误

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的值,又不改变原本的指向。


遇到其它问题会更行,待续…

你可能感兴趣的:(Pytorch)