modeling_auto.py 45.6 KB
Newer Older
thomwolf's avatar
thomwolf committed
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 Model class."""
thomwolf's avatar
thomwolf committed
16

17
import warnings
Julien Chaumond's avatar
Julien Chaumond committed
18
from collections import OrderedDict
thomwolf's avatar
thomwolf committed
19

Sylvain Gugger's avatar
Sylvain Gugger committed
20
from ...utils import logging
21
22
from .auto_factory import _BaseAutoModelClass, _LazyAutoMapping, auto_class_update
from .configuration_auto import CONFIG_MAPPING_NAMES
thomwolf's avatar
thomwolf committed
23

thomwolf's avatar
thomwolf committed
24

Lysandre Debut's avatar
Lysandre Debut committed
25
logger = logging.get_logger(__name__)
thomwolf's avatar
thomwolf committed
26
27


28
MODEL_MAPPING_NAMES = OrderedDict(
Julien Chaumond's avatar
Julien Chaumond committed
29
    [
30
        # Base model mapping
31
32
        ("albert", "AlbertModel"),
        ("bart", "BartModel"),
33
        ("beit", "BeitModel"),
34
35
36
37
38
39
        ("bert", "BertModel"),
        ("bert-generation", "BertGenerationEncoder"),
        ("big_bird", "BigBirdModel"),
        ("bigbird_pegasus", "BigBirdPegasusModel"),
        ("blenderbot", "BlenderbotModel"),
        ("blenderbot-small", "BlenderbotSmallModel"),
Younes Belkada's avatar
Younes Belkada committed
40
        ("bloom", "BloomModel"),
41
        ("camembert", "CamembertModel"),
42
43
        ("canine", "CanineModel"),
        ("clip", "CLIPModel"),
NielsRogge's avatar
NielsRogge committed
44
        ("clipseg", "CLIPSegModel"),
rooa's avatar
rooa committed
45
        ("codegen", "CodeGenModel"),
46
        ("conditional_detr", "ConditionalDetrModel"),
47
48
49
        ("convbert", "ConvBertModel"),
        ("convnext", "ConvNextModel"),
        ("ctrl", "CTRLModel"),
NielsRogge's avatar
NielsRogge committed
50
        ("cvt", "CvtModel"),
51
52
53
54
55
56
57
        ("data2vec-audio", "Data2VecAudioModel"),
        ("data2vec-text", "Data2VecTextModel"),
        ("data2vec-vision", "Data2VecVisionModel"),
        ("deberta", "DebertaModel"),
        ("deberta-v2", "DebertaV2Model"),
        ("decision_transformer", "DecisionTransformerModel"),
        ("decision_transformer_gpt2", "DecisionTransformerGPT2Model"),
NielsRogge's avatar
NielsRogge committed
58
        ("deformable_detr", "DeformableDetrModel"),
59
60
        ("deit", "DeiTModel"),
        ("detr", "DetrModel"),
61
        ("distilbert", "DistilBertModel"),
NielsRogge's avatar
NielsRogge committed
62
        ("donut-swin", "DonutSwinModel"),
63
64
65
        ("dpr", "DPRQuestionEncoder"),
        ("dpt", "DPTModel"),
        ("electra", "ElectraModel"),
66
        ("ernie", "ErnieModel"),
67
        ("esm", "EsmModel"),
68
69
70
71
72
73
74
        ("flaubert", "FlaubertModel"),
        ("flava", "FlavaModel"),
        ("fnet", "FNetModel"),
        ("fsmt", "FSMTModel"),
        ("funnel", ("FunnelModel", "FunnelBaseModel")),
        ("glpn", "GLPNModel"),
        ("gpt2", "GPT2Model"),
75
        ("gpt_neo", "GPTNeoModel"),
76
        ("gpt_neox", "GPTNeoXModel"),
77
        ("gpt_neox_japanese", "GPTNeoXJapaneseModel"),
78
        ("gptj", "GPTJModel"),
79
        ("groupvit", "GroupViTModel"),
80
        ("hubert", "HubertModel"),
81
82
        ("ibert", "IBertModel"),
        ("imagegpt", "ImageGPTModel"),
83
        ("jukebox", "JukeboxModel"),
84
85
        ("layoutlm", "LayoutLMModel"),
        ("layoutlmv2", "LayoutLMv2Model"),
NielsRogge's avatar
NielsRogge committed
86
        ("layoutlmv3", "LayoutLMv3Model"),
87
        ("led", "LEDModel"),
88
        ("levit", "LevitModel"),
NielsRogge's avatar
NielsRogge committed
89
        ("lilt", "LiltModel"),
90
        ("longformer", "LongformerModel"),
Daniel Stancl's avatar
Daniel Stancl committed
91
        ("longt5", "LongT5Model"),
92
93
94
        ("luke", "LukeModel"),
        ("lxmert", "LxmertModel"),
        ("m2m_100", "M2M100Model"),
95
        ("marian", "MarianModel"),
NielsRogge's avatar
NielsRogge committed
96
        ("markuplm", "MarkupLMModel"),
97
        ("maskformer", "MaskFormerModel"),
98
        ("mbart", "MBartModel"),
Chan Woo Kim's avatar
Chan Woo Kim committed
99
        ("mctct", "MCTCTModel"),
100
101
        ("megatron-bert", "MegatronBertModel"),
        ("mobilebert", "MobileBertModel"),
102
        ("mobilenet_v2", "MobileNetV2Model"),
103
        ("mobilevit", "MobileViTModel"),
104
105
        ("mpnet", "MPNetModel"),
        ("mt5", "MT5Model"),
StevenTang1998's avatar
StevenTang1998 committed
106
        ("mvp", "MvpModel"),
107
        ("nezha", "NezhaModel"),
Lysandre Debut's avatar
Lysandre Debut committed
108
        ("nllb", "M2M100Model"),
109
110
        ("nystromformer", "NystromformerModel"),
        ("openai-gpt", "OpenAIGPTModel"),
Younes Belkada's avatar
Younes Belkada committed
111
        ("opt", "OPTModel"),
112
        ("owlvit", "OwlViTModel"),
113
        ("pegasus", "PegasusModel"),
Jason Phang's avatar
Jason Phang committed
114
        ("pegasus_x", "PegasusXModel"),
115
116
117
118
119
120
121
122
123
124
        ("perceiver", "PerceiverModel"),
        ("plbart", "PLBartModel"),
        ("poolformer", "PoolFormerModel"),
        ("prophetnet", "ProphetNetModel"),
        ("qdqbert", "QDQBertModel"),
        ("reformer", "ReformerModel"),
        ("regnet", "RegNetModel"),
        ("rembert", "RemBertModel"),
        ("resnet", "ResNetModel"),
        ("retribert", "RetriBertModel"),
125
        ("roberta", "RobertaModel"),
Weiwe Shi's avatar
Weiwe Shi committed
126
        ("roc_bert", "RoCBertModel"),
127
128
129
130
131
132
        ("roformer", "RoFormerModel"),
        ("segformer", "SegformerModel"),
        ("sew", "SEWModel"),
        ("sew-d", "SEWDModel"),
        ("speech_to_text", "Speech2TextModel"),
        ("splinter", "SplinterModel"),
133
        ("squeezebert", "SqueezeBertModel"),
134
        ("swin", "SwinModel"),
135
        ("swinv2", "Swinv2Model"),
136
        ("switch_transformers", "SwitchTransformersModel"),
137
        ("t5", "T5Model"),
138
        ("table-transformer", "TableTransformerModel"),
139
        ("tapas", "TapasModel"),
140
        ("time_series_transformer", "TimeSeriesTransformerModel"),
Carl's avatar
Carl committed
141
        ("trajectory_transformer", "TrajectoryTransformerModel"),
142
        ("transfo-xl", "TransfoXLModel"),
143
144
145
        ("unispeech", "UniSpeechModel"),
        ("unispeech-sat", "UniSpeechSatModel"),
        ("van", "VanModel"),
NielsRogge's avatar
NielsRogge committed
146
        ("videomae", "VideoMAEModel"),
147
148
149
150
151
        ("vilt", "ViltModel"),
        ("vision-text-dual-encoder", "VisionTextDualEncoderModel"),
        ("visual_bert", "VisualBertModel"),
        ("vit", "ViTModel"),
        ("vit_mae", "ViTMAEModel"),
152
        ("vit_msn", "ViTMSNModel"),
153
        ("wav2vec2", "Wav2Vec2Model"),
154
        ("wav2vec2-conformer", "Wav2Vec2ConformerModel"),
155
        ("wavlm", "WavLMModel"),
156
        ("whisper", "WhisperModel"),
NielsRogge's avatar
NielsRogge committed
157
        ("xclip", "XCLIPModel"),
158
        ("xglm", "XGLMModel"),
159
160
        ("xlm", "XLMModel"),
        ("xlm-prophetnet", "XLMProphetNetModel"),
161
162
163
164
165
        ("xlm-roberta", "XLMRobertaModel"),
        ("xlm-roberta-xl", "XLMRobertaXLModel"),
        ("xlnet", "XLNetModel"),
        ("yolos", "YolosModel"),
        ("yoso", "YosoModel"),
Julien Chaumond's avatar
Julien Chaumond committed
166
167
168
    ]
)

169
MODEL_FOR_PRETRAINING_MAPPING_NAMES = OrderedDict(
thomwolf's avatar
thomwolf committed
170
    [
171
        # Model for pre-training mapping
172
173
174
175
        ("albert", "AlbertForPreTraining"),
        ("bart", "BartForConditionalGeneration"),
        ("bert", "BertForPreTraining"),
        ("big_bird", "BigBirdForPreTraining"),
Younes Belkada's avatar
Younes Belkada committed
176
        ("bloom", "BloomForCausalLM"),
177
        ("camembert", "CamembertForMaskedLM"),
178
        ("ctrl", "CTRLLMHeadModel"),
179
180
181
182
        ("data2vec-text", "Data2VecTextForMaskedLM"),
        ("deberta", "DebertaForMaskedLM"),
        ("deberta-v2", "DebertaV2ForMaskedLM"),
        ("distilbert", "DistilBertForMaskedLM"),
183
        ("electra", "ElectraForPreTraining"),
184
        ("ernie", "ErnieForPreTraining"),
185
186
187
188
        ("flaubert", "FlaubertWithLMHeadModel"),
        ("flava", "FlavaForPreTraining"),
        ("fnet", "FNetForPreTraining"),
        ("fsmt", "FSMTForConditionalGeneration"),
189
        ("funnel", "FunnelForPreTraining"),
190
191
192
193
        ("gpt2", "GPT2LMHeadModel"),
        ("ibert", "IBertForMaskedLM"),
        ("layoutlm", "LayoutLMForMaskedLM"),
        ("longformer", "LongformerForMaskedLM"),
194
        ("luke", "LukeForMaskedLM"),
195
196
197
        ("lxmert", "LxmertForPreTraining"),
        ("megatron-bert", "MegatronBertForPreTraining"),
        ("mobilebert", "MobileBertForPreTraining"),
198
        ("mpnet", "MPNetForMaskedLM"),
StevenTang1998's avatar
StevenTang1998 committed
199
        ("mvp", "MvpForConditionalGeneration"),
200
        ("nezha", "NezhaForPreTraining"),
201
202
203
        ("openai-gpt", "OpenAIGPTLMHeadModel"),
        ("retribert", "RetriBertModel"),
        ("roberta", "RobertaForMaskedLM"),
Weiwe Shi's avatar
Weiwe Shi committed
204
        ("roc_bert", "RoCBertForPreTraining"),
205
        ("splinter", "SplinterForPreTraining"),
206
        ("squeezebert", "SqueezeBertForMaskedLM"),
207
        ("switch_transformers", "SwitchTransformersForConditionalGeneration"),
208
        ("t5", "T5ForConditionalGeneration"),
209
        ("tapas", "TapasForMaskedLM"),
210
        ("transfo-xl", "TransfoXLLMHeadModel"),
211
        ("unispeech", "UniSpeechForPreTraining"),
212
        ("unispeech-sat", "UniSpeechSatForPreTraining"),
NielsRogge's avatar
NielsRogge committed
213
        ("videomae", "VideoMAEForPreTraining"),
214
215
216
        ("visual_bert", "VisualBertForPreTraining"),
        ("vit_mae", "ViTMAEForPreTraining"),
        ("wav2vec2", "Wav2Vec2ForPreTraining"),
217
        ("wav2vec2-conformer", "Wav2Vec2ConformerForPreTraining"),
218
219
220
221
        ("xlm", "XLMWithLMHeadModel"),
        ("xlm-roberta", "XLMRobertaForMaskedLM"),
        ("xlm-roberta-xl", "XLMRobertaXLForMaskedLM"),
        ("xlnet", "XLNetLMHeadModel"),
thomwolf's avatar
thomwolf committed
222
223
224
    ]
)

225
MODEL_WITH_LM_HEAD_MAPPING_NAMES = OrderedDict(
226
    [
227
        # Model with LM heads mapping
228
229
230
        ("albert", "AlbertForMaskedLM"),
        ("bart", "BartForConditionalGeneration"),
        ("bert", "BertForMaskedLM"),
231
232
233
        ("big_bird", "BigBirdForMaskedLM"),
        ("bigbird_pegasus", "BigBirdPegasusForConditionalGeneration"),
        ("blenderbot-small", "BlenderbotSmallForConditionalGeneration"),
Younes Belkada's avatar
Younes Belkada committed
234
        ("bloom", "BloomForCausalLM"),
235
        ("camembert", "CamembertForMaskedLM"),
rooa's avatar
rooa committed
236
        ("codegen", "CodeGenForCausalLM"),
237
        ("convbert", "ConvBertForMaskedLM"),
238
        ("ctrl", "CTRLLMHeadModel"),
239
240
241
242
        ("data2vec-text", "Data2VecTextForMaskedLM"),
        ("deberta", "DebertaForMaskedLM"),
        ("deberta-v2", "DebertaV2ForMaskedLM"),
        ("distilbert", "DistilBertForMaskedLM"),
243
244
        ("electra", "ElectraForMaskedLM"),
        ("encoder-decoder", "EncoderDecoderModel"),
245
        ("ernie", "ErnieForMaskedLM"),
246
        ("esm", "EsmForMaskedLM"),
247
248
249
        ("flaubert", "FlaubertWithLMHeadModel"),
        ("fnet", "FNetForMaskedLM"),
        ("fsmt", "FSMTForConditionalGeneration"),
250
        ("funnel", "FunnelForMaskedLM"),
251
252
        ("gpt2", "GPT2LMHeadModel"),
        ("gpt_neo", "GPTNeoForCausalLM"),
253
        ("gpt_neox", "GPTNeoXForCausalLM"),
254
        ("gpt_neox_japanese", "GPTNeoXJapaneseForCausalLM"),
255
256
257
258
259
        ("gptj", "GPTJForCausalLM"),
        ("ibert", "IBertForMaskedLM"),
        ("layoutlm", "LayoutLMForMaskedLM"),
        ("led", "LEDForConditionalGeneration"),
        ("longformer", "LongformerForMaskedLM"),
Daniel Stancl's avatar
Daniel Stancl committed
260
        ("longt5", "LongT5ForConditionalGeneration"),
261
        ("luke", "LukeForMaskedLM"),
262
263
264
265
        ("m2m_100", "M2M100ForConditionalGeneration"),
        ("marian", "MarianMTModel"),
        ("megatron-bert", "MegatronBertForCausalLM"),
        ("mobilebert", "MobileBertForMaskedLM"),
266
        ("mpnet", "MPNetForMaskedLM"),
StevenTang1998's avatar
StevenTang1998 committed
267
        ("mvp", "MvpForConditionalGeneration"),
268
        ("nezha", "NezhaForMaskedLM"),
Lysandre Debut's avatar
Lysandre Debut committed
269
        ("nllb", "M2M100ForConditionalGeneration"),
270
271
        ("nystromformer", "NystromformerForMaskedLM"),
        ("openai-gpt", "OpenAIGPTLMHeadModel"),
Jason Phang's avatar
Jason Phang committed
272
        ("pegasus_x", "PegasusXForConditionalGeneration"),
273
274
275
276
277
        ("plbart", "PLBartForConditionalGeneration"),
        ("qdqbert", "QDQBertForMaskedLM"),
        ("reformer", "ReformerModelWithLMHead"),
        ("rembert", "RemBertForMaskedLM"),
        ("roberta", "RobertaForMaskedLM"),
Weiwe Shi's avatar
Weiwe Shi committed
278
        ("roc_bert", "RoCBertForMaskedLM"),
279
280
281
        ("roformer", "RoFormerForMaskedLM"),
        ("speech_to_text", "Speech2TextForConditionalGeneration"),
        ("squeezebert", "SqueezeBertForMaskedLM"),
282
        ("switch_transformers", "SwitchTransformersForConditionalGeneration"),
283
        ("t5", "T5ForConditionalGeneration"),
284
        ("tapas", "TapasForMaskedLM"),
285
286
        ("transfo-xl", "TransfoXLLMHeadModel"),
        ("wav2vec2", "Wav2Vec2ForMaskedLM"),
287
        ("whisper", "WhisperForConditionalGeneration"),
288
289
290
291
292
        ("xlm", "XLMWithLMHeadModel"),
        ("xlm-roberta", "XLMRobertaForMaskedLM"),
        ("xlm-roberta-xl", "XLMRobertaXLForMaskedLM"),
        ("xlnet", "XLNetLMHeadModel"),
        ("yoso", "YosoForMaskedLM"),
293
294
295
    ]
)

296
MODEL_FOR_CAUSAL_LM_MAPPING_NAMES = OrderedDict(
297
    [
298
        # Model for Causal LM mapping
299
300
301
302
303
304
305
        ("bart", "BartForCausalLM"),
        ("bert", "BertLMHeadModel"),
        ("bert-generation", "BertGenerationDecoder"),
        ("big_bird", "BigBirdForCausalLM"),
        ("bigbird_pegasus", "BigBirdPegasusForCausalLM"),
        ("blenderbot", "BlenderbotForCausalLM"),
        ("blenderbot-small", "BlenderbotSmallForCausalLM"),
Younes Belkada's avatar
Younes Belkada committed
306
        ("bloom", "BloomForCausalLM"),
307
        ("camembert", "CamembertForCausalLM"),
rooa's avatar
rooa committed
308
        ("codegen", "CodeGenForCausalLM"),
309
310
311
        ("ctrl", "CTRLLMHeadModel"),
        ("data2vec-text", "Data2VecTextForCausalLM"),
        ("electra", "ElectraForCausalLM"),
312
        ("ernie", "ErnieForCausalLM"),
313
314
        ("gpt2", "GPT2LMHeadModel"),
        ("gpt_neo", "GPTNeoForCausalLM"),
315
        ("gpt_neox", "GPTNeoXForCausalLM"),
316
        ("gpt_neox_japanese", "GPTNeoXJapaneseForCausalLM"),
317
318
319
320
        ("gptj", "GPTJForCausalLM"),
        ("marian", "MarianForCausalLM"),
        ("mbart", "MBartForCausalLM"),
        ("megatron-bert", "MegatronBertForCausalLM"),
StevenTang1998's avatar
StevenTang1998 committed
321
        ("mvp", "MvpForCausalLM"),
322
323
324
        ("openai-gpt", "OpenAIGPTLMHeadModel"),
        ("opt", "OPTForCausalLM"),
        ("pegasus", "PegasusForCausalLM"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
325
        ("plbart", "PLBartForCausalLM"),
326
        ("prophetnet", "ProphetNetForCausalLM"),
327
        ("qdqbert", "QDQBertLMHeadModel"),
328
        ("reformer", "ReformerModelWithLMHead"),
329
330
        ("rembert", "RemBertForCausalLM"),
        ("roberta", "RobertaForCausalLM"),
Weiwe Shi's avatar
Weiwe Shi committed
331
        ("roc_bert", "RoCBertForCausalLM"),
332
333
        ("roformer", "RoFormerForCausalLM"),
        ("speech_to_text_2", "Speech2Text2ForCausalLM"),
334
        ("transfo-xl", "TransfoXLLMHeadModel"),
335
336
        ("trocr", "TrOCRForCausalLM"),
        ("xglm", "XGLMForCausalLM"),
337
338
        ("xlm", "XLMWithLMHeadModel"),
        ("xlm-prophetnet", "XLMProphetNetForCausalLM"),
339
340
341
        ("xlm-roberta", "XLMRobertaForCausalLM"),
        ("xlm-roberta-xl", "XLMRobertaXLForCausalLM"),
        ("xlnet", "XLNetLMHeadModel"),
342
343
344
    ]
)

NielsRogge's avatar
NielsRogge committed
345
346
347
348
MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING_NAMES = OrderedDict(
    [
        ("deit", "DeiTForMaskedImageModeling"),
        ("swin", "SwinForMaskedImageModeling"),
349
        ("swinv2", "Swinv2ForMaskedImageModeling"),
350
        ("vit", "ViTForMaskedImageModeling"),
NielsRogge's avatar
NielsRogge committed
351
352
353
354
    ]
)


NielsRogge's avatar
NielsRogge committed
355
356
357
358
359
360
361
MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING_NAMES = OrderedDict(
    # Model for Causal Image Modeling mapping
    [
        ("imagegpt", "ImageGPTForCausalImageModeling"),
    ]
)

362
MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
363
364
    [
        # Model for Image Classification mapping
365
        ("beit", "BeitForImageClassification"),
366
        ("convnext", "ConvNextForImageClassification"),
NielsRogge's avatar
NielsRogge committed
367
        ("cvt", "CvtForImageClassification"),
368
        ("data2vec-vision", "Data2VecVisionForImageClassification"),
369
        ("deit", ("DeiTForImageClassification", "DeiTForImageClassificationWithTeacher")),
NielsRogge's avatar
NielsRogge committed
370
        ("imagegpt", "ImageGPTForImageClassification"),
371
        ("levit", ("LevitForImageClassification", "LevitForImageClassificationWithTeacher")),
372
        ("mobilenet_v2", "MobileNetV2ForImageClassification"),
373
        ("mobilevit", "MobileViTForImageClassification"),
NielsRogge's avatar
NielsRogge committed
374
375
376
377
378
379
380
381
        (
            "perceiver",
            (
                "PerceiverForImageClassificationLearned",
                "PerceiverForImageClassificationFourier",
                "PerceiverForImageClassificationConvProcessing",
            ),
        ),
382
383
384
385
        ("poolformer", "PoolFormerForImageClassification"),
        ("regnet", "RegNetForImageClassification"),
        ("resnet", "ResNetForImageClassification"),
        ("segformer", "SegformerForImageClassification"),
novice's avatar
novice committed
386
        ("swin", "SwinForImageClassification"),
387
        ("swinv2", "Swinv2ForImageClassification"),
388
        ("van", "VanForImageClassification"),
389
        ("vit", "ViTForImageClassification"),
390
        ("vit_msn", "ViTMSNForImageClassification"),
391
392
393
    ]
)

394
395
MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES = OrderedDict(
    [
396
        # Do not add new models here, this class will be deprecated in the future.
397
398
399
400
401
        # Model for Image Segmentation mapping
        ("detr", "DetrForSegmentation"),
    ]
)

402
403
404
405
MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES = OrderedDict(
    [
        # Model for Semantic Segmentation mapping
        ("beit", "BeitForSemanticSegmentation"),
406
        ("data2vec-vision", "Data2VecVisionForSemanticSegmentation"),
NielsRogge's avatar
NielsRogge committed
407
        ("dpt", "DPTForSemanticSegmentation"),
408
        ("mobilenet_v2", "MobileNetV2ForSemanticSegmentation"),
409
        ("mobilevit", "MobileViTForSemanticSegmentation"),
410
        ("segformer", "SegformerForSemanticSegmentation"),
411
412
413
    ]
)

414
415
416
417
418
419
420
MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING_NAMES = OrderedDict(
    [
        # Model for Instance Segmentation mapping
        ("maskformer", "MaskFormerForInstanceSegmentation"),
    ]
)

NielsRogge's avatar
NielsRogge committed
421
422
423
424
425
426
MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    [
        ("videomae", "VideoMAEForVideoClassification"),
    ]
)

427
428
429
430
431
432
MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES = OrderedDict(
    [
        ("vision-encoder-decoder", "VisionEncoderDecoderModel"),
    ]
)

433
MODEL_FOR_MASKED_LM_MAPPING_NAMES = OrderedDict(
434
    [
435
        # Model for Masked LM mapping
436
437
        ("albert", "AlbertForMaskedLM"),
        ("bart", "BartForConditionalGeneration"),
438
439
        ("bert", "BertForMaskedLM"),
        ("big_bird", "BigBirdForMaskedLM"),
440
        ("camembert", "CamembertForMaskedLM"),
441
        ("convbert", "ConvBertForMaskedLM"),
442
        ("data2vec-text", "Data2VecTextForMaskedLM"),
443
444
445
        ("deberta", "DebertaForMaskedLM"),
        ("deberta-v2", "DebertaV2ForMaskedLM"),
        ("distilbert", "DistilBertForMaskedLM"),
446
        ("electra", "ElectraForMaskedLM"),
447
        ("ernie", "ErnieForMaskedLM"),
448
449
        ("flaubert", "FlaubertWithLMHeadModel"),
        ("fnet", "FNetForMaskedLM"),
450
        ("funnel", "FunnelForMaskedLM"),
451
452
453
        ("ibert", "IBertForMaskedLM"),
        ("layoutlm", "LayoutLMForMaskedLM"),
        ("longformer", "LongformerForMaskedLM"),
Ryokan RI's avatar
Ryokan RI committed
454
        ("luke", "LukeForMaskedLM"),
455
456
457
        ("mbart", "MBartForConditionalGeneration"),
        ("megatron-bert", "MegatronBertForMaskedLM"),
        ("mobilebert", "MobileBertForMaskedLM"),
458
        ("mpnet", "MPNetForMaskedLM"),
StevenTang1998's avatar
StevenTang1998 committed
459
        ("mvp", "MvpForConditionalGeneration"),
460
        ("nezha", "NezhaForMaskedLM"),
461
462
463
464
465
466
        ("nystromformer", "NystromformerForMaskedLM"),
        ("perceiver", "PerceiverForMaskedLM"),
        ("qdqbert", "QDQBertForMaskedLM"),
        ("reformer", "ReformerForMaskedLM"),
        ("rembert", "RemBertForMaskedLM"),
        ("roberta", "RobertaForMaskedLM"),
Weiwe Shi's avatar
Weiwe Shi committed
467
        ("roc_bert", "RoCBertForMaskedLM"),
468
469
        ("roformer", "RoFormerForMaskedLM"),
        ("squeezebert", "SqueezeBertForMaskedLM"),
470
        ("tapas", "TapasForMaskedLM"),
471
472
473
474
475
        ("wav2vec2", "Wav2Vec2ForMaskedLM"),
        ("xlm", "XLMWithLMHeadModel"),
        ("xlm-roberta", "XLMRobertaForMaskedLM"),
        ("xlm-roberta-xl", "XLMRobertaXLForMaskedLM"),
        ("yoso", "YosoForMaskedLM"),
476
477
478
    ]
)

479
MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES = OrderedDict(
NielsRogge's avatar
NielsRogge committed
480
481
    [
        # Model for Object Detection mapping
482
        ("conditional_detr", "ConditionalDetrForObjectDetection"),
NielsRogge's avatar
NielsRogge committed
483
        ("deformable_detr", "DeformableDetrForObjectDetection"),
484
        ("detr", "DetrForObjectDetection"),
485
        ("table-transformer", "TableTransformerForObjectDetection"),
486
        ("yolos", "YolosForObjectDetection"),
NielsRogge's avatar
NielsRogge committed
487
488
489
    ]
)

490
491
492
493
494
495
496
MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES = OrderedDict(
    [
        # Model for Zero Shot Object Detection mapping
        ("owlvit", "OwlViTForObjectDetection")
    ]
)

497
498
499
500
501
502
503
MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES = OrderedDict(
    [
        # Model for depth estimation mapping
        ("dpt", "DPTForDepthEstimation"),
        ("glpn", "GLPNForDepthEstimation"),
    ]
)
504
MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES = OrderedDict(
505
    [
506
        # Model for Seq2Seq Causal LM mapping
507
        ("bart", "BartForConditionalGeneration"),
508
        ("bigbird_pegasus", "BigBirdPegasusForConditionalGeneration"),
509
        ("blenderbot", "BlenderbotForConditionalGeneration"),
510
        ("blenderbot-small", "BlenderbotSmallForConditionalGeneration"),
511
512
513
        ("encoder-decoder", "EncoderDecoderModel"),
        ("fsmt", "FSMTForConditionalGeneration"),
        ("led", "LEDForConditionalGeneration"),
Daniel Stancl's avatar
Daniel Stancl committed
514
        ("longt5", "LongT5ForConditionalGeneration"),
515
        ("m2m_100", "M2M100ForConditionalGeneration"),
516
517
        ("marian", "MarianMTModel"),
        ("mbart", "MBartForConditionalGeneration"),
518
        ("mt5", "MT5ForConditionalGeneration"),
StevenTang1998's avatar
StevenTang1998 committed
519
        ("mvp", "MvpForConditionalGeneration"),
Lysandre Debut's avatar
Lysandre Debut committed
520
        ("nllb", "M2M100ForConditionalGeneration"),
521
        ("pegasus", "PegasusForConditionalGeneration"),
Jason Phang's avatar
Jason Phang committed
522
        ("pegasus_x", "PegasusXForConditionalGeneration"),
523
        ("plbart", "PLBartForConditionalGeneration"),
524
        ("prophetnet", "ProphetNetForConditionalGeneration"),
525
        ("switch_transformers", "SwitchTransformersForConditionalGeneration"),
526
527
        ("t5", "T5ForConditionalGeneration"),
        ("xlm-prophetnet", "XLMProphetNetForConditionalGeneration"),
528
529
530
    ]
)

531
532
533
534
MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES = OrderedDict(
    [
        ("speech-encoder-decoder", "SpeechEncoderDecoderModel"),
        ("speech_to_text", "Speech2TextForConditionalGeneration"),
535
        ("whisper", "WhisperForConditionalGeneration"),
536
537
538
    ]
)

539
MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
540
    [
541
        # Model for Sequence Classification mapping
542
543
544
        ("albert", "AlbertForSequenceClassification"),
        ("bart", "BartForSequenceClassification"),
        ("bert", "BertForSequenceClassification"),
545
546
        ("big_bird", "BigBirdForSequenceClassification"),
        ("bigbird_pegasus", "BigBirdPegasusForSequenceClassification"),
547
        ("bloom", "BloomForSequenceClassification"),
548
549
550
551
552
        ("camembert", "CamembertForSequenceClassification"),
        ("canine", "CanineForSequenceClassification"),
        ("convbert", "ConvBertForSequenceClassification"),
        ("ctrl", "CTRLForSequenceClassification"),
        ("data2vec-text", "Data2VecTextForSequenceClassification"),
553
554
        ("deberta", "DebertaForSequenceClassification"),
        ("deberta-v2", "DebertaV2ForSequenceClassification"),
555
556
        ("distilbert", "DistilBertForSequenceClassification"),
        ("electra", "ElectraForSequenceClassification"),
557
        ("ernie", "ErnieForSequenceClassification"),
558
        ("esm", "EsmForSequenceClassification"),
559
560
561
        ("flaubert", "FlaubertForSequenceClassification"),
        ("fnet", "FNetForSequenceClassification"),
        ("funnel", "FunnelForSequenceClassification"),
562
563
        ("gpt2", "GPT2ForSequenceClassification"),
        ("gpt_neo", "GPTNeoForSequenceClassification"),
564
565
566
567
        ("gptj", "GPTJForSequenceClassification"),
        ("ibert", "IBertForSequenceClassification"),
        ("layoutlm", "LayoutLMForSequenceClassification"),
        ("layoutlmv2", "LayoutLMv2ForSequenceClassification"),
NielsRogge's avatar
NielsRogge committed
568
        ("layoutlmv3", "LayoutLMv3ForSequenceClassification"),
569
        ("led", "LEDForSequenceClassification"),
NielsRogge's avatar
NielsRogge committed
570
        ("lilt", "LiltForSequenceClassification"),
571
        ("longformer", "LongformerForSequenceClassification"),
572
        ("luke", "LukeForSequenceClassification"),
NielsRogge's avatar
NielsRogge committed
573
        ("markuplm", "MarkupLMForSequenceClassification"),
574
575
576
577
        ("mbart", "MBartForSequenceClassification"),
        ("megatron-bert", "MegatronBertForSequenceClassification"),
        ("mobilebert", "MobileBertForSequenceClassification"),
        ("mpnet", "MPNetForSequenceClassification"),
StevenTang1998's avatar
StevenTang1998 committed
578
        ("mvp", "MvpForSequenceClassification"),
579
        ("nezha", "NezhaForSequenceClassification"),
580
        ("nystromformer", "NystromformerForSequenceClassification"),
581
        ("openai-gpt", "OpenAIGPTForSequenceClassification"),
582
        ("opt", "OPTForSequenceClassification"),
583
584
585
        ("perceiver", "PerceiverForSequenceClassification"),
        ("plbart", "PLBartForSequenceClassification"),
        ("qdqbert", "QDQBertForSequenceClassification"),
586
        ("reformer", "ReformerForSequenceClassification"),
587
588
        ("rembert", "RemBertForSequenceClassification"),
        ("roberta", "RobertaForSequenceClassification"),
Weiwe Shi's avatar
Weiwe Shi committed
589
        ("roc_bert", "RoCBertForSequenceClassification"),
590
591
        ("roformer", "RoFormerForSequenceClassification"),
        ("squeezebert", "SqueezeBertForSequenceClassification"),
592
        ("tapas", "TapasForSequenceClassification"),
593
594
595
596
597
598
        ("transfo-xl", "TransfoXLForSequenceClassification"),
        ("xlm", "XLMForSequenceClassification"),
        ("xlm-roberta", "XLMRobertaForSequenceClassification"),
        ("xlm-roberta-xl", "XLMRobertaXLForSequenceClassification"),
        ("xlnet", "XLNetForSequenceClassification"),
        ("yoso", "YosoForSequenceClassification"),
599
600
601
    ]
)

602
MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES = OrderedDict(
603
    [
604
        # Model for Question Answering mapping
605
606
607
608
609
        ("albert", "AlbertForQuestionAnswering"),
        ("bart", "BartForQuestionAnswering"),
        ("bert", "BertForQuestionAnswering"),
        ("big_bird", "BigBirdForQuestionAnswering"),
        ("bigbird_pegasus", "BigBirdPegasusForQuestionAnswering"),
610
        ("bloom", "BloomForQuestionAnswering"),
611
612
613
614
615
616
617
618
        ("camembert", "CamembertForQuestionAnswering"),
        ("canine", "CanineForQuestionAnswering"),
        ("convbert", "ConvBertForQuestionAnswering"),
        ("data2vec-text", "Data2VecTextForQuestionAnswering"),
        ("deberta", "DebertaForQuestionAnswering"),
        ("deberta-v2", "DebertaV2ForQuestionAnswering"),
        ("distilbert", "DistilBertForQuestionAnswering"),
        ("electra", "ElectraForQuestionAnswering"),
619
        ("ernie", "ErnieForQuestionAnswering"),
620
        ("flaubert", "FlaubertForQuestionAnsweringSimple"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
621
        ("fnet", "FNetForQuestionAnswering"),
622
        ("funnel", "FunnelForQuestionAnswering"),
623
        ("gptj", "GPTJForQuestionAnswering"),
624
        ("ibert", "IBertForQuestionAnswering"),
625
        ("layoutlmv2", "LayoutLMv2ForQuestionAnswering"),
NielsRogge's avatar
NielsRogge committed
626
        ("layoutlmv3", "LayoutLMv3ForQuestionAnswering"),
627
        ("led", "LEDForQuestionAnswering"),
NielsRogge's avatar
NielsRogge committed
628
        ("lilt", "LiltForQuestionAnswering"),
629
        ("longformer", "LongformerForQuestionAnswering"),
630
        ("luke", "LukeForQuestionAnswering"),
631
        ("lxmert", "LxmertForQuestionAnswering"),
NielsRogge's avatar
NielsRogge committed
632
        ("markuplm", "MarkupLMForQuestionAnswering"),
633
        ("mbart", "MBartForQuestionAnswering"),
634
635
636
        ("megatron-bert", "MegatronBertForQuestionAnswering"),
        ("mobilebert", "MobileBertForQuestionAnswering"),
        ("mpnet", "MPNetForQuestionAnswering"),
StevenTang1998's avatar
StevenTang1998 committed
637
        ("mvp", "MvpForQuestionAnswering"),
638
        ("nezha", "NezhaForQuestionAnswering"),
639
        ("nystromformer", "NystromformerForQuestionAnswering"),
640
        ("opt", "OPTForQuestionAnswering"),
641
642
643
644
        ("qdqbert", "QDQBertForQuestionAnswering"),
        ("reformer", "ReformerForQuestionAnswering"),
        ("rembert", "RemBertForQuestionAnswering"),
        ("roberta", "RobertaForQuestionAnswering"),
Weiwe Shi's avatar
Weiwe Shi committed
645
        ("roc_bert", "RoCBertForQuestionAnswering"),
646
        ("roformer", "RoFormerForQuestionAnswering"),
Ori Ram's avatar
Ori Ram committed
647
        ("splinter", "SplinterForQuestionAnswering"),
648
649
650
651
652
653
        ("squeezebert", "SqueezeBertForQuestionAnswering"),
        ("xlm", "XLMForQuestionAnsweringSimple"),
        ("xlm-roberta", "XLMRobertaForQuestionAnswering"),
        ("xlm-roberta-xl", "XLMRobertaXLForQuestionAnswering"),
        ("xlnet", "XLNetForQuestionAnsweringSimple"),
        ("yoso", "YosoForQuestionAnswering"),
654
655
656
    ]
)

657
MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING_NAMES = OrderedDict(
658
659
    [
        # Model for Table Question Answering mapping
660
        ("tapas", "TapasForQuestionAnswering"),
661
662
663
    ]
)

664
665
666
667
668
669
MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING_NAMES = OrderedDict(
    [
        ("vilt", "ViltForQuestionAnswering"),
    ]
)

670
671
672
673
674
675
676
677
MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES = OrderedDict(
    [
        ("layoutlm", "LayoutLMForQuestionAnswering"),
        ("layoutlmv2", "LayoutLMv2ForQuestionAnswering"),
        ("layoutlmv3", "LayoutLMv3ForQuestionAnswering"),
    ]
)

678
MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
Julien Chaumond's avatar
Julien Chaumond committed
679
    [
680
        # Model for Token Classification mapping
681
682
        ("albert", "AlbertForTokenClassification"),
        ("bert", "BertForTokenClassification"),
683
        ("big_bird", "BigBirdForTokenClassification"),
684
        ("bloom", "BloomForTokenClassification"),
685
686
        ("camembert", "CamembertForTokenClassification"),
        ("canine", "CanineForTokenClassification"),
687
        ("convbert", "ConvBertForTokenClassification"),
688
689
690
        ("data2vec-text", "Data2VecTextForTokenClassification"),
        ("deberta", "DebertaForTokenClassification"),
        ("deberta-v2", "DebertaV2ForTokenClassification"),
691
        ("distilbert", "DistilBertForTokenClassification"),
692
        ("electra", "ElectraForTokenClassification"),
693
        ("ernie", "ErnieForTokenClassification"),
694
        ("esm", "EsmForTokenClassification"),
695
        ("flaubert", "FlaubertForTokenClassification"),
696
697
698
699
700
701
        ("fnet", "FNetForTokenClassification"),
        ("funnel", "FunnelForTokenClassification"),
        ("gpt2", "GPT2ForTokenClassification"),
        ("ibert", "IBertForTokenClassification"),
        ("layoutlm", "LayoutLMForTokenClassification"),
        ("layoutlmv2", "LayoutLMv2ForTokenClassification"),
NielsRogge's avatar
NielsRogge committed
702
        ("layoutlmv3", "LayoutLMv3ForTokenClassification"),
NielsRogge's avatar
NielsRogge committed
703
        ("lilt", "LiltForTokenClassification"),
704
        ("longformer", "LongformerForTokenClassification"),
705
        ("luke", "LukeForTokenClassification"),
NielsRogge's avatar
NielsRogge committed
706
        ("markuplm", "MarkupLMForTokenClassification"),
707
708
709
        ("megatron-bert", "MegatronBertForTokenClassification"),
        ("mobilebert", "MobileBertForTokenClassification"),
        ("mpnet", "MPNetForTokenClassification"),
710
        ("nezha", "NezhaForTokenClassification"),
711
712
713
714
        ("nystromformer", "NystromformerForTokenClassification"),
        ("qdqbert", "QDQBertForTokenClassification"),
        ("rembert", "RemBertForTokenClassification"),
        ("roberta", "RobertaForTokenClassification"),
Weiwe Shi's avatar
Weiwe Shi committed
715
        ("roc_bert", "RoCBertForTokenClassification"),
716
717
718
719
720
721
722
        ("roformer", "RoFormerForTokenClassification"),
        ("squeezebert", "SqueezeBertForTokenClassification"),
        ("xlm", "XLMForTokenClassification"),
        ("xlm-roberta", "XLMRobertaForTokenClassification"),
        ("xlm-roberta-xl", "XLMRobertaXLForTokenClassification"),
        ("xlnet", "XLNetForTokenClassification"),
        ("yoso", "YosoForTokenClassification"),
Julien Chaumond's avatar
Julien Chaumond committed
723
724
725
    ]
)

726
MODEL_FOR_MULTIPLE_CHOICE_MAPPING_NAMES = OrderedDict(
Julien Chaumond's avatar
Julien Chaumond committed
727
    [
728
        # Model for Multiple Choice mapping
729
730
        ("albert", "AlbertForMultipleChoice"),
        ("bert", "BertForMultipleChoice"),
731
732
        ("big_bird", "BigBirdForMultipleChoice"),
        ("camembert", "CamembertForMultipleChoice"),
733
734
        ("canine", "CanineForMultipleChoice"),
        ("convbert", "ConvBertForMultipleChoice"),
735
        ("data2vec-text", "Data2VecTextForMultipleChoice"),
736
        ("deberta-v2", "DebertaV2ForMultipleChoice"),
737
        ("distilbert", "DistilBertForMultipleChoice"),
738
        ("electra", "ElectraForMultipleChoice"),
739
        ("ernie", "ErnieForMultipleChoice"),
740
        ("flaubert", "FlaubertForMultipleChoice"),
741
        ("fnet", "FNetForMultipleChoice"),
742
743
        ("funnel", "FunnelForMultipleChoice"),
        ("ibert", "IBertForMultipleChoice"),
744
        ("longformer", "LongformerForMultipleChoice"),
745
        ("luke", "LukeForMultipleChoice"),
746
747
748
        ("megatron-bert", "MegatronBertForMultipleChoice"),
        ("mobilebert", "MobileBertForMultipleChoice"),
        ("mpnet", "MPNetForMultipleChoice"),
749
        ("nezha", "NezhaForMultipleChoice"),
750
751
752
753
        ("nystromformer", "NystromformerForMultipleChoice"),
        ("qdqbert", "QDQBertForMultipleChoice"),
        ("rembert", "RemBertForMultipleChoice"),
        ("roberta", "RobertaForMultipleChoice"),
Weiwe Shi's avatar
Weiwe Shi committed
754
        ("roc_bert", "RoCBertForMultipleChoice"),
755
756
757
758
759
760
761
        ("roformer", "RoFormerForMultipleChoice"),
        ("squeezebert", "SqueezeBertForMultipleChoice"),
        ("xlm", "XLMForMultipleChoice"),
        ("xlm-roberta", "XLMRobertaForMultipleChoice"),
        ("xlm-roberta-xl", "XLMRobertaXLForMultipleChoice"),
        ("xlnet", "XLNetForMultipleChoice"),
        ("yoso", "YosoForMultipleChoice"),
Julien Chaumond's avatar
Julien Chaumond committed
762
763
764
    ]
)

765
MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING_NAMES = OrderedDict(
766
    [
767
        ("bert", "BertForNextSentencePrediction"),
768
        ("ernie", "ErnieForNextSentencePrediction"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
769
        ("fnet", "FNetForNextSentencePrediction"),
770
771
        ("megatron-bert", "MegatronBertForNextSentencePrediction"),
        ("mobilebert", "MobileBertForNextSentencePrediction"),
772
        ("nezha", "NezhaForNextSentencePrediction"),
773
        ("qdqbert", "QDQBertForNextSentencePrediction"),
774
775
776
    ]
)

777
778
779
MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    [
        # Model for Audio Classification mapping
780
        ("data2vec-audio", "Data2VecAudioForSequenceClassification"),
781
        ("hubert", "HubertForSequenceClassification"),
782
783
        ("sew", "SEWForSequenceClassification"),
        ("sew-d", "SEWDForSequenceClassification"),
784
785
786
        ("unispeech", "UniSpeechForSequenceClassification"),
        ("unispeech-sat", "UniSpeechSatForSequenceClassification"),
        ("wav2vec2", "Wav2Vec2ForSequenceClassification"),
787
        ("wav2vec2-conformer", "Wav2Vec2ConformerForSequenceClassification"),
Patrick von Platen's avatar
Patrick von Platen committed
788
        ("wavlm", "WavLMForSequenceClassification"),
789
790
791
    ]
)

792
793
794
MODEL_FOR_CTC_MAPPING_NAMES = OrderedDict(
    [
        # Model for Connectionist temporal classification (CTC) mapping
795
        ("data2vec-audio", "Data2VecAudioForCTC"),
796
        ("hubert", "HubertForCTC"),
Chan Woo Kim's avatar
Chan Woo Kim committed
797
        ("mctct", "MCTCTForCTC"),
798
799
        ("sew", "SEWForCTC"),
        ("sew-d", "SEWDForCTC"),
800
801
802
        ("unispeech", "UniSpeechForCTC"),
        ("unispeech-sat", "UniSpeechSatForCTC"),
        ("wav2vec2", "Wav2Vec2ForCTC"),
803
        ("wav2vec2-conformer", "Wav2Vec2ConformerForCTC"),
Patrick von Platen's avatar
Patrick von Platen committed
804
        ("wavlm", "WavLMForCTC"),
805
806
807
    ]
)

808
809
810
MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    [
        # Model for Audio Classification mapping
811
        ("data2vec-audio", "Data2VecAudioForAudioFrameClassification"),
812
        ("unispeech-sat", "UniSpeechSatForAudioFrameClassification"),
813
        ("wav2vec2", "Wav2Vec2ForAudioFrameClassification"),
814
        ("wav2vec2-conformer", "Wav2Vec2ConformerForAudioFrameClassification"),
815
        ("wavlm", "WavLMForAudioFrameClassification"),
816
817
818
819
820
821
    ]
)

MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES = OrderedDict(
    [
        # Model for Audio Classification mapping
822
        ("data2vec-audio", "Data2VecAudioForXVector"),
823
        ("unispeech-sat", "UniSpeechSatForXVector"),
824
        ("wav2vec2", "Wav2Vec2ForXVector"),
825
        ("wav2vec2-conformer", "Wav2Vec2ConformerForXVector"),
826
        ("wavlm", "WavLMForXVector"),
827
828
829
    ]
)

830
831
832
833
_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    [
        # Model for Zero Shot Image Classification mapping
        ("clip", "CLIPModel"),
NielsRogge's avatar
NielsRogge committed
834
        ("clipseg", "CLIPSegModel"),
835
836
837
    ]
)

838
839
840
841
MODEL_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_MAPPING_NAMES)
MODEL_FOR_PRETRAINING_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_PRETRAINING_MAPPING_NAMES)
MODEL_WITH_LM_HEAD_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_WITH_LM_HEAD_MAPPING_NAMES)
MODEL_FOR_CAUSAL_LM_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_CAUSAL_LM_MAPPING_NAMES)
NielsRogge's avatar
NielsRogge committed
842
843
844
MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING_NAMES
)
845
846
847
MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES
)
848
849
850
MODEL_FOR_IMAGE_SEGMENTATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES
)
851
852
853
MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES
)
854
855
856
MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING_NAMES
)
NielsRogge's avatar
NielsRogge committed
857
858
859
MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING_NAMES
)
860
MODEL_FOR_VISION_2_SEQ_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES)
861
862
863
MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING_NAMES
)
864
865
866
MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES
)
867
MODEL_FOR_MASKED_LM_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_MASKED_LM_MAPPING_NAMES)
NielsRogge's avatar
NielsRogge committed
868
869
870
MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING_NAMES
)
871
MODEL_FOR_OBJECT_DETECTION_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES)
872
873
874
MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING_NAMES
)
875
MODEL_FOR_DEPTH_ESTIMATION_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_DEPTH_ESTIMATION_MAPPING_NAMES)
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES
)
MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES
)
MODEL_FOR_QUESTION_ANSWERING_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES
)
MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING_NAMES
)
MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES
)
MODEL_FOR_MULTIPLE_CHOICE_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_MULTIPLE_CHOICE_MAPPING_NAMES)
MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING_NAMES
)
895
896
897
MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES
)
898
899
MODEL_FOR_CTC_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_CTC_MAPPING_NAMES)
MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES)
900
901
902
903
MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES
)
MODEL_FOR_AUDIO_XVECTOR_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES)
904

905

Sylvain Gugger's avatar
Sylvain Gugger committed
906
907
908
909
910
911
912
913
914
915
916
917
class AutoModel(_BaseAutoModelClass):
    _model_mapping = MODEL_MAPPING


AutoModel = auto_class_update(AutoModel)


class AutoModelForPreTraining(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_PRETRAINING_MAPPING


AutoModelForPreTraining = auto_class_update(AutoModelForPreTraining, head_doc="pretraining")
918

thomwolf's avatar
thomwolf committed
919

920
# Private on purpose, the public class will add the deprecation warnings.
Sylvain Gugger's avatar
Sylvain Gugger committed
921
922
class _AutoModelWithLMHead(_BaseAutoModelClass):
    _model_mapping = MODEL_WITH_LM_HEAD_MAPPING
thomwolf's avatar
thomwolf committed
923
924


Sylvain Gugger's avatar
Sylvain Gugger committed
925
_AutoModelWithLMHead = auto_class_update(_AutoModelWithLMHead, head_doc="language modeling")
thomwolf's avatar
thomwolf committed
926
927


Sylvain Gugger's avatar
Sylvain Gugger committed
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
class AutoModelForCausalLM(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_CAUSAL_LM_MAPPING


AutoModelForCausalLM = auto_class_update(AutoModelForCausalLM, head_doc="causal language modeling")


class AutoModelForMaskedLM(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_MASKED_LM_MAPPING


AutoModelForMaskedLM = auto_class_update(AutoModelForMaskedLM, head_doc="masked language modeling")


class AutoModelForSeq2SeqLM(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING


AutoModelForSeq2SeqLM = auto_class_update(
    AutoModelForSeq2SeqLM, head_doc="sequence-to-sequence language modeling", checkpoint_for_example="t5-base"
948
)
thomwolf's avatar
thomwolf committed
949

Sylvain Gugger's avatar
Sylvain Gugger committed
950
951
952
953
954
955
956

class AutoModelForSequenceClassification(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING


AutoModelForSequenceClassification = auto_class_update(
    AutoModelForSequenceClassification, head_doc="sequence classification"
957
)
thomwolf's avatar
thomwolf committed
958

Sylvain Gugger's avatar
Sylvain Gugger committed
959
960
961
962
963
964
965
966
967
968
969
970
971
972

class AutoModelForQuestionAnswering(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_QUESTION_ANSWERING_MAPPING


AutoModelForQuestionAnswering = auto_class_update(AutoModelForQuestionAnswering, head_doc="question answering")


class AutoModelForTableQuestionAnswering(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING


AutoModelForTableQuestionAnswering = auto_class_update(
    AutoModelForTableQuestionAnswering,
973
974
975
    head_doc="table question answering",
    checkpoint_for_example="google/tapas-base-finetuned-wtq",
)
thomwolf's avatar
thomwolf committed
976
977


978
979
980
981
982
983
984
985
986
987
988
class AutoModelForVisualQuestionAnswering(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING


AutoModelForVisualQuestionAnswering = auto_class_update(
    AutoModelForVisualQuestionAnswering,
    head_doc="visual question answering",
    checkpoint_for_example="dandelin/vilt-b32-finetuned-vqa",
)


989
990
991
992
993
994
995
class AutoModelForDocumentQuestionAnswering(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING


AutoModelForDocumentQuestionAnswering = auto_class_update(
    AutoModelForDocumentQuestionAnswering,
    head_doc="document question answering",
996
    checkpoint_for_example='impira/layoutlm-document-qa", revision="52e01b3',
997
998
999
)


Sylvain Gugger's avatar
Sylvain Gugger committed
1000
1001
class AutoModelForTokenClassification(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING
1002

1003

Sylvain Gugger's avatar
Sylvain Gugger committed
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
AutoModelForTokenClassification = auto_class_update(AutoModelForTokenClassification, head_doc="token classification")


class AutoModelForMultipleChoice(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_MULTIPLE_CHOICE_MAPPING


AutoModelForMultipleChoice = auto_class_update(AutoModelForMultipleChoice, head_doc="multiple choice")


class AutoModelForNextSentencePrediction(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING


AutoModelForNextSentencePrediction = auto_class_update(
    AutoModelForNextSentencePrediction, head_doc="next sentence prediction"
1020
)
1021

1022

Sylvain Gugger's avatar
Sylvain Gugger committed
1023
1024
1025
1026
1027
1028
1029
class AutoModelForImageClassification(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING


AutoModelForImageClassification = auto_class_update(AutoModelForImageClassification, head_doc="image classification")


1030
1031
1032
1033
1034
1035
1036
class AutoModelForImageSegmentation(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_IMAGE_SEGMENTATION_MAPPING


AutoModelForImageSegmentation = auto_class_update(AutoModelForImageSegmentation, head_doc="image segmentation")


1037
1038
1039
1040
1041
1042
1043
1044
1045
class AutoModelForSemanticSegmentation(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING


AutoModelForSemanticSegmentation = auto_class_update(
    AutoModelForSemanticSegmentation, head_doc="semantic segmentation"
)


1046
1047
1048
1049
1050
1051
1052
1053
1054
class AutoModelForInstanceSegmentation(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING


AutoModelForInstanceSegmentation = auto_class_update(
    AutoModelForInstanceSegmentation, head_doc="instance segmentation"
)


1055
1056
1057
1058
1059
1060
1061
class AutoModelForObjectDetection(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_OBJECT_DETECTION_MAPPING


AutoModelForObjectDetection = auto_class_update(AutoModelForObjectDetection, head_doc="object detection")


1062
1063
1064
1065
1066
1067
1068
1069
1070
class AutoModelForZeroShotObjectDetection(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING


AutoModelForZeroShotObjectDetection = auto_class_update(
    AutoModelForZeroShotObjectDetection, head_doc="zero-shot object detection"
)


1071
1072
1073
1074
1075
1076
1077
class AutoModelForDepthEstimation(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_DEPTH_ESTIMATION_MAPPING


AutoModelForDepthEstimation = auto_class_update(AutoModelForDepthEstimation, head_doc="depth estimation")


NielsRogge's avatar
NielsRogge committed
1078
1079
1080
1081
1082
1083
1084
class AutoModelForVideoClassification(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING


AutoModelForVideoClassification = auto_class_update(AutoModelForVideoClassification, head_doc="video classification")


1085
1086
1087
1088
1089
1090
1091
class AutoModelForVision2Seq(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_VISION_2_SEQ_MAPPING


AutoModelForVision2Seq = auto_class_update(AutoModelForVision2Seq, head_doc="vision-to-text modeling")


1092
1093
1094
1095
1096
1097
1098
class AutoModelForAudioClassification(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING


AutoModelForAudioClassification = auto_class_update(AutoModelForAudioClassification, head_doc="audio classification")


1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
class AutoModelForCTC(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_CTC_MAPPING


AutoModelForCTC = auto_class_update(AutoModelForCTC, head_doc="connectionist temporal classification")


class AutoModelForSpeechSeq2Seq(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING


AutoModelForSpeechSeq2Seq = auto_class_update(
Joao Gante's avatar
Joao Gante committed
1111
    AutoModelForSpeechSeq2Seq, head_doc="sequence-to-sequence speech-to-text modeling"
1112
1113
1114
)


1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
class AutoModelForAudioFrameClassification(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING


AutoModelForAudioFrameClassification = auto_class_update(
    AutoModelForAudioFrameClassification, head_doc="audio frame (token) classification"
)


class AutoModelForAudioXVector(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_AUDIO_XVECTOR_MAPPING


AutoModelForAudioXVector = auto_class_update(AutoModelForAudioXVector, head_doc="audio retrieval via x-vector")


NielsRogge's avatar
NielsRogge committed
1131
1132
1133
1134
1135
1136
1137
class AutoModelForMaskedImageModeling(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING


AutoModelForMaskedImageModeling = auto_class_update(AutoModelForMaskedImageModeling, head_doc="masked image modeling")


1138
class AutoModelWithLMHead(_AutoModelWithLMHead):
1139
1140
    @classmethod
    def from_config(cls, config):
1141
        warnings.warn(
1142
1143
1144
            "The class `AutoModelWithLMHead` is deprecated and will be removed in a future version. Please use "
            "`AutoModelForCausalLM` for causal language models, `AutoModelForMaskedLM` for masked language models and "
            "`AutoModelForSeq2SeqLM` for encoder-decoder models.",
1145
1146
            FutureWarning,
        )
1147
        return super().from_config(config)
1148
1149
1150

    @classmethod
    def from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):
1151
        warnings.warn(
1152
1153
1154
            "The class `AutoModelWithLMHead` is deprecated and will be removed in a future version. Please use "
            "`AutoModelForCausalLM` for causal language models, `AutoModelForMaskedLM` for masked language models and "
            "`AutoModelForSeq2SeqLM` for encoder-decoder models.",
1155
1156
            FutureWarning,
        )
1157
        return super().from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)