RuntimeError:减少同步失败:设备端断言已触发

时间:2018-11-29 02:04:18

标签: python-3.x pytorch

File "/home/username/anaconda3/lib/python3.6/site-packages/torch/nn/modules/loss.py", line 433, in forward     reduce=self.reduce)   
File "/home/username/anaconda3/lib/python3.6/site-packages/torch/nn/functional.py", line 1483, in binary_cross_entropy     
return torch._C._nn.binary_cross_entropy(input, target, weight, size_average, reduce)

RuntimeError: reduce failed to synchronize: device-side assert triggered 

1 个答案:

答案 0 :(得分:1)

在使用cuda时,您可能会遇到此通用错误,它不是很有帮助。尝试改用cpu设备device = torch.device("cpu")来查看实际的错误堆栈跟踪。

在我的情况下,此问题是由于二进制互熵期望输入值介于0〜1之间而引起的,但是我发送的值介于-1和1之间。对输出应用sigmoid可解决该问题