Does torchscript not support torch.nn.utils.rnn.pack_sequence
?
Here’s a minimal example of what isn’t working on my computer:
import torch
class Test(torch.nn.Module):
def forward(self):
# return torch.tensor(1)
sequences = [torch.randn(torch.randint(1,5,(1,)),3) for i in range(10)]
packed = torch.nn.utils.rnn.pack_sequence(sequences, enforce_sorted=False)
model = Test()
model()
print("successfully called normal model")
try:
tsModel = torch.jit.script(model)
print("Successfully converted model")
except Exception as e:
print("Failed to convert torchscript model!")
print(e)
This code outputs the following for me:
successfully called normal model
Failed to convert torchscript model!
Tried to access nonexistent attribute or method 'new' of type 'Tensor'.:
File "/home/jack/.pyenv/versions/3.7.0/lib/python3.7/site-packages/torch/nn/utils/rnn.py", line 365
out_dims = (max_len, len(sequences)) + trailing_dims
out_tensor = sequences[0].data.new(*out_dims).fill_(padding_value)
~~~~~~~~~~~~~~~~~~~~ <--- HERE
for i, tensor in enumerate(sequences):
length = tensor.size(0)
'pad_sequence' is being compiled since it was called from 'pack_sequence'
File "/home/jack/.pyenv/versions/3.7.0/lib/python3.7/site-packages/torch/nn/utils/rnn.py", line 409
"""
lengths = [v.size(0) for v in sequences]
return pack_padded_sequence(pad_sequence(sequences), lengths, enforce_sorted=enforce_sorted)
~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
'pack_sequence' is being compiled since it was called from 'Test.forward'
File "test.py", line 9
# return torch.tensor(1)
sequences = [torch.randn(torch.randint(1,5,(1,)),3) for i in range(10)]
packed = torch.nn.utils.rnn.pack_sequence(sequences, enforce_sorted=False)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE