benchmark
benchmark copied to clipboard
'custom_lstms.py': name 'List' is not defined
I got this error, but i'm not able to find where the error come from.
File "lstm_test.py", line 300, in <module>
test_script_stacked_bidir_rnn(5, 2, 3, 7, 4)
File "lstm_test.py", line 275, in test_script_stacked_bidir_rnn
rnn = script_lstm(input_size, hidden_size, num_layers, bidirectional=True)
File "lstm_test.py", line 50, in script_lstm
hidden_size])
File "C:\Users\feder\Anaconda3\lib\site-packages\torch\jit\__init__.py", line 950, in init_then_register
original_init(self, *args, **kwargs)
File "lstm_test.py", line 189, in __init__
other_layer_args)
File "lstm_test.py", line 150, in init_stacked_lstm
layers = [layer(*first_layer_args)] + [layer(*other_layer_args)
File "C:\Users\feder\Anaconda3\lib\site-packages\torch\jit\__init__.py", line 950, in init_then_register
original_init(self, *args, **kwargs)
File "lstm_test.py", line 129, in __init__
ReverseLSTMLayer(cell, *cell_args),
File "C:\Users\feder\Anaconda3\lib\site-packages\torch\jit\__init__.py", line 951, in init_then_register
_create_methods_from_stubs(self, methods)
File "C:\Users\feder\Anaconda3\lib\site-packages\torch\jit\__init__.py", line 912, in _create_methods_from_stubs
self._create_methods(defs, rcbs, defaults)
File "C:\Users\feder\Anaconda3\lib\site-packages\torch\jit\annotations.py", line 52, in get_signature
return parse_type_line(type_line)
File "C:\Users\feder\Anaconda3\lib\site-packages\torch\jit\annotations.py", line 90, in parse_type_line
arg_ann = eval(arg_ann_str, _eval_env)
File "<string>", line 1, in <module>
NameError: name 'List' is not defined
I confirm the bug
Please follow the issue template and at least post a minimal example that would let us reproduce this error.
The error is raised when I run rnns\fastrnns\custom_lstm.py (I renamed it 'lstm_test.py') The problem is in the test of bidirectional lstm, the Traceback error is posted above. Thank you for your help
@FedericOldani
https://github.com/pytorch/pytorch/blob/44a607b90c9bba0cf268f833bae4715221346709/torch/jit/annotations.py#L33
Check this in the annotations.py of your pytorch version. Probably this is missing .
So how to fix this ? update to pytorch1.1 ? I use pytorch1.0.1 and in annotations.py it has
_eval_env = {
'torch': Module('torch', {'Tensor': torch.Tensor}),
'Tensor': torch.Tensor,
'typing': Module('typing', {'Tuple': Tuple}),
'Tuple': Tuple,
}
For fast fixing, I remove all the lines @jit.script_method
. Let me know if you solve the problem.
@FedericOldani But it seems that the custom lstm has no relation with jit
. It also woks if class LSTMCell(nn.Module)
without undering jit
. And LSTMCell(nn.Module)
runs faster than LSTMCell(jit.Module)
.
I was looking at the issue from triage aspect, and I couldn't reproduce the error, and I see don't rnns\fastrnns\custom_lstm.py
anymore. Perhaps, the issue is not relevant and now and we should close. Thanks! cc @xuzhao9
Yes, we should close this issue because it is not relevant anymore.