RuntimeError:reduce 同步失败:触发设备端断言

M.N*_*iaz 2 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 
Run Code Online (Sandbox Code Playgroud)

Zah*_*hra 6

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

就我而言,问题是由于二进制交叉熵预期输入值介于 0~1 之间,但我发送的值介于 -1 和 1 之间。应用于sigmoid输出解决了该问题。