Pytorch RuntimeError: expected device cpu but got device cuda:0

Hello, i am doing someting wrong but i dont know what and i get this runtime error.

d_r = [T.sum(T.FloatTensor([self.gamma**i for i in range(r[j:].size(0))])
RuntimeError: expected device cpu but got device cuda:0

Codes is:


s = T.tensor(self.buffer['s'], dtype=T.double).to(self.device)
a = T.tensor(self.buffer['a'], dtype=T.double).to(self.device).view(-1, 1)
r = T.tensor(self.buffer['r'], dtype=T.double).to(self.device)
s_n = T.tensor(self.buffer['s_n'], dtype=T.double).to(self.device)
d = T.tensor(self.buffer['d'], dtype=T.double).to(self.device).view(-1, 1)

d_r = [T.sum(T.FloatTensor([self.gamma**i for i in range(r[j:].size(0))])\
             * r[j:]) for j in range(r.size(0))]

Can someone help me what i am doing wrong?

could you share a minimal code that the others can just copy and paste to reproduce the error?

There is link to GitHub repo
https://github.com/xPetricko/A2C-pytorch

But it needs packages for Gym to run in it.

The runtime error is from file a2c.py