BlueWolf90:

ust need to predict one


First problem, the most important problem of your code:

r_out = r_out.view(-1, self.hidden_dim)

You need to know the output of RNN, which is (batch, seq_len, num_directions * hidden_size) for batch_first=True. Pytorch stacks the output for each step, so you see the second dim of the output is seq_len. When you predict 1 step ahead, you don’t need all the output of RNN. What you really need from r_out is r_out[ :, -1, : ]. The alternative is to use a combination of the outputs of all the steps. One classic method to do that is using attention mechanism.
Second,

x_tensor = torch.Tensor(x).unsqueeze(0) # unsqueeze gives a 1, batch_size dimension

The 1st dim of x_tensor is batch_size, but in your RNN

self.rnn = nn.RNN(input_size, hidden_dim, n_layers, batch_first=False)

You set batch_first=False