I am trying to use nn.utils.rnn.pack_sequence to provide input to an LSTM.
a = torch.Tensor([1, 2, 3])
b = torch.Tensor([4, 5])
c = torch.Tensor([6])
packed = rnn_utils.pack_sequence([a,b,c])
The above (pulled straight from the docs) seems to run just fine and returns the following:
PackedSequence(data=tensor([1., 4., 6., 2., 5., 3.]), batch_sizes=tensor([3, 2, 1]))
The problem is that despite the documentation stating you can provide an rnn/lstm/gru a packedsequence and linking to the pack_sequence util, I cannot get it to work. Creating a simple rnn layer-- nn.RNN(3,3)
--and supplying the above packed sequence yields the following error:
124 raise RuntimeError(
125 'input must have {} dimensions, got {}'.format(
--> 126 expected_input_dim, input.dim()))
127 if self.input_size != input.size(-1):
128 raise RuntimeError(
RuntimeError: input must have 2 dimensions, got 1
What am I doing wrong here?