RuntimeError: reduce failed to synchronize: device-side assert triggered
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 


When using cuda you may get this generic error which is not very helpful. Try switching to cpu device instead, device = torch.device("cpu"), to see the actual error stack trace.

In my case, the issue was caused because binary cross entropy expected the input values to be between 0~1, but I was sending in values between -1 and 1. Applying sigmoid to the output resolved that issue.
