configuration_auto.py 46.3 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# coding=utf-8
# Copyright 2018 The HuggingFace Inc. team.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
Sylvain Gugger's avatar
Sylvain Gugger committed
15
""" Auto Config class."""
16
import importlib
17
import os
18
import re
19
import warnings
20
from collections import OrderedDict
21
from typing import List, Union
22

Sylvain Gugger's avatar
Sylvain Gugger committed
23
from ...configuration_utils import PretrainedConfig
24
from ...dynamic_module_utils import get_class_from_dynamic_module, resolve_trust_remote_code
25
from ...utils import CONFIG_NAME, logging
Aymeric Augustin's avatar
Aymeric Augustin committed
26

27

28
29
logger = logging.get_logger(__name__)

30
31
32
CONFIG_MAPPING_NAMES = OrderedDict(
    [
        # Add configs here
33
        ("albert", "AlbertConfig"),
34
        ("align", "AlignConfig"),
Jongjyh's avatar
Jongjyh committed
35
        ("altclip", "AltCLIPConfig"),
36
        ("audio-spectrogram-transformer", "ASTConfig"),
37
        ("autoformer", "AutoformerConfig"),
Yoach Lacombe's avatar
Yoach Lacombe committed
38
        ("bark", "BarkConfig"),
39
        ("bart", "BartConfig"),
40
        ("beit", "BeitConfig"),
41
42
43
44
        ("bert", "BertConfig"),
        ("bert-generation", "BertGenerationConfig"),
        ("big_bird", "BigBirdConfig"),
        ("bigbird_pegasus", "BigBirdPegasusConfig"),
Kamal Raj Kanakarajan's avatar
Kamal Raj Kanakarajan committed
45
        ("biogpt", "BioGptConfig"),
NielsRogge's avatar
NielsRogge committed
46
        ("bit", "BitConfig"),
47
48
        ("blenderbot", "BlenderbotConfig"),
        ("blenderbot-small", "BlenderbotSmallConfig"),
Younes Belkada's avatar
Younes Belkada committed
49
        ("blip", "BlipConfig"),
NielsRogge's avatar
NielsRogge committed
50
        ("blip-2", "Blip2Config"),
Younes Belkada's avatar
Younes Belkada committed
51
        ("bloom", "BloomConfig"),
52
        ("bridgetower", "BridgeTowerConfig"),
Jinho Park's avatar
Jinho Park committed
53
        ("bros", "BrosConfig"),
54
        ("camembert", "CamembertConfig"),
55
        ("canine", "CanineConfig"),
56
        ("chinese_clip", "ChineseCLIPConfig"),
57
        ("clap", "ClapConfig"),
58
        ("clip", "CLIPConfig"),
NielsRogge's avatar
NielsRogge committed
59
        ("clipseg", "CLIPSegConfig"),
Susnato Dhar's avatar
Susnato Dhar committed
60
        ("clvp", "ClvpConfig"),
61
        ("code_llama", "LlamaConfig"),
rooa's avatar
rooa committed
62
        ("codegen", "CodeGenConfig"),
63
        ("conditional_detr", "ConditionalDetrConfig"),
64
65
        ("convbert", "ConvBertConfig"),
        ("convnext", "ConvNextConfig"),
Alara Dirik's avatar
Alara Dirik committed
66
        ("convnextv2", "ConvNextV2Config"),
67
        ("cpmant", "CpmAntConfig"),
68
        ("ctrl", "CTRLConfig"),
NielsRogge's avatar
NielsRogge committed
69
        ("cvt", "CvtConfig"),
70
71
72
73
74
75
        ("data2vec-audio", "Data2VecAudioConfig"),
        ("data2vec-text", "Data2VecTextConfig"),
        ("data2vec-vision", "Data2VecVisionConfig"),
        ("deberta", "DebertaConfig"),
        ("deberta-v2", "DebertaV2Config"),
        ("decision_transformer", "DecisionTransformerConfig"),
NielsRogge's avatar
NielsRogge committed
76
        ("deformable_detr", "DeformableDetrConfig"),
77
        ("deit", "DeiTConfig"),
NielsRogge's avatar
NielsRogge committed
78
        ("deta", "DetaConfig"),
79
        ("detr", "DetrConfig"),
80
        ("dinat", "DinatConfig"),
NielsRogge's avatar
NielsRogge committed
81
        ("dinov2", "Dinov2Config"),
82
        ("distilbert", "DistilBertConfig"),
NielsRogge's avatar
NielsRogge committed
83
        ("donut-swin", "DonutSwinConfig"),
84
85
        ("dpr", "DPRConfig"),
        ("dpt", "DPTConfig"),
86
        ("efficientformer", "EfficientFormerConfig"),
Alara Dirik's avatar
Alara Dirik committed
87
        ("efficientnet", "EfficientNetConfig"),
88
        ("electra", "ElectraConfig"),
89
        ("encodec", "EncodecConfig"),
90
        ("encoder-decoder", "EncoderDecoderConfig"),
91
        ("ernie", "ErnieConfig"),
92
        ("ernie_m", "ErnieMConfig"),
93
        ("esm", "EsmConfig"),
Matt's avatar
Matt committed
94
        ("falcon", "FalconConfig"),
95
96
97
        ("flaubert", "FlaubertConfig"),
        ("flava", "FlavaConfig"),
        ("fnet", "FNetConfig"),
NielsRogge's avatar
NielsRogge committed
98
        ("focalnet", "FocalNetConfig"),
99
100
        ("fsmt", "FSMTConfig"),
        ("funnel", "FunnelConfig"),
Pablo Montalvo's avatar
Pablo Montalvo committed
101
        ("fuyu", "FuyuConfig"),
102
        ("git", "GitConfig"),
103
        ("glpn", "GLPNConfig"),
104
        ("gpt-sw3", "GPT2Config"),
105
        ("gpt2", "GPT2Config"),
106
        ("gpt_bigcode", "GPTBigCodeConfig"),
107
        ("gpt_neo", "GPTNeoConfig"),
108
        ("gpt_neox", "GPTNeoXConfig"),
109
        ("gpt_neox_japanese", "GPTNeoXJapaneseConfig"),
110
        ("gptj", "GPTJConfig"),
111
        ("gptsan-japanese", "GPTSanJapaneseConfig"),
112
        ("graphormer", "GraphormerConfig"),
113
        ("groupvit", "GroupViTConfig"),
114
        ("hubert", "HubertConfig"),
115
        ("ibert", "IBertConfig"),
116
        ("idefics", "IdeficsConfig"),
117
        ("imagegpt", "ImageGPTConfig"),
118
        ("informer", "InformerConfig"),
NielsRogge's avatar
NielsRogge committed
119
        ("instructblip", "InstructBlipConfig"),
120
        ("jukebox", "JukeboxConfig"),
Yih-Dar's avatar
Yih-Dar committed
121
        ("kosmos-2", "Kosmos2Config"),
122
123
        ("layoutlm", "LayoutLMConfig"),
        ("layoutlmv2", "LayoutLMv2Config"),
NielsRogge's avatar
NielsRogge committed
124
        ("layoutlmv3", "LayoutLMv3Config"),
125
        ("led", "LEDConfig"),
126
        ("levit", "LevitConfig"),
NielsRogge's avatar
NielsRogge committed
127
        ("lilt", "LiltConfig"),
Jason Phang's avatar
Jason Phang committed
128
        ("llama", "LlamaConfig"),
129
        ("longformer", "LongformerConfig"),
Daniel Stancl's avatar
Daniel Stancl committed
130
        ("longt5", "LongT5Config"),
131
132
133
        ("luke", "LukeConfig"),
        ("lxmert", "LxmertConfig"),
        ("m2m_100", "M2M100Config"),
134
        ("marian", "MarianConfig"),
NielsRogge's avatar
NielsRogge committed
135
        ("markuplm", "MarkupLMConfig"),
Alara Dirik's avatar
Alara Dirik committed
136
        ("mask2former", "Mask2FormerConfig"),
137
        ("maskformer", "MaskFormerConfig"),
138
        ("maskformer-swin", "MaskFormerSwinConfig"),
139
        ("mbart", "MBartConfig"),
Chan Woo Kim's avatar
Chan Woo Kim committed
140
        ("mctct", "MCTCTConfig"),
141
        ("mega", "MegaConfig"),
142
        ("megatron-bert", "MegatronBertConfig"),
wangpeng's avatar
wangpeng committed
143
        ("mgp-str", "MgpstrConfig"),
144
        ("mistral", "MistralConfig"),
145
        ("mobilebert", "MobileBertConfig"),
146
        ("mobilenet_v1", "MobileNetV1Config"),
147
        ("mobilenet_v2", "MobileNetV2Config"),
148
        ("mobilevit", "MobileViTConfig"),
Shehan Munasinghe's avatar
Shehan Munasinghe committed
149
        ("mobilevitv2", "MobileViTV2Config"),
150
        ("mpnet", "MPNetConfig"),
151
        ("mpt", "MptConfig"),
152
        ("mra", "MraConfig"),
153
        ("mt5", "MT5Config"),
Sanchit Gandhi's avatar
Sanchit Gandhi committed
154
        ("musicgen", "MusicgenConfig"),
StevenTang1998's avatar
StevenTang1998 committed
155
        ("mvp", "MvpConfig"),
156
        ("nat", "NatConfig"),
157
        ("nezha", "NezhaConfig"),
158
        ("nllb-moe", "NllbMoeConfig"),
NielsRogge's avatar
NielsRogge committed
159
        ("nougat", "VisionEncoderDecoderConfig"),
160
        ("nystromformer", "NystromformerConfig"),
Jitesh Jain's avatar
Jitesh Jain committed
161
        ("oneformer", "OneFormerConfig"),
162
        ("open-llama", "OpenLlamaConfig"),
163
        ("openai-gpt", "OpenAIGPTConfig"),
Younes Belkada's avatar
Younes Belkada committed
164
        ("opt", "OPTConfig"),
NielsRogge's avatar
NielsRogge committed
165
        ("owlv2", "Owlv2Config"),
166
        ("owlvit", "OwlViTConfig"),
167
        ("pegasus", "PegasusConfig"),
Jason Phang's avatar
Jason Phang committed
168
        ("pegasus_x", "PegasusXConfig"),
169
        ("perceiver", "PerceiverConfig"),
170
        ("persimmon", "PersimmonConfig"),
Younes Belkada's avatar
Younes Belkada committed
171
        ("pix2struct", "Pix2StructConfig"),
172
173
        ("plbart", "PLBartConfig"),
        ("poolformer", "PoolFormerConfig"),
Susnato Dhar's avatar
Susnato Dhar committed
174
        ("pop2piano", "Pop2PianoConfig"),
175
        ("prophetnet", "ProphetNetConfig"),
Rinat's avatar
Rinat committed
176
        ("pvt", "PvtConfig"),
177
178
179
        ("qdqbert", "QDQBertConfig"),
        ("rag", "RagConfig"),
        ("realm", "RealmConfig"),
180
        ("reformer", "ReformerConfig"),
181
182
183
184
        ("regnet", "RegNetConfig"),
        ("rembert", "RemBertConfig"),
        ("resnet", "ResNetConfig"),
        ("retribert", "RetriBertConfig"),
185
        ("roberta", "RobertaConfig"),
186
        ("roberta-prelayernorm", "RobertaPreLayerNormConfig"),
Weiwe Shi's avatar
Weiwe Shi committed
187
        ("roc_bert", "RoCBertConfig"),
188
        ("roformer", "RoFormerConfig"),
Sylvain Gugger's avatar
Sylvain Gugger committed
189
        ("rwkv", "RwkvConfig"),
190
        ("sam", "SamConfig"),
191
        ("seamless_m4t", "SeamlessM4TConfig"),
192
193
194
        ("segformer", "SegformerConfig"),
        ("sew", "SEWConfig"),
        ("sew-d", "SEWDConfig"),
195
        ("speech-encoder-decoder", "SpeechEncoderDecoderConfig"),
196
197
        ("speech_to_text", "Speech2TextConfig"),
        ("speech_to_text_2", "Speech2Text2Config"),
198
        ("speecht5", "SpeechT5Config"),
Ori Ram's avatar
Ori Ram committed
199
        ("splinter", "SplinterConfig"),
200
        ("squeezebert", "SqueezeBertConfig"),
Shehan Munasinghe's avatar
Shehan Munasinghe committed
201
        ("swiftformer", "SwiftFormerConfig"),
202
        ("swin", "SwinConfig"),
NielsRogge's avatar
NielsRogge committed
203
        ("swin2sr", "Swin2SRConfig"),
204
        ("swinv2", "Swinv2Config"),
205
        ("switch_transformers", "SwitchTransformersConfig"),
206
        ("t5", "T5Config"),
207
        ("table-transformer", "TableTransformerConfig"),
208
        ("tapas", "TapasConfig"),
209
        ("time_series_transformer", "TimeSeriesTransformerConfig"),
210
        ("timesformer", "TimesformerConfig"),
amyeroberts's avatar
amyeroberts committed
211
        ("timm_backbone", "TimmBackboneConfig"),
Carl's avatar
Carl committed
212
        ("trajectory_transformer", "TrajectoryTransformerConfig"),
213
214
        ("transfo-xl", "TransfoXLConfig"),
        ("trocr", "TrOCRConfig"),
Zineng Tang's avatar
Zineng Tang committed
215
        ("tvlt", "TvltConfig"),
216
        ("umt5", "UMT5Config"),
217
        ("unispeech", "UniSpeechConfig"),
218
        ("unispeech-sat", "UniSpeechSatConfig"),
NielsRogge's avatar
NielsRogge committed
219
        ("upernet", "UperNetConfig"),
220
        ("van", "VanConfig"),
NielsRogge's avatar
NielsRogge committed
221
        ("videomae", "VideoMAEConfig"),
222
223
224
225
226
        ("vilt", "ViltConfig"),
        ("vision-encoder-decoder", "VisionEncoderDecoderConfig"),
        ("vision-text-dual-encoder", "VisionTextDualEncoderConfig"),
        ("visual_bert", "VisualBertConfig"),
        ("vit", "ViTConfig"),
NielsRogge's avatar
NielsRogge committed
227
        ("vit_hybrid", "ViTHybridConfig"),
228
        ("vit_mae", "ViTMAEConfig"),
229
        ("vit_msn", "ViTMSNConfig"),
NielsRogge's avatar
NielsRogge committed
230
        ("vitdet", "VitDetConfig"),
NielsRogge's avatar
NielsRogge committed
231
        ("vitmatte", "VitMatteConfig"),
Matthijs Hollemans's avatar
Matthijs Hollemans committed
232
        ("vits", "VitsConfig"),
Jegor Kit拧kerkin's avatar
Jegor Kit拧kerkin committed
233
        ("vivit", "VivitConfig"),
234
        ("wav2vec2", "Wav2Vec2Config"),
235
        ("wav2vec2-conformer", "Wav2Vec2ConformerConfig"),
Patrick von Platen's avatar
Patrick von Platen committed
236
        ("wavlm", "WavLMConfig"),
237
        ("whisper", "WhisperConfig"),
NielsRogge's avatar
NielsRogge committed
238
        ("xclip", "XCLIPConfig"),
239
240
241
242
243
244
        ("xglm", "XGLMConfig"),
        ("xlm", "XLMConfig"),
        ("xlm-prophetnet", "XLMProphetNetConfig"),
        ("xlm-roberta", "XLMRobertaConfig"),
        ("xlm-roberta-xl", "XLMRobertaXLConfig"),
        ("xlnet", "XLNetConfig"),
Jannis Vamvas's avatar
Jannis Vamvas committed
245
        ("xmod", "XmodConfig"),
246
247
        ("yolos", "YolosConfig"),
        ("yoso", "YosoConfig"),
248
249
    ]
)
250

251
CONFIG_ARCHIVE_MAP_MAPPING_NAMES = OrderedDict(
252
    [
NielsRogge's avatar
NielsRogge committed
253
        # Add archive maps here)
254
        ("albert", "ALBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
255
        ("align", "ALIGN_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Jongjyh's avatar
Jongjyh committed
256
        ("altclip", "ALTCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
257
        ("audio-spectrogram-transformer", "AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
258
        ("autoformer", "AUTOFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Yoach Lacombe's avatar
Yoach Lacombe committed
259
        ("bark", "BARK_PRETRAINED_CONFIG_ARCHIVE_MAP"),
260
        ("bart", "BART_PRETRAINED_CONFIG_ARCHIVE_MAP"),
261
        ("beit", "BEIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
262
263
264
        ("bert", "BERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("big_bird", "BIG_BIRD_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("bigbird_pegasus", "BIGBIRD_PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Kamal Raj Kanakarajan's avatar
Kamal Raj Kanakarajan committed
265
        ("biogpt", "BIOGPT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
266
        ("bit", "BIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
267
268
        ("blenderbot", "BLENDERBOT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("blenderbot-small", "BLENDERBOT_SMALL_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Younes Belkada's avatar
Younes Belkada committed
269
        ("blip", "BLIP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
270
        ("blip-2", "BLIP_2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Younes Belkada's avatar
Younes Belkada committed
271
        ("bloom", "BLOOM_PRETRAINED_CONFIG_ARCHIVE_MAP"),
272
        ("bridgetower", "BRIDGETOWER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Jinho Park's avatar
Jinho Park committed
273
        ("bros", "BROS_PRETRAINED_CONFIG_ARCHIVE_MAP"),
274
        ("camembert", "CAMEMBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
275
        ("canine", "CANINE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
276
        ("chinese_clip", "CHINESE_CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
277
        ("clap", "CLAP_PRETRAINED_MODEL_ARCHIVE_LIST"),
278
        ("clip", "CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
279
        ("clipseg", "CLIPSEG_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Susnato Dhar's avatar
Susnato Dhar committed
280
        ("clvp", "CLVP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
rooa's avatar
rooa committed
281
        ("codegen", "CODEGEN_PRETRAINED_CONFIG_ARCHIVE_MAP"),
282
        ("conditional_detr", "CONDITIONAL_DETR_PRETRAINED_CONFIG_ARCHIVE_MAP"),
283
        ("convbert", "CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
284
        ("convnext", "CONVNEXT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Alara Dirik's avatar
Alara Dirik committed
285
        ("convnextv2", "CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
286
        ("cpmant", "CPMANT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
287
        ("ctrl", "CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
288
        ("cvt", "CVT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
289
        ("data2vec-audio", "DATA2VEC_AUDIO_PRETRAINED_CONFIG_ARCHIVE_MAP"),
290
291
292
293
        ("data2vec-text", "DATA2VEC_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("data2vec-vision", "DATA2VEC_VISION_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("deberta", "DEBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("deberta-v2", "DEBERTA_V2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
294
        ("deformable_detr", "DEFORMABLE_DETR_PRETRAINED_CONFIG_ARCHIVE_MAP"),
295
        ("deit", "DEIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
296
        ("deta", "DETA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
297
        ("detr", "DETR_PRETRAINED_CONFIG_ARCHIVE_MAP"),
298
        ("dinat", "DINAT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
299
        ("dinov2", "DINOV2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
300
        ("distilbert", "DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
301
        ("donut-swin", "DONUT_SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP"),
302
303
        ("dpr", "DPR_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("dpt", "DPT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
304
        ("efficientformer", "EFFICIENTFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Alara Dirik's avatar
Alara Dirik committed
305
        ("efficientnet", "EFFICIENTNET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
306
        ("electra", "ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
307
        ("encodec", "ENCODEC_PRETRAINED_CONFIG_ARCHIVE_MAP"),
308
        ("ernie", "ERNIE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
309
        ("ernie_m", "ERNIE_M_PRETRAINED_CONFIG_ARCHIVE_MAP"),
310
        ("esm", "ESM_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Matt's avatar
Matt committed
311
        ("falcon", "FALCON_PRETRAINED_CONFIG_ARCHIVE_MAP"),
312
        ("flaubert", "FLAUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
313
314
        ("flava", "FLAVA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("fnet", "FNET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
315
        ("focalnet", "FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
316
317
        ("fsmt", "FSMT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("funnel", "FUNNEL_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Pablo Montalvo's avatar
Pablo Montalvo committed
318
        ("fuyu", "FUYU_PRETRAINED_CONFIG_ARCHIVE_MAP"),
319
        ("git", "GIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
320
321
        ("glpn", "GLPN_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("gpt2", "GPT2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
322
        ("gpt_bigcode", "GPT_BIGCODE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
323
        ("gpt_neo", "GPT_NEO_PRETRAINED_CONFIG_ARCHIVE_MAP"),
324
        ("gpt_neox", "GPT_NEOX_PRETRAINED_CONFIG_ARCHIVE_MAP"),
325
        ("gpt_neox_japanese", "GPT_NEOX_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
326
        ("gptj", "GPTJ_PRETRAINED_CONFIG_ARCHIVE_MAP"),
327
        ("gptsan-japanese", "GPTSAN_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
328
        ("graphormer", "GRAPHORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
329
        ("groupvit", "GROUPVIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
330
331
        ("hubert", "HUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("ibert", "IBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
332
        ("idefics", "IDEFICS_PRETRAINED_CONFIG_ARCHIVE_MAP"),
333
        ("imagegpt", "IMAGEGPT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
334
        ("informer", "INFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
335
        ("instructblip", "INSTRUCTBLIP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
336
        ("jukebox", "JUKEBOX_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Yih-Dar's avatar
Yih-Dar committed
337
        ("kosmos-2", "KOSMOS2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
338
        ("layoutlm", "LAYOUTLM_PRETRAINED_CONFIG_ARCHIVE_MAP"),
339
        ("layoutlmv2", "LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
340
        ("layoutlmv3", "LAYOUTLMV3_PRETRAINED_CONFIG_ARCHIVE_MAP"),
341
        ("led", "LED_PRETRAINED_CONFIG_ARCHIVE_MAP"),
342
        ("levit", "LEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
343
        ("lilt", "LILT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Jason Phang's avatar
Jason Phang committed
344
        ("llama", "LLAMA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
345
        ("longformer", "LONGFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Daniel Stancl's avatar
Daniel Stancl committed
346
        ("longt5", "LONGT5_PRETRAINED_CONFIG_ARCHIVE_MAP"),
347
348
349
        ("luke", "LUKE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("lxmert", "LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("m2m_100", "M2M_100_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
350
        ("markuplm", "MARKUPLM_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Alara Dirik's avatar
Alara Dirik committed
351
        ("mask2former", "MASK2FORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
352
353
        ("maskformer", "MASKFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("mbart", "MBART_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Chan Woo Kim's avatar
Chan Woo Kim committed
354
        ("mctct", "MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
355
        ("mega", "MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
356
        ("megatron-bert", "MEGATRON_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
wangpeng's avatar
wangpeng committed
357
        ("mgp-str", "MGP_STR_PRETRAINED_CONFIG_ARCHIVE_MAP"),
358
        ("mistral", "MISTRAL_PRETRAINED_CONFIG_ARCHIVE_MAP"),
359
        ("mobilenet_v1", "MOBILENET_V1_PRETRAINED_CONFIG_ARCHIVE_MAP"),
360
        ("mobilenet_v2", "MOBILENET_V2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
361
        ("mobilevit", "MOBILEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Shehan Munasinghe's avatar
Shehan Munasinghe committed
362
        ("mobilevitv2", "MOBILEVITV2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
363
        ("mpnet", "MPNET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
364
        ("mpt", "MPT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
365
        ("mra", "MRA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Sanchit Gandhi's avatar
Sanchit Gandhi committed
366
        ("musicgen", "MUSICGEN_PRETRAINED_CONFIG_ARCHIVE_MAP"),
StevenTang1998's avatar
StevenTang1998 committed
367
        ("mvp", "MVP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
368
        ("nat", "NAT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
369
        ("nezha", "NEZHA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
370
        ("nllb-moe", "NLLB_MOE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
371
        ("nystromformer", "NYSTROMFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Jitesh Jain's avatar
Jitesh Jain committed
372
        ("oneformer", "ONEFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
373
        ("open-llama", "OPEN_LLAMA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
374
375
        ("openai-gpt", "OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("opt", "OPT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
376
        ("owlv2", "OWLV2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
377
        ("owlvit", "OWLVIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
378
        ("pegasus", "PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Jason Phang's avatar
Jason Phang committed
379
        ("pegasus_x", "PEGASUS_X_PRETRAINED_CONFIG_ARCHIVE_MAP"),
380
        ("perceiver", "PERCEIVER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
381
        ("persimmon", "PERSIMMON_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Younes Belkada's avatar
Younes Belkada committed
382
        ("pix2struct", "PIX2STRUCT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
383
384
        ("plbart", "PLBART_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("poolformer", "POOLFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Susnato Dhar's avatar
Susnato Dhar committed
385
        ("pop2piano", "POP2PIANO_PRETRAINED_CONFIG_ARCHIVE_MAP"),
386
        ("prophetnet", "PROPHETNET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Rinat's avatar
Rinat committed
387
        ("pvt", "PVT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
388
389
390
391
392
393
394
        ("qdqbert", "QDQBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("realm", "REALM_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("regnet", "REGNET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("rembert", "REMBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("resnet", "RESNET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("retribert", "RETRIBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("roberta", "ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
395
        ("roberta-prelayernorm", "ROBERTA_PRELAYERNORM_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Weiwe Shi's avatar
Weiwe Shi committed
396
        ("roc_bert", "ROC_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
397
        ("roformer", "ROFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Sylvain Gugger's avatar
Sylvain Gugger committed
398
        ("rwkv", "RWKV_PRETRAINED_CONFIG_ARCHIVE_MAP"),
399
        ("sam", "SAM_PRETRAINED_CONFIG_ARCHIVE_MAP"),
400
        ("seamless_m4t", "SEAMLESS_M4T_PRETRAINED_CONFIG_ARCHIVE_MAP"),
401
        ("segformer", "SEGFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
402
        ("sew", "SEW_PRETRAINED_CONFIG_ARCHIVE_MAP"),
403
404
405
        ("sew-d", "SEW_D_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("speech_to_text", "SPEECH_TO_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("speech_to_text_2", "SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
406
        ("speecht5", "SPEECHT5_PRETRAINED_CONFIG_ARCHIVE_MAP"),
407
408
        ("splinter", "SPLINTER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("squeezebert", "SQUEEZEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Shehan Munasinghe's avatar
Shehan Munasinghe committed
409
        ("swiftformer", "SWIFTFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
410
        ("swin", "SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
411
        ("swin2sr", "SWIN2SR_PRETRAINED_CONFIG_ARCHIVE_MAP"),
412
        ("swinv2", "SWINV2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
413
        ("switch_transformers", "SWITCH_TRANSFORMERS_PRETRAINED_CONFIG_ARCHIVE_MAP"),
414
        ("t5", "T5_PRETRAINED_CONFIG_ARCHIVE_MAP"),
415
        ("table-transformer", "TABLE_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
416
        ("tapas", "TAPAS_PRETRAINED_CONFIG_ARCHIVE_MAP"),
417
        ("time_series_transformer", "TIME_SERIES_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
418
        ("timesformer", "TIMESFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
419
        ("transfo-xl", "TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Zineng Tang's avatar
Zineng Tang committed
420
        ("tvlt", "TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
421
        ("unispeech", "UNISPEECH_PRETRAINED_CONFIG_ARCHIVE_MAP"),
422
423
        ("unispeech-sat", "UNISPEECH_SAT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("van", "VAN_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
424
        ("videomae", "VIDEOMAE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
425
426
427
        ("vilt", "VILT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("visual_bert", "VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("vit", "VIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
428
        ("vit_hybrid", "VIT_HYBRID_PRETRAINED_CONFIG_ARCHIVE_MAP"),
429
        ("vit_mae", "VIT_MAE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
430
        ("vit_msn", "VIT_MSN_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
431
        ("vitdet", "VITDET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
432
        ("vitmatte", "VITMATTE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Matthijs Hollemans's avatar
Matthijs Hollemans committed
433
        ("vits", "VITS_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Jegor Kit拧kerkin's avatar
Jegor Kit拧kerkin committed
434
        ("vivit", "VIVIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
435
        ("wav2vec2", "WAV_2_VEC_2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
436
        ("wav2vec2-conformer", "WAV2VEC2_CONFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
437
        ("whisper", "WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
438
        ("xclip", "XCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
439
440
441
442
443
        ("xglm", "XGLM_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("xlm", "XLM_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("xlm-prophetnet", "XLM_PROPHETNET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("xlm-roberta", "XLM_ROBERTA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("xlnet", "XLNET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Jannis Vamvas's avatar
Jannis Vamvas committed
444
        ("xmod", "XMOD_PRETRAINED_CONFIG_ARCHIVE_MAP"),
445
446
        ("yolos", "YOLOS_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("yoso", "YOSO_PRETRAINED_CONFIG_ARCHIVE_MAP"),
447
448
449
450
451
    ]
)

MODEL_NAMES_MAPPING = OrderedDict(
    [
452
        # Add full (and cased) model names here
453
        ("albert", "ALBERT"),
454
        ("align", "ALIGN"),
Jongjyh's avatar
Jongjyh committed
455
        ("altclip", "AltCLIP"),
456
        ("audio-spectrogram-transformer", "Audio Spectrogram Transformer"),
457
        ("autoformer", "Autoformer"),
Yoach Lacombe's avatar
Yoach Lacombe committed
458
        ("bark", "Bark"),
459
460
461
        ("bart", "BART"),
        ("barthez", "BARThez"),
        ("bartpho", "BARTpho"),
NielsRogge's avatar
NielsRogge committed
462
        ("beit", "BEiT"),
463
464
465
        ("bert", "BERT"),
        ("bert-generation", "Bert Generation"),
        ("bert-japanese", "BertJapanese"),
466
        ("bertweet", "BERTweet"),
467
        ("big_bird", "BigBird"),
468
        ("bigbird_pegasus", "BigBird-Pegasus"),
Kamal Raj Kanakarajan's avatar
Kamal Raj Kanakarajan committed
469
        ("biogpt", "BioGpt"),
NielsRogge's avatar
NielsRogge committed
470
        ("bit", "BiT"),
471
472
        ("blenderbot", "Blenderbot"),
        ("blenderbot-small", "BlenderbotSmall"),
Younes Belkada's avatar
Younes Belkada committed
473
        ("blip", "BLIP"),
NielsRogge's avatar
NielsRogge committed
474
        ("blip-2", "BLIP-2"),
Younes Belkada's avatar
Younes Belkada committed
475
        ("bloom", "BLOOM"),
476
        ("bort", "BORT"),
477
        ("bridgetower", "BridgeTower"),
Jinho Park's avatar
Jinho Park committed
478
        ("bros", "BROS"),
479
480
        ("byt5", "ByT5"),
        ("camembert", "CamemBERT"),
481
        ("canine", "CANINE"),
482
        ("chinese_clip", "Chinese-CLIP"),
483
        ("clap", "CLAP"),
Suraj Patil's avatar
Suraj Patil committed
484
        ("clip", "CLIP"),
NielsRogge's avatar
NielsRogge committed
485
        ("clipseg", "CLIPSeg"),
Susnato Dhar's avatar
Susnato Dhar committed
486
        ("clvp", "CLVP"),
487
        ("code_llama", "CodeLlama"),
rooa's avatar
rooa committed
488
        ("codegen", "CodeGen"),
489
        ("conditional_detr", "Conditional DETR"),
490
        ("convbert", "ConvBERT"),
491
        ("convnext", "ConvNeXT"),
Alara Dirik's avatar
Alara Dirik committed
492
        ("convnextv2", "ConvNeXTV2"),
493
        ("cpm", "CPM"),
494
        ("cpmant", "CPM-Ant"),
495
        ("ctrl", "CTRL"),
NielsRogge's avatar
NielsRogge committed
496
        ("cvt", "CvT"),
497
498
499
500
501
502
        ("data2vec-audio", "Data2VecAudio"),
        ("data2vec-text", "Data2VecText"),
        ("data2vec-vision", "Data2VecVision"),
        ("deberta", "DeBERTa"),
        ("deberta-v2", "DeBERTa-v2"),
        ("decision_transformer", "Decision Transformer"),
NielsRogge's avatar
NielsRogge committed
503
        ("deformable_detr", "Deformable DETR"),
NielsRogge's avatar
NielsRogge committed
504
        ("deit", "DeiT"),
505
        ("deplot", "DePlot"),
NielsRogge's avatar
NielsRogge committed
506
        ("deta", "DETA"),
NielsRogge's avatar
NielsRogge committed
507
        ("detr", "DETR"),
508
        ("dialogpt", "DialoGPT"),
509
        ("dinat", "DiNAT"),
NielsRogge's avatar
NielsRogge committed
510
        ("dinov2", "DINOv2"),
511
512
        ("distilbert", "DistilBERT"),
        ("dit", "DiT"),
NielsRogge's avatar
NielsRogge committed
513
        ("donut-swin", "DonutSwin"),
514
515
        ("dpr", "DPR"),
        ("dpt", "DPT"),
516
        ("efficientformer", "EfficientFormer"),
Alara Dirik's avatar
Alara Dirik committed
517
        ("efficientnet", "EfficientNet"),
518
        ("electra", "ELECTRA"),
519
        ("encodec", "EnCodec"),
520
        ("encoder-decoder", "Encoder decoder"),
521
        ("ernie", "ERNIE"),
522
        ("ernie_m", "ErnieM"),
523
        ("esm", "ESM"),
Matt's avatar
Matt committed
524
        ("falcon", "Falcon"),
525
        ("flan-t5", "FLAN-T5"),
Arthur's avatar
Arthur committed
526
        ("flan-ul2", "FLAN-UL2"),
527
        ("flaubert", "FlauBERT"),
528
        ("flava", "FLAVA"),
529
        ("fnet", "FNet"),
NielsRogge's avatar
NielsRogge committed
530
        ("focalnet", "FocalNet"),
531
532
        ("fsmt", "FairSeq Machine-Translation"),
        ("funnel", "Funnel Transformer"),
Pablo Montalvo's avatar
Pablo Montalvo committed
533
        ("fuyu", "Fuyu"),
534
        ("git", "GIT"),
535
        ("glpn", "GLPN"),
536
        ("gpt-sw3", "GPT-Sw3"),
537
        ("gpt2", "OpenAI GPT-2"),
538
        ("gpt_bigcode", "GPTBigCode"),
Suraj Patil's avatar
Suraj Patil committed
539
        ("gpt_neo", "GPT Neo"),
540
        ("gpt_neox", "GPT NeoX"),
541
        ("gpt_neox_japanese", "GPT NeoX Japanese"),
542
        ("gptj", "GPT-J"),
543
        ("gptsan-japanese", "GPTSAN-japanese"),
544
        ("graphormer", "Graphormer"),
545
        ("groupvit", "GroupViT"),
546
547
        ("herbert", "HerBERT"),
        ("hubert", "Hubert"),
Sehoon Kim's avatar
Sehoon Kim committed
548
        ("ibert", "I-BERT"),
549
        ("idefics", "IDEFICS"),
550
        ("imagegpt", "ImageGPT"),
551
        ("informer", "Informer"),
NielsRogge's avatar
NielsRogge committed
552
        ("instructblip", "InstructBLIP"),
553
        ("jukebox", "Jukebox"),
Yih-Dar's avatar
Yih-Dar committed
554
        ("kosmos-2", "KOSMOS-2"),
555
556
        ("layoutlm", "LayoutLM"),
        ("layoutlmv2", "LayoutLMv2"),
NielsRogge's avatar
NielsRogge committed
557
        ("layoutlmv3", "LayoutLMv3"),
558
559
        ("layoutxlm", "LayoutXLM"),
        ("led", "LED"),
560
        ("levit", "LeViT"),
NielsRogge's avatar
NielsRogge committed
561
        ("lilt", "LiLT"),
Jason Phang's avatar
Jason Phang committed
562
        ("llama", "LLaMA"),
563
        ("llama2", "Llama2"),
564
        ("longformer", "Longformer"),
Daniel Stancl's avatar
Daniel Stancl committed
565
        ("longt5", "LongT5"),
566
567
568
        ("luke", "LUKE"),
        ("lxmert", "LXMERT"),
        ("m2m_100", "M2M100"),
569
        ("marian", "Marian"),
NielsRogge's avatar
NielsRogge committed
570
        ("markuplm", "MarkupLM"),
Alara Dirik's avatar
Alara Dirik committed
571
        ("mask2former", "Mask2Former"),
572
        ("maskformer", "MaskFormer"),
573
        ("maskformer-swin", "MaskFormerSwin"),
574
        ("matcha", "MatCha"),
575
        ("mbart", "mBART"),
576
        ("mbart50", "mBART-50"),
Chan Woo Kim's avatar
Chan Woo Kim committed
577
        ("mctct", "M-CTC-T"),
578
        ("mega", "MEGA"),
579
580
        ("megatron-bert", "Megatron-BERT"),
        ("megatron_gpt2", "Megatron-GPT2"),
wangpeng's avatar
wangpeng committed
581
        ("mgp-str", "MGP-STR"),
582
        ("mistral", "Mistral"),
583
        ("mluke", "mLUKE"),
584
        ("mms", "MMS"),
585
        ("mobilebert", "MobileBERT"),
586
        ("mobilenet_v1", "MobileNetV1"),
587
        ("mobilenet_v2", "MobileNetV2"),
588
        ("mobilevit", "MobileViT"),
Shehan Munasinghe's avatar
Shehan Munasinghe committed
589
        ("mobilevitv2", "MobileViTV2"),
590
        ("mpnet", "MPNet"),
591
        ("mpt", "MPT"),
592
        ("mra", "MRA"),
593
        ("mt5", "MT5"),
Sanchit Gandhi's avatar
Sanchit Gandhi committed
594
        ("musicgen", "MusicGen"),
StevenTang1998's avatar
StevenTang1998 committed
595
        ("mvp", "MVP"),
596
        ("nat", "NAT"),
597
        ("nezha", "Nezha"),
Lysandre Debut's avatar
Lysandre Debut committed
598
        ("nllb", "NLLB"),
599
        ("nllb-moe", "NLLB-MOE"),
NielsRogge's avatar
NielsRogge committed
600
        ("nougat", "Nougat"),
601
        ("nystromformer", "Nystr枚mformer"),
Jitesh Jain's avatar
Jitesh Jain committed
602
        ("oneformer", "OneFormer"),
603
        ("open-llama", "OpenLlama"),
604
        ("openai-gpt", "OpenAI GPT"),
Younes Belkada's avatar
Younes Belkada committed
605
        ("opt", "OPT"),
NielsRogge's avatar
NielsRogge committed
606
        ("owlv2", "OWLv2"),
607
        ("owlvit", "OWL-ViT"),
608
        ("pegasus", "Pegasus"),
Jason Phang's avatar
Jason Phang committed
609
        ("pegasus_x", "PEGASUS-X"),
610
        ("perceiver", "Perceiver"),
611
        ("persimmon", "Persimmon"),
612
        ("phobert", "PhoBERT"),
Younes Belkada's avatar
Younes Belkada committed
613
        ("pix2struct", "Pix2Struct"),
614
615
        ("plbart", "PLBart"),
        ("poolformer", "PoolFormer"),
Susnato Dhar's avatar
Susnato Dhar committed
616
        ("pop2piano", "Pop2Piano"),
617
        ("prophetnet", "ProphetNet"),
Rinat's avatar
Rinat committed
618
        ("pvt", "PVT"),
619
620
        ("qdqbert", "QDQBert"),
        ("rag", "RAG"),
621
        ("realm", "REALM"),
622
        ("reformer", "Reformer"),
623
624
625
626
        ("regnet", "RegNet"),
        ("rembert", "RemBERT"),
        ("resnet", "ResNet"),
        ("retribert", "RetriBERT"),
627
        ("roberta", "RoBERTa"),
628
        ("roberta-prelayernorm", "RoBERTa-PreLayerNorm"),
Weiwe Shi's avatar
Weiwe Shi committed
629
        ("roc_bert", "RoCBert"),
630
        ("roformer", "RoFormer"),
Sylvain Gugger's avatar
Sylvain Gugger committed
631
        ("rwkv", "RWKV"),
632
        ("sam", "SAM"),
633
        ("seamless_m4t", "SeamlessM4T"),
634
635
636
        ("segformer", "SegFormer"),
        ("sew", "SEW"),
        ("sew-d", "SEW-D"),
637
        ("speech-encoder-decoder", "Speech Encoder decoder"),
638
639
        ("speech_to_text", "Speech2Text"),
        ("speech_to_text_2", "Speech2Text2"),
640
        ("speecht5", "SpeechT5"),
Ori Ram's avatar
Ori Ram committed
641
        ("splinter", "Splinter"),
642
        ("squeezebert", "SqueezeBERT"),
Shehan Munasinghe's avatar
Shehan Munasinghe committed
643
        ("swiftformer", "SwiftFormer"),
644
        ("swin", "Swin Transformer"),
NielsRogge's avatar
NielsRogge committed
645
        ("swin2sr", "Swin2SR"),
646
        ("swinv2", "Swin Transformer V2"),
647
        ("switch_transformers", "SwitchTransformers"),
648
649
        ("t5", "T5"),
        ("t5v1.1", "T5v1.1"),
650
        ("table-transformer", "Table Transformer"),
651
652
        ("tapas", "TAPAS"),
        ("tapex", "TAPEX"),
653
        ("time_series_transformer", "Time Series Transformer"),
654
        ("timesformer", "TimeSformer"),
amyeroberts's avatar
amyeroberts committed
655
        ("timm_backbone", "TimmBackbone"),
Carl's avatar
Carl committed
656
        ("trajectory_transformer", "Trajectory Transformer"),
657
658
        ("transfo-xl", "Transformer-XL"),
        ("trocr", "TrOCR"),
Zineng Tang's avatar
Zineng Tang committed
659
        ("tvlt", "TVLT"),
660
        ("ul2", "UL2"),
661
        ("umt5", "UMT5"),
662
        ("unispeech", "UniSpeech"),
663
        ("unispeech-sat", "UniSpeechSat"),
NielsRogge's avatar
NielsRogge committed
664
        ("upernet", "UPerNet"),
665
        ("van", "VAN"),
NielsRogge's avatar
NielsRogge committed
666
        ("videomae", "VideoMAE"),
667
668
669
        ("vilt", "ViLT"),
        ("vision-encoder-decoder", "Vision Encoder decoder"),
        ("vision-text-dual-encoder", "VisionTextDualEncoder"),
670
        ("visual_bert", "VisualBERT"),
671
        ("vit", "ViT"),
NielsRogge's avatar
NielsRogge committed
672
        ("vit_hybrid", "ViT Hybrid"),
673
        ("vit_mae", "ViTMAE"),
674
        ("vit_msn", "ViTMSN"),
NielsRogge's avatar
NielsRogge committed
675
        ("vitdet", "VitDet"),
NielsRogge's avatar
NielsRogge committed
676
        ("vitmatte", "ViTMatte"),
Matthijs Hollemans's avatar
Matthijs Hollemans committed
677
        ("vits", "VITS"),
Jegor Kit拧kerkin's avatar
Jegor Kit拧kerkin committed
678
        ("vivit", "ViViT"),
679
        ("wav2vec2", "Wav2Vec2"),
680
        ("wav2vec2-conformer", "Wav2Vec2-Conformer"),
681
        ("wav2vec2_phoneme", "Wav2Vec2Phoneme"),
Patrick von Platen's avatar
Patrick von Platen committed
682
        ("wavlm", "WavLM"),
683
        ("whisper", "Whisper"),
NielsRogge's avatar
NielsRogge committed
684
        ("xclip", "X-CLIP"),
685
686
        ("xglm", "XGLM"),
        ("xlm", "XLM"),
687
        ("xlm-prophetnet", "XLM-ProphetNet"),
688
689
        ("xlm-roberta", "XLM-RoBERTa"),
        ("xlm-roberta-xl", "XLM-RoBERTa-XL"),
690
        ("xlm-v", "XLM-V"),
691
        ("xlnet", "XLNet"),
692
693
        ("xls_r", "XLS-R"),
        ("xlsr_wav2vec2", "XLSR-Wav2Vec2"),
Jannis Vamvas's avatar
Jannis Vamvas committed
694
        ("xmod", "X-MOD"),
695
696
        ("yolos", "YOLOS"),
        ("yoso", "YOSO"),
697
698
699
    ]
)

Sylvain Gugger's avatar
Sylvain Gugger committed
700
701
702
703
DEPRECATED_MODELS = [
    "bort",
    "mctct",
    "mmbt",
704
    "open_llama",
Sylvain Gugger's avatar
Sylvain Gugger committed
705
    "retribert",
706
    "tapex",
Sylvain Gugger's avatar
Sylvain Gugger committed
707
708
709
710
    "trajectory_transformer",
    "van",
]

711
SPECIAL_MODEL_TYPE_TO_MODULE_NAME = OrderedDict(
712
713
714
715
716
    [
        ("openai-gpt", "openai"),
        ("data2vec-audio", "data2vec"),
        ("data2vec-text", "data2vec"),
        ("data2vec-vision", "data2vec"),
NielsRogge's avatar
NielsRogge committed
717
        ("donut-swin", "donut"),
Yih-Dar's avatar
Yih-Dar committed
718
        ("kosmos-2", "kosmos2"),
719
        ("maskformer-swin", "maskformer"),
NielsRogge's avatar
NielsRogge committed
720
        ("xclip", "x_clip"),
721
    ]
722
)
723
724
725
726
727
728
729
730


def model_type_to_module_name(key):
    """Converts a config key to the corresponding module."""
    # Special treatment
    if key in SPECIAL_MODEL_TYPE_TO_MODULE_NAME:
        return SPECIAL_MODEL_TYPE_TO_MODULE_NAME[key]

Sylvain Gugger's avatar
Sylvain Gugger committed
731
732
733
734
735
    key = key.replace("-", "_")
    if key in DEPRECATED_MODELS:
        key = f"deprecated.{key}"

    return key
736
737
738
739
740
741
742


def config_class_to_model_type(config):
    """Converts a config class name to the corresponding model type"""
    for key, cls in CONFIG_MAPPING_NAMES.items():
        if cls == config:
            return key
743
744
745
746
    # if key not found check in extra content
    for key, cls in CONFIG_MAPPING._extra_content.items():
        if cls.__name__ == config:
            return key
747
748
749
750
751
752
753
754
755
756
    return None


class _LazyConfigMapping(OrderedDict):
    """
    A dictionary that lazily load its values when they are requested.
    """

    def __init__(self, mapping):
        self._mapping = mapping
757
        self._extra_content = {}
758
759
760
        self._modules = {}

    def __getitem__(self, key):
761
762
        if key in self._extra_content:
            return self._extra_content[key]
763
764
765
766
767
768
        if key not in self._mapping:
            raise KeyError(key)
        value = self._mapping[key]
        module_name = model_type_to_module_name(key)
        if module_name not in self._modules:
            self._modules[module_name] = importlib.import_module(f".{module_name}", "transformers.models")
769
770
771
772
773
774
775
        if hasattr(self._modules[module_name], value):
            return getattr(self._modules[module_name], value)

        # Some of the mappings have entries model_type -> config of another model type. In that case we try to grab the
        # object at the top level.
        transformers_module = importlib.import_module("transformers")
        return getattr(transformers_module, value)
776
777

    def keys(self):
778
        return list(self._mapping.keys()) + list(self._extra_content.keys())
779
780

    def values(self):
781
        return [self[k] for k in self._mapping.keys()] + list(self._extra_content.values())
782

783
    def items(self):
784
        return [(k, self[k]) for k in self._mapping.keys()] + list(self._extra_content.items())
785
786

    def __iter__(self):
787
        return iter(list(self._mapping.keys()) + list(self._extra_content.keys()))
788
789

    def __contains__(self, item):
790
791
        return item in self._mapping or item in self._extra_content

792
    def register(self, key, value, exist_ok=False):
793
794
795
        """
        Register a new configuration in this mapping.
        """
796
        if key in self._mapping.keys() and not exist_ok:
797
798
            raise ValueError(f"'{key}' is already used by a Transformers config, pick another name.")
        self._extra_content[key] = value
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863


CONFIG_MAPPING = _LazyConfigMapping(CONFIG_MAPPING_NAMES)


class _LazyLoadAllMappings(OrderedDict):
    """
    A mapping that will load all pairs of key values at the first access (either by indexing, requestions keys, values,
    etc.)

    Args:
        mapping: The mapping to load.
    """

    def __init__(self, mapping):
        self._mapping = mapping
        self._initialized = False
        self._data = {}

    def _initialize(self):
        if self._initialized:
            return
        warnings.warn(
            "ALL_PRETRAINED_CONFIG_ARCHIVE_MAP is deprecated and will be removed in v5 of Transformers. "
            "It does not contain all available model checkpoints, far from it. Checkout hf.co/models for that.",
            FutureWarning,
        )

        for model_type, map_name in self._mapping.items():
            module_name = model_type_to_module_name(model_type)
            module = importlib.import_module(f".{module_name}", "transformers.models")
            mapping = getattr(module, map_name)
            self._data.update(mapping)

        self._initialized = True

    def __getitem__(self, key):
        self._initialize()
        return self._data[key]

    def keys(self):
        self._initialize()
        return self._data.keys()

    def values(self):
        self._initialize()
        return self._data.values()

    def items(self):
        self._initialize()
        return self._data.keys()

    def __iter__(self):
        self._initialize()
        return iter(self._data)

    def __contains__(self, item):
        self._initialize()
        return item in self._data


ALL_PRETRAINED_CONFIG_ARCHIVE_MAP = _LazyLoadAllMappings(CONFIG_ARCHIVE_MAP_MAPPING_NAMES)


def _get_class_name(model_class: Union[str, List[str]]):
864
    if isinstance(model_class, (list, tuple)):
Stas Bekman's avatar
Stas Bekman committed
865
866
        return " or ".join([f"[`{c}`]" for c in model_class if c is not None])
    return f"[`{model_class}`]"
867
868


869
870
871
872
873
def _list_model_options(indent, config_to_class=None, use_model_types=True):
    if config_to_class is None and not use_model_types:
        raise ValueError("Using `use_model_types=False` requires a `config_to_class` dictionary.")
    if use_model_types:
        if config_to_class is None:
Stas Bekman's avatar
Stas Bekman committed
874
            model_type_to_name = {model_type: f"[`{config}`]" for model_type, config in CONFIG_MAPPING_NAMES.items()}
875
876
        else:
            model_type_to_name = {
877
878
879
                model_type: _get_class_name(model_class)
                for model_type, model_class in config_to_class.items()
                if model_type in MODEL_NAMES_MAPPING
880
881
            }
        lines = [
882
            f"{indent}- **{model_type}** -- {model_type_to_name[model_type]} ({MODEL_NAMES_MAPPING[model_type]} model)"
883
            for model_type in sorted(model_type_to_name.keys())
884
885
        ]
    else:
886
887
888
889
890
        config_to_name = {
            CONFIG_MAPPING_NAMES[config]: _get_class_name(clas)
            for config, clas in config_to_class.items()
            if config in CONFIG_MAPPING_NAMES
        }
891
        config_to_model_name = {
892
            config: MODEL_NAMES_MAPPING[model_type] for model_type, config in CONFIG_MAPPING_NAMES.items()
893
894
        }
        lines = [
Sylvain Gugger's avatar
Sylvain Gugger committed
895
896
            f"{indent}- [`{config_name}`] configuration class:"
            f" {config_to_name[config_name]} ({config_to_model_name[config_name]} model)"
897
            for config_name in sorted(config_to_name.keys())
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
        ]
    return "\n".join(lines)


def replace_list_option_in_docstrings(config_to_class=None, use_model_types=True):
    def docstring_decorator(fn):
        docstrings = fn.__doc__
        lines = docstrings.split("\n")
        i = 0
        while i < len(lines) and re.search(r"^(\s*)List options\s*$", lines[i]) is None:
            i += 1
        if i < len(lines):
            indent = re.search(r"^(\s*)List options\s*$", lines[i]).groups()[0]
            if use_model_types:
                indent = f"{indent}    "
            lines[i] = _list_model_options(indent, config_to_class=config_to_class, use_model_types=use_model_types)
            docstrings = "\n".join(lines)
        else:
            raise ValueError(
Sylvain Gugger's avatar
Sylvain Gugger committed
917
918
                f"The function {fn} should have an empty 'List options' in its docstring as placeholder, current"
                f" docstring is:\n{docstrings}"
919
920
921
922
923
924
925
            )
        fn.__doc__ = docstrings
        return fn

    return docstring_decorator


Julien Chaumond's avatar
Julien Chaumond committed
926
class AutoConfig:
Lysandre Debut's avatar
Lysandre Debut committed
927
    r"""
928
    This is a generic configuration class that will be instantiated as one of the configuration classes of the library
929
    when created with the [`~AutoConfig.from_pretrained`] class method.
930

931
    This class cannot be instantiated directly using `__init__()` (throws an error).
932
    """
933

934
    def __init__(self):
935
936
937
938
        raise EnvironmentError(
            "AutoConfig is designed to be instantiated "
            "using the `AutoConfig.from_pretrained(pretrained_model_name_or_path)` method."
        )
939

940
    @classmethod
941
942
943
944
    def for_model(cls, model_type: str, *args, **kwargs):
        if model_type in CONFIG_MAPPING:
            config_class = CONFIG_MAPPING[model_type]
            return config_class(*args, **kwargs)
945
        raise ValueError(
946
            f"Unrecognized model identifier: {model_type}. Should contain one of {', '.join(CONFIG_MAPPING.keys())}"
947
        )
948

949
    @classmethod
950
    @replace_list_option_in_docstrings()
951
    def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):
952
953
        r"""
        Instantiate one of the configuration classes of the library from a pretrained model configuration.
954

Sylvain Gugger's avatar
Sylvain Gugger committed
955
956
        The configuration class to instantiate is selected based on the `model_type` property of the config object that
        is loaded, or when it's missing, by falling back to using pattern matching on `pretrained_model_name_or_path`:
957

958
        List options
Lysandre Debut's avatar
Lysandre Debut committed
959
960

        Args:
961
            pretrained_model_name_or_path (`str` or `os.PathLike`):
962
963
                Can be either:

964
965
966
967
                    - A string, the *model id* of a pretrained model configuration hosted inside a model repo on
                      huggingface.co. Valid model ids can be located at the root-level, like `bert-base-uncased`, or
                      namespaced under a user or organization name, like `dbmdz/bert-base-german-cased`.
                    - A path to a *directory* containing a configuration file saved using the
Sylvain Gugger's avatar
Sylvain Gugger committed
968
969
                      [`~PretrainedConfig.save_pretrained`] method, or the [`~PreTrainedModel.save_pretrained`] method,
                      e.g., `./my_model_directory/`.
970
971
972
                    - A path or url to a saved configuration JSON *file*, e.g.,
                      `./my_model_directory/configuration.json`.
            cache_dir (`str` or `os.PathLike`, *optional*):
973
974
                Path to a directory in which a downloaded pretrained model configuration should be cached if the
                standard cache should not be used.
975
            force_download (`bool`, *optional*, defaults to `False`):
976
977
                Whether or not to force the (re-)download the model weights and configuration files and override the
                cached versions if they exist.
978
            resume_download (`bool`, *optional*, defaults to `False`):
979
980
                Whether or not to delete incompletely received files. Will attempt to resume the download if such a
                file exists.
981
            proxies (`Dict[str, str]`, *optional*):
Sylvain Gugger's avatar
Sylvain Gugger committed
982
983
                A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
                'http://hostname': 'foo.bar:4012'}`. The proxies are used on each request.
984
            revision (`str`, *optional*, defaults to `"main"`):
Julien Chaumond's avatar
Julien Chaumond committed
985
                The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
986
                git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
Julien Chaumond's avatar
Julien Chaumond committed
987
                identifier allowed by git.
988
989
            return_unused_kwargs (`bool`, *optional*, defaults to `False`):
                If `False`, then this function returns just the final configuration object.
990

Sylvain Gugger's avatar
Sylvain Gugger committed
991
992
993
                If `True`, then this functions returns a `Tuple(config, unused_kwargs)` where *unused_kwargs* is a
                dictionary consisting of the key/value pairs whose keys are not configuration attributes: i.e., the
                part of `kwargs` which has not been used to update `config` and is otherwise ignored.
994
            trust_remote_code (`bool`, *optional*, defaults to `False`):
995
                Whether or not to allow for custom models defined on the Hub in their own modeling files. This option
Sylvain Gugger's avatar
Sylvain Gugger committed
996
997
                should only be set to `True` for repositories you trust and in which you have read the code, as it will
                execute code present on the Hub on your local machine.
998
            kwargs(additional keyword arguments, *optional*):
999
                The values in kwargs of any keys which are configuration attributes will be used to override the loaded
Sylvain Gugger's avatar
Sylvain Gugger committed
1000
                values. Behavior concerning key/value pairs whose keys are *not* configuration attributes is controlled
1001
                by the `return_unused_kwargs` keyword parameter.
Lysandre Debut's avatar
Lysandre Debut committed
1002

1003
        Examples:
1004

1005
1006
        ```python
        >>> from transformers import AutoConfig
1007

1008
        >>> # Download configuration from huggingface.co and cache.
Sylvain Gugger's avatar
Sylvain Gugger committed
1009
        >>> config = AutoConfig.from_pretrained("bert-base-uncased")
Lysandre Debut's avatar
Lysandre Debut committed
1010

1011
        >>> # Download configuration from huggingface.co (user-uploaded) and cache.
Sylvain Gugger's avatar
Sylvain Gugger committed
1012
        >>> config = AutoConfig.from_pretrained("dbmdz/bert-base-german-cased")
Lysandre Debut's avatar
Lysandre Debut committed
1013

1014
        >>> # If configuration file is in a directory (e.g., was saved using *save_pretrained('./test/saved_model/')*).
Sylvain Gugger's avatar
Sylvain Gugger committed
1015
        >>> config = AutoConfig.from_pretrained("./test/bert_saved_model/")
1016

1017
        >>> # Load a specific configuration file.
Sylvain Gugger's avatar
Sylvain Gugger committed
1018
        >>> config = AutoConfig.from_pretrained("./test/bert_saved_model/my_configuration.json")
1019

1020
        >>> # Change some config attributes when loading a pretrained config.
Sylvain Gugger's avatar
Sylvain Gugger committed
1021
        >>> config = AutoConfig.from_pretrained("bert-base-uncased", output_attentions=True, foo=False)
1022
1023
        >>> config.output_attentions
        True
Sylvain Gugger's avatar
Sylvain Gugger committed
1024
1025
1026
1027

        >>> config, unused_kwargs = AutoConfig.from_pretrained(
        ...     "bert-base-uncased", output_attentions=True, foo=False, return_unused_kwargs=True
        ... )
1028
1029
        >>> config.output_attentions
        True
Sylvain Gugger's avatar
Sylvain Gugger committed
1030

1031
        >>> unused_kwargs
1032
1033
        {'foo': False}
        ```"""
1034
1035
1036
        use_auth_token = kwargs.pop("use_auth_token", None)
        if use_auth_token is not None:
            warnings.warn(
1037
1038
                "The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.",
                FutureWarning,
1039
1040
1041
1042
1043
1044
1045
            )
            if kwargs.get("token", None) is not None:
                raise ValueError(
                    "`token` and `use_auth_token` are both specified. Please set only the argument `token`."
                )
            kwargs["token"] = use_auth_token

1046
        kwargs["_from_auto"] = True
1047
        kwargs["name_or_path"] = pretrained_model_name_or_path
1048
        trust_remote_code = kwargs.pop("trust_remote_code", None)
1049
1050
        code_revision = kwargs.pop("code_revision", None)

1051
        config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
1052
1053
1054
1055
1056
1057
1058
        has_remote_code = "auto_map" in config_dict and "AutoConfig" in config_dict["auto_map"]
        has_local_code = "model_type" in config_dict and config_dict["model_type"] in CONFIG_MAPPING
        trust_remote_code = resolve_trust_remote_code(
            trust_remote_code, pretrained_model_name_or_path, has_local_code, has_remote_code
        )

        if has_remote_code and trust_remote_code:
1059
            class_ref = config_dict["auto_map"]["AutoConfig"]
1060
1061
1062
            config_class = get_class_from_dynamic_module(
                class_ref, pretrained_model_name_or_path, code_revision=code_revision, **kwargs
            )
1063
1064
            if os.path.isdir(pretrained_model_name_or_path):
                config_class.register_for_auto_class()
1065
1066
            return config_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
        elif "model_type" in config_dict:
1067
            config_class = CONFIG_MAPPING[config_dict["model_type"]]
1068
            return config_class.from_dict(config_dict, **unused_kwargs)
1069
1070
        else:
            # Fallback: use pattern matching on the string.
1071
1072
            # We go from longer names to shorter names to catch roberta before bert (for instance)
            for pattern in sorted(CONFIG_MAPPING.keys(), key=len, reverse=True):
1073
                if pattern in str(pretrained_model_name_or_path):
1074
                    return CONFIG_MAPPING[pattern].from_dict(config_dict, **unused_kwargs)
1075

1076
        raise ValueError(
1077
            f"Unrecognized model in {pretrained_model_name_or_path}. "
1078
            f"Should have a `model_type` key in its {CONFIG_NAME}, or contain one of the following strings "
1079
            f"in its name: {', '.join(CONFIG_MAPPING.keys())}"
1080
        )
1081
1082

    @staticmethod
zspo's avatar
zspo committed
1083
    def register(model_type, config, exist_ok=False):
1084
1085
1086
1087
        """
        Register a new configuration for this class.

        Args:
1088
1089
            model_type (`str`): The model type like "bert" or "gpt".
            config ([`PretrainedConfig`]): The config to register.
1090
1091
1092
1093
1094
1095
1096
        """
        if issubclass(config, PretrainedConfig) and config.model_type != model_type:
            raise ValueError(
                "The config you are passing has a `model_type` attribute that is not consistent with the model type "
                f"you passed (config has {config.model_type} and you passed {model_type}. Fix one of those so they "
                "match!"
            )
zspo's avatar
zspo committed
1097
        CONFIG_MAPPING.register(model_type, config, exist_ok=exist_ok)