I wrote a  (1) simple LSTM class and the memory usage is unusual.
However using (2) LSTM directly without writing a LSTM class to use will not cause problem.
What makes the different from using sequential class for RNN and directly use RNN?
Here is the code for (1) and (2):

  
      github.com
  
  
    vagr8/R_Unet/blob/master/rnn_test.py 7
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.optim as optim
import numpy as np
import os
from torch.autograd import Variable
import torch.autograd as autograd
import psutil
import gc

cuda_gpu = torch.cuda.is_available()

class LSTMM(nn.Sequential):
    def __init__(self):
        super(LSTMM, self).__init__()
        self.lstm = nn.LSTM(10, 30, batch_first=True)
        self.h0 = Variable(torch.randn(1, 50, 30))
        self.c0 = Variable(torch.randn(1, 50 ,30))
    


  This file has been truncated. show original

  
  
    
    
  
  


Edit: I found the way I provide code is hard to read, so I put a Github link instead.