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

275
CONFIG_ARCHIVE_MAP_MAPPING_NAMES = OrderedDict(
276
    [
NielsRogge's avatar
NielsRogge committed
277
        # Add archive maps here)
278
        ("albert", "ALBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
279
        ("align", "ALIGN_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Jongjyh's avatar
Jongjyh committed
280
        ("altclip", "ALTCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
281
        ("audio-spectrogram-transformer", "AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
282
        ("autoformer", "AUTOFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Yoach Lacombe's avatar
Yoach Lacombe committed
283
        ("bark", "BARK_PRETRAINED_CONFIG_ARCHIVE_MAP"),
284
        ("bart", "BART_PRETRAINED_CONFIG_ARCHIVE_MAP"),
285
        ("beit", "BEIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
286
287
288
        ("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
289
        ("biogpt", "BIOGPT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
290
        ("bit", "BIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
291
292
        ("blenderbot", "BLENDERBOT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("blenderbot-small", "BLENDERBOT_SMALL_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Younes Belkada's avatar
Younes Belkada committed
293
        ("blip", "BLIP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
294
        ("blip-2", "BLIP_2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Younes Belkada's avatar
Younes Belkada committed
295
        ("bloom", "BLOOM_PRETRAINED_CONFIG_ARCHIVE_MAP"),
296
        ("bridgetower", "BRIDGETOWER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Jinho Park's avatar
Jinho Park committed
297
        ("bros", "BROS_PRETRAINED_CONFIG_ARCHIVE_MAP"),
298
        ("camembert", "CAMEMBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
299
        ("canine", "CANINE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
300
        ("chinese_clip", "CHINESE_CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
301
        ("clap", "CLAP_PRETRAINED_MODEL_ARCHIVE_LIST"),
302
        ("clip", "CLIP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
303
        ("clipseg", "CLIPSEG_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Susnato Dhar's avatar
Susnato Dhar committed
304
        ("clvp", "CLVP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
rooa's avatar
rooa committed
305
        ("codegen", "CODEGEN_PRETRAINED_CONFIG_ARCHIVE_MAP"),
306
        ("conditional_detr", "CONDITIONAL_DETR_PRETRAINED_CONFIG_ARCHIVE_MAP"),
307
        ("convbert", "CONVBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
308
        ("convnext", "CONVNEXT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Alara Dirik's avatar
Alara Dirik committed
309
        ("convnextv2", "CONVNEXTV2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
310
        ("cpmant", "CPMANT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
311
        ("ctrl", "CTRL_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
312
        ("cvt", "CVT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
313
        ("data2vec-audio", "DATA2VEC_AUDIO_PRETRAINED_CONFIG_ARCHIVE_MAP"),
314
315
316
317
        ("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
318
        ("deformable_detr", "DEFORMABLE_DETR_PRETRAINED_CONFIG_ARCHIVE_MAP"),
319
        ("deit", "DEIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
320
        ("depth_anything", "DEPTH_ANYTHING_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
321
        ("deta", "DETA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
322
        ("detr", "DETR_PRETRAINED_CONFIG_ARCHIVE_MAP"),
323
        ("dinat", "DINAT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
324
        ("dinov2", "DINOV2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
325
        ("distilbert", "DISTILBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
326
        ("donut-swin", "DONUT_SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP"),
327
328
        ("dpr", "DPR_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("dpt", "DPT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
329
        ("efficientformer", "EFFICIENTFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Alara Dirik's avatar
Alara Dirik committed
330
        ("efficientnet", "EFFICIENTNET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
331
        ("electra", "ELECTRA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
332
        ("encodec", "ENCODEC_PRETRAINED_CONFIG_ARCHIVE_MAP"),
333
        ("ernie", "ERNIE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
334
        ("ernie_m", "ERNIE_M_PRETRAINED_CONFIG_ARCHIVE_MAP"),
335
        ("esm", "ESM_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Matt's avatar
Matt committed
336
        ("falcon", "FALCON_PRETRAINED_CONFIG_ARCHIVE_MAP"),
337
        ("fastspeech2_conformer", "FASTSPEECH2_CONFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
338
        ("flaubert", "FLAUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
339
340
        ("flava", "FLAVA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("fnet", "FNET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
341
        ("focalnet", "FOCALNET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
342
343
        ("fsmt", "FSMT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("funnel", "FUNNEL_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Pablo Montalvo's avatar
Pablo Montalvo committed
344
        ("fuyu", "FUYU_PRETRAINED_CONFIG_ARCHIVE_MAP"),
345
        ("gemma", "GEMMA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
346
        ("git", "GIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
347
348
        ("glpn", "GLPN_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("gpt2", "GPT2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
349
        ("gpt_bigcode", "GPT_BIGCODE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
350
        ("gpt_neo", "GPT_NEO_PRETRAINED_CONFIG_ARCHIVE_MAP"),
351
        ("gpt_neox", "GPT_NEOX_PRETRAINED_CONFIG_ARCHIVE_MAP"),
352
        ("gpt_neox_japanese", "GPT_NEOX_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
353
        ("gptj", "GPTJ_PRETRAINED_CONFIG_ARCHIVE_MAP"),
354
        ("gptsan-japanese", "GPTSAN_JAPANESE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
355
        ("graphormer", "GRAPHORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
356
        ("groupvit", "GROUPVIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
357
358
        ("hubert", "HUBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("ibert", "IBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
359
        ("idefics", "IDEFICS_PRETRAINED_CONFIG_ARCHIVE_MAP"),
360
        ("imagegpt", "IMAGEGPT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
361
        ("informer", "INFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
362
        ("instructblip", "INSTRUCTBLIP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
363
        ("jukebox", "JUKEBOX_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Yih-Dar's avatar
Yih-Dar committed
364
        ("kosmos-2", "KOSMOS2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
365
        ("layoutlm", "LAYOUTLM_PRETRAINED_CONFIG_ARCHIVE_MAP"),
366
        ("layoutlmv2", "LAYOUTLMV2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
367
        ("layoutlmv3", "LAYOUTLMV3_PRETRAINED_CONFIG_ARCHIVE_MAP"),
368
        ("led", "LED_PRETRAINED_CONFIG_ARCHIVE_MAP"),
369
        ("levit", "LEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
370
        ("lilt", "LILT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Jason Phang's avatar
Jason Phang committed
371
        ("llama", "LLAMA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
372
        ("llava", "LLAVA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
373
        ("longformer", "LONGFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Daniel Stancl's avatar
Daniel Stancl committed
374
        ("longt5", "LONGT5_PRETRAINED_CONFIG_ARCHIVE_MAP"),
375
376
377
        ("luke", "LUKE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("lxmert", "LXMERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("m2m_100", "M2M_100_PRETRAINED_CONFIG_ARCHIVE_MAP"),
378
        ("mamba", "MAMBA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
379
        ("markuplm", "MARKUPLM_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Alara Dirik's avatar
Alara Dirik committed
380
        ("mask2former", "MASK2FORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
381
382
        ("maskformer", "MASKFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("mbart", "MBART_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Chan Woo Kim's avatar
Chan Woo Kim committed
383
        ("mctct", "MCTCT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
384
        ("mega", "MEGA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
385
        ("megatron-bert", "MEGATRON_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
wangpeng's avatar
wangpeng committed
386
        ("mgp-str", "MGP_STR_PRETRAINED_CONFIG_ARCHIVE_MAP"),
387
        ("mistral", "MISTRAL_PRETRAINED_CONFIG_ARCHIVE_MAP"),
388
        ("mixtral", "MIXTRAL_PRETRAINED_CONFIG_ARCHIVE_MAP"),
389
        ("mobilenet_v1", "MOBILENET_V1_PRETRAINED_CONFIG_ARCHIVE_MAP"),
390
        ("mobilenet_v2", "MOBILENET_V2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
391
        ("mobilevit", "MOBILEVIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Shehan Munasinghe's avatar
Shehan Munasinghe committed
392
        ("mobilevitv2", "MOBILEVITV2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
393
        ("mpnet", "MPNET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
394
        ("mpt", "MPT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
395
        ("mra", "MRA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Sanchit Gandhi's avatar
Sanchit Gandhi committed
396
        ("musicgen", "MUSICGEN_PRETRAINED_CONFIG_ARCHIVE_MAP"),
StevenTang1998's avatar
StevenTang1998 committed
397
        ("mvp", "MVP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
398
        ("nat", "NAT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
399
        ("nezha", "NEZHA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
400
        ("nllb-moe", "NLLB_MOE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
401
        ("nystromformer", "NYSTROMFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Jitesh Jain's avatar
Jitesh Jain committed
402
        ("oneformer", "ONEFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
403
        ("open-llama", "OPEN_LLAMA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
404
405
        ("openai-gpt", "OPENAI_GPT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("opt", "OPT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
406
        ("owlv2", "OWLV2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
407
        ("owlvit", "OWLVIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
408
        ("patchtsmixer", "PATCHTSMIXER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
409
        ("patchtst", "PATCHTST_PRETRAINED_CONFIG_ARCHIVE_MAP"),
410
        ("pegasus", "PEGASUS_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Jason Phang's avatar
Jason Phang committed
411
        ("pegasus_x", "PEGASUS_X_PRETRAINED_CONFIG_ARCHIVE_MAP"),
412
        ("perceiver", "PERCEIVER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
413
        ("persimmon", "PERSIMMON_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Susnato Dhar's avatar
Susnato Dhar committed
414
        ("phi", "PHI_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Younes Belkada's avatar
Younes Belkada committed
415
        ("pix2struct", "PIX2STRUCT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
416
417
        ("plbart", "PLBART_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("poolformer", "POOLFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Susnato Dhar's avatar
Susnato Dhar committed
418
        ("pop2piano", "POP2PIANO_PRETRAINED_CONFIG_ARCHIVE_MAP"),
419
        ("prophetnet", "PROPHETNET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Rinat's avatar
Rinat committed
420
        ("pvt", "PVT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Nate Cibik's avatar
Nate Cibik committed
421
        ("pvt_v2", "PVT_V2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
422
        ("qdqbert", "QDQBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Junyang Lin's avatar
Junyang Lin committed
423
        ("qwen2", "QWEN2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
424
425
426
427
428
429
        ("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"),
430
        ("roberta-prelayernorm", "ROBERTA_PRELAYERNORM_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Weiwe Shi's avatar
Weiwe Shi committed
431
        ("roc_bert", "ROC_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
432
        ("roformer", "ROFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Sylvain Gugger's avatar
Sylvain Gugger committed
433
        ("rwkv", "RWKV_PRETRAINED_CONFIG_ARCHIVE_MAP"),
434
        ("sam", "SAM_PRETRAINED_CONFIG_ARCHIVE_MAP"),
435
        ("seamless_m4t", "SEAMLESS_M4T_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Yoach Lacombe's avatar
Yoach Lacombe committed
436
        ("seamless_m4t_v2", "SEAMLESS_M4T_V2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
437
        ("segformer", "SEGFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Eduardo Pacheco's avatar
Eduardo Pacheco committed
438
        ("seggpt", "SEGGPT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
439
        ("sew", "SEW_PRETRAINED_CONFIG_ARCHIVE_MAP"),
440
        ("sew-d", "SEW_D_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
441
        ("siglip", "SIGLIP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
442
443
        ("speech_to_text", "SPEECH_TO_TEXT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("speech_to_text_2", "SPEECH_TO_TEXT_2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
444
        ("speecht5", "SPEECHT5_PRETRAINED_CONFIG_ARCHIVE_MAP"),
445
446
        ("splinter", "SPLINTER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("squeezebert", "SQUEEZEBERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Jonathan Tow's avatar
Jonathan Tow committed
447
        ("stablelm", "STABLELM_PRETRAINED_CONFIG_ARCHIVE_MAP"),
RaymondLi0's avatar
RaymondLi0 committed
448
        ("starcoder2", "STARCODER2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Shehan Munasinghe's avatar
Shehan Munasinghe committed
449
        ("swiftformer", "SWIFTFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
450
        ("swin", "SWIN_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
451
        ("swin2sr", "SWIN2SR_PRETRAINED_CONFIG_ARCHIVE_MAP"),
452
        ("swinv2", "SWINV2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
453
        ("switch_transformers", "SWITCH_TRANSFORMERS_PRETRAINED_CONFIG_ARCHIVE_MAP"),
454
        ("t5", "T5_PRETRAINED_CONFIG_ARCHIVE_MAP"),
455
        ("table-transformer", "TABLE_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
456
        ("tapas", "TAPAS_PRETRAINED_CONFIG_ARCHIVE_MAP"),
457
        ("time_series_transformer", "TIME_SERIES_TRANSFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
458
        ("timesformer", "TIMESFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
459
        ("transfo-xl", "TRANSFO_XL_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Zineng Tang's avatar
Zineng Tang committed
460
        ("tvlt", "TVLT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
jiqing-feng's avatar
jiqing-feng committed
461
        ("tvp", "TVP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
462
        ("udop", "UDOP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
463
        ("unispeech", "UNISPEECH_PRETRAINED_CONFIG_ARCHIVE_MAP"),
464
        ("unispeech-sat", "UNISPEECH_SAT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
465
        ("univnet", "UNIVNET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
466
        ("van", "VAN_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
467
        ("videomae", "VIDEOMAE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
468
        ("vilt", "VILT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
469
        ("vipllava", "VIPLLAVA_PRETRAINED_CONFIG_ARCHIVE_MAP"),
470
471
        ("visual_bert", "VISUAL_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("vit", "VIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
472
        ("vit_hybrid", "VIT_HYBRID_PRETRAINED_CONFIG_ARCHIVE_MAP"),
473
        ("vit_mae", "VIT_MAE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
474
        ("vit_msn", "VIT_MSN_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
475
        ("vitdet", "VITDET_PRETRAINED_CONFIG_ARCHIVE_MAP"),
NielsRogge's avatar
NielsRogge committed
476
        ("vitmatte", "VITMATTE_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Matthijs Hollemans's avatar
Matthijs Hollemans committed
477
        ("vits", "VITS_PRETRAINED_CONFIG_ARCHIVE_MAP"),
Jegor Kit拧kerkin's avatar
Jegor Kit拧kerkin committed
478
        ("vivit", "VIVIT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
479
        ("wav2vec2", "WAV_2_VEC_2_PRETRAINED_CONFIG_ARCHIVE_MAP"),
480
        ("wav2vec2-bert", "WAV2VEC2_BERT_PRETRAINED_CONFIG_ARCHIVE_MAP"),
481
        ("wav2vec2-conformer", "WAV2VEC2_CONFORMER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
482
        ("whisper", "WHISPER_PRETRAINED_CONFIG_ARCHIVE_MAP"),
483
        ("xclip", "XCLIP_PRETRAINED_CONFIG_ARCHIVE_MAP"),
484
485
486
487
488
        ("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
489
        ("xmod", "XMOD_PRETRAINED_CONFIG_ARCHIVE_MAP"),
490
491
        ("yolos", "YOLOS_PRETRAINED_CONFIG_ARCHIVE_MAP"),
        ("yoso", "YOSO_PRETRAINED_CONFIG_ARCHIVE_MAP"),
492
493
494
495
496
    ]
)

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

Yih-Dar's avatar
Yih-Dar committed
770
771
# This is tied to the processing `-` -> `_` in `model_type_to_module_name`. For example, instead of putting
# `transfo-xl` (as in `CONFIG_MAPPING_NAMES`), we should use `transfo_xl`.
Sylvain Gugger's avatar
Sylvain Gugger committed
772
773
774
775
DEPRECATED_MODELS = [
    "bort",
    "mctct",
    "mmbt",
776
    "open_llama",
Sylvain Gugger's avatar
Sylvain Gugger committed
777
    "retribert",
778
    "tapex",
Sylvain Gugger's avatar
Sylvain Gugger committed
779
    "trajectory_transformer",
Yih-Dar's avatar
Yih-Dar committed
780
    "transfo_xl",
Sylvain Gugger's avatar
Sylvain Gugger committed
781
782
783
    "van",
]

784
SPECIAL_MODEL_TYPE_TO_MODULE_NAME = OrderedDict(
785
786
787
788
789
    [
        ("openai-gpt", "openai"),
        ("data2vec-audio", "data2vec"),
        ("data2vec-text", "data2vec"),
        ("data2vec-vision", "data2vec"),
NielsRogge's avatar
NielsRogge committed
790
        ("donut-swin", "donut"),
Yih-Dar's avatar
Yih-Dar committed
791
        ("kosmos-2", "kosmos2"),
792
        ("maskformer-swin", "maskformer"),
NielsRogge's avatar
NielsRogge committed
793
        ("xclip", "x_clip"),
794
        ("clip_vision_model", "clip"),
NielsRogge's avatar
NielsRogge committed
795
        ("siglip_vision_model", "siglip"),
796
        ("chinese_clip_vision_model", "chinese_clip"),
797
    ]
798
)
799
800
801
802
803
804
805
806


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
807
808
809
810
811
    key = key.replace("-", "_")
    if key in DEPRECATED_MODELS:
        key = f"deprecated.{key}"

    return key
812
813
814
815
816
817
818


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
819
820
821
822
    # if key not found check in extra content
    for key, cls in CONFIG_MAPPING._extra_content.items():
        if cls.__name__ == config:
            return key
823
824
825
826
827
828
829
830
831
832
    return None


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

    def __init__(self, mapping):
        self._mapping = mapping
833
        self._extra_content = {}
834
835
836
        self._modules = {}

    def __getitem__(self, key):
837
838
        if key in self._extra_content:
            return self._extra_content[key]
839
840
841
842
843
844
        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")
845
846
847
848
849
850
851
        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)
852
853

    def keys(self):
854
        return list(self._mapping.keys()) + list(self._extra_content.keys())
855
856

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

859
    def items(self):
860
        return [(k, self[k]) for k in self._mapping.keys()] + list(self._extra_content.items())
861
862

    def __iter__(self):
863
        return iter(list(self._mapping.keys()) + list(self._extra_content.keys()))
864
865

    def __contains__(self, item):
866
867
        return item in self._mapping or item in self._extra_content

868
    def register(self, key, value, exist_ok=False):
869
870
871
        """
        Register a new configuration in this mapping.
        """
872
        if key in self._mapping.keys() and not exist_ok:
873
874
            raise ValueError(f"'{key}' is already used by a Transformers config, pick another name.")
        self._extra_content[key] = value
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939


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


945
946
947
948
949
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
950
            model_type_to_name = {model_type: f"[`{config}`]" for model_type, config in CONFIG_MAPPING_NAMES.items()}
951
952
        else:
            model_type_to_name = {
953
954
955
                model_type: _get_class_name(model_class)
                for model_type, model_class in config_to_class.items()
                if model_type in MODEL_NAMES_MAPPING
956
957
            }
        lines = [
958
            f"{indent}- **{model_type}** -- {model_type_to_name[model_type]} ({MODEL_NAMES_MAPPING[model_type]} model)"
959
            for model_type in sorted(model_type_to_name.keys())
960
961
        ]
    else:
962
963
964
965
966
        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
        }
967
        config_to_model_name = {
968
            config: MODEL_NAMES_MAPPING[model_type] for model_type, config in CONFIG_MAPPING_NAMES.items()
969
970
        }
        lines = [
Sylvain Gugger's avatar
Sylvain Gugger committed
971
972
            f"{indent}- [`{config_name}`] configuration class:"
            f" {config_to_name[config_name]} ({config_to_model_name[config_name]} model)"
973
            for config_name in sorted(config_to_name.keys())
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
        ]
    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
993
994
                f"The function {fn} should have an empty 'List options' in its docstring as placeholder, current"
                f" docstring is:\n{docstrings}"
995
996
997
998
999
1000
1001
            )
        fn.__doc__ = docstrings
        return fn

    return docstring_decorator


Julien Chaumond's avatar
Julien Chaumond committed
1002
class AutoConfig:
Lysandre Debut's avatar
Lysandre Debut committed
1003
    r"""
1004
    This is a generic configuration class that will be instantiated as one of the configuration classes of the library
1005
    when created with the [`~AutoConfig.from_pretrained`] class method.
1006

1007
    This class cannot be instantiated directly using `__init__()` (throws an error).
1008
    """
1009

1010
    def __init__(self):
1011
1012
1013
1014
        raise EnvironmentError(
            "AutoConfig is designed to be instantiated "
            "using the `AutoConfig.from_pretrained(pretrained_model_name_or_path)` method."
        )
1015

1016
    @classmethod
1017
1018
1019
1020
    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)
1021
        raise ValueError(
1022
            f"Unrecognized model identifier: {model_type}. Should contain one of {', '.join(CONFIG_MAPPING.keys())}"
1023
        )
1024

1025
    @classmethod
1026
    @replace_list_option_in_docstrings()
1027
    def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):
1028
1029
        r"""
        Instantiate one of the configuration classes of the library from a pretrained model configuration.
1030

Sylvain Gugger's avatar
Sylvain Gugger committed
1031
1032
        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`:
1033

1034
        List options
Lysandre Debut's avatar
Lysandre Debut committed
1035
1036

        Args:
1037
            pretrained_model_name_or_path (`str` or `os.PathLike`):
1038
1039
                Can be either:

1040
                    - A string, the *model id* of a pretrained model configuration hosted inside a model repo on
1041
                      huggingface.co.
1042
                    - A path to a *directory* containing a configuration file saved using the
Sylvain Gugger's avatar
Sylvain Gugger committed
1043
1044
                      [`~PretrainedConfig.save_pretrained`] method, or the [`~PreTrainedModel.save_pretrained`] method,
                      e.g., `./my_model_directory/`.
1045
1046
1047
                    - A path or url to a saved configuration JSON *file*, e.g.,
                      `./my_model_directory/configuration.json`.
            cache_dir (`str` or `os.PathLike`, *optional*):
1048
1049
                Path to a directory in which a downloaded pretrained model configuration should be cached if the
                standard cache should not be used.
1050
            force_download (`bool`, *optional*, defaults to `False`):
1051
1052
                Whether or not to force the (re-)download the model weights and configuration files and override the
                cached versions if they exist.
1053
            resume_download (`bool`, *optional*, defaults to `False`):
1054
1055
                Whether or not to delete incompletely received files. Will attempt to resume the download if such a
                file exists.
1056
            proxies (`Dict[str, str]`, *optional*):
Sylvain Gugger's avatar
Sylvain Gugger committed
1057
1058
                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.
1059
            revision (`str`, *optional*, defaults to `"main"`):
Julien Chaumond's avatar
Julien Chaumond committed
1060
                The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
1061
                git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
Julien Chaumond's avatar
Julien Chaumond committed
1062
                identifier allowed by git.
1063
1064
            return_unused_kwargs (`bool`, *optional*, defaults to `False`):
                If `False`, then this function returns just the final configuration object.
1065

Sylvain Gugger's avatar
Sylvain Gugger committed
1066
1067
1068
                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.
1069
            trust_remote_code (`bool`, *optional*, defaults to `False`):
1070
                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
1071
1072
                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.
1073
            kwargs(additional keyword arguments, *optional*):
1074
                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
1075
                values. Behavior concerning key/value pairs whose keys are *not* configuration attributes is controlled
1076
                by the `return_unused_kwargs` keyword parameter.
Lysandre Debut's avatar
Lysandre Debut committed
1077

1078
        Examples:
1079

1080
1081
        ```python
        >>> from transformers import AutoConfig
1082

1083
        >>> # Download configuration from huggingface.co and cache.
1084
        >>> config = AutoConfig.from_pretrained("google-bert/bert-base-uncased")
Lysandre Debut's avatar
Lysandre Debut committed
1085

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

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

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

1095
        >>> # Change some config attributes when loading a pretrained config.
1096
        >>> config = AutoConfig.from_pretrained("google-bert/bert-base-uncased", output_attentions=True, foo=False)
1097
1098
        >>> config.output_attentions
        True
Sylvain Gugger's avatar
Sylvain Gugger committed
1099
1100

        >>> config, unused_kwargs = AutoConfig.from_pretrained(
1101
        ...     "google-bert/bert-base-uncased", output_attentions=True, foo=False, return_unused_kwargs=True
Sylvain Gugger's avatar
Sylvain Gugger committed
1102
        ... )
1103
1104
        >>> config.output_attentions
        True
Sylvain Gugger's avatar
Sylvain Gugger committed
1105

1106
        >>> unused_kwargs
1107
1108
        {'foo': False}
        ```"""
1109
1110
1111
        use_auth_token = kwargs.pop("use_auth_token", None)
        if use_auth_token is not None:
            warnings.warn(
1112
1113
                "The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.",
                FutureWarning,
1114
1115
1116
1117
1118
1119
1120
            )
            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

1121
        kwargs["_from_auto"] = True
1122
        kwargs["name_or_path"] = pretrained_model_name_or_path
1123
        trust_remote_code = kwargs.pop("trust_remote_code", None)
1124
1125
        code_revision = kwargs.pop("code_revision", None)

1126
        config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
1127
1128
1129
1130
1131
1132
1133
        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:
1134
            class_ref = config_dict["auto_map"]["AutoConfig"]
1135
1136
1137
            config_class = get_class_from_dynamic_module(
                class_ref, pretrained_model_name_or_path, code_revision=code_revision, **kwargs
            )
1138
1139
            if os.path.isdir(pretrained_model_name_or_path):
                config_class.register_for_auto_class()
1140
1141
            return config_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
        elif "model_type" in config_dict:
1142
1143
1144
1145
1146
1147
1148
1149
            try:
                config_class = CONFIG_MAPPING[config_dict["model_type"]]
            except KeyError:
                raise ValueError(
                    f"The checkpoint you are trying to load has model type `{config_dict['model_type']}` "
                    "but Transformers does not recognize this architecture. This could be because of an "
                    "issue with the checkpoint, or because your version of Transformers is out of date."
                )
1150
            return config_class.from_dict(config_dict, **unused_kwargs)
1151
1152
        else:
            # Fallback: use pattern matching on the string.
1153
1154
            # 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):
1155
                if pattern in str(pretrained_model_name_or_path):
1156
                    return CONFIG_MAPPING[pattern].from_dict(config_dict, **unused_kwargs)
1157

1158
        raise ValueError(
1159
            f"Unrecognized model in {pretrained_model_name_or_path}. "
1160
            f"Should have a `model_type` key in its {CONFIG_NAME}, or contain one of the following strings "
1161
            f"in its name: {', '.join(CONFIG_MAPPING.keys())}"
1162
        )
1163
1164

    @staticmethod
zspo's avatar
zspo committed
1165
    def register(model_type, config, exist_ok=False):
1166
1167
1168
1169
        """
        Register a new configuration for this class.

        Args:
1170
1171
            model_type (`str`): The model type like "bert" or "gpt".
            config ([`PretrainedConfig`]): The config to register.
1172
1173
1174
1175
1176
1177
1178
        """
        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
1179
        CONFIG_MAPPING.register(model_type, config, exist_ok=exist_ok)