The reason you are getting this error is because the number of input neurons in your linear layer is less than the number of inputs to the layer. You need to change the size to match the output size of your lstm. Can you print the shape of the lstm output doing this
        x = x.view(N, T, D).type(torch.FloatTensor).to(device)
        out, (ht, ct) = self.lstm(x, hidden)
        out = self.tanh(out)
        print(out.shape)
        out = self.output_layer(out)

whatever that outputs you should change the number of input neurons in you linear layer to.