Convert Variable with torch.FloatTensor to torch.cuda.FloatTensor

a = Variable(torch.ones(2)
if torch.cuda.is_available():
    a.cuda()

However, this is not working for some reason. a is still a Variable of torch.FloatTensor. Any workaround?

1 Like

The tensor.cuda() method returns a new tensor. Try a = a.cuda().

2 Likes