I am trying to modify some code that uses GRU rnn to use GRUCells instead (I need to experiment on the output of the cells). In the following code I have variables output and hidden that are given to the GRU rnn without problems; when I try to modify them to sue GRUCell, it does not work unless I call .cpu(). Here is what I do and the error message:
>>> output.size()
torch.Size([1, 1, 256])
>>> hidden.size()
torch.Size([1, 1, 256])
>>> self.gru
GRU(256, 256)
>>> k=self.gru(output, hidden) #no errors
>>> cell = torch.nn.GRUCell(256,256)
>>> o = output.view(1,-1)
>>> h = output.view(1,-1)
>>> o.size()
torch.Size([1, 256])
>>> h.size()
torch.Size([1, 256])
>>> k = cell(o.cpu(), h.cpu()) #no errors
>>> k = cell(o, h)
Traceback (most recent call last):
TypeError: addmm_ received an invalid combination of arguments - got (int, int, torch.cuda.FloatTensor, torch.FloatTensor), but expected one of:
 * (torch.cuda.FloatTensor mat1, torch.cuda.FloatTensor mat2)
 * (torch.cuda.sparse.FloatTensor mat1, torch.cuda.FloatTensor mat2)
 * (float beta, torch.cuda.FloatTensor mat1, torch.cuda.FloatTensor mat2)
 * (float alpha, torch.cuda.FloatTensor mat1, torch.cuda.FloatTensor mat2)
 * (float beta, torch.cuda.sparse.FloatTensor mat1, torch.cuda.FloatTensor mat2)
 * (float alpha, torch.cuda.sparse.FloatTensor mat1, torch.cuda.FloatTensor mat2)
 * (float beta, float alpha, torch.cuda.FloatTensor mat1, torch.cuda.FloatTensor mat2)
      didn't match because some of the arguments have invalid types: (int, int, torch.cuda.FloatTensor, torch.FloatTensor)
 * (float beta, float alpha, torch.cuda.sparse.FloatTensor mat1, torch.cuda.FloatTensor mat2)
      didn't match because some of the arguments have invalid types: (int, int, torch.cuda.FloatTensor, torch.FloatTensor)

As you see with .cpu() it works, if I leave them as cuda tensor this error is raised.