pytorch / translate

Translate - a PyTorch Language Library
BSD 3-Clause "New" or "Revised" License
826 stars 192 forks source link

NameError: name 'LevenshteinTransformerModel' is not defined #673

Closed erip closed 4 years ago

erip commented 4 years ago

When running bash pytorch_translate/examples/train_iwslt14.sh

Traceback (most recent call last):
  File "pytorch_translate/train.py", line 835, in <module>
    _main()
  File "pytorch_translate/train.py", line 831, in _main
    main(args)
  File "pytorch_translate/train.py", line 809, in main
    single_process_main(args, trainer_class, **train_step_kwargs)
  File "pytorch_translate/train.py", line 719, in single_process_main
    **train_step_kwargs,
  File "pytorch_translate/train.py", line 639, in train
    checkpoint_manager=checkpoint_manager,
  File "/Users/erippeth/Code/independent/onnx_junk/translate/pytorch_translate/evals.py", line 395, in save_and_eval
    averaged_params=averaged_params,
  File "/Users/erippeth/Code/independent/onnx_junk/translate/pytorch_translate/evals.py", line 181, in evaluate_bleu
    model_params=averaged_params,
  File "/Users/erippeth/Code/independent/onnx_junk/translate/pytorch_translate/evals.py", line 275, in calculate_bleu_on_subset
    modify_target_dict=False,
  File "/Users/erippeth/Code/independent/onnx_junk/translate/pytorch_translate/generate.py", line 101, in generate_score
    modify_target_dict=modify_target_dict,
  File "/Users/erippeth/Code/independent/onnx_junk/translate/pytorch_translate/generate.py", line 178, in _generate_score
    translator = build_sequence_generator(args, task, models)
  File "/Users/erippeth/Code/independent/onnx_junk/translate/pytorch_translate/generate.py", line 136, in build_sequence_generator
    elif isinstance(models[0], LevenshteinTransformerModel):
NameError: name 'LevenshteinTransformerModel' is not defined

The culprit is this fella: https://github.com/pytorch/translate/blob/master/pytorch_translate/generate.py#L48

Because the import is conditional, there's a name error when the import fails.

streamhsa commented 4 years ago

I am also facing same issue with pytorch translate , Can you please provide solution ?

erip commented 4 years ago

You can edit the file locally, but that's not a great long term solution. Just remove the references to the class in the generate.py listed in the stack trace.

streamhsa commented 4 years ago

Thank You . i have defined the LevenshteinTransformerModel in fairseq/models/ path , now i am able to running the pytorch-translate .