Solved by SimonW in post #2 
              
              
                You need cuda.LongTensor to index a cuda tensor. You should probably change torch.arange(sample_size).type(torch.LongTensor) to torch.arange(sample_size).type_as(target.data).