I tried the code below from http://pytorch.org/docs/master/nn.html?highlight=lstm#torch.nn.LSTM
rnn = nn.LSTM(10, 20, 2)
i = torch.randn(5, 3, 10)
h0 = torch.randn(2, 3, 20)
c0 = torch.randn(2, 3, 20)
output, hn = rnn(i, (h0, c0))
But got this error
RuntimeError Traceback (most recent call last)
<ipython-input-2-573e79300cd2> in <module>()
3 h0 = torch.randn(2, 3, 20)
4 c0 = torch.randn(2, 3, 20)
----> 5 output, hn = rnn(i, (h0, c0))
~\Anaconda3\envs\dl\lib\site-packages\torch\nn\modules\module.py in __call__(self, *input, **kwargs)
355 result = self._slow_forward(*input, **kwargs)
356 else:
--> 357 result = self.forward(*input, **kwargs)
358 for hook in self._forward_hooks.values():
359 hook_result = hook(self, input, result)
~\Anaconda3\envs\dl\lib\site-packages\torch\nn\modules\rnn.py in forward(self, input, hx)
202 flat_weight=flat_weight
203 )
--> 204 output, hidden = func(input, self.all_weights, hx)
205 if is_packed:
206 output = PackedSequence(output, batch_sizes)
~\Anaconda3\envs\dl\lib\site-packages\torch\nn\_functions\rnn.py in forward(input, *fargs, **fkwargs)
371 def RNN(*args, **kwargs):
372 def forward(input, *fargs, **fkwargs):
--> 373 if cudnn.is_acceptable(input.data):
374 func = CudnnRNN(*args, **kwargs)
375 else:
~\Anaconda3\envs\dl\lib\site-packages\torch\tensor.py in data(self)
405 @property
406 def data(self):
--> 407 raise RuntimeError('cannot call .data on a torch.Tensor: did you intend to use autograd.Variable?')
408
409 # Numpy array interface, to support `numpy.asarray(tensor) -> ndarray`
RuntimeError: cannot call .data on a torch.Tensor: did you intend to use autograd.Variable?