facebookresearch / fairseq

Facebook AI Research Sequence-to-Sequence Toolkit written in Python.
MIT License
30.56k stars 6.41k forks source link

omegaconf error when loading RoBERTa #3776

Open PhoenixClank opened 3 years ago

PhoenixClank commented 3 years ago

🐛 Bug

Omegaconf encounters an error when loading RoBERTa.

To Reproduce

remove argument strict in function call to circumvent #3723

composed_cfg = compose("config", overrides=overrides) #, strict=False)

rum cmd

import torch
roberta = torch.hub.load('pytorch/fairseq', 'roberta.large')

see error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/felix/.local/lib/python3.8/site-packages/torch/hub.py", line 364, in load
    model = _load_local(repo_or_dir, model, *args, **kwargs)
  File "/home/felix/.local/lib/python3.8/site-packages/torch/hub.py", line 393, in _load_local
    model = entry(*args, **kwargs)
  File "/home/felix/.cache/torch/hub/pytorch_fairseq_master/fairseq/models/roberta/model.py", line 277, in from_pretrained
    x = hub_utils.from_pretrained(
  File "/home/felix/.cache/torch/hub/pytorch_fairseq_master/fairseq/hub_utils.py", line 73, in from_pretrained
    models, args, task = checkpoint_utils.load_model_ensemble_and_task(
  File "/home/felix/.cache/torch/hub/pytorch_fairseq_master/fairseq/checkpoint_utils.py", line 421, in load_model_ensemble_and_task
    state = load_checkpoint_to_cpu(filename, arg_overrides)
  File "/home/felix/.cache/torch/hub/pytorch_fairseq_master/fairseq/checkpoint_utils.py", line 339, in load_checkpoint_to_cpu
    state = _upgrade_state_dict(state)
  File "/home/felix/.cache/torch/hub/pytorch_fairseq_master/fairseq/checkpoint_utils.py", line 643, in _upgrade_state_dict
    state["cfg"] = convert_namespace_to_omegaconf(state["args"])
  File "/home/felix/.cache/torch/hub/pytorch_fairseq_master/fairseq/dataclass/utils.py", line 395, in convert_namespace_to_omegaconf
    composed_cfg[k] = None
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 310, in __setitem__
    self._format_and_raise(
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/base.py", line 190, in _format_and_raise
    format_and_raise(
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/_utils.py", line 741, in format_and_raise
    _raise(ex, cause)
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/_utils.py", line 719, in _raise
    raise ex.with_traceback(sys.exc_info()[2])  # set end OC_CAUSE=1 for full backtrace
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 308, in __setitem__
    self.__set_impl(key=key, value=value)
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 318, in __set_impl
    self._set_item_impl(key, value)
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/basecontainer.py", line 497, in _set_item_impl
    self._validate_set(key, value)
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 176, in _validate_set
    self._validate_non_optional(key, value)
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 246, in _validate_non_optional
    child = self._get_node(key)
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 465, in _get_node
    self._validate_get(key)
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 166, in _validate_get
    self._format_and_raise(
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/base.py", line 190, in _format_and_raise
    format_and_raise(
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/_utils.py", line 821, in format_and_raise
    _raise(ex, cause)
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/_utils.py", line 719, in _raise
    raise ex.with_traceback(sys.exc_info()[2])  # set end OC_CAUSE=1 for full backtrace
omegaconf.errors.ConfigKeyError: Key 'simul_type' not in 'FairseqConfig'
    full_key: simul_type
    object_type=FairseqConfig

Environment

karin0018 commented 2 years ago

🐛 Bug

Omegaconf encounters an error when loading RoBERTa.

To Reproduce

remove argument strict in function call to circumvent #3723

composed_cfg = compose("config", overrides=overrides) #, strict=False)

rum cmd

import torch
roberta = torch.hub.load('pytorch/fairseq', 'roberta.large')

see error

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/felix/.local/lib/python3.8/site-packages/torch/hub.py", line 364, in load
    model = _load_local(repo_or_dir, model, *args, **kwargs)
  File "/home/felix/.local/lib/python3.8/site-packages/torch/hub.py", line 393, in _load_local
    model = entry(*args, **kwargs)
  File "/home/felix/.cache/torch/hub/pytorch_fairseq_master/fairseq/models/roberta/model.py", line 277, in from_pretrained
    x = hub_utils.from_pretrained(
  File "/home/felix/.cache/torch/hub/pytorch_fairseq_master/fairseq/hub_utils.py", line 73, in from_pretrained
    models, args, task = checkpoint_utils.load_model_ensemble_and_task(
  File "/home/felix/.cache/torch/hub/pytorch_fairseq_master/fairseq/checkpoint_utils.py", line 421, in load_model_ensemble_and_task
    state = load_checkpoint_to_cpu(filename, arg_overrides)
  File "/home/felix/.cache/torch/hub/pytorch_fairseq_master/fairseq/checkpoint_utils.py", line 339, in load_checkpoint_to_cpu
    state = _upgrade_state_dict(state)
  File "/home/felix/.cache/torch/hub/pytorch_fairseq_master/fairseq/checkpoint_utils.py", line 643, in _upgrade_state_dict
    state["cfg"] = convert_namespace_to_omegaconf(state["args"])
  File "/home/felix/.cache/torch/hub/pytorch_fairseq_master/fairseq/dataclass/utils.py", line 395, in convert_namespace_to_omegaconf
    composed_cfg[k] = None
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 310, in __setitem__
    self._format_and_raise(
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/base.py", line 190, in _format_and_raise
    format_and_raise(
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/_utils.py", line 741, in format_and_raise
    _raise(ex, cause)
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/_utils.py", line 719, in _raise
    raise ex.with_traceback(sys.exc_info()[2])  # set end OC_CAUSE=1 for full backtrace
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 308, in __setitem__
    self.__set_impl(key=key, value=value)
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 318, in __set_impl
    self._set_item_impl(key, value)
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/basecontainer.py", line 497, in _set_item_impl
    self._validate_set(key, value)
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 176, in _validate_set
    self._validate_non_optional(key, value)
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 246, in _validate_non_optional
    child = self._get_node(key)
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 465, in _get_node
    self._validate_get(key)
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/dictconfig.py", line 166, in _validate_get
    self._format_and_raise(
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/base.py", line 190, in _format_and_raise
    format_and_raise(
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/_utils.py", line 821, in format_and_raise
    _raise(ex, cause)
  File "/home/felix/.local/lib/python3.8/site-packages/omegaconf/_utils.py", line 719, in _raise
    raise ex.with_traceback(sys.exc_info()[2])  # set end OC_CAUSE=1 for full backtrace
omegaconf.errors.ConfigKeyError: Key 'simul_type' not in 'FairseqConfig'
    full_key: simul_type
    object_type=FairseqConfig

Environment

  • fairseq Version: master
  • PyTorch Version: 1.9.0+cpu
  • OS: Ubuntu
  • How you installed fairseq: pip
  • Python version: 3.8.10

hi! I have the same bug with you, do you solve it?