pytorch / translate

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

Cannot load pretrained model #696

Closed erip closed 4 years ago

erip commented 4 years ago

When I try to load the pretrained iwslt de-en model, I see an exception:

>>> import torch
>>> from fairseq.models.transformer import TransformerModel
>>> model = TransformerModel.from_pretrained("./", "averaged_checkpoint_best_0.pt")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/erippeth/miniconda3/envs/fairseq-dev/lib/python3.6/site-packages/fairseq/models/fairseq_model.py", line 218, in from_pretrained
    **kwargs,
  File "/Users/erippeth/miniconda3/envs/fairseq-dev/lib/python3.6/site-packages/fairseq/hub_utils.py", line 73, in from_pretrained
    arg_overrides=kwargs,
  File "/Users/erippeth/miniconda3/envs/fairseq-dev/lib/python3.6/site-packages/fairseq/checkpoint_utils.py", line 202, in load_model_ensemble_and_task
    state = load_checkpoint_to_cpu(filename, arg_overrides)
  File "/Users/erippeth/miniconda3/envs/fairseq-dev/lib/python3.6/site-packages/fairseq/checkpoint_utils.py", line 175, in load_checkpoint_to_cpu
    state = _upgrade_state_dict(state)
  File "/Users/erippeth/miniconda3/envs/fairseq-dev/lib/python3.6/site-packages/fairseq/checkpoint_utils.py", line 366, in _upgrade_state_dict
    registry.set_defaults(state["args"], tasks.TASK_REGISTRY[state["args"].task])
KeyError: 'pytorch_translate'

Do I need to retrain this model because of API changes or am I doing something wrong in loading?

jmp84 commented 4 years ago

Hi @erip, we're deprecating translate, see announcement at the top of the README in https://github.com/pytorch/translate Please use https://github.com/fairseq instead There is some functionality like TorchScript that we're working in integrating into fairseq. If you have any feedback or feature requests, please feel free to raise a github issue directly in fairseq.