"docs/source/es/tasks/question_answering.md" did not exist on "371337a95b5d82cc9376c2595ed2022a5eb2ee6e"
modeling_auto.py 36.3 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
NielsRogge's avatar
NielsRogge committed
31
        ("yolos", "YolosModel"),
NielsRogge's avatar
NielsRogge committed
32
        ("dpt", "DPTModel"),
33
        ("decision_transformer", "DecisionTransformerModel"),
NielsRogge's avatar
NielsRogge committed
34
        ("glpn", "GLPNModel"),
35
        ("maskformer", "MaskFormerModel"),
36
37
        ("decision_transformer", "DecisionTransformerModel"),
        ("decision_transformer_gpt2", "DecisionTransformerGPT2Model"),
Tanay Mehta's avatar
Tanay Mehta committed
38
        ("poolformer", "PoolFormerModel"),
NielsRogge's avatar
NielsRogge committed
39
        ("convnext", "ConvNextModel"),
40
        ("van", "VanModel"),
41
        ("resnet", "ResNetModel"),
Francesco Saverio Zuppichini's avatar
Francesco Saverio Zuppichini committed
42
        ("regnet", "RegNetModel"),
novice's avatar
novice committed
43
        ("yoso", "YosoModel"),
novice's avatar
novice committed
44
        ("swin", "SwinModel"),
NielsRogge's avatar
NielsRogge committed
45
        ("vilt", "ViltModel"),
NielsRogge's avatar
NielsRogge committed
46
        ("vit_mae", "ViTMAEModel"),
novice's avatar
novice committed
47
        ("nystromformer", "NystromformerModel"),
Suraj Patil's avatar
Suraj Patil committed
48
        ("xglm", "XGLMModel"),
NielsRogge's avatar
NielsRogge committed
49
        ("imagegpt", "ImageGPTModel"),
50
        ("qdqbert", "QDQBertModel"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
51
        ("fnet", "FNetModel"),
NielsRogge's avatar
NielsRogge committed
52
        ("segformer", "SegformerModel"),
Suraj Patil's avatar
Suraj Patil committed
53
        ("vision-text-dual-encoder", "VisionTextDualEncoderModel"),
NielsRogge's avatar
NielsRogge committed
54
        ("perceiver", "PerceiverModel"),
Stella Biderman's avatar
Stella Biderman committed
55
        ("gptj", "GPTJModel"),
56
        ("layoutlmv2", "LayoutLMv2Model"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
57
        ("plbart", "PLBartModel"),
58
        ("beit", "BeitModel"),
59
        ("data2vec-vision", "Data2VecVisionModel"),
60
61
62
63
64
        ("rembert", "RemBertModel"),
        ("visual_bert", "VisualBertModel"),
        ("canine", "CanineModel"),
        ("roformer", "RoFormerModel"),
        ("clip", "CLIPModel"),
65
        ("flava", "FlavaModel"),
66
67
68
69
70
71
72
73
74
        ("bigbird_pegasus", "BigBirdPegasusModel"),
        ("deit", "DeiTModel"),
        ("luke", "LukeModel"),
        ("detr", "DetrModel"),
        ("gpt_neo", "GPTNeoModel"),
        ("big_bird", "BigBirdModel"),
        ("speech_to_text", "Speech2TextModel"),
        ("vit", "ViTModel"),
        ("wav2vec2", "Wav2Vec2Model"),
75
        ("unispeech-sat", "UniSpeechSatModel"),
Patrick von Platen's avatar
Patrick von Platen committed
76
        ("wavlm", "WavLMModel"),
77
        ("unispeech", "UniSpeechModel"),
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
        ("hubert", "HubertModel"),
        ("m2m_100", "M2M100Model"),
        ("convbert", "ConvBertModel"),
        ("led", "LEDModel"),
        ("blenderbot-small", "BlenderbotSmallModel"),
        ("retribert", "RetriBertModel"),
        ("mt5", "MT5Model"),
        ("t5", "T5Model"),
        ("pegasus", "PegasusModel"),
        ("marian", "MarianModel"),
        ("mbart", "MBartModel"),
        ("blenderbot", "BlenderbotModel"),
        ("distilbert", "DistilBertModel"),
        ("albert", "AlbertModel"),
        ("camembert", "CamembertModel"),
93
        ("xlm-roberta-xl", "XLMRobertaXLModel"),
94
95
        ("xlm-roberta", "XLMRobertaModel"),
        ("bart", "BartModel"),
Younes Belkada's avatar
Younes Belkada committed
96
        ("opt", "OPTModel"),
97
98
        ("longformer", "LongformerModel"),
        ("roberta", "RobertaModel"),
99
100
        ("data2vec-text", "Data2VecTextModel"),
        ("data2vec-audio", "Data2VecAudioModel"),
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
        ("layoutlm", "LayoutLMModel"),
        ("squeezebert", "SqueezeBertModel"),
        ("bert", "BertModel"),
        ("openai-gpt", "OpenAIGPTModel"),
        ("gpt2", "GPT2Model"),
        ("megatron-bert", "MegatronBertModel"),
        ("mobilebert", "MobileBertModel"),
        ("transfo-xl", "TransfoXLModel"),
        ("xlnet", "XLNetModel"),
        ("flaubert", "FlaubertModel"),
        ("fsmt", "FSMTModel"),
        ("xlm", "XLMModel"),
        ("ctrl", "CTRLModel"),
        ("electra", "ElectraModel"),
        ("reformer", "ReformerModel"),
        ("funnel", ("FunnelModel", "FunnelBaseModel")),
        ("lxmert", "LxmertModel"),
        ("bert-generation", "BertGenerationEncoder"),
        ("deberta", "DebertaModel"),
        ("deberta-v2", "DebertaV2Model"),
        ("dpr", "DPRQuestionEncoder"),
        ("xlm-prophetnet", "XLMProphetNetModel"),
        ("prophetnet", "ProphetNetModel"),
        ("mpnet", "MPNetModel"),
        ("tapas", "TapasModel"),
        ("ibert", "IBertModel"),
Ori Ram's avatar
Ori Ram committed
127
        ("splinter", "SplinterModel"),
128
129
        ("sew", "SEWModel"),
        ("sew-d", "SEWDModel"),
Julien Chaumond's avatar
Julien Chaumond committed
130
131
132
    ]
)

133
MODEL_FOR_PRETRAINING_MAPPING_NAMES = OrderedDict(
thomwolf's avatar
thomwolf committed
134
    [
135
        # Model for pre-training mapping
136
        ("flava", "FlavaForPreTraining"),
NielsRogge's avatar
NielsRogge committed
137
        ("vit_mae", "ViTMAEForPreTraining"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
138
        ("fnet", "FNetForPreTraining"),
139
140
141
142
143
144
145
        ("visual_bert", "VisualBertForPreTraining"),
        ("layoutlm", "LayoutLMForMaskedLM"),
        ("retribert", "RetriBertModel"),
        ("t5", "T5ForConditionalGeneration"),
        ("distilbert", "DistilBertForMaskedLM"),
        ("albert", "AlbertForPreTraining"),
        ("camembert", "CamembertForMaskedLM"),
146
        ("xlm-roberta-xl", "XLMRobertaXLForMaskedLM"),
147
148
149
150
151
        ("xlm-roberta", "XLMRobertaForMaskedLM"),
        ("bart", "BartForConditionalGeneration"),
        ("fsmt", "FSMTForConditionalGeneration"),
        ("longformer", "LongformerForMaskedLM"),
        ("roberta", "RobertaForMaskedLM"),
152
        ("data2vec-text", "Data2VecTextForMaskedLM"),
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
        ("squeezebert", "SqueezeBertForMaskedLM"),
        ("bert", "BertForPreTraining"),
        ("big_bird", "BigBirdForPreTraining"),
        ("openai-gpt", "OpenAIGPTLMHeadModel"),
        ("gpt2", "GPT2LMHeadModel"),
        ("megatron-bert", "MegatronBertForPreTraining"),
        ("mobilebert", "MobileBertForPreTraining"),
        ("transfo-xl", "TransfoXLLMHeadModel"),
        ("xlnet", "XLNetLMHeadModel"),
        ("flaubert", "FlaubertWithLMHeadModel"),
        ("xlm", "XLMWithLMHeadModel"),
        ("ctrl", "CTRLLMHeadModel"),
        ("electra", "ElectraForPreTraining"),
        ("lxmert", "LxmertForPreTraining"),
        ("funnel", "FunnelForPreTraining"),
        ("mpnet", "MPNetForMaskedLM"),
        ("tapas", "TapasForMaskedLM"),
        ("ibert", "IBertForMaskedLM"),
        ("deberta", "DebertaForMaskedLM"),
        ("deberta-v2", "DebertaV2ForMaskedLM"),
        ("wav2vec2", "Wav2Vec2ForPreTraining"),
174
175
        ("unispeech-sat", "UniSpeechSatForPreTraining"),
        ("unispeech", "UniSpeechForPreTraining"),
thomwolf's avatar
thomwolf committed
176
177
178
    ]
)

179
MODEL_WITH_LM_HEAD_MAPPING_NAMES = OrderedDict(
180
    [
181
        # Model with LM heads mapping
novice's avatar
novice committed
182
        ("yoso", "YosoForMaskedLM"),
novice's avatar
novice committed
183
        ("nystromformer", "NystromformerForMaskedLM"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
184
        ("plbart", "PLBartForConditionalGeneration"),
185
        ("qdqbert", "QDQBertForMaskedLM"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
186
        ("fnet", "FNetForMaskedLM"),
Stella Biderman's avatar
Stella Biderman committed
187
        ("gptj", "GPTJForCausalLM"),
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
        ("rembert", "RemBertForMaskedLM"),
        ("roformer", "RoFormerForMaskedLM"),
        ("bigbird_pegasus", "BigBirdPegasusForConditionalGeneration"),
        ("gpt_neo", "GPTNeoForCausalLM"),
        ("big_bird", "BigBirdForMaskedLM"),
        ("speech_to_text", "Speech2TextForConditionalGeneration"),
        ("wav2vec2", "Wav2Vec2ForMaskedLM"),
        ("m2m_100", "M2M100ForConditionalGeneration"),
        ("convbert", "ConvBertForMaskedLM"),
        ("led", "LEDForConditionalGeneration"),
        ("blenderbot-small", "BlenderbotSmallForConditionalGeneration"),
        ("layoutlm", "LayoutLMForMaskedLM"),
        ("t5", "T5ForConditionalGeneration"),
        ("distilbert", "DistilBertForMaskedLM"),
        ("albert", "AlbertForMaskedLM"),
        ("camembert", "CamembertForMaskedLM"),
204
        ("xlm-roberta-xl", "XLMRobertaXLForMaskedLM"),
205
206
207
208
209
210
        ("xlm-roberta", "XLMRobertaForMaskedLM"),
        ("marian", "MarianMTModel"),
        ("fsmt", "FSMTForConditionalGeneration"),
        ("bart", "BartForConditionalGeneration"),
        ("longformer", "LongformerForMaskedLM"),
        ("roberta", "RobertaForMaskedLM"),
211
        ("data2vec-text", "Data2VecTextForMaskedLM"),
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
        ("squeezebert", "SqueezeBertForMaskedLM"),
        ("bert", "BertForMaskedLM"),
        ("openai-gpt", "OpenAIGPTLMHeadModel"),
        ("gpt2", "GPT2LMHeadModel"),
        ("megatron-bert", "MegatronBertForCausalLM"),
        ("mobilebert", "MobileBertForMaskedLM"),
        ("transfo-xl", "TransfoXLLMHeadModel"),
        ("xlnet", "XLNetLMHeadModel"),
        ("flaubert", "FlaubertWithLMHeadModel"),
        ("xlm", "XLMWithLMHeadModel"),
        ("ctrl", "CTRLLMHeadModel"),
        ("electra", "ElectraForMaskedLM"),
        ("encoder-decoder", "EncoderDecoderModel"),
        ("reformer", "ReformerModelWithLMHead"),
        ("funnel", "FunnelForMaskedLM"),
        ("mpnet", "MPNetForMaskedLM"),
        ("tapas", "TapasForMaskedLM"),
        ("deberta", "DebertaForMaskedLM"),
        ("deberta-v2", "DebertaV2ForMaskedLM"),
        ("ibert", "IBertForMaskedLM"),
232
233
234
    ]
)

235
MODEL_FOR_CAUSAL_LM_MAPPING_NAMES = OrderedDict(
236
    [
237
        # Model for Causal LM mapping
Suraj Patil's avatar
Suraj Patil committed
238
        ("xglm", "XGLMForCausalLM"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
239
        ("plbart", "PLBartForCausalLM"),
240
        ("qdqbert", "QDQBertLMHeadModel"),
241
        ("trocr", "TrOCRForCausalLM"),
Stella Biderman's avatar
Stella Biderman committed
242
        ("gptj", "GPTJForCausalLM"),
243
244
245
246
247
248
        ("rembert", "RemBertForCausalLM"),
        ("roformer", "RoFormerForCausalLM"),
        ("bigbird_pegasus", "BigBirdPegasusForCausalLM"),
        ("gpt_neo", "GPTNeoForCausalLM"),
        ("big_bird", "BigBirdForCausalLM"),
        ("camembert", "CamembertForCausalLM"),
249
        ("xlm-roberta-xl", "XLMRobertaXLForCausalLM"),
250
251
252
253
254
255
256
257
        ("xlm-roberta", "XLMRobertaForCausalLM"),
        ("roberta", "RobertaForCausalLM"),
        ("bert", "BertLMHeadModel"),
        ("openai-gpt", "OpenAIGPTLMHeadModel"),
        ("gpt2", "GPT2LMHeadModel"),
        ("transfo-xl", "TransfoXLLMHeadModel"),
        ("xlnet", "XLNetLMHeadModel"),
        ("xlm", "XLMWithLMHeadModel"),
258
        ("electra", "ElectraForCausalLM"),
259
260
261
262
263
264
        ("ctrl", "CTRLLMHeadModel"),
        ("reformer", "ReformerModelWithLMHead"),
        ("bert-generation", "BertGenerationDecoder"),
        ("xlm-prophetnet", "XLMProphetNetForCausalLM"),
        ("prophetnet", "ProphetNetForCausalLM"),
        ("bart", "BartForCausalLM"),
Younes Belkada's avatar
Younes Belkada committed
265
        ("opt", "OPTForCausalLM"),
266
267
268
269
270
271
        ("mbart", "MBartForCausalLM"),
        ("pegasus", "PegasusForCausalLM"),
        ("marian", "MarianForCausalLM"),
        ("blenderbot", "BlenderbotForCausalLM"),
        ("blenderbot-small", "BlenderbotSmallForCausalLM"),
        ("megatron-bert", "MegatronBertForCausalLM"),
272
        ("speech_to_text_2", "Speech2Text2ForCausalLM"),
273
        ("data2vec-text", "Data2VecTextForCausalLM"),
274
275
276
    ]
)

NielsRogge's avatar
NielsRogge committed
277
278
279
280
281
282
283
284
285
MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING_NAMES = OrderedDict(
    [
        ("vit", "ViTForMaskedImageModeling"),
        ("deit", "DeiTForMaskedImageModeling"),
        ("swin", "SwinForMaskedImageModeling"),
    ]
)


NielsRogge's avatar
NielsRogge committed
286
287
288
289
290
291
292
MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING_NAMES = OrderedDict(
    # Model for Causal Image Modeling mapping
    [
        ("imagegpt", "ImageGPTForCausalImageModeling"),
    ]
)

293
MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
294
295
    [
        # Model for Image Classification mapping
296
297
298
        ("vit", "ViTForImageClassification"),
        ("deit", ("DeiTForImageClassification", "DeiTForImageClassificationWithTeacher")),
        ("beit", "BeitForImageClassification"),
299
        ("data2vec-vision", "Data2VecVisionForImageClassification"),
NielsRogge's avatar
NielsRogge committed
300
        ("segformer", "SegformerForImageClassification"),
NielsRogge's avatar
NielsRogge committed
301
        ("imagegpt", "ImageGPTForImageClassification"),
NielsRogge's avatar
NielsRogge committed
302
303
304
305
306
307
308
309
        (
            "perceiver",
            (
                "PerceiverForImageClassificationLearned",
                "PerceiverForImageClassificationFourier",
                "PerceiverForImageClassificationConvProcessing",
            ),
        ),
novice's avatar
novice committed
310
        ("swin", "SwinForImageClassification"),
NielsRogge's avatar
NielsRogge committed
311
        ("convnext", "ConvNextForImageClassification"),
312
        ("van", "VanForImageClassification"),
313
        ("resnet", "ResNetForImageClassification"),
Francesco Saverio Zuppichini's avatar
Francesco Saverio Zuppichini committed
314
        ("regnet", "RegNetForImageClassification"),
Tanay Mehta's avatar
Tanay Mehta committed
315
        ("poolformer", "PoolFormerForImageClassification"),
316
317
318
    ]
)

319
320
MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES = OrderedDict(
    [
321
        # Do not add new models here, this class will be deprecated in the future.
322
323
324
325
326
        # Model for Image Segmentation mapping
        ("detr", "DetrForSegmentation"),
    ]
)

327
328
329
330
MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES = OrderedDict(
    [
        # Model for Semantic Segmentation mapping
        ("beit", "BeitForSemanticSegmentation"),
331
        ("data2vec-vision", "Data2VecVisionForSemanticSegmentation"),
332
        ("segformer", "SegformerForSemanticSegmentation"),
NielsRogge's avatar
NielsRogge committed
333
        ("dpt", "DPTForSemanticSegmentation"),
334
335
336
    ]
)

337
338
339
340
341
342
343
MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING_NAMES = OrderedDict(
    [
        # Model for Instance Segmentation mapping
        ("maskformer", "MaskFormerForInstanceSegmentation"),
    ]
)

344
345
346
347
348
349
MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES = OrderedDict(
    [
        ("vision-encoder-decoder", "VisionEncoderDecoderModel"),
    ]
)

350
MODEL_FOR_MASKED_LM_MAPPING_NAMES = OrderedDict(
351
    [
352
        # Model for Masked LM mapping
novice's avatar
novice committed
353
        ("yoso", "YosoForMaskedLM"),
novice's avatar
novice committed
354
        ("nystromformer", "NystromformerForMaskedLM"),
NielsRogge's avatar
NielsRogge committed
355
        ("perceiver", "PerceiverForMaskedLM"),
356
        ("qdqbert", "QDQBertForMaskedLM"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
357
        ("fnet", "FNetForMaskedLM"),
358
359
360
361
362
363
364
365
366
367
368
        ("rembert", "RemBertForMaskedLM"),
        ("roformer", "RoFormerForMaskedLM"),
        ("big_bird", "BigBirdForMaskedLM"),
        ("wav2vec2", "Wav2Vec2ForMaskedLM"),
        ("convbert", "ConvBertForMaskedLM"),
        ("layoutlm", "LayoutLMForMaskedLM"),
        ("distilbert", "DistilBertForMaskedLM"),
        ("albert", "AlbertForMaskedLM"),
        ("bart", "BartForConditionalGeneration"),
        ("mbart", "MBartForConditionalGeneration"),
        ("camembert", "CamembertForMaskedLM"),
369
        ("xlm-roberta-xl", "XLMRobertaXLForMaskedLM"),
370
371
372
        ("xlm-roberta", "XLMRobertaForMaskedLM"),
        ("longformer", "LongformerForMaskedLM"),
        ("roberta", "RobertaForMaskedLM"),
373
        ("data2vec-text", "Data2VecTextForMaskedLM"),
374
375
376
377
378
379
380
381
382
383
384
385
386
387
        ("squeezebert", "SqueezeBertForMaskedLM"),
        ("bert", "BertForMaskedLM"),
        ("megatron-bert", "MegatronBertForMaskedLM"),
        ("mobilebert", "MobileBertForMaskedLM"),
        ("flaubert", "FlaubertWithLMHeadModel"),
        ("xlm", "XLMWithLMHeadModel"),
        ("electra", "ElectraForMaskedLM"),
        ("reformer", "ReformerForMaskedLM"),
        ("funnel", "FunnelForMaskedLM"),
        ("mpnet", "MPNetForMaskedLM"),
        ("tapas", "TapasForMaskedLM"),
        ("deberta", "DebertaForMaskedLM"),
        ("deberta-v2", "DebertaV2ForMaskedLM"),
        ("ibert", "IBertForMaskedLM"),
388
389
390
    ]
)

391
MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES = OrderedDict(
NielsRogge's avatar
NielsRogge committed
392
393
    [
        # Model for Object Detection mapping
NielsRogge's avatar
NielsRogge committed
394
        ("yolos", "YolosForObjectDetection"),
395
        ("detr", "DetrForObjectDetection"),
NielsRogge's avatar
NielsRogge committed
396
397
398
    ]
)

399
MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES = OrderedDict(
400
    [
401
        # Model for Seq2Seq Causal LM mapping
NielsRogge's avatar
NielsRogge committed
402
        ("tapex", "BartForConditionalGeneration"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
403
        ("plbart", "PLBartForConditionalGeneration"),
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
        ("bigbird_pegasus", "BigBirdPegasusForConditionalGeneration"),
        ("m2m_100", "M2M100ForConditionalGeneration"),
        ("led", "LEDForConditionalGeneration"),
        ("blenderbot-small", "BlenderbotSmallForConditionalGeneration"),
        ("mt5", "MT5ForConditionalGeneration"),
        ("t5", "T5ForConditionalGeneration"),
        ("pegasus", "PegasusForConditionalGeneration"),
        ("marian", "MarianMTModel"),
        ("mbart", "MBartForConditionalGeneration"),
        ("blenderbot", "BlenderbotForConditionalGeneration"),
        ("bart", "BartForConditionalGeneration"),
        ("fsmt", "FSMTForConditionalGeneration"),
        ("encoder-decoder", "EncoderDecoderModel"),
        ("xlm-prophetnet", "XLMProphetNetForConditionalGeneration"),
        ("prophetnet", "ProphetNetForConditionalGeneration"),
419
420
421
    ]
)

422
423
424
425
426
427
428
MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES = OrderedDict(
    [
        ("speech-encoder-decoder", "SpeechEncoderDecoderModel"),
        ("speech_to_text", "Speech2TextForConditionalGeneration"),
    ]
)

429
MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
430
    [
431
        # Model for Sequence Classification mapping
NielsRogge's avatar
NielsRogge committed
432
        ("tapex", "BartForSequenceClassification"),
novice's avatar
novice committed
433
        ("yoso", "YosoForSequenceClassification"),
novice's avatar
novice committed
434
        ("nystromformer", "NystromformerForSequenceClassification"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
435
        ("plbart", "PLBartForSequenceClassification"),
NielsRogge's avatar
NielsRogge committed
436
        ("perceiver", "PerceiverForSequenceClassification"),
437
        ("qdqbert", "QDQBertForSequenceClassification"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
438
        ("fnet", "FNetForSequenceClassification"),
Stella Biderman's avatar
Stella Biderman committed
439
        ("gptj", "GPTJForSequenceClassification"),
440
        ("layoutlmv2", "LayoutLMv2ForSequenceClassification"),
441
442
443
444
445
446
447
448
449
450
        ("rembert", "RemBertForSequenceClassification"),
        ("canine", "CanineForSequenceClassification"),
        ("roformer", "RoFormerForSequenceClassification"),
        ("bigbird_pegasus", "BigBirdPegasusForSequenceClassification"),
        ("big_bird", "BigBirdForSequenceClassification"),
        ("convbert", "ConvBertForSequenceClassification"),
        ("led", "LEDForSequenceClassification"),
        ("distilbert", "DistilBertForSequenceClassification"),
        ("albert", "AlbertForSequenceClassification"),
        ("camembert", "CamembertForSequenceClassification"),
451
        ("xlm-roberta-xl", "XLMRobertaXLForSequenceClassification"),
452
453
454
455
456
        ("xlm-roberta", "XLMRobertaForSequenceClassification"),
        ("mbart", "MBartForSequenceClassification"),
        ("bart", "BartForSequenceClassification"),
        ("longformer", "LongformerForSequenceClassification"),
        ("roberta", "RobertaForSequenceClassification"),
457
        ("data2vec-text", "Data2VecTextForSequenceClassification"),
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
        ("squeezebert", "SqueezeBertForSequenceClassification"),
        ("layoutlm", "LayoutLMForSequenceClassification"),
        ("bert", "BertForSequenceClassification"),
        ("xlnet", "XLNetForSequenceClassification"),
        ("megatron-bert", "MegatronBertForSequenceClassification"),
        ("mobilebert", "MobileBertForSequenceClassification"),
        ("flaubert", "FlaubertForSequenceClassification"),
        ("xlm", "XLMForSequenceClassification"),
        ("electra", "ElectraForSequenceClassification"),
        ("funnel", "FunnelForSequenceClassification"),
        ("deberta", "DebertaForSequenceClassification"),
        ("deberta-v2", "DebertaV2ForSequenceClassification"),
        ("gpt2", "GPT2ForSequenceClassification"),
        ("gpt_neo", "GPTNeoForSequenceClassification"),
        ("openai-gpt", "OpenAIGPTForSequenceClassification"),
        ("reformer", "ReformerForSequenceClassification"),
        ("ctrl", "CTRLForSequenceClassification"),
        ("transfo-xl", "TransfoXLForSequenceClassification"),
        ("mpnet", "MPNetForSequenceClassification"),
        ("tapas", "TapasForSequenceClassification"),
        ("ibert", "IBertForSequenceClassification"),
479
480
481
    ]
)

482
MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES = OrderedDict(
483
    [
484
        # Model for Question Answering mapping
novice's avatar
novice committed
485
        ("yoso", "YosoForQuestionAnswering"),
novice's avatar
novice committed
486
        ("nystromformer", "NystromformerForQuestionAnswering"),
487
        ("qdqbert", "QDQBertForQuestionAnswering"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
488
        ("fnet", "FNetForQuestionAnswering"),
489
        ("gptj", "GPTJForQuestionAnswering"),
490
        ("layoutlmv2", "LayoutLMv2ForQuestionAnswering"),
491
492
493
494
495
496
497
498
499
500
501
502
503
        ("rembert", "RemBertForQuestionAnswering"),
        ("canine", "CanineForQuestionAnswering"),
        ("roformer", "RoFormerForQuestionAnswering"),
        ("bigbird_pegasus", "BigBirdPegasusForQuestionAnswering"),
        ("big_bird", "BigBirdForQuestionAnswering"),
        ("convbert", "ConvBertForQuestionAnswering"),
        ("led", "LEDForQuestionAnswering"),
        ("distilbert", "DistilBertForQuestionAnswering"),
        ("albert", "AlbertForQuestionAnswering"),
        ("camembert", "CamembertForQuestionAnswering"),
        ("bart", "BartForQuestionAnswering"),
        ("mbart", "MBartForQuestionAnswering"),
        ("longformer", "LongformerForQuestionAnswering"),
504
        ("xlm-roberta-xl", "XLMRobertaXLForQuestionAnswering"),
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
        ("xlm-roberta", "XLMRobertaForQuestionAnswering"),
        ("roberta", "RobertaForQuestionAnswering"),
        ("squeezebert", "SqueezeBertForQuestionAnswering"),
        ("bert", "BertForQuestionAnswering"),
        ("xlnet", "XLNetForQuestionAnsweringSimple"),
        ("flaubert", "FlaubertForQuestionAnsweringSimple"),
        ("megatron-bert", "MegatronBertForQuestionAnswering"),
        ("mobilebert", "MobileBertForQuestionAnswering"),
        ("xlm", "XLMForQuestionAnsweringSimple"),
        ("electra", "ElectraForQuestionAnswering"),
        ("reformer", "ReformerForQuestionAnswering"),
        ("funnel", "FunnelForQuestionAnswering"),
        ("lxmert", "LxmertForQuestionAnswering"),
        ("mpnet", "MPNetForQuestionAnswering"),
        ("deberta", "DebertaForQuestionAnswering"),
        ("deberta-v2", "DebertaV2ForQuestionAnswering"),
        ("ibert", "IBertForQuestionAnswering"),
Ori Ram's avatar
Ori Ram committed
522
        ("splinter", "SplinterForQuestionAnswering"),
523
        ("data2vec-text", "Data2VecTextForQuestionAnswering"),
524
525
526
    ]
)

527
MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING_NAMES = OrderedDict(
528
529
    [
        # Model for Table Question Answering mapping
530
        ("tapas", "TapasForQuestionAnswering"),
531
532
533
    ]
)

534
MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
Julien Chaumond's avatar
Julien Chaumond committed
535
    [
536
        # Model for Token Classification mapping
novice's avatar
novice committed
537
        ("yoso", "YosoForTokenClassification"),
novice's avatar
novice committed
538
        ("nystromformer", "NystromformerForTokenClassification"),
539
        ("qdqbert", "QDQBertForTokenClassification"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
540
        ("fnet", "FNetForTokenClassification"),
541
        ("layoutlmv2", "LayoutLMv2ForTokenClassification"),
542
543
544
545
546
547
548
549
550
551
        ("rembert", "RemBertForTokenClassification"),
        ("canine", "CanineForTokenClassification"),
        ("roformer", "RoFormerForTokenClassification"),
        ("big_bird", "BigBirdForTokenClassification"),
        ("convbert", "ConvBertForTokenClassification"),
        ("layoutlm", "LayoutLMForTokenClassification"),
        ("distilbert", "DistilBertForTokenClassification"),
        ("camembert", "CamembertForTokenClassification"),
        ("flaubert", "FlaubertForTokenClassification"),
        ("xlm", "XLMForTokenClassification"),
552
        ("xlm-roberta-xl", "XLMRobertaXLForTokenClassification"),
553
554
555
556
557
558
559
560
561
562
563
564
565
566
        ("xlm-roberta", "XLMRobertaForTokenClassification"),
        ("longformer", "LongformerForTokenClassification"),
        ("roberta", "RobertaForTokenClassification"),
        ("squeezebert", "SqueezeBertForTokenClassification"),
        ("bert", "BertForTokenClassification"),
        ("megatron-bert", "MegatronBertForTokenClassification"),
        ("mobilebert", "MobileBertForTokenClassification"),
        ("xlnet", "XLNetForTokenClassification"),
        ("albert", "AlbertForTokenClassification"),
        ("electra", "ElectraForTokenClassification"),
        ("funnel", "FunnelForTokenClassification"),
        ("mpnet", "MPNetForTokenClassification"),
        ("deberta", "DebertaForTokenClassification"),
        ("deberta-v2", "DebertaV2ForTokenClassification"),
567
        ("gpt2", "GPT2ForTokenClassification"),
568
        ("ibert", "IBertForTokenClassification"),
569
        ("data2vec-text", "Data2VecTextForTokenClassification"),
Julien Chaumond's avatar
Julien Chaumond committed
570
571
572
    ]
)

573
MODEL_FOR_MULTIPLE_CHOICE_MAPPING_NAMES = OrderedDict(
Julien Chaumond's avatar
Julien Chaumond committed
574
    [
575
        # Model for Multiple Choice mapping
novice's avatar
novice committed
576
        ("yoso", "YosoForMultipleChoice"),
novice's avatar
novice committed
577
        ("nystromformer", "NystromformerForMultipleChoice"),
578
        ("qdqbert", "QDQBertForMultipleChoice"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
579
        ("fnet", "FNetForMultipleChoice"),
580
581
582
583
584
585
586
        ("rembert", "RemBertForMultipleChoice"),
        ("canine", "CanineForMultipleChoice"),
        ("roformer", "RoFormerForMultipleChoice"),
        ("big_bird", "BigBirdForMultipleChoice"),
        ("convbert", "ConvBertForMultipleChoice"),
        ("camembert", "CamembertForMultipleChoice"),
        ("electra", "ElectraForMultipleChoice"),
587
        ("xlm-roberta-xl", "XLMRobertaXLForMultipleChoice"),
588
589
590
        ("xlm-roberta", "XLMRobertaForMultipleChoice"),
        ("longformer", "LongformerForMultipleChoice"),
        ("roberta", "RobertaForMultipleChoice"),
591
        ("data2vec-text", "Data2VecTextForMultipleChoice"),
592
593
594
595
596
597
598
599
600
601
602
603
        ("squeezebert", "SqueezeBertForMultipleChoice"),
        ("bert", "BertForMultipleChoice"),
        ("distilbert", "DistilBertForMultipleChoice"),
        ("megatron-bert", "MegatronBertForMultipleChoice"),
        ("mobilebert", "MobileBertForMultipleChoice"),
        ("xlnet", "XLNetForMultipleChoice"),
        ("albert", "AlbertForMultipleChoice"),
        ("xlm", "XLMForMultipleChoice"),
        ("flaubert", "FlaubertForMultipleChoice"),
        ("funnel", "FunnelForMultipleChoice"),
        ("mpnet", "MPNetForMultipleChoice"),
        ("ibert", "IBertForMultipleChoice"),
604
        ("deberta-v2", "DebertaV2ForMultipleChoice"),
Julien Chaumond's avatar
Julien Chaumond committed
605
606
607
    ]
)

608
MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING_NAMES = OrderedDict(
609
    [
610
        ("qdqbert", "QDQBertForNextSentencePrediction"),
611
        ("bert", "BertForNextSentencePrediction"),
Gunjan Chhablani's avatar
Gunjan Chhablani committed
612
        ("fnet", "FNetForNextSentencePrediction"),
613
614
        ("megatron-bert", "MegatronBertForNextSentencePrediction"),
        ("mobilebert", "MobileBertForNextSentencePrediction"),
615
616
617
    ]
)

618
619
620
621
MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    [
        # Model for Audio Classification mapping
        ("wav2vec2", "Wav2Vec2ForSequenceClassification"),
622
623
        ("unispeech-sat", "UniSpeechSatForSequenceClassification"),
        ("unispeech", "UniSpeechForSequenceClassification"),
624
        ("hubert", "HubertForSequenceClassification"),
625
626
        ("sew", "SEWForSequenceClassification"),
        ("sew-d", "SEWDForSequenceClassification"),
Patrick von Platen's avatar
Patrick von Platen committed
627
        ("wavlm", "WavLMForSequenceClassification"),
628
        ("data2vec-audio", "Data2VecAudioForSequenceClassification"),
629
630
631
    ]
)

632
633
634
635
MODEL_FOR_CTC_MAPPING_NAMES = OrderedDict(
    [
        # Model for Connectionist temporal classification (CTC) mapping
        ("wav2vec2", "Wav2Vec2ForCTC"),
636
637
        ("unispeech-sat", "UniSpeechSatForCTC"),
        ("unispeech", "UniSpeechForCTC"),
638
        ("hubert", "HubertForCTC"),
639
640
        ("sew", "SEWForCTC"),
        ("sew-d", "SEWDForCTC"),
Patrick von Platen's avatar
Patrick von Platen committed
641
        ("wavlm", "WavLMForCTC"),
642
        ("data2vec-audio", "Data2VecAudioForCTC"),
643
644
645
    ]
)

646
647
648
649
650
MODEL_FOR_AUDIO_FRAME_CLASSIFICATION_MAPPING_NAMES = OrderedDict(
    [
        # Model for Audio Classification mapping
        ("wav2vec2", "Wav2Vec2ForAudioFrameClassification"),
        ("unispeech-sat", "UniSpeechSatForAudioFrameClassification"),
651
        ("wavlm", "WavLMForAudioFrameClassification"),
652
        ("data2vec-audio", "Data2VecAudioForAudioFrameClassification"),
653
654
655
656
657
658
659
660
    ]
)

MODEL_FOR_AUDIO_XVECTOR_MAPPING_NAMES = OrderedDict(
    [
        # Model for Audio Classification mapping
        ("wav2vec2", "Wav2Vec2ForXVector"),
        ("unispeech-sat", "UniSpeechSatForXVector"),
661
        ("wavlm", "WavLMForXVector"),
662
        ("data2vec-audio", "Data2VecAudioForXVector"),
663
664
665
    ]
)

666
667
668
669
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
670
671
672
MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_CAUSAL_IMAGE_MODELING_MAPPING_NAMES
)
673
674
675
MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES
)
676
677
678
MODEL_FOR_IMAGE_SEGMENTATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_IMAGE_SEGMENTATION_MAPPING_NAMES
)
679
680
681
MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES
)
682
683
684
MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING_NAMES
)
685
MODEL_FOR_VISION_2_SEQ_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES)
686
MODEL_FOR_MASKED_LM_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_MASKED_LM_MAPPING_NAMES)
NielsRogge's avatar
NielsRogge committed
687
688
689
MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING_NAMES
)
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
MODEL_FOR_OBJECT_DETECTION_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, MODEL_FOR_OBJECT_DETECTION_MAPPING_NAMES)
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
)
710
711
712
MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING = _LazyAutoMapping(
    CONFIG_MAPPING_NAMES, MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES
)
713
714
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)
715
716
717
718
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)
719

720

Sylvain Gugger's avatar
Sylvain Gugger committed
721
722
723
724
725
726
727
728
729
730
731
732
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")
733

thomwolf's avatar
thomwolf committed
734

735
# Private on purpose, the public class will add the deprecation warnings.
Sylvain Gugger's avatar
Sylvain Gugger committed
736
737
class _AutoModelWithLMHead(_BaseAutoModelClass):
    _model_mapping = MODEL_WITH_LM_HEAD_MAPPING
thomwolf's avatar
thomwolf committed
738
739


Sylvain Gugger's avatar
Sylvain Gugger committed
740
_AutoModelWithLMHead = auto_class_update(_AutoModelWithLMHead, head_doc="language modeling")
thomwolf's avatar
thomwolf committed
741
742


Sylvain Gugger's avatar
Sylvain Gugger committed
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
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"
763
)
thomwolf's avatar
thomwolf committed
764

Sylvain Gugger's avatar
Sylvain Gugger committed
765
766
767
768
769
770
771

class AutoModelForSequenceClassification(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING


AutoModelForSequenceClassification = auto_class_update(
    AutoModelForSequenceClassification, head_doc="sequence classification"
772
)
thomwolf's avatar
thomwolf committed
773

Sylvain Gugger's avatar
Sylvain Gugger committed
774
775
776
777
778
779
780
781
782
783
784
785
786
787

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,
788
789
790
    head_doc="table question answering",
    checkpoint_for_example="google/tapas-base-finetuned-wtq",
)
thomwolf's avatar
thomwolf committed
791
792


Sylvain Gugger's avatar
Sylvain Gugger committed
793
794
class AutoModelForTokenClassification(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING
795

796

Sylvain Gugger's avatar
Sylvain Gugger committed
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
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"
813
)
814

815

Sylvain Gugger's avatar
Sylvain Gugger committed
816
817
818
819
820
821
822
class AutoModelForImageClassification(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING


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


823
824
825
826
827
828
829
class AutoModelForImageSegmentation(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_IMAGE_SEGMENTATION_MAPPING


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


830
831
832
833
834
835
836
837
838
class AutoModelForSemanticSegmentation(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING


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


839
840
841
842
843
844
845
846
847
class AutoModelForInstanceSegmentation(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING


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


848
849
850
851
852
853
854
class AutoModelForObjectDetection(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_OBJECT_DETECTION_MAPPING


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


855
856
857
858
859
860
861
class AutoModelForVision2Seq(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_VISION_2_SEQ_MAPPING


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


862
863
864
865
866
867
868
class AutoModelForAudioClassification(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING


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


869
870
871
872
873
874
875
876
877
878
879
880
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
881
    AutoModelForSpeechSeq2Seq, head_doc="sequence-to-sequence speech-to-text modeling"
882
883
884
)


885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
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
901
902
903
904
905
906
907
class AutoModelForMaskedImageModeling(_BaseAutoModelClass):
    _model_mapping = MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING


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


908
class AutoModelWithLMHead(_AutoModelWithLMHead):
909
910
    @classmethod
    def from_config(cls, config):
911
        warnings.warn(
912
913
914
            "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.",
915
916
            FutureWarning,
        )
917
        return super().from_config(config)
918
919
920

    @classmethod
    def from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):
921
        warnings.warn(
922
923
924
            "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.",
925
926
            FutureWarning,
        )
927
        return super().from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)