huggingface / transformers

🤗 Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
134.65k stars 26.92k forks source link

`AutoConfig` doesn't support `gpt-neox` #15190

Closed mkshing closed 2 years ago

mkshing commented 2 years ago

@patil-suraj

Environment info

Who can help

Information

Model I am using (Bert, XLNet ...): GPT-NeoX

The problem arises when using:

The tasks I am working on is:

To reproduce

from transformers import AutoConfig
config = AutoConfig.from_pretrained(PRIVATE_GPT_NEOX_MODEL_PATH)
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-6-7344d2d8cc3c> in <module>
      1 from transformers import AutoConfig
----> 2 config = AutoConfig.from_pretrained(GPT_NEOX_1B_MODEL)

/opt/anaconda3/lib/python3.8/site-packages/transformers/models/auto/configuration_auto.py in from_pretrained(cls, pretrained_model_name_or_path, **kwargs)
    527         config_dict, _ = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
    528         if "model_type" in config_dict:
--> 529             config_class = CONFIG_MAPPING[config_dict["model_type"]]
    530             return config_class.from_dict(config_dict, **kwargs)
    531         else:

/opt/anaconda3/lib/python3.8/site-packages/transformers/models/auto/configuration_auto.py in __getitem__(self, key)
    276     def __getitem__(self, key):
    277         if key not in self._mapping:
--> 278             raise KeyError(key)
    279         value = self._mapping[key]
    280         module_name = model_type_to_module_name(key)

KeyError: 'gpt-neox'

Expected behavior

The reason why I need to load gpt-neox from Auto is because my code will be capable to load multiple kinds of models. To achieve it, I use AutoConfig.from_pretrained(model_path) to identify model_type before loading the model. My expectation would be supporting gpt-neox in AutoConfig or providing other nicer ways. Thank you in advance!

mkshing commented 2 years ago

@patil-suraj I found the problem in my code. Because I defined the gpt-neox model by my own custom class, of course, transformers couldn't recognize it! My apologies! I will close this issue.