I am facing a similar problem. In fact, I tried the exact code given by Florian (with batch_first=True) and I hardly get about  25 % accuracy on the test set,  with number of iteration ( epochs) set to 50.
However, the Keras code at the above described link, easily attains 80% + accuracy with just 5 epochs over the training data.  The NN architecture  between the two seems to be identical, except for the default values for the LSTM and GRU cells in the Keras and Pytorch implementations, such as LSTM’s kernel initialization, recurrenct_activation==‘hard_sigmoid’ … and so on.
Can someone please clarify if I am missing something ?