Makes sense. However, changing to
rnn = nn.RNN(input_size=input_dim, hidden_size=hidden_size, num_layers=num_layers, batch_first=True)
linear = nn.Linear(hidden_size, 1)

and, in the loop:
pred, hidden = rnn(inp, hidden)
pred = linear(pred)

makes learning much worse. Definitely slower and doesn’t converge well. Even for hidden=1, the performance is much worse with the addition of nn.Linear().