The indices (empty tensor) returned by topk for k=0, leads to
RuntimeError: CUDA error: device-side assert triggered when being used for selecting indexes within another tensor. However, when using an empty tensor (not from
topk.indices) for selecting indexes to the another tensor works fine. Is this an expected behavior ? Note that the behavior with
device="cpu" is correct.
Pytorch version 1.5.1. The code runs fine on older version (1.2.0)
Code to reproduce the above:
import torch #device = "cpu" device = "cuda:0" x = torch.arange(1,10).float().to(device) # Case - 1: use an empty cuda tensor for index y =  y_t = torch.LongTensor(y).to(device) # Case - 2: use an empty cuda tensor from topk.indices for index topk = torch.topk (x, k=0, largest=False) print(y_t, topk.indices) x[y_t] = 0.0 print(x) x[topk.indices] = 0.0 print(x)