benchmark icon indicating copy to clipboard operation
benchmark copied to clipboard

'custom_lstms.py': name 'List' is not defined

Open FedericOldani opened this issue 6 years ago • 7 comments

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

FedericOldani avatar Jan 25 '19 14:01 FedericOldani

I confirm the bug

FedericOldani avatar Jan 25 '19 14:01 FedericOldani

Please follow the issue template and at least post a minimal example that would let us reproduce this error.

apaszke avatar Jan 25 '19 15:01 apaszke

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 avatar Jan 25 '19 16:01 FedericOldani

@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 .

surgan12 avatar Feb 27 '19 13:02 surgan12

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,
}

kangkang59812 avatar Jul 08 '19 06:07 kangkang59812

For fast fixing, I remove all the lines @jit.script_method. Let me know if you solve the problem.

FedericOldani avatar Jul 08 '19 08:07 FedericOldani

@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).

kangkang59812 avatar Jul 08 '19 12:07 kangkang59812

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

spzala avatar May 29 '23 21:05 spzala

Yes, we should close this issue because it is not relevant anymore.

xuzhao9 avatar Jul 26 '23 18:07 xuzhao9