title: I meet a problem which is "RuntimeError: Input and hidden tensors are not at the same device, found input tensor at cuda:0 and hidden tensor at cpu"
body: <p>I guess the hidden tensor is the tenor which I need to initialize in the beginning of RNN. So I set the h0 and c0 by .cuda(), but that is not useful. Following is my code.Please, who can give me a hand?</p>
  
  <pre><code>class LSTM_net(nn.Module):
  def __init__(self, Embedding, vocab, label, batch):
      super(LSTM_net, self).__init__()
      self.Hidden_dim = Embedding
      self.Embedding = nn.Embedding(vocab, Embedding)  
      self.lstm = nn.LSTM(Embedding, self.Hidden_dim)  # 32 * 32
      self.hidden2label = nn.Linear(Embedding, label)
      self.hidden = self.init_hidden(batch)
  
  def init_hidden(self, batch):  
      # the first is the hidden h
      # the second is the cell c
  
      if torch.cuda.is_available():
          return (autograd.Variable(torch.zeros(1, batch, self.Hidden_dim)),
                  autograd.Variable(torch.zeros(1, batch, self.Hidden_dim)))
      else:
          return (autograd.Variable(torch.zeros(1, batch, self.Hidden_dim).cuda()),
                  autograd.Variable(torch.zeros(1, batch, self.Hidden_dim).cuda()))
  
  def forward(self, sentence):
      # 64 * 52
      x = self.Embedding(sentence)
      # x = 64 * 52 * 32
      x = x.permute(1, 0, 2)
      # x = 52 * 64 * 32
      lstm_y, lstm_hidden = self.lstm(x, self.hidden)
      # lstm_y = batch * 52 * 32
      # input: lstm_y[-1] = batch * 32
      y = self.hidden2label(lstm_y[-1])
      # y = batch * 5
      log_probs = F.log_softmax(y)
      return log_probs
  </code></pre>