Aluode/PerceptionLabPortable
0
1# coding=utf-82# Copyright 2018 The HuggingFace Inc. team.3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15"""Auto Model class."""16 17import warnings18from collections import OrderedDict19 20from ...utils import logging21from .auto_factory import _BaseAutoModelClass, _LazyAutoMapping, auto_class_update22from .configuration_auto import CONFIG_MAPPING_NAMES23 24 25logger = logging.get_logger(__name__)26 27 28TF_MODEL_MAPPING_NAMES = OrderedDict(29 [30 # Base model mapping31 ("albert", "TFAlbertModel"),32 ("bart", "TFBartModel"),33 ("bert", "TFBertModel"),34 ("blenderbot", "TFBlenderbotModel"),35 ("blenderbot-small", "TFBlenderbotSmallModel"),36 ("blip", "TFBlipModel"),37 ("camembert", "TFCamembertModel"),38 ("clip", "TFCLIPModel"),39 ("convbert", "TFConvBertModel"),40 ("convnext", "TFConvNextModel"),41 ("convnextv2", "TFConvNextV2Model"),42 ("ctrl", "TFCTRLModel"),43 ("cvt", "TFCvtModel"),44 ("data2vec-vision", "TFData2VecVisionModel"),45 ("deberta", "TFDebertaModel"),46 ("deberta-v2", "TFDebertaV2Model"),47 ("deit", "TFDeiTModel"),48 ("distilbert", "TFDistilBertModel"),49 ("dpr", "TFDPRQuestionEncoder"),50 ("efficientformer", "TFEfficientFormerModel"),51 ("electra", "TFElectraModel"),52 ("esm", "TFEsmModel"),53 ("flaubert", "TFFlaubertModel"),54 ("funnel", ("TFFunnelModel", "TFFunnelBaseModel")),55 ("gpt-sw3", "TFGPT2Model"),56 ("gpt2", "TFGPT2Model"),57 ("gptj", "TFGPTJModel"),58 ("groupvit", "TFGroupViTModel"),59 ("hubert", "TFHubertModel"),60 ("idefics", "TFIdeficsModel"),61 ("layoutlm", "TFLayoutLMModel"),62 ("layoutlmv3", "TFLayoutLMv3Model"),63 ("led", "TFLEDModel"),64 ("longformer", "TFLongformerModel"),65 ("lxmert", "TFLxmertModel"),66 ("marian", "TFMarianModel"),67 ("mbart", "TFMBartModel"),68 ("mistral", "TFMistralModel"),69 ("mobilebert", "TFMobileBertModel"),70 ("mobilevit", "TFMobileViTModel"),71 ("mpnet", "TFMPNetModel"),72 ("mt5", "TFMT5Model"),73 ("openai-gpt", "TFOpenAIGPTModel"),74 ("opt", "TFOPTModel"),75 ("pegasus", "TFPegasusModel"),76 ("regnet", "TFRegNetModel"),77 ("rembert", "TFRemBertModel"),78 ("resnet", "TFResNetModel"),79 ("roberta", "TFRobertaModel"),80 ("roberta-prelayernorm", "TFRobertaPreLayerNormModel"),81 ("roformer", "TFRoFormerModel"),82 ("sam", "TFSamModel"),83 ("sam_vision_model", "TFSamVisionModel"),84 ("segformer", "TFSegformerModel"),85 ("speech_to_text", "TFSpeech2TextModel"),86 ("swiftformer", "TFSwiftFormerModel"),87 ("swin", "TFSwinModel"),88 ("t5", "TFT5Model"),89 ("tapas", "TFTapasModel"),90 ("transfo-xl", "TFTransfoXLModel"),91 ("vision-text-dual-encoder", "TFVisionTextDualEncoderModel"),92 ("vit", "TFViTModel"),93 ("vit_mae", "TFViTMAEModel"),94 ("wav2vec2", "TFWav2Vec2Model"),95 ("whisper", "TFWhisperModel"),96 ("xglm", "TFXGLMModel"),97 ("xlm", "TFXLMModel"),98 ("xlm-roberta", "TFXLMRobertaModel"),99 ("xlnet", "TFXLNetModel"),100 ]101)102 103TF_MODEL_FOR_PRETRAINING_MAPPING_NAMES = OrderedDict(104 [105 # Model for pre-training mapping106 ("albert", "TFAlbertForPreTraining"),107 ("bart", "TFBartForConditionalGeneration"),108 ("bert", "TFBertForPreTraining"),109 ("camembert", "TFCamembertForMaskedLM"),110 ("ctrl", "TFCTRLLMHeadModel"),111 ("distilbert", "TFDistilBertForMaskedLM"),112 ("electra", "TFElectraForPreTraining"),113 ("flaubert", "TFFlaubertWithLMHeadModel"),114 ("funnel", "TFFunnelForPreTraining"),115 ("gpt-sw3", "TFGPT2LMHeadModel"),116 ("gpt2", "TFGPT2LMHeadModel"),117 ("idefics", "TFIdeficsForVisionText2Text"),118 ("layoutlm", "TFLayoutLMForMaskedLM"),119 ("lxmert", "TFLxmertForPreTraining"),120 ("mobilebert", "TFMobileBertForPreTraining"),121 ("mpnet", "TFMPNetForMaskedLM"),122 ("openai-gpt", "TFOpenAIGPTLMHeadModel"),123 ("roberta", "TFRobertaForMaskedLM"),124 ("roberta-prelayernorm", "TFRobertaPreLayerNormForMaskedLM"),125 ("t5", "TFT5ForConditionalGeneration"),126 ("tapas", "TFTapasForMaskedLM"),127 ("transfo-xl", "TFTransfoXLLMHeadModel"),128 ("vit_mae", "TFViTMAEForPreTraining"),129 ("xlm", "TFXLMWithLMHeadModel"),130 ("xlm-roberta", "TFXLMRobertaForMaskedLM"),131 ("xlnet", "TFXLNetLMHeadModel"),132 ]133)134 135TF_MODEL_WITH_LM_HEAD_MAPPING_NAMES = OrderedDict(136 [137 # Model with LM heads mapping138 ("albert", "TFAlbertForMaskedLM"),139 ("bart", "TFBartForConditionalGeneration"),140 ("bert", "TFBertForMaskedLM"),141 ("camembert", "TFCamembertForMaskedLM"),142 ("convbert", "TFConvBertForMaskedLM"),143 ("ctrl", "TFCTRLLMHeadModel"),144 ("distilbert", "TFDistilBertForMaskedLM"),145 ("electra", "TFElectraForMaskedLM"),146 ("esm", "TFEsmForMaskedLM"),147 ("flaubert", "TFFlaubertWithLMHeadModel"),148 ("funnel", "TFFunnelForMaskedLM"),149 ("gpt-sw3", "TFGPT2LMHeadModel"),150 ("gpt2", "TFGPT2LMHeadModel"),151 ("gptj", "TFGPTJForCausalLM"),152 ("layoutlm", "TFLayoutLMForMaskedLM"),153 ("led", "TFLEDForConditionalGeneration"),154 ("longformer", "TFLongformerForMaskedLM"),155 ("marian", "TFMarianMTModel"),156 ("mobilebert", "TFMobileBertForMaskedLM"),157 ("mpnet", "TFMPNetForMaskedLM"),158 ("openai-gpt", "TFOpenAIGPTLMHeadModel"),159 ("rembert", "TFRemBertForMaskedLM"),160 ("roberta", "TFRobertaForMaskedLM"),161 ("roberta-prelayernorm", "TFRobertaPreLayerNormForMaskedLM"),162 ("roformer", "TFRoFormerForMaskedLM"),163 ("speech_to_text", "TFSpeech2TextForConditionalGeneration"),164 ("t5", "TFT5ForConditionalGeneration"),165 ("tapas", "TFTapasForMaskedLM"),166 ("transfo-xl", "TFTransfoXLLMHeadModel"),167 ("whisper", "TFWhisperForConditionalGeneration"),168 ("xlm", "TFXLMWithLMHeadModel"),169 ("xlm-roberta", "TFXLMRobertaForMaskedLM"),170 ("xlnet", "TFXLNetLMHeadModel"),171 ]172)173 174TF_MODEL_FOR_CAUSAL_LM_MAPPING_NAMES = OrderedDict(175 [176 # Model for Causal LM mapping177 ("bert", "TFBertLMHeadModel"),178 ("camembert", "TFCamembertForCausalLM"),179 ("ctrl", "TFCTRLLMHeadModel"),180 ("gpt-sw3", "TFGPT2LMHeadModel"),181 ("gpt2", "TFGPT2LMHeadModel"),182 ("gptj", "TFGPTJForCausalLM"),183 ("mistral", "TFMistralForCausalLM"),184 ("openai-gpt", "TFOpenAIGPTLMHeadModel"),185 ("opt", "TFOPTForCausalLM"),186 ("rembert", "TFRemBertForCausalLM"),187 ("roberta", "TFRobertaForCausalLM"),188 ("roberta-prelayernorm", "TFRobertaPreLayerNormForCausalLM"),189 ("roformer", "TFRoFormerForCausalLM"),190 ("transfo-xl", "TFTransfoXLLMHeadModel"),191 ("xglm", "TFXGLMForCausalLM"),192 ("xlm", "TFXLMWithLMHeadModel"),193 ("xlm-roberta", "TFXLMRobertaForCausalLM"),194 ("xlnet", "TFXLNetLMHeadModel"),195 ]196)197 198TF_MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING_NAMES = OrderedDict(199 [200 ("deit", "TFDeiTForMaskedImageModeling"),201 ("swin", "TFSwinForMaskedImageModeling"),202 ]203)204 205TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES = OrderedDict(206 [207 # Model for Image-classsification208 ("convnext", "TFConvNextForImageClassification"),209 ("convnextv2", "TFConvNextV2ForImageClassification"),210 ("cvt", "TFCvtForImageClassification"),211 ("data2vec-vision", "TFData2VecVisionForImageClassification"),212 ("deit", ("TFDeiTForImageClassification", "TFDeiTForImageClassificationWithTeacher")),213 (214 "efficientformer",215 ("TFEfficientFormerForImageClassification", "TFEfficientFormerForImageClassificationWithTeacher"),216 ),217 ("mobilevit", "TFMobileViTForImageClassification"),218 ("regnet", "TFRegNetForImageClassification"),219 ("resnet", "TFResNetForImageClassification"),220 ("segformer", "TFSegformerForImageClassification"),221 ("swiftformer", "TFSwiftFormerForImageClassification"),222 ("swin", "TFSwinForImageClassification"),223 ("vit", "TFViTForImageClassification"),224 ]225)226 227 228TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING_NAMES = OrderedDict(229 [230 # Model for Zero Shot Image Classification mapping231 ("blip", "TFBlipModel"),232 ("clip", "TFCLIPModel"),233 ]234)235 236 237TF_MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES = OrderedDict(238 [239 # Model for Semantic Segmentation mapping240 ("data2vec-vision", "TFData2VecVisionForSemanticSegmentation"),241 ("mobilevit", "TFMobileViTForSemanticSegmentation"),242 ("segformer", "TFSegformerForSemanticSegmentation"),243 ]244)245 246TF_MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES = OrderedDict(247 [248 ("blip", "TFBlipForConditionalGeneration"),249 ("vision-encoder-decoder", "TFVisionEncoderDecoderModel"),250 ]251)252 253TF_MODEL_FOR_MASKED_LM_MAPPING_NAMES = OrderedDict(254 [255 # Model for Masked LM mapping256 ("albert", "TFAlbertForMaskedLM"),257 ("bert", "TFBertForMaskedLM"),258 ("camembert", "TFCamembertForMaskedLM"),259 ("convbert", "TFConvBertForMaskedLM"),260 ("deberta", "TFDebertaForMaskedLM"),261 ("deberta-v2", "TFDebertaV2ForMaskedLM"),262 ("distilbert", "TFDistilBertForMaskedLM"),263 ("electra", "TFElectraForMaskedLM"),264 ("esm", "TFEsmForMaskedLM"),265 ("flaubert", "TFFlaubertWithLMHeadModel"),266 ("funnel", "TFFunnelForMaskedLM"),267 ("layoutlm", "TFLayoutLMForMaskedLM"),268 ("longformer", "TFLongformerForMaskedLM"),269 ("mobilebert", "TFMobileBertForMaskedLM"),270 ("mpnet", "TFMPNetForMaskedLM"),271 ("rembert", "TFRemBertForMaskedLM"),272 ("roberta", "TFRobertaForMaskedLM"),273 ("roberta-prelayernorm", "TFRobertaPreLayerNormForMaskedLM"),274 ("roformer", "TFRoFormerForMaskedLM"),275 ("tapas", "TFTapasForMaskedLM"),276 ("xlm", "TFXLMWithLMHeadModel"),277 ("xlm-roberta", "TFXLMRobertaForMaskedLM"),278 ]279)280 281TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES = OrderedDict(282 [283 # Model for Seq2Seq Causal LM mapping284 ("bart", "TFBartForConditionalGeneration"),285 ("blenderbot", "TFBlenderbotForConditionalGeneration"),286 ("blenderbot-small", "TFBlenderbotSmallForConditionalGeneration"),287 ("encoder-decoder", "TFEncoderDecoderModel"),288 ("led", "TFLEDForConditionalGeneration"),289 ("marian", "TFMarianMTModel"),290 ("mbart", "TFMBartForConditionalGeneration"),291 ("mt5", "TFMT5ForConditionalGeneration"),292 ("pegasus", "TFPegasusForConditionalGeneration"),293 ("t5", "TFT5ForConditionalGeneration"),294 ]295)296 297TF_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES = OrderedDict(298 [299 ("speech_to_text", "TFSpeech2TextForConditionalGeneration"),300 ("whisper", "TFWhisperForConditionalGeneration"),301 ]302)303 304TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES = OrderedDict(305 [306 # Model for Sequence Classification mapping307 ("albert", "TFAlbertForSequenceClassification"),308 ("bart", "TFBartForSequenceClassification"),309 ("bert", "TFBertForSequenceClassification"),310 ("camembert", "TFCamembertForSequenceClassification"),311 ("convbert", "TFConvBertForSequenceClassification"),312 ("ctrl", "TFCTRLForSequenceClassification"),313 ("deberta", "TFDebertaForSequenceClassification"),314 ("deberta-v2", "TFDebertaV2ForSequenceClassification"),315 ("distilbert", "TFDistilBertForSequenceClassification"),316 ("electra", "TFElectraForSequenceClassification"),317 ("esm", "TFEsmForSequenceClassification"),318 ("flaubert", "TFFlaubertForSequenceClassification"),319 ("funnel", "TFFunnelForSequenceClassification"),320 ("gpt-sw3", "TFGPT2ForSequenceClassification"),321 ("gpt2", "TFGPT2ForSequenceClassification"),322 ("gptj", "TFGPTJForSequenceClassification"),323 ("layoutlm", "TFLayoutLMForSequenceClassification"),324 ("layoutlmv3", "TFLayoutLMv3ForSequenceClassification"),325 ("longformer", "TFLongformerForSequenceClassification"),326 ("mistral", "TFMistralForSequenceClassification"),327 ("mobilebert", "TFMobileBertForSequenceClassification"),328 ("mpnet", "TFMPNetForSequenceClassification"),329 ("openai-gpt", "TFOpenAIGPTForSequenceClassification"),330 ("rembert", "TFRemBertForSequenceClassification"),331 ("roberta", "TFRobertaForSequenceClassification"),332 ("roberta-prelayernorm", "TFRobertaPreLayerNormForSequenceClassification"),333 ("roformer", "TFRoFormerForSequenceClassification"),334 ("tapas", "TFTapasForSequenceClassification"),335 ("transfo-xl", "TFTransfoXLForSequenceClassification"),336 ("xlm", "TFXLMForSequenceClassification"),337 ("xlm-roberta", "TFXLMRobertaForSequenceClassification"),338 ("xlnet", "TFXLNetForSequenceClassification"),339 ]340)341 342TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES = OrderedDict(343 [344 # Model for Question Answering mapping345 ("albert", "TFAlbertForQuestionAnswering"),346 ("bert", "TFBertForQuestionAnswering"),347 ("camembert", "TFCamembertForQuestionAnswering"),348 ("convbert", "TFConvBertForQuestionAnswering"),349 ("deberta", "TFDebertaForQuestionAnswering"),350 ("deberta-v2", "TFDebertaV2ForQuestionAnswering"),351 ("distilbert", "TFDistilBertForQuestionAnswering"),352 ("electra", "TFElectraForQuestionAnswering"),353 ("flaubert", "TFFlaubertForQuestionAnsweringSimple"),354 ("funnel", "TFFunnelForQuestionAnswering"),355 ("gptj", "TFGPTJForQuestionAnswering"),356 ("layoutlmv3", "TFLayoutLMv3ForQuestionAnswering"),357 ("longformer", "TFLongformerForQuestionAnswering"),358 ("mobilebert", "TFMobileBertForQuestionAnswering"),359 ("mpnet", "TFMPNetForQuestionAnswering"),360 ("rembert", "TFRemBertForQuestionAnswering"),361 ("roberta", "TFRobertaForQuestionAnswering"),362 ("roberta-prelayernorm", "TFRobertaPreLayerNormForQuestionAnswering"),363 ("roformer", "TFRoFormerForQuestionAnswering"),364 ("xlm", "TFXLMForQuestionAnsweringSimple"),365 ("xlm-roberta", "TFXLMRobertaForQuestionAnswering"),366 ("xlnet", "TFXLNetForQuestionAnsweringSimple"),367 ]368)369TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES = OrderedDict([("wav2vec2", "TFWav2Vec2ForSequenceClassification")])370 371TF_MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES = OrderedDict(372 [373 ("layoutlm", "TFLayoutLMForQuestionAnswering"),374 ("layoutlmv3", "TFLayoutLMv3ForQuestionAnswering"),375 ]376)377 378 379TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING_NAMES = OrderedDict(380 [381 # Model for Table Question Answering mapping382 ("tapas", "TFTapasForQuestionAnswering"),383 ]384)385 386TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES = OrderedDict(387 [388 # Model for Token Classification mapping389 ("albert", "TFAlbertForTokenClassification"),390 ("bert", "TFBertForTokenClassification"),391 ("camembert", "TFCamembertForTokenClassification"),392 ("convbert", "TFConvBertForTokenClassification"),393 ("deberta", "TFDebertaForTokenClassification"),394 ("deberta-v2", "TFDebertaV2ForTokenClassification"),395 ("distilbert", "TFDistilBertForTokenClassification"),396 ("electra", "TFElectraForTokenClassification"),397 ("esm", "TFEsmForTokenClassification"),398 ("flaubert", "TFFlaubertForTokenClassification"),399 ("funnel", "TFFunnelForTokenClassification"),400 ("layoutlm", "TFLayoutLMForTokenClassification"),401 ("layoutlmv3", "TFLayoutLMv3ForTokenClassification"),402 ("longformer", "TFLongformerForTokenClassification"),403 ("mobilebert", "TFMobileBertForTokenClassification"),404 ("mpnet", "TFMPNetForTokenClassification"),405 ("rembert", "TFRemBertForTokenClassification"),406 ("roberta", "TFRobertaForTokenClassification"),407 ("roberta-prelayernorm", "TFRobertaPreLayerNormForTokenClassification"),408 ("roformer", "TFRoFormerForTokenClassification"),409 ("xlm", "TFXLMForTokenClassification"),410 ("xlm-roberta", "TFXLMRobertaForTokenClassification"),411 ("xlnet", "TFXLNetForTokenClassification"),412 ]413)414 415TF_MODEL_FOR_MULTIPLE_CHOICE_MAPPING_NAMES = OrderedDict(416 [417 # Model for Multiple Choice mapping418 ("albert", "TFAlbertForMultipleChoice"),419 ("bert", "TFBertForMultipleChoice"),420 ("camembert", "TFCamembertForMultipleChoice"),421 ("convbert", "TFConvBertForMultipleChoice"),422 ("deberta-v2", "TFDebertaV2ForMultipleChoice"),423 ("distilbert", "TFDistilBertForMultipleChoice"),424 ("electra", "TFElectraForMultipleChoice"),425 ("flaubert", "TFFlaubertForMultipleChoice"),426 ("funnel", "TFFunnelForMultipleChoice"),427 ("longformer", "TFLongformerForMultipleChoice"),428 ("mobilebert", "TFMobileBertForMultipleChoice"),429 ("mpnet", "TFMPNetForMultipleChoice"),430 ("rembert", "TFRemBertForMultipleChoice"),431 ("roberta", "TFRobertaForMultipleChoice"),432 ("roberta-prelayernorm", "TFRobertaPreLayerNormForMultipleChoice"),433 ("roformer", "TFRoFormerForMultipleChoice"),434 ("xlm", "TFXLMForMultipleChoice"),435 ("xlm-roberta", "TFXLMRobertaForMultipleChoice"),436 ("xlnet", "TFXLNetForMultipleChoice"),437 ]438)439 440TF_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING_NAMES = OrderedDict(441 [442 ("bert", "TFBertForNextSentencePrediction"),443 ("mobilebert", "TFMobileBertForNextSentencePrediction"),444 ]445)446TF_MODEL_FOR_MASK_GENERATION_MAPPING_NAMES = OrderedDict(447 [448 ("sam", "TFSamModel"),449 ]450)451TF_MODEL_FOR_TEXT_ENCODING_MAPPING_NAMES = OrderedDict(452 [453 ("albert", "TFAlbertModel"),454 ("bert", "TFBertModel"),455 ("convbert", "TFConvBertModel"),456 ("deberta", "TFDebertaModel"),457 ("deberta-v2", "TFDebertaV2Model"),458 ("distilbert", "TFDistilBertModel"),459 ("electra", "TFElectraModel"),460 ("flaubert", "TFFlaubertModel"),461 ("longformer", "TFLongformerModel"),462 ("mobilebert", "TFMobileBertModel"),463 ("mt5", "TFMT5EncoderModel"),464 ("rembert", "TFRemBertModel"),465 ("roberta", "TFRobertaModel"),466 ("roberta-prelayernorm", "TFRobertaPreLayerNormModel"),467 ("roformer", "TFRoFormerModel"),468 ("t5", "TFT5EncoderModel"),469 ("xlm", "TFXLMModel"),470 ("xlm-roberta", "TFXLMRobertaModel"),471 ]472)473 474TF_MODEL_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, TF_MODEL_MAPPING_NAMES)475TF_MODEL_FOR_PRETRAINING_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, TF_MODEL_FOR_PRETRAINING_MAPPING_NAMES)476TF_MODEL_WITH_LM_HEAD_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, TF_MODEL_WITH_LM_HEAD_MAPPING_NAMES)477TF_MODEL_FOR_CAUSAL_LM_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, TF_MODEL_FOR_CAUSAL_LM_MAPPING_NAMES)478TF_MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING = _LazyAutoMapping(479 CONFIG_MAPPING_NAMES, TF_MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING_NAMES480)481TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING = _LazyAutoMapping(482 CONFIG_MAPPING_NAMES, TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING_NAMES483)484TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING = _LazyAutoMapping(485 CONFIG_MAPPING_NAMES, TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING_NAMES486)487TF_MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING = _LazyAutoMapping(488 CONFIG_MAPPING_NAMES, TF_MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING_NAMES489)490TF_MODEL_FOR_VISION_2_SEQ_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, TF_MODEL_FOR_VISION_2_SEQ_MAPPING_NAMES)491TF_MODEL_FOR_MASKED_LM_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, TF_MODEL_FOR_MASKED_LM_MAPPING_NAMES)492TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING = _LazyAutoMapping(493 CONFIG_MAPPING_NAMES, TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMES494)495TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING = _LazyAutoMapping(496 CONFIG_MAPPING_NAMES, TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING_NAMES497)498TF_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING = _LazyAutoMapping(499 CONFIG_MAPPING_NAMES, TF_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING_NAMES500)501TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING = _LazyAutoMapping(502 CONFIG_MAPPING_NAMES, TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING_NAMES503)504TF_MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING = _LazyAutoMapping(505 CONFIG_MAPPING_NAMES, TF_MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING_NAMES506)507TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING = _LazyAutoMapping(508 CONFIG_MAPPING_NAMES, TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING_NAMES509)510TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING = _LazyAutoMapping(511 CONFIG_MAPPING_NAMES, TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING_NAMES512)513TF_MODEL_FOR_MULTIPLE_CHOICE_MAPPING = _LazyAutoMapping(514 CONFIG_MAPPING_NAMES, TF_MODEL_FOR_MULTIPLE_CHOICE_MAPPING_NAMES515)516TF_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING = _LazyAutoMapping(517 CONFIG_MAPPING_NAMES, TF_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING_NAMES518)519TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING = _LazyAutoMapping(520 CONFIG_MAPPING_NAMES, TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING_NAMES521)522 523TF_MODEL_FOR_MASK_GENERATION_MAPPING = _LazyAutoMapping(524 CONFIG_MAPPING_NAMES, TF_MODEL_FOR_MASK_GENERATION_MAPPING_NAMES525)526 527TF_MODEL_FOR_TEXT_ENCODING_MAPPING = _LazyAutoMapping(CONFIG_MAPPING_NAMES, TF_MODEL_FOR_TEXT_ENCODING_MAPPING_NAMES)528 529 530class TFAutoModelForMaskGeneration(_BaseAutoModelClass):531 _model_mapping = TF_MODEL_FOR_MASK_GENERATION_MAPPING532 533 534class TFAutoModelForTextEncoding(_BaseAutoModelClass):535 _model_mapping = TF_MODEL_FOR_TEXT_ENCODING_MAPPING536 537 538class TFAutoModel(_BaseAutoModelClass):539 _model_mapping = TF_MODEL_MAPPING540 541 542TFAutoModel = auto_class_update(TFAutoModel)543 544 545class TFAutoModelForAudioClassification(_BaseAutoModelClass):546 _model_mapping = TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING547 548 549TFAutoModelForAudioClassification = auto_class_update(550 TFAutoModelForAudioClassification, head_doc="audio classification"551)552 553 554class TFAutoModelForPreTraining(_BaseAutoModelClass):555 _model_mapping = TF_MODEL_FOR_PRETRAINING_MAPPING556 557 558TFAutoModelForPreTraining = auto_class_update(TFAutoModelForPreTraining, head_doc="pretraining")559 560 561# Private on purpose, the public class will add the deprecation warnings.562class _TFAutoModelWithLMHead(_BaseAutoModelClass):563 _model_mapping = TF_MODEL_WITH_LM_HEAD_MAPPING564 565 566_TFAutoModelWithLMHead = auto_class_update(_TFAutoModelWithLMHead, head_doc="language modeling")567 568 569class TFAutoModelForCausalLM(_BaseAutoModelClass):570 _model_mapping = TF_MODEL_FOR_CAUSAL_LM_MAPPING571 572 573TFAutoModelForCausalLM = auto_class_update(TFAutoModelForCausalLM, head_doc="causal language modeling")574 575 576class TFAutoModelForMaskedImageModeling(_BaseAutoModelClass):577 _model_mapping = TF_MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING578 579 580TFAutoModelForMaskedImageModeling = auto_class_update(581 TFAutoModelForMaskedImageModeling, head_doc="masked image modeling"582)583 584 585class TFAutoModelForImageClassification(_BaseAutoModelClass):586 _model_mapping = TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING587 588 589TFAutoModelForImageClassification = auto_class_update(590 TFAutoModelForImageClassification, head_doc="image classification"591)592 593 594class TFAutoModelForZeroShotImageClassification(_BaseAutoModelClass):595 _model_mapping = TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING596 597 598TFAutoModelForZeroShotImageClassification = auto_class_update(599 TFAutoModelForZeroShotImageClassification, head_doc="zero-shot image classification"600)601 602 603class TFAutoModelForSemanticSegmentation(_BaseAutoModelClass):604 _model_mapping = TF_MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING605 606 607TFAutoModelForSemanticSegmentation = auto_class_update(608 TFAutoModelForSemanticSegmentation, head_doc="semantic segmentation"609)610 611 612class TFAutoModelForVision2Seq(_BaseAutoModelClass):613 _model_mapping = TF_MODEL_FOR_VISION_2_SEQ_MAPPING614 615 616TFAutoModelForVision2Seq = auto_class_update(TFAutoModelForVision2Seq, head_doc="vision-to-text modeling")617 618 619class TFAutoModelForMaskedLM(_BaseAutoModelClass):620 _model_mapping = TF_MODEL_FOR_MASKED_LM_MAPPING621 622 623TFAutoModelForMaskedLM = auto_class_update(TFAutoModelForMaskedLM, head_doc="masked language modeling")624 625 626class TFAutoModelForSeq2SeqLM(_BaseAutoModelClass):627 _model_mapping = TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING628 629 630TFAutoModelForSeq2SeqLM = auto_class_update(631 TFAutoModelForSeq2SeqLM,632 head_doc="sequence-to-sequence language modeling",633 checkpoint_for_example="google-t5/t5-base",634)635 636 637class TFAutoModelForSequenceClassification(_BaseAutoModelClass):638 _model_mapping = TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING639 640 641TFAutoModelForSequenceClassification = auto_class_update(642 TFAutoModelForSequenceClassification, head_doc="sequence classification"643)644 645 646class TFAutoModelForQuestionAnswering(_BaseAutoModelClass):647 _model_mapping = TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING648 649 650TFAutoModelForQuestionAnswering = auto_class_update(TFAutoModelForQuestionAnswering, head_doc="question answering")651 652 653class TFAutoModelForDocumentQuestionAnswering(_BaseAutoModelClass):654 _model_mapping = TF_MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING655 656 657TFAutoModelForDocumentQuestionAnswering = auto_class_update(658 TFAutoModelForDocumentQuestionAnswering,659 head_doc="document question answering",660 checkpoint_for_example='impira/layoutlm-document-qa", revision="52e01b3',661)662 663 664class TFAutoModelForTableQuestionAnswering(_BaseAutoModelClass):665 _model_mapping = TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING666 667 668TFAutoModelForTableQuestionAnswering = auto_class_update(669 TFAutoModelForTableQuestionAnswering,670 head_doc="table question answering",671 checkpoint_for_example="google/tapas-base-finetuned-wtq",672)673 674 675class TFAutoModelForTokenClassification(_BaseAutoModelClass):676 _model_mapping = TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING677 678 679TFAutoModelForTokenClassification = auto_class_update(680 TFAutoModelForTokenClassification, head_doc="token classification"681)682 683 684class TFAutoModelForMultipleChoice(_BaseAutoModelClass):685 _model_mapping = TF_MODEL_FOR_MULTIPLE_CHOICE_MAPPING686 687 688TFAutoModelForMultipleChoice = auto_class_update(TFAutoModelForMultipleChoice, head_doc="multiple choice")689 690 691class TFAutoModelForNextSentencePrediction(_BaseAutoModelClass):692 _model_mapping = TF_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING693 694 695TFAutoModelForNextSentencePrediction = auto_class_update(696 TFAutoModelForNextSentencePrediction, head_doc="next sentence prediction"697)698 699 700class TFAutoModelForSpeechSeq2Seq(_BaseAutoModelClass):701 _model_mapping = TF_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING702 703 704TFAutoModelForSpeechSeq2Seq = auto_class_update(705 TFAutoModelForSpeechSeq2Seq, head_doc="sequence-to-sequence speech-to-text modeling"706)707 708 709class TFAutoModelWithLMHead(_TFAutoModelWithLMHead):710 @classmethod711 def from_config(cls, config):712 warnings.warn(713 "The class `TFAutoModelWithLMHead` is deprecated and will be removed in a future version. Please use"714 " `TFAutoModelForCausalLM` for causal language models, `TFAutoModelForMaskedLM` for masked language models"715 " and `TFAutoModelForSeq2SeqLM` for encoder-decoder models.",716 FutureWarning,717 )718 return super().from_config(config)719 720 @classmethod721 def from_pretrained(cls, pretrained_model_name_or_path, *model_args, **kwargs):722 warnings.warn(723 "The class `TFAutoModelWithLMHead` is deprecated and will be removed in a future version. Please use"724 " `TFAutoModelForCausalLM` for causal language models, `TFAutoModelForMaskedLM` for masked language models"725 " and `TFAutoModelForSeq2SeqLM` for encoder-decoder models.",726 FutureWarning,727 )728 return super().from_pretrained(pretrained_model_name_or_path, *model_args, **kwargs)729 730 731__all__ = [732 "TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING",733 "TF_MODEL_FOR_CAUSAL_LM_MAPPING",734 "TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING",735 "TF_MODEL_FOR_MASK_GENERATION_MAPPING",736 "TF_MODEL_FOR_MASKED_IMAGE_MODELING_MAPPING",737 "TF_MODEL_FOR_MASKED_LM_MAPPING",738 "TF_MODEL_FOR_MULTIPLE_CHOICE_MAPPING",739 "TF_MODEL_FOR_NEXT_SENTENCE_PREDICTION_MAPPING",740 "TF_MODEL_FOR_PRETRAINING_MAPPING",741 "TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING",742 "TF_MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING",743 "TF_MODEL_FOR_SEMANTIC_SEGMENTATION_MAPPING",744 "TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING",745 "TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING",746 "TF_MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING",747 "TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING",748 "TF_MODEL_FOR_TEXT_ENCODING_MAPPING",749 "TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING",750 "TF_MODEL_FOR_VISION_2_SEQ_MAPPING",751 "TF_MODEL_FOR_ZERO_SHOT_IMAGE_CLASSIFICATION_MAPPING",752 "TF_MODEL_MAPPING",753 "TF_MODEL_WITH_LM_HEAD_MAPPING",754 "TFAutoModel",755 "TFAutoModelForAudioClassification",756 "TFAutoModelForCausalLM",757 "TFAutoModelForImageClassification",758 "TFAutoModelForMaskedImageModeling",759 "TFAutoModelForMaskedLM",760 "TFAutoModelForMaskGeneration",761 "TFAutoModelForMultipleChoice",762 "TFAutoModelForNextSentencePrediction",763 "TFAutoModelForPreTraining",764 "TFAutoModelForDocumentQuestionAnswering",765 "TFAutoModelForQuestionAnswering",766 "TFAutoModelForSemanticSegmentation",767 "TFAutoModelForSeq2SeqLM",768 "TFAutoModelForSequenceClassification",769 "TFAutoModelForSpeechSeq2Seq",770 "TFAutoModelForTableQuestionAnswering",771 "TFAutoModelForTextEncoding",772 "TFAutoModelForTokenClassification",773 "TFAutoModelForVision2Seq",774 "TFAutoModelForZeroShotImageClassification",775 "TFAutoModelWithLMHead",776]777 