I design my lstm model like this:
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
class LSTMpred(nn.Module):
    def __init__(self, input_size, hidden_dim):
        super(LSTMpred, self).__init__()
        self.input_dim = input_size
        self.hidden_dim = hidden_dim
        self.lstm = nn.LSTM(input_size, hidden_dim)
        self.hidden2out = nn.Linear(hidden_dim, 1)
        self.hidden = self.initHidden()

    def initHidden(self):
        return (Variable(torch.zeros(1, 1, self.hidden_dim)),
                Variable(torch.zeros(1, 1, self.hidden_dim)))

    def forward(self, *input):
        x = input[0]
        lstm_out, self.hidden = self.lstm(
            x.view(len(x), 1, -1), self.hidden
        )
        outdat = self.hidden2out(lstm_out.view(len(x), -1))
        return outdat

I use model = LSTMModel.LSTMpred(1,40).to(device) to initialize my model, but when I try to train it, it’s just stuck on the code modelout = model(indata) and the whole program gets existed after a few seconds saying Process finished with exit code -1073741819 (0xC0000005).
However, when I initialize device to cpu, like device = torch.device('cpu') it starts to work
I’m confused about it, why does it happen? I would appreciate your help.