PyTorch: copy_if failed to synchronize: device-side assert triggered
Getting the following error:


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


when trying to execute:

if torch.nonzero(gt_class_ids &gt; n_classes).size()[0] &gt; 0:

where gt_class_ids is Torch.cuda.LongTensor of size [128] and n_classes = 81.
Running on cuda 9.x

The following code works for me.

n_classes = 81
gt_class_ids = torch.from_numpy(numpy.random.randint(1, 100, size=128)).long()

if torch.nonzero(gt_class_ids &gt; n_classes).size(0) &gt; 0:
    print('okay')


One suggestion: run the code without using cuda and then you will be able to see the real error message. Sometimes when we run code using cuda, it gives error message having device-side assert triggered which hides the real error message.
