OpenNMT Forum

Translation doesn't continue after specific number of statements

I have trained my model for 12369 training steps , I want to test on new data through this command:
onmt_translate -model data/model_step_12369.pt -src data/test.src.txt -output pred.txt -replace_unk -report_bleu -verbose -gpu 0

it being test but stop after statement 630 and report this error

Traceback (most recent call last):
File “/home/ubuntu/anaconda3/bin/onmt_translate”, line 11, in
load_entry_point(‘OpenNMT-py==1.0.0rc2’, ‘console_scripts’, ‘onmt_translate’)()
File “/home/ubuntu/anaconda3/lib/python3.6/site-packages/OpenNMT_py-1.0.0rc2-py3.6.egg/onmt/bin/translate.py”, line 49, in main
translate(opt)
File “/home/ubuntu/anaconda3/lib/python3.6/site-packages/OpenNMT_py-1.0.0rc2-py3.6.egg/onmt/bin/translate.py”, line 33, in translate
attn_debug=opt.attn_debug
File “/home/ubuntu/anaconda3/lib/python3.6/site-packages/OpenNMT_py-1.0.0rc2-py3.6.egg/onmt/translate/translator.py”, line 353, in translate
translations = xlation_builder.from_batch(batch_data)
File “/home/ubuntu/anaconda3/lib/python3.6/site-packages/OpenNMT_py-1.0.0rc2-py3.6.egg/onmt/translate/translation.py”, line 95, in from_batch
for n in range(self.n_best)]
File “/home/ubuntu/anaconda3/lib/python3.6/site-packages/OpenNMT_py-1.0.0rc2-py3.6.egg/onmt/translate/translation.py”, line 95, in
for n in range(self.n_best)]
IndexError: list index out of range
What is the cause of this error and what is the solution?

Apparently this could be a bug with PyTorch 1.3:

Can you check if this applies?

Hi,
Did you find the solution? I’m also getting the same error. When I use beam size of 1 , I don’t get this error.

Traceback (most recent call last):
File “/content/OpenNMT-py/translate.py”, line 6, in
main()
File “/content/OpenNMT-py/onmt/bin/translate.py”, line 49, in main
translate(opt)
File “/content/OpenNMT-py/onmt/bin/translate.py”, line 33, in translate
attn_debug=opt.attn_debug
File “/content/OpenNMT-py/onmt/translate/translator.py”, line 353, in translate
translations = xlation_builder.from_batch(batch_data)
File “/content/OpenNMT-py/onmt/translate/translation.py”, line 95, in from_batch
for n in range(self.n_best)]
File “/content/OpenNMT-py/onmt/translate/translation.py”, line 95, in
for n in range(self.n_best)]
IndexError: list index out of range

Restricting PyTorch to version 1.2 seems to do the trick. Can you do pip install 'torch==1.2' and try again?

1 Like

this is really work, Thank you
but when Translation give this error :
Traceback (most recent call last):
File “/home/ubuntu/anaconda3/bin/onmt_translate”, line 11, in
load_entry_point(‘OpenNMT-py==1.0.0rc2’, ‘console_scripts’, ‘onmt_translate’)()
File “/home/ubuntu/anaconda3/lib/python3.6/site-packages/OpenNMT_py-1.0.0rc2-py3.6.egg/onmt/bin/translate.py”, line 49, in main
translate(opt)
File “/home/ubuntu/anaconda3/lib/python3.6/site-packages/OpenNMT_py-1.0.0rc2-py3.6.egg/onmt/bin/translate.py”, line 33, in translate
attn_debug=opt.attn_debug
File “/home/ubuntu/anaconda3/lib/python3.6/site-packages/OpenNMT_py-1.0.0rc2-py3.6.egg/onmt/translate/translator.py”, line 351, in translate
batch, data.src_vocabs, attn_debug
File “/home/ubuntu/anaconda3/lib/python3.6/site-packages/OpenNMT_py-1.0.0rc2-py3.6.egg/onmt/translate/translator.py”, line 544, in translate_batch
return_attention=attn_debug or self.replace_unk)
File “/home/ubuntu/anaconda3/lib/python3.6/site-packages/OpenNMT_py-1.0.0rc2-py3.6.egg/onmt/translate/translator.py”, line 696, in _translate_batch
beam.advance(log_probs, attn)
File “/home/ubuntu/anaconda3/lib/python3.6/site-packages/OpenNMT_py-1.0.0rc2-py3.6.egg/onmt/translate/beam_search.py”, line 184, in advance
1, self.select_indices)
RuntimeError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 15.75 GiB total capacity; 8.96 GiB already allocated; 4.88 MiB free; 5.65 GiB cached)

Another Question:
This is Translation command
!onmt_translate -model data/model_tokens_step_37107.pt -src data/test.src.txt -output pred.txt -replace_unk -verbose -gpu 0 -max_length 10000 -batch_type tokens
it translates test source to short sentence
How can I control for length of output?

I think you are running out of memory. Try reducing the batch size.