TypeError: only integer tensors of a single element can be converted to an index

Could you try to pass the indices as LongTensors?
If they are not already in that type, just use .to(dtype=torch.long, device=device).

PS: Variables are deprecated since PyTorch 0.4. If you are using a newer version, you can just use tensors instead.

2 Likes