Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Facing errors in basic test run #1

Open
purealpha001 opened this issue Aug 10, 2020 · 4 comments
Open

Facing errors in basic test run #1

purealpha001 opened this issue Aug 10, 2020 · 4 comments

Comments

@purealpha001
Copy link

Unable to run either examples/mm_all.py or the basic test script provided.

Steps:

cd ~
git clone https://github.com/jerinphilip/fairseq-ilmt.git
cd fairseq-ilmt
pip3 install --editable .
cd ~
git clone https://github.com/jerinphilip/ilmulti.git
cd ilmulti
pwd
python3 -m pip install -r requirements.txt 
python3 setup.py install 

No errors reported.

Downloaded models via"

cd ~
bash ilmulti/scripts/download-and-setup-models.sh

Test Code:

from ilmulti.translator import from_pretrained

translator = from_pretrained(tag='mm-all-iter0')
sample = translator("The quick brown fox jumps over the lazy dog", tgt_lang='hi')

Error log:

| [src] dictionary: 40897 types
| [tgt] dictionary: 40897 types
./ilmulti/translator/translator.py:23: UserWarning: utils.load_ensemble_for_inference is deprecated. Please use checkpoint_utils.load_model_ensemble instead.
  self.models, model_args = fairseq.utils.load_ensemble_for_inference(model_paths, self.task, model_arg_overrides=eval(args.model_overrides))
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-19-d75d9cb5891a> in <module>()
      2 
      3 translator = from_pretrained(tag='mm-all-iter0')
----> 4 sample = translator("The quick brown fox jumps over the lazy dog", tgt_lang='hi')

5 frames
/content/ilmulti/ilmulti/translator/mt_engine.py in __call__(self, source, tgt_lang, src_lang, detokenize)
     22             sources.append(content)
     23 
---> 24         export = self.translator(sources)
     25         export = self._handle_empty_lines_noise(export)
     26         if detokenize:

/content/ilmulti/ilmulti/translator/translator.py in __call__(self, lines, attention)
     65                 },
     66             }
---> 67             translations = self.task.inference_step(self.generator, self.models, sample)
     68             for i, (id, hypos) in enumerate(zip(batch.ids.tolist(), translations)):
     69                 src_tokens_i = utils.strip_pad(src_tokens[i], tgt_dict.pad())

/usr/local/lib/python3.6/dist-packages/fairseq/tasks/fairseq_task.py in inference_step(self, generator, models, sample, prefix_tokens)
    242     def inference_step(self, generator, models, sample, prefix_tokens=None):
    243         with torch.no_grad():
--> 244             return generator.generate(models, sample, prefix_tokens=prefix_tokens)
    245 
    246     def update_step(self, num_updates):

/usr/local/lib/python3.6/dist-packages/torch/autograd/grad_mode.py in decorate_context(*args, **kwargs)
     13         def decorate_context(*args, **kwargs):
     14             with self:
---> 15                 return func(*args, **kwargs)
     16         return decorate_context
     17 

/usr/local/lib/python3.6/dist-packages/fairseq/sequence_generator.py in generate(self, models, sample, prefix_tokens, bos_token, **kwargs)
    374                 step,
    375                 lprobs.view(bsz, -1, self.vocab_size),
--> 376                 scores.view(bsz, beam_size, -1)[:, :, :step],
    377             )
    378 

/usr/local/lib/python3.6/dist-packages/fairseq/search.py in step(self, step, lprobs, scores)
     79             out=(self.scores_buf, self.indices_buf),
     80         )
---> 81         torch.div(self.indices_buf, vocab_size, out=self.beams_buf)
     82         self.indices_buf.fmod_(vocab_size)
     83         return self.scores_buf, self.indices_buf, self.beams_buf

RuntimeError: Integer division of tensors using div or / is no longer supported, and in a future release div will perform true division as in Python 3. Use true_divide or floor_divide (// in Python) instead.
@jerinphilip
Copy link
Owner

Use torch 1.0.0 for now, that should do okay. Will fix it later.

@rahulraj80
Copy link

Alternatively:
Change

torch.div(self.indices_buf, vocab_size, out=self.beams_buf)

to

torch.floor_divide(self.indices_buf, vocab_size, out=self.beams_buf)

on the offending line. It works.

@jerinphilip
Copy link
Owner

^ Not advisable. The torch version might break more places, create inconsistencies and will have to fix everywhere. If you want to translate a large batch of samples, I'd recommend the fairseq-ilmt which is minimal mods on fairseq. I know this works with fairseq v0.7.2 (where I branched to make some mods which was compatible with pytorch 1.0.0 and maybe 1.1.0).

The example here is just to for some specific use-cases and demonstrate this model works. If you have higher volumes you should switch to fairseq level batching optimizations which are in fairseq-ilmt.

@rahulraj80
Copy link

OK - makes sense. Tested it on a colab so was more adventurous. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants