I can see the following issues with your code:

The constructor of LSTM does not have a parameter batch_size. LSTM does not do batch handling but takes all batches you give it. It’s up to you to split your dataset into batches.
In you training loop, you just loop over epochs. I cannot see any loop over batches. You have to do this manually, e.g., in a nested loop with the outer loop fir the epochs and the inner loop for the batches within each eopch. In short, I think you give your whole dataset to the LSTM, which naturally will bust your memory.
You also don’t seem the re-initialize or detach() the hidden state after each batch. Check out the initHidden() method in this tutorial 36. In a nutshell, without that your backprop graph for the hidden state would grow with every batch.

I hope that helps.