The following code snippet from the documentation except I changed the target to be out of bound.
loss = nn.CrossEntropyLoss().to(device)
input = torch.randn(3, 2, requires_grad=True)
target = torch.empty(3, dtype=torch.long).random_(15)
output = loss(input, target)

On device = cpu it raises the correct error
# example
IndexError: Target 2 is out of bounds.

However, the same code snippet (with target out of bound) does not raise the same error on device = cuda:0 but returns a loss = 0
I couldn’t figure out why the behavior is as such or did I missed out something.
PyTorch version = 1.5.0