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

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

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

Sylvain Gugger's avatar
Sylvain Gugger committed
671
672
673
674
DEPRECATED_MODELS = [
    "bort",
    "mctct",
    "mmbt",
675
    "open_llama",
Sylvain Gugger's avatar
Sylvain Gugger committed
676
    "retribert",
677
    "tapex",
Sylvain Gugger's avatar
Sylvain Gugger committed
678
679
680
681
    "trajectory_transformer",
    "van",
]

682
SPECIAL_MODEL_TYPE_TO_MODULE_NAME = OrderedDict(
683
684
685
686
687
    [
        ("openai-gpt", "openai"),
        ("data2vec-audio", "data2vec"),
        ("data2vec-text", "data2vec"),
        ("data2vec-vision", "data2vec"),
NielsRogge's avatar
NielsRogge committed
688
        ("donut-swin", "donut"),
689
        ("maskformer-swin", "maskformer"),
NielsRogge's avatar
NielsRogge committed
690
        ("xclip", "x_clip"),
691
    ]
692
)
693
694
695
696
697
698
699
700


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
701
702
703
704
705
    key = key.replace("-", "_")
    if key in DEPRECATED_MODELS:
        key = f"deprecated.{key}"

    return key
706
707
708
709
710
711
712


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
713
714
715
716
    # if key not found check in extra content
    for key, cls in CONFIG_MAPPING._extra_content.items():
        if cls.__name__ == config:
            return key
717
718
719
720
721
722
723
724
725
726
    return None


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

    def __init__(self, mapping):
        self._mapping = mapping
727
        self._extra_content = {}
728
729
730
        self._modules = {}

    def __getitem__(self, key):
731
732
        if key in self._extra_content:
            return self._extra_content[key]
733
734
735
736
737
738
        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")
739
740
741
742
743
744
745
        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)
746
747

    def keys(self):
748
        return list(self._mapping.keys()) + list(self._extra_content.keys())
749
750

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

753
    def items(self):
754
        return [(k, self[k]) for k in self._mapping.keys()] + list(self._extra_content.items())
755
756

    def __iter__(self):
757
        return iter(list(self._mapping.keys()) + list(self._extra_content.keys()))
758
759

    def __contains__(self, item):
760
761
        return item in self._mapping or item in self._extra_content

762
    def register(self, key, value, exist_ok=False):
763
764
765
        """
        Register a new configuration in this mapping.
        """
766
        if key in self._mapping.keys() and not exist_ok:
767
768
            raise ValueError(f"'{key}' is already used by a Transformers config, pick another name.")
        self._extra_content[key] = value
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
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


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]]):
834
    if isinstance(model_class, (list, tuple)):
Stas Bekman's avatar
Stas Bekman committed
835
836
        return " or ".join([f"[`{c}`]" for c in model_class if c is not None])
    return f"[`{model_class}`]"
837
838


839
840
841
842
843
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
844
            model_type_to_name = {model_type: f"[`{config}`]" for model_type, config in CONFIG_MAPPING_NAMES.items()}
845
846
        else:
            model_type_to_name = {
847
848
849
                model_type: _get_class_name(model_class)
                for model_type, model_class in config_to_class.items()
                if model_type in MODEL_NAMES_MAPPING
850
851
            }
        lines = [
852
            f"{indent}- **{model_type}** -- {model_type_to_name[model_type]} ({MODEL_NAMES_MAPPING[model_type]} model)"
853
            for model_type in sorted(model_type_to_name.keys())
854
855
        ]
    else:
856
857
858
859
860
        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
        }
861
        config_to_model_name = {
862
            config: MODEL_NAMES_MAPPING[model_type] for model_type, config in CONFIG_MAPPING_NAMES.items()
863
864
        }
        lines = [
Sylvain Gugger's avatar
Sylvain Gugger committed
865
866
            f"{indent}- [`{config_name}`] configuration class:"
            f" {config_to_name[config_name]} ({config_to_model_name[config_name]} model)"
867
            for config_name in sorted(config_to_name.keys())
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
        ]
    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
887
888
                f"The function {fn} should have an empty 'List options' in its docstring as placeholder, current"
                f" docstring is:\n{docstrings}"
889
890
891
892
893
894
895
            )
        fn.__doc__ = docstrings
        return fn

    return docstring_decorator


Julien Chaumond's avatar
Julien Chaumond committed
896
class AutoConfig:
Lysandre Debut's avatar
Lysandre Debut committed
897
    r"""
898
    This is a generic configuration class that will be instantiated as one of the configuration classes of the library
899
    when created with the [`~AutoConfig.from_pretrained`] class method.
900

901
    This class cannot be instantiated directly using `__init__()` (throws an error).
902
    """
903

904
    def __init__(self):
905
906
907
908
        raise EnvironmentError(
            "AutoConfig is designed to be instantiated "
            "using the `AutoConfig.from_pretrained(pretrained_model_name_or_path)` method."
        )
909

910
    @classmethod
911
912
913
914
    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)
915
        raise ValueError(
916
            f"Unrecognized model identifier: {model_type}. Should contain one of {', '.join(CONFIG_MAPPING.keys())}"
917
        )
918

919
    @classmethod
920
    @replace_list_option_in_docstrings()
921
    def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):
922
923
        r"""
        Instantiate one of the configuration classes of the library from a pretrained model configuration.
924

Sylvain Gugger's avatar
Sylvain Gugger committed
925
926
        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`:
927

928
        List options
Lysandre Debut's avatar
Lysandre Debut committed
929
930

        Args:
931
            pretrained_model_name_or_path (`str` or `os.PathLike`):
932
933
                Can be either:

934
935
936
937
                    - 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
938
939
                      [`~PretrainedConfig.save_pretrained`] method, or the [`~PreTrainedModel.save_pretrained`] method,
                      e.g., `./my_model_directory/`.
940
941
942
                    - A path or url to a saved configuration JSON *file*, e.g.,
                      `./my_model_directory/configuration.json`.
            cache_dir (`str` or `os.PathLike`, *optional*):
943
944
                Path to a directory in which a downloaded pretrained model configuration should be cached if the
                standard cache should not be used.
945
            force_download (`bool`, *optional*, defaults to `False`):
946
947
                Whether or not to force the (re-)download the model weights and configuration files and override the
                cached versions if they exist.
948
            resume_download (`bool`, *optional*, defaults to `False`):
949
950
                Whether or not to delete incompletely received files. Will attempt to resume the download if such a
                file exists.
951
            proxies (`Dict[str, str]`, *optional*):
Sylvain Gugger's avatar
Sylvain Gugger committed
952
953
                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.
954
            revision (`str`, *optional*, defaults to `"main"`):
Julien Chaumond's avatar
Julien Chaumond committed
955
                The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
956
                git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
Julien Chaumond's avatar
Julien Chaumond committed
957
                identifier allowed by git.
958
959
            return_unused_kwargs (`bool`, *optional*, defaults to `False`):
                If `False`, then this function returns just the final configuration object.
960

Sylvain Gugger's avatar
Sylvain Gugger committed
961
962
963
                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.
964
            trust_remote_code (`bool`, *optional*, defaults to `False`):
965
                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
966
967
                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.
968
            kwargs(additional keyword arguments, *optional*):
969
                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
970
                values. Behavior concerning key/value pairs whose keys are *not* configuration attributes is controlled
971
                by the `return_unused_kwargs` keyword parameter.
Lysandre Debut's avatar
Lysandre Debut committed
972

973
        Examples:
974

975
976
        ```python
        >>> from transformers import AutoConfig
977

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

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

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

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

990
        >>> # Change some config attributes when loading a pretrained config.
Sylvain Gugger's avatar
Sylvain Gugger committed
991
        >>> config = AutoConfig.from_pretrained("bert-base-uncased", output_attentions=True, foo=False)
992
993
        >>> config.output_attentions
        True
Sylvain Gugger's avatar
Sylvain Gugger committed
994
995
996
997

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

1001
        >>> unused_kwargs
1002
1003
        {'foo': False}
        ```"""
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
        use_auth_token = kwargs.pop("use_auth_token", None)
        if use_auth_token is not None:
            warnings.warn(
                "The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers.", FutureWarning
            )
            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

1015
        kwargs["_from_auto"] = True
1016
        kwargs["name_or_path"] = pretrained_model_name_or_path
1017
        trust_remote_code = kwargs.pop("trust_remote_code", None)
1018
        code_revision = kwargs.pop("code_revision", None)
Lysandre Debut's avatar
Lysandre Debut committed
1019
        revision = kwargs.pop("revision", None)
1020

Lysandre Debut's avatar
Lysandre Debut committed
1021
1022
1023
1024
1025
        revision = sanitize_code_revision(pretrained_model_name_or_path, revision, trust_remote_code)

        config_dict, unused_kwargs = PretrainedConfig.get_config_dict(
            pretrained_model_name_or_path, revision=revision, **kwargs
        )
1026
1027
1028
1029
1030
1031
1032
        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:
1033
            class_ref = config_dict["auto_map"]["AutoConfig"]
1034
1035
1036
            config_class = get_class_from_dynamic_module(
                class_ref, pretrained_model_name_or_path, code_revision=code_revision, **kwargs
            )
1037
1038
            if os.path.isdir(pretrained_model_name_or_path):
                config_class.register_for_auto_class()
1039
1040
            return config_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
        elif "model_type" in config_dict:
1041
            config_class = CONFIG_MAPPING[config_dict["model_type"]]
1042
            return config_class.from_dict(config_dict, **unused_kwargs)
1043
1044
        else:
            # Fallback: use pattern matching on the string.
1045
1046
            # 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):
1047
                if pattern in str(pretrained_model_name_or_path):
1048
                    return CONFIG_MAPPING[pattern].from_dict(config_dict, **unused_kwargs)
1049

1050
        raise ValueError(
1051
            f"Unrecognized model in {pretrained_model_name_or_path}. "
1052
            f"Should have a `model_type` key in its {CONFIG_NAME}, or contain one of the following strings "
1053
            f"in its name: {', '.join(CONFIG_MAPPING.keys())}"
1054
        )
1055
1056

    @staticmethod
zspo's avatar
zspo committed
1057
    def register(model_type, config, exist_ok=False):
1058
1059
1060
1061
        """
        Register a new configuration for this class.

        Args:
1062
1063
            model_type (`str`): The model type like "bert" or "gpt".
            config ([`PretrainedConfig`]): The config to register.
1064
1065
1066
1067
1068
1069
1070
        """
        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
1071
        CONFIG_MAPPING.register(model_type, config, exist_ok=exist_ok)
Lysandre Debut's avatar
Lysandre Debut committed
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092


def sanitize_code_revision(pretrained_model_name_or_path, revision, trust_remote_code):
    if revision in ["main", None] and not trust_remote_code:
        revision_dict = {
            "tiiuae/falcon-7b": "4e2d06f0a7c6370ebabbc30c6f59377ae8f73d76",
            "tiiuae/falcon-7b-instruct": "f8dac3fff96d5debd43edf56fb4e1abcfffbef28",
            "tiiuae/falcon-40b": "f1ba7d328c06aa6fbb4a8afd3c756f46d7e6b232",
            "tiiuae/falcon-40b-instruct": "7475ff8cfc36ed9a962b658ae3c33391566a85a5",
        }

        if isinstance(pretrained_model_name_or_path, str) and pretrained_model_name_or_path.lower() in revision_dict:
            revision = revision_dict.get(pretrained_model_name_or_path.lower())
            logger.warning(
                "The Falcon model was initialized without `trust_remote_code=True`, and will therefore leverage the "
                f"transformers library implementation. {pretrained_model_name_or_path}'s revision is set to a version that doesn't "
                f"leverage remote code ({revision}).\n\nIn order to override this, please set a revision manually or set "
                "`trust_remote_code=True`."
            )

    return revision