class RNN(nn.Module):
    def __init__(self):
        super(RNN, self).__init__()

        self.rnn = nn.LSTM(
            input_size=6,
            hidden_size=6,
            num_layers=2,
            batch_first=True,
        )
        self.fc = nn.Linear(6,2)

    def forward(self, x):
        out, (h_n, h_c) = self.rnn(x, None)
        return out[:, -1, :]    # Return output at last time-step

X = torch.FloatTensor(X)
y = torch.LongTensor(Y)

rnn = RNN()
optimizer = torch.optim.Adam(rnn.parameters(), lr=0.001)
loss_func = nn.CrossEntropyLoss()     


for j in range(500):
    for i, item in enumerate(X):
        item = item.unsqueeze(0)
        output = rnn(item)
        target = y[i]
        #print(target)
        #target = target.squeeze_()
        #print("input shape:",output.shape, "output shape:", target.shape)
        loss = loss_func(output, target.argmax(dim=1))
        optimizer.zero_grad()
        loss.backward()
        optimizer.step()


this is the complete code
and x = (1000,1,6) and Y = (1000,1,2)