I guess topRestIdx might be a numpy array, so you could try to call:
topRestIdx = torch.from_numpy(topRestIdx)

before using it.
Also, Variables are deprecated since PyTorch 0.4, so you can use tensors now.
If your code still doesn’t work, could you please post a small code snippet to reproduce this issue by wrapping it into three backticks ```?