Linear Layer accepts tensor, but gets tuple

I wanted to play around with RNN’s a bit, and was curious if LSTM could predict the next 2 number given a single number, e.g.

x = [1]
y = [2, 3]

For this, I tried the following:

def create_training_data(n):

    x = torch.randint(0, 200, size=(n, 1), dtype=torch.float32, requires_grad=True)
    y =  torch.cat([x+1, x+2], dim=1)

    return x, y 

x, y = create_training_data(1000)

model= nn.Sequential(
    nn.Linear(1, 10),
    nn.ReLU(),
    nn.LSTM(input_size=10, hidden_size=10),
    nn.Linear(10, 2)
)

loss_fn = nn.MSELoss()
optimizer = torch.optim.SGD(model.parameters(), lr=0.01, momentum=0.9)
train = data_utils.TensorDataset(x, y)
train_dataloder = DataLoader(train, batch_size=64, shuffle=True)

for batch_idx, (x, y) in enumerate(train_dataloder):
    res = model(x)

However, I get the error:

TypeError: linear(): argument 'input' (position 1) must be Tensor, not tuple

I do not understand why it is a tuple though, it should clearly be a tensor. What am I doing wrong?

nn.LSTM returns multiple outputs as described in the docs, while the next nn.Linear layer expects a single tensor input.
You could either write a custom nn.Module for the entire model or only for the nn.LSTM module returning the desired output tensor.