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

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

27

28
29
logger = logging.get_logger(__name__)

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

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

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

Yih-Dar's avatar
Yih-Dar committed
744
745
# 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
746
747
748
749
DEPRECATED_MODELS = [
    "bort",
    "mctct",
    "mmbt",
750
    "open_llama",
Sylvain Gugger's avatar
Sylvain Gugger committed
751
    "retribert",
752
    "tapex",
Sylvain Gugger's avatar
Sylvain Gugger committed
753
    "trajectory_transformer",
Yih-Dar's avatar
Yih-Dar committed
754
    "transfo_xl",
Sylvain Gugger's avatar
Sylvain Gugger committed
755
756
757
    "van",
]

758
SPECIAL_MODEL_TYPE_TO_MODULE_NAME = OrderedDict(
759
760
761
762
763
    [
        ("openai-gpt", "openai"),
        ("data2vec-audio", "data2vec"),
        ("data2vec-text", "data2vec"),
        ("data2vec-vision", "data2vec"),
NielsRogge's avatar
NielsRogge committed
764
        ("donut-swin", "donut"),
Yih-Dar's avatar
Yih-Dar committed
765
        ("kosmos-2", "kosmos2"),
766
        ("maskformer-swin", "maskformer"),
NielsRogge's avatar
NielsRogge committed
767
        ("xclip", "x_clip"),
768
        ("clip_vision_model", "clip"),
NielsRogge's avatar
NielsRogge committed
769
        ("siglip_vision_model", "siglip"),
770
    ]
771
)
772
773
774
775
776
777
778
779


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
780
781
782
783
784
    key = key.replace("-", "_")
    if key in DEPRECATED_MODELS:
        key = f"deprecated.{key}"

    return key
785
786
787
788
789
790
791


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
792
793
794
795
    # if key not found check in extra content
    for key, cls in CONFIG_MAPPING._extra_content.items():
        if cls.__name__ == config:
            return key
796
797
798
799
800
801
802
803
804
805
    return None


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

    def __init__(self, mapping):
        self._mapping = mapping
806
        self._extra_content = {}
807
808
809
        self._modules = {}

    def __getitem__(self, key):
810
811
        if key in self._extra_content:
            return self._extra_content[key]
812
813
814
815
816
817
        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")
818
819
820
821
822
823
824
        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)
825
826

    def keys(self):
827
        return list(self._mapping.keys()) + list(self._extra_content.keys())
828
829

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

832
    def items(self):
833
        return [(k, self[k]) for k in self._mapping.keys()] + list(self._extra_content.items())
834
835

    def __iter__(self):
836
        return iter(list(self._mapping.keys()) + list(self._extra_content.keys()))
837
838

    def __contains__(self, item):
839
840
        return item in self._mapping or item in self._extra_content

841
    def register(self, key, value, exist_ok=False):
842
843
844
        """
        Register a new configuration in this mapping.
        """
845
        if key in self._mapping.keys() and not exist_ok:
846
847
            raise ValueError(f"'{key}' is already used by a Transformers config, pick another name.")
        self._extra_content[key] = value
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
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


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


918
919
920
921
922
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
923
            model_type_to_name = {model_type: f"[`{config}`]" for model_type, config in CONFIG_MAPPING_NAMES.items()}
924
925
        else:
            model_type_to_name = {
926
927
928
                model_type: _get_class_name(model_class)
                for model_type, model_class in config_to_class.items()
                if model_type in MODEL_NAMES_MAPPING
929
930
            }
        lines = [
931
            f"{indent}- **{model_type}** -- {model_type_to_name[model_type]} ({MODEL_NAMES_MAPPING[model_type]} model)"
932
            for model_type in sorted(model_type_to_name.keys())
933
934
        ]
    else:
935
936
937
938
939
        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
        }
940
        config_to_model_name = {
941
            config: MODEL_NAMES_MAPPING[model_type] for model_type, config in CONFIG_MAPPING_NAMES.items()
942
943
        }
        lines = [
Sylvain Gugger's avatar
Sylvain Gugger committed
944
945
            f"{indent}- [`{config_name}`] configuration class:"
            f" {config_to_name[config_name]} ({config_to_model_name[config_name]} model)"
946
            for config_name in sorted(config_to_name.keys())
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
        ]
    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
966
967
                f"The function {fn} should have an empty 'List options' in its docstring as placeholder, current"
                f" docstring is:\n{docstrings}"
968
969
970
971
972
973
974
            )
        fn.__doc__ = docstrings
        return fn

    return docstring_decorator


Julien Chaumond's avatar
Julien Chaumond committed
975
class AutoConfig:
Lysandre Debut's avatar
Lysandre Debut committed
976
    r"""
977
    This is a generic configuration class that will be instantiated as one of the configuration classes of the library
978
    when created with the [`~AutoConfig.from_pretrained`] class method.
979

980
    This class cannot be instantiated directly using `__init__()` (throws an error).
981
    """
982

983
    def __init__(self):
984
985
986
987
        raise EnvironmentError(
            "AutoConfig is designed to be instantiated "
            "using the `AutoConfig.from_pretrained(pretrained_model_name_or_path)` method."
        )
988

989
    @classmethod
990
991
992
993
    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)
994
        raise ValueError(
995
            f"Unrecognized model identifier: {model_type}. Should contain one of {', '.join(CONFIG_MAPPING.keys())}"
996
        )
997

998
    @classmethod
999
    @replace_list_option_in_docstrings()
1000
    def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):
1001
1002
        r"""
        Instantiate one of the configuration classes of the library from a pretrained model configuration.
1003

Sylvain Gugger's avatar
Sylvain Gugger committed
1004
1005
        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`:
1006

1007
        List options
Lysandre Debut's avatar
Lysandre Debut committed
1008
1009

        Args:
1010
            pretrained_model_name_or_path (`str` or `os.PathLike`):
1011
1012
                Can be either:

1013
1014
1015
1016
                    - 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
1017
1018
                      [`~PretrainedConfig.save_pretrained`] method, or the [`~PreTrainedModel.save_pretrained`] method,
                      e.g., `./my_model_directory/`.
1019
1020
1021
                    - A path or url to a saved configuration JSON *file*, e.g.,
                      `./my_model_directory/configuration.json`.
            cache_dir (`str` or `os.PathLike`, *optional*):
1022
1023
                Path to a directory in which a downloaded pretrained model configuration should be cached if the
                standard cache should not be used.
1024
            force_download (`bool`, *optional*, defaults to `False`):
1025
1026
                Whether or not to force the (re-)download the model weights and configuration files and override the
                cached versions if they exist.
1027
            resume_download (`bool`, *optional*, defaults to `False`):
1028
1029
                Whether or not to delete incompletely received files. Will attempt to resume the download if such a
                file exists.
1030
            proxies (`Dict[str, str]`, *optional*):
Sylvain Gugger's avatar
Sylvain Gugger committed
1031
1032
                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.
1033
            revision (`str`, *optional*, defaults to `"main"`):
Julien Chaumond's avatar
Julien Chaumond committed
1034
                The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
1035
                git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
Julien Chaumond's avatar
Julien Chaumond committed
1036
                identifier allowed by git.
1037
1038
            return_unused_kwargs (`bool`, *optional*, defaults to `False`):
                If `False`, then this function returns just the final configuration object.
1039

Sylvain Gugger's avatar
Sylvain Gugger committed
1040
1041
1042
                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.
1043
            trust_remote_code (`bool`, *optional*, defaults to `False`):
1044
                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
1045
1046
                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.
1047
            kwargs(additional keyword arguments, *optional*):
1048
                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
1049
                values. Behavior concerning key/value pairs whose keys are *not* configuration attributes is controlled
1050
                by the `return_unused_kwargs` keyword parameter.
Lysandre Debut's avatar
Lysandre Debut committed
1051

1052
        Examples:
1053

1054
1055
        ```python
        >>> from transformers import AutoConfig
1056

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

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

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

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

1069
        >>> # Change some config attributes when loading a pretrained config.
Sylvain Gugger's avatar
Sylvain Gugger committed
1070
        >>> config = AutoConfig.from_pretrained("bert-base-uncased", output_attentions=True, foo=False)
1071
1072
        >>> config.output_attentions
        True
Sylvain Gugger's avatar
Sylvain Gugger committed
1073
1074
1075
1076

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

1080
        >>> unused_kwargs
1081
1082
        {'foo': False}
        ```"""
1083
1084
1085
        use_auth_token = kwargs.pop("use_auth_token", None)
        if use_auth_token is not None:
            warnings.warn(
1086
1087
                "The `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.",
                FutureWarning,
1088
1089
1090
1091
1092
1093
1094
            )
            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

1095
        kwargs["_from_auto"] = True
1096
        kwargs["name_or_path"] = pretrained_model_name_or_path
1097
        trust_remote_code = kwargs.pop("trust_remote_code", None)
1098
1099
        code_revision = kwargs.pop("code_revision", None)

1100
        config_dict, unused_kwargs = PretrainedConfig.get_config_dict(pretrained_model_name_or_path, **kwargs)
1101
1102
1103
1104
1105
1106
1107
        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:
1108
            class_ref = config_dict["auto_map"]["AutoConfig"]
1109
1110
1111
            config_class = get_class_from_dynamic_module(
                class_ref, pretrained_model_name_or_path, code_revision=code_revision, **kwargs
            )
1112
1113
            if os.path.isdir(pretrained_model_name_or_path):
                config_class.register_for_auto_class()
1114
1115
            return config_class.from_pretrained(pretrained_model_name_or_path, **kwargs)
        elif "model_type" in config_dict:
1116
1117
1118
1119
1120
1121
1122
1123
            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."
                )
1124
            return config_class.from_dict(config_dict, **unused_kwargs)
1125
1126
        else:
            # Fallback: use pattern matching on the string.
1127
1128
            # 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):
1129
                if pattern in str(pretrained_model_name_or_path):
1130
                    return CONFIG_MAPPING[pattern].from_dict(config_dict, **unused_kwargs)
1131

1132
        raise ValueError(
1133
            f"Unrecognized model in {pretrained_model_name_or_path}. "
1134
            f"Should have a `model_type` key in its {CONFIG_NAME}, or contain one of the following strings "
1135
            f"in its name: {', '.join(CONFIG_MAPPING.keys())}"
1136
        )
1137
1138

    @staticmethod
zspo's avatar
zspo committed
1139
    def register(model_type, config, exist_ok=False):
1140
1141
1142
1143
        """
        Register a new configuration for this class.

        Args:
1144
1145
            model_type (`str`): The model type like "bert" or "gpt".
            config ([`PretrainedConfig`]): The config to register.
1146
1147
1148
1149
1150
1151
1152
        """
        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
1153
        CONFIG_MAPPING.register(model_type, config, exist_ok=exist_ok)