title: AttributeError: 'tuple' object has no attribute 'size'
body: <p>UPDATE: after looking back on this question, most of the code was unnecessary. In summary, the hidden layer of a Pytorch RNN needs to be a torch tensor. When I posted the question, the hidden layer was a tuple.</p>
  <p>Below is my data loader.</p>
  <pre><code>from torch.utils.data import TensorDataset, DataLoader
  
  def batch_data(log_returns, sequence_length, batch_size):
      &quot;&quot;&quot;
      Batch the neural network data using DataLoader
      :param log_returns: asset's daily log returns
      :param sequence_length: The sequence length of each batch
      :param batch_size: The size of each batch; the number of sequences in a batch
      :return: DataLoader with batched data
      &quot;&quot;&quot;
      
      # total number of batches we can make
      n_batches = len(log_returns)//batch_size
      
      # Keep only enough characters to make full batches
      log_returns = log_returns[:n_batches * batch_size]
      
      y_len = len(log_returns) - sequence_length
      
      x, y = [], []
      for idx in range(0, y_len):
          idx_end = sequence_length + idx
          x_batch = log_returns[idx:idx_end]
          x.append(x_batch)
          # only making predictions after the last word in the batch
          batch_y = log_returns[idx_end]    
          y.append(batch_y)    
      
      # create tensor datasets
      x_tensor = torch.from_numpy(np.asarray(x))
      y_tensor = torch.from_numpy(np.asarray(y))
      
      # make x_tensor 3-d instead of 2-d
      x_tensor = x_tensor.unsqueeze(-1)
      
      data = TensorDataset(x_tensor, y_tensor)
      
      data_loader = DataLoader(data, shuffle=False, batch_size=batch_size)
      
      # return a dataloader
      return data_loader
  </code></pre>
  <pre><code>    def init_hidden(self, batch_size):
          ''' Initializes hidden state '''
          # Create two new tensors with sizes n_layers x batch_size x n_hidden,
          # initialized to zero, for hidden state and cell state of LSTM
          weight = next(self.parameters()).data
          
          if (train_on_gpu):
              hidden = (weight.new(self.n_layers, batch_size, self.n_hidden).zero_().cuda(),
                        weight.new(self.n_layers, batch_size, self.n_hidden).zero_().cuda())
          else:
              hidden = (weight.new(self.n_layers, batch_size, self.n_hidden).zero_(),
                        weight.new(self.n_layers, batch_size, self.n_hidden).zero_())
          
          return hidden
  </code></pre>
  <p>I don't know what is wrong. When I try to start training the model, I am getting the error message:</p>
  <pre><code>AttributeError: 'tuple' object has no attribute 'size'
  </code></pre>