OpenNMT / OpenNMT-py

Open Source Neural Machine Translation and (Large) Language Models in PyTorch
https://opennmt.net/
MIT License
6.75k stars 2.25k forks source link

inconsistent tensor size error when doing translation #440

Closed aotemandess closed 6 years ago

aotemandess commented 6 years ago

Thanks for your code! For the WMT'16 Multimodal Translation: Multi30k (de-en): I train the model successfully, however when I run 'translate.py', there is an error:

 python translate.py -model multi30k_model_acc_69.50_ppl_6.13_e13.pt -src data/multi30k/test2016.en.atok  -tgt data/multi30k/test2016.de.atok -replace_unk -verbose -output multi30k.test.pred.atok
Loading model parameters.
Traceback (most recent call last):
  File "translate.py", line 129, in <module>
    main()
  File "translate.py", line 70, in main
    = translator.translate(batch, data)
  File "/home/qzw123/wangyuan/OpenNMT-py-master/onmt/Translator.py", line 206, in translate
    pred, predScore, attn, goldScore = self.translateBatch(batch, data)
  File "/home/qzw123/wangyuan/OpenNMT-py-master/onmt/Translator.py", line 153, in translateBatch
    inp, context, decStates, context_lengths=context_lengths)
  File "/root/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.py", line 206, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/qzw123/wangyuan/OpenNMT-py-master/onmt/Models.py", line 176, in forward
    input, context, state, context_lengths=context_lengths)
  File "/home/qzw123/wangyuan/OpenNMT-py-master/onmt/Models.py", line 347, in _run_forward_pass
    context_lengths=context_lengths)
  File "/root/anaconda2/lib/python2.7/site-packages/torch/nn/modules/module.py", line 206, in __call__
    result = self.forward(*input, **kwargs)
  File "/home/qzw123/wangyuan/OpenNMT-py-master/onmt/modules/GlobalAttention.py", line 138, in forward
    mask = sequence_mask(context_lengths)
  File "/home/qzw123/wangyuan/OpenNMT-py-master/onmt/Utils.py", line 23, in sequence_mask
    .lt(lengths.unsqueeze(1)))
RuntimeError: inconsistent tensor size at /opt/conda/conda-bld/pytorch_1501972792122/work/pytorch-0.1.12/torch/lib/TH/generic/THTensorMath.c:2675**
guillaumekln commented 6 years ago

Recent changes seemed to break compatibility with PyTorch v0.1. Do you mind updating your installation?

@srush Do we want to support beta versions other than the latest?

srush commented 6 years ago

yeah, I think we do not as there are vital new features.

cobude commented 6 years ago

This is an incompatible version of the pytorch version,and a different pytorch version will do.