I met the same problem and solved it by adding
self.rnn.flatten_parameters()
into the
def forward(self, x)
at the position before calling
rnn_output, _ = self.rnn(x, h)
By doing so, the error never showed up.
如果想看如何解决详情查看这个链接
我在rnn_out 前加了个图片所高亮的代码,解决了我的问题。