'PyTorch analogue of stateful=True in GRU/LSTM/RNN as in tensorflow

I need to make real-time application, so in training I want to preserve states between batches. This means I need something like stateful=True in tensorflow, but in pytorch.

All I found is https://github.com/lmnt-com/haste/issues/8 But their realization looks redundant, maybe it is already created and I can just do something like import StatefulLSTM



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source