From 871c31a6f120330677911224584f80c554958ae4 Mon Sep 17 00:00:00 2001 From: Yih-Dar <2521628+ydshieh@users.noreply.github.com> Date: Tue, 28 Feb 2023 19:40:57 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=94=A5Rework=20pipeline=20testing=20by=20?= =?UTF-8?q?removing=20`PipelineTestCaseMeta`=20=F0=9F=9A=80=20(#21516)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add PipelineTesterMixin * remove class PipelineTestCaseMeta * move validate_test_components * Add for ViT * Add to SPECIAL_MODULE_TO_TEST_MAP * style and quality * Add feature-extraction * update * raise instead of skip * add tiny_model_summary.json * more explicit * skip tasks not in mapping * add availability check * Add Copyright * A way to diable irrelevant tests * update with main * remove disable_irrelevant_tests * skip tests * better skip message * better skip message * Add all pipeline task tests * revert * Import PipelineTesterMixin * subclass test classes with PipelineTesterMixin * Add pipieline_model_mapping * Fix import after adding pipieline_model_mapping * Fix style and quality after adding pipieline_model_mapping * Fix one more import after adding pipieline_model_mapping * Fix style and quality after adding pipieline_model_mapping * Fix test issues * Fix import requirements * Fix mapping for MobileViTModelTest * Update * Better skip message * pipieline_model_mapping could not be None * Remove some PipelineTesterMixin * Fix typo * revert tests_fetcher.py * update * rename * revert * Remove PipelineTestCaseMeta from ZeroShotAudioClassificationPipelineTests * style and quality * test fetcher for all pipeline/model tests --------- Co-authored-by: ydshieh --- tests/models/albert/test_modeling_albert.py | 15 +- .../models/albert/test_modeling_tf_albert.py | 15 +- tests/models/altclip/test_modeling_altclip.py | 4 +- ..._modeling_audio_spectrogram_transformer.py | 8 +- tests/models/bart/test_modeling_bart.py | 18 +- tests/models/bart/test_modeling_tf_bart.py | 15 +- tests/models/beit/test_modeling_beit.py | 12 +- tests/models/bert/test_modeling_bert.py | 16 +- tests/models/bert/test_modeling_tf_bert.py | 16 +- .../test_modeling_bert_generation.py | 8 +- .../models/big_bird/test_modeling_big_bird.py | 16 +- .../test_modeling_bigbird_pegasus.py | 17 +- tests/models/biogpt/test_modeling_biogpt.py | 6 +- tests/models/bit/test_modeling_bit.py | 8 +- .../blenderbot/test_modeling_blenderbot.py | 14 +- .../blenderbot/test_modeling_tf_blenderbot.py | 13 +- .../test_modeling_blenderbot_small.py | 14 +- .../test_modeling_tf_blenderbot_small.py | 13 +- tests/models/blip/test_modeling_blip.py | 4 +- tests/models/bloom/test_modeling_bloom.py | 15 +- .../bridgetower/test_modeling_bridgetower.py | 4 +- tests/models/canine/test_modeling_canine.py | 14 +- .../test_modeling_chinese_clip.py | 4 +- tests/models/clap/test_modeling_clap.py | 4 +- tests/models/clip/test_modeling_clip.py | 4 +- tests/models/clip/test_modeling_tf_clip.py | 4 +- tests/models/clipseg/test_modeling_clipseg.py | 4 +- tests/models/codegen/test_modeling_codegen.py | 6 +- .../test_modeling_conditional_detr.py | 8 +- .../models/convbert/test_modeling_convbert.py | 15 +- .../convbert/test_modeling_tf_convbert.py | 15 +- .../models/convnext/test_modeling_convnext.py | 8 +- .../convnext/test_modeling_tf_convnext.py | 8 +- tests/models/ctrl/test_modeling_ctrl.py | 13 +- tests/models/ctrl/test_modeling_tf_ctrl.py | 13 +- tests/models/cvt/test_modeling_cvt.py | 8 +- tests/models/cvt/test_modeling_tf_cvt.py | 8 +- .../data2vec/test_modeling_data2vec_audio.py | 12 +- .../data2vec/test_modeling_data2vec_text.py | 16 +- .../data2vec/test_modeling_data2vec_vision.py | 12 +- .../test_modeling_tf_data2vec_vision.py | 8 +- tests/models/deberta/test_modeling_deberta.py | 15 +- .../deberta/test_modeling_tf_deberta.py | 15 +- .../deberta_v2/test_modeling_deberta_v2.py | 15 +- .../deberta_v2/test_modeling_tf_deberta_v2.py | 15 +- .../test_modeling_decision_transformer.py | 4 +- .../test_modeling_deformable_detr.py | 8 +- tests/models/deit/test_modeling_deit.py | 11 +- tests/models/deit/test_modeling_tf_deit.py | 11 +- tests/models/deta/test_modeling_deta.py | 8 +- tests/models/detr/test_modeling_detr.py | 12 +- tests/models/dinat/test_modeling_dinat.py | 8 +- .../distilbert/test_modeling_distilbert.py | 15 +- .../distilbert/test_modeling_tf_distilbert.py | 15 +- .../models/donut/test_modeling_donut_swin.py | 4 +- tests/models/dpr/test_modeling_dpr.py | 4 +- tests/models/dpr/test_modeling_tf_dpr.py | 4 +- tests/models/dpt/test_modeling_dpt.py | 12 +- tests/models/dpt/test_modeling_dpt_hybrid.py | 12 +- .../test_modeling_efficientformer.py | 14 +- tests/models/electra/test_modeling_electra.py | 16 +- .../electra/test_modeling_tf_electra.py | 15 +- tests/models/ernie/test_modeling_ernie.py | 16 +- tests/models/ernie_m/test_modeling_ernie_m.py | 14 +- tests/models/esm/test_modeling_esm.py | 14 +- tests/models/esm/test_modeling_esmfold.py | 4 +- tests/models/esm/test_modeling_tf_esm.py | 14 +- .../models/flaubert/test_modeling_flaubert.py | 15 +- .../flaubert/test_modeling_tf_flaubert.py | 15 +- tests/models/flava/test_modeling_flava.py | 4 +- tests/models/fnet/test_modeling_fnet.py | 15 +- tests/models/fsmt/test_modeling_fsmt.py | 13 +- tests/models/funnel/test_modeling_funnel.py | 15 +- .../models/funnel/test_modeling_tf_funnel.py | 15 +- tests/models/git/test_modeling_git.py | 6 +- tests/models/glpn/test_modeling_glpn.py | 6 +- tests/models/gpt2/test_modeling_gpt2.py | 14 +- tests/models/gpt2/test_modeling_tf_gpt2.py | 13 +- tests/models/gpt_neo/test_modeling_gpt_neo.py | 13 +- .../models/gpt_neox/test_modeling_gpt_neox.py | 6 +- .../test_modeling_gpt_neox_japanese.py | 8 +- tests/models/gptj/test_modeling_gptj.py | 14 +- tests/models/gptj/test_modeling_tf_gptj.py | 14 +- .../graphormer/test_modeling_graphormer.py | 4 +- .../models/groupvit/test_modeling_groupvit.py | 4 +- .../groupvit/test_modeling_tf_groupvit.py | 4 +- tests/models/hubert/test_modeling_hubert.py | 12 +- .../models/hubert/test_modeling_tf_hubert.py | 4 +- tests/models/ibert/test_modeling_ibert.py | 15 +- .../models/imagegpt/test_modeling_imagegpt.py | 8 +- .../models/layoutlm/test_modeling_layoutlm.py | 15 +- .../layoutlm/test_modeling_tf_layoutlm.py | 14 +- .../layoutlmv2/test_modeling_layoutlmv2.py | 15 +- .../layoutlmv3/test_modeling_layoutlmv3.py | 15 +- .../layoutlmv3/test_modeling_tf_layoutlmv3.py | 14 +- tests/models/led/test_modeling_led.py | 16 +- tests/models/led/test_modeling_tf_led.py | 13 +- tests/models/levit/test_modeling_levit.py | 11 +- tests/models/lilt/test_modeling_lilt.py | 14 +- .../longformer/test_modeling_longformer.py | 15 +- .../longformer/test_modeling_tf_longformer.py | 15 +- tests/models/longt5/test_modeling_longt5.py | 13 +- tests/models/luke/test_modeling_luke.py | 15 +- tests/models/lxmert/test_modeling_lxmert.py | 8 +- .../models/lxmert/test_modeling_tf_lxmert.py | 4 +- tests/models/m2m_100/test_modeling_m2m_100.py | 13 +- tests/models/marian/test_modeling_marian.py | 14 +- .../models/marian/test_modeling_tf_marian.py | 13 +- .../models/markuplm/test_modeling_markuplm.py | 14 +- .../mask2former/test_modeling_mask2former.py | 4 +- .../maskformer/test_modeling_maskformer.py | 8 +- .../test_modeling_maskformer_swin.py | 4 +- tests/models/mbart/test_modeling_mbart.py | 18 +- tests/models/mbart/test_modeling_tf_mbart.py | 13 +- tests/models/mctct/test_modeling_mctct.py | 6 +- .../test_modeling_megatron_bert.py | 16 +- .../mobilebert/test_modeling_mobilebert.py | 15 +- .../mobilebert/test_modeling_tf_mobilebert.py | 15 +- .../test_modeling_mobilenet_v1.py | 8 +- .../test_modeling_mobilenet_v2.py | 12 +- .../mobilevit/test_modeling_mobilevit.py | 12 +- .../mobilevit/test_modeling_tf_mobilevit.py | 8 +- tests/models/mpnet/test_modeling_mpnet.py | 15 +- tests/models/mpnet/test_modeling_tf_mpnet.py | 15 +- tests/models/mvp/test_modeling_mvp.py | 18 +- tests/models/nat/test_modeling_nat.py | 8 +- tests/models/nezha/test_modeling_nezha.py | 15 +- .../test_modeling_nystromformer.py | 15 +- .../oneformer/test_modeling_oneformer.py | 4 +- tests/models/openai/test_modeling_openai.py | 13 +- .../models/openai/test_modeling_tf_openai.py | 13 +- tests/models/opt/test_modeling_opt.py | 14 +- tests/models/opt/test_modeling_tf_opt.py | 6 +- tests/models/owlvit/test_modeling_owlvit.py | 8 +- tests/models/pegasus/test_modeling_pegasus.py | 14 +- .../pegasus/test_modeling_tf_pegasus.py | 13 +- .../pegasus_x/test_modeling_pegasus_x.py | 13 +- .../perceiver/test_modeling_perceiver.py | 18 +- tests/models/plbart/test_modeling_plbart.py | 16 +- .../poolformer/test_modeling_poolformer.py | 8 +- .../prophetnet/test_modeling_prophetnet.py | 14 +- tests/models/qdqbert/test_modeling_qdqbert.py | 16 +- tests/models/realm/test_modeling_realm.py | 4 +- .../models/reformer/test_modeling_reformer.py | 17 +- tests/models/regnet/test_modeling_regnet.py | 8 +- .../models/regnet/test_modeling_tf_regnet.py | 8 +- tests/models/rembert/test_modeling_rembert.py | 16 +- .../rembert/test_modeling_tf_rembert.py | 16 +- tests/models/resnet/test_modeling_resnet.py | 8 +- .../models/resnet/test_modeling_tf_resnet.py | 8 +- tests/models/roberta/test_modeling_roberta.py | 16 +- .../roberta/test_modeling_tf_roberta.py | 16 +- .../test_modeling_roberta_prelayernorm.py | 16 +- .../test_modeling_tf_roberta_prelayernorm.py | 16 +- .../models/roc_bert/test_modeling_roc_bert.py | 16 +- .../models/roformer/test_modeling_roformer.py | 16 +- .../roformer/test_modeling_tf_roformer.py | 16 +- .../segformer/test_modeling_segformer.py | 12 +- .../segformer/test_modeling_tf_segformer.py | 8 +- tests/models/sew/test_modeling_sew.py | 12 +- tests/models/sew_d/test_modeling_sew_d.py | 12 +- .../test_modeling_speech_to_text.py | 8 +- .../test_modeling_tf_speech_to_text.py | 4 +- .../test_modeling_speech_to_text_2.py | 6 +- .../models/speecht5/test_modeling_speecht5.py | 8 +- .../models/splinter/test_modeling_splinter.py | 8 +- .../squeezebert/test_modeling_squeezebert.py | 15 +- tests/models/swin/test_modeling_swin.py | 8 +- tests/models/swin/test_modeling_tf_swin.py | 8 +- tests/models/swin2sr/test_modeling_swin2sr.py | 4 +- tests/models/swinv2/test_modeling_swinv2.py | 8 +- .../test_modeling_switch_transformers.py | 13 +- tests/models/t5/test_modeling_t5.py | 13 +- tests/models/t5/test_modeling_tf_t5.py | 13 +- .../test_modeling_table_transformer.py | 8 +- tests/models/tapas/test_modeling_tapas.py | 14 +- tests/models/tapas/test_modeling_tf_tapas.py | 13 +- .../test_modeling_time_series_transformer.py | 4 +- .../timesformer/test_modeling_timesformer.py | 8 +- .../test_modeling_trajectory_transformer.py | 4 +- .../transfo_xl/test_modeling_tf_transfo_xl.py | 13 +- .../transfo_xl/test_modeling_transfo_xl.py | 13 +- tests/models/trocr/test_modeling_trocr.py | 4 +- tests/models/tvlt/test_modeling_tvlt.py | 4 +- .../unispeech/test_modeling_unispeech.py | 12 +- .../test_modeling_unispeech_sat.py | 12 +- tests/models/upernet/test_modeling_upernet.py | 4 +- tests/models/van/test_modeling_van.py | 8 +- .../models/videomae/test_modeling_videomae.py | 8 +- tests/models/vilt/test_modeling_vilt.py | 8 +- .../visual_bert/test_modeling_visual_bert.py | 4 +- tests/models/vit/test_modeling_tf_vit.py | 8 +- tests/models/vit/test_modeling_vit.py | 8 +- .../vit_hybrid/test_modeling_vit_hybrid.py | 8 +- .../vit_mae/test_modeling_tf_vit_mae.py | 4 +- tests/models/vit_mae/test_modeling_vit_mae.py | 4 +- tests/models/vit_msn/test_modeling_vit_msn.py | 8 +- .../wav2vec2/test_modeling_tf_wav2vec2.py | 4 +- .../models/wav2vec2/test_modeling_wav2vec2.py | 13 +- .../test_modeling_wav2vec2_conformer.py | 12 +- tests/models/wavlm/test_modeling_wavlm.py | 12 +- .../whisper/test_modeling_tf_whisper.py | 4 +- tests/models/whisper/test_modeling_whisper.py | 8 +- tests/models/x_clip/test_modeling_x_clip.py | 4 +- tests/models/xglm/test_modeling_tf_xglm.py | 6 +- tests/models/xglm/test_modeling_xglm.py | 6 +- tests/models/xlm/test_modeling_tf_xlm.py | 16 +- tests/models/xlm/test_modeling_xlm.py | 16 +- .../test_modeling_xlm_roberta_xl.py | 16 +- tests/models/xlnet/test_modeling_tf_xlnet.py | 15 +- tests/models/xlnet/test_modeling_xlnet.py | 15 +- tests/models/xmod/test_modeling_xmod.py | 16 +- tests/models/yolos/test_modeling_yolos.py | 6 +- tests/models/yoso/test_modeling_yoso.py | 15 +- .../test_pipelines_audio_classification.py | 4 +- ..._pipelines_automatic_speech_recognition.py | 4 +- tests/pipelines/test_pipelines_common.py | 254 -- .../test_pipelines_conversational.py | 4 +- .../test_pipelines_depth_estimation.py | 4 +- ...t_pipelines_document_question_answering.py | 4 +- .../test_pipelines_feature_extraction.py | 4 +- tests/pipelines/test_pipelines_fill_mask.py | 4 +- .../test_pipelines_image_classification.py | 4 +- .../test_pipelines_image_segmentation.py | 4 +- .../pipelines/test_pipelines_image_to_text.py | 4 +- .../test_pipelines_object_detection.py | 4 +- .../test_pipelines_question_answering.py | 4 +- .../pipelines/test_pipelines_summarization.py | 4 +- ...test_pipelines_table_question_answering.py | 4 +- .../test_pipelines_text2text_generation.py | 4 +- .../test_pipelines_text_classification.py | 4 +- .../test_pipelines_text_generation.py | 4 +- .../test_pipelines_token_classification.py | 4 +- tests/pipelines/test_pipelines_translation.py | 4 +- .../test_pipelines_video_classification.py | 4 +- ...est_pipelines_visual_question_answering.py | 4 +- tests/pipelines/test_pipelines_zero_shot.py | 4 +- ...ipelines_zero_shot_audio_classification.py | 4 +- ...ipelines_zero_shot_image_classification.py | 4 +- ...st_pipelines_zero_shot_object_detection.py | 4 +- tests/test_pipeline_mixin.py | 513 +++ tests/utils/tiny_model_summary.json | 3181 +++++++++++++++++ utils/tests_fetcher.py | 11 +- 243 files changed, 5871 insertions(+), 523 deletions(-) create mode 100644 tests/test_pipeline_mixin.py create mode 100644 tests/utils/tiny_model_summary.json diff --git a/tests/models/albert/test_modeling_albert.py b/tests/models/albert/test_modeling_albert.py index 9cd62918db..96fa5596a2 100644 --- a/tests/models/albert/test_modeling_albert.py +++ b/tests/models/albert/test_modeling_albert.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -239,7 +240,7 @@ class AlbertModelTester: @require_torch -class AlbertModelTest(ModelTesterMixin, unittest.TestCase): +class AlbertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( AlbertModel, @@ -253,6 +254,18 @@ class AlbertModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": AlbertModel, + "fill-mask": AlbertForMaskedLM, + "question-answering": AlbertForQuestionAnswering, + "text-classification": AlbertForSequenceClassification, + "token-classification": AlbertForTokenClassification, + "zero-shot": AlbertForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = True # special case for ForPreTraining model diff --git a/tests/models/albert/test_modeling_tf_albert.py b/tests/models/albert/test_modeling_tf_albert.py index 873116c0d3..104fb09252 100644 --- a/tests/models/albert/test_modeling_tf_albert.py +++ b/tests/models/albert/test_modeling_tf_albert.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -227,7 +228,7 @@ class TFAlbertModelTester: @require_tf -class TFAlbertModelTest(TFModelTesterMixin, unittest.TestCase): +class TFAlbertModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFAlbertModel, @@ -241,6 +242,18 @@ class TFAlbertModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFAlbertModel, + "fill-mask": TFAlbertForMaskedLM, + "question-answering": TFAlbertForQuestionAnswering, + "text-classification": TFAlbertForSequenceClassification, + "token-classification": TFAlbertForTokenClassification, + "zero-shot": TFAlbertForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/altclip/test_modeling_altclip.py b/tests/models/altclip/test_modeling_altclip.py index ff39329d84..a032ec1cee 100755 --- a/tests/models/altclip/test_modeling_altclip.py +++ b/tests/models/altclip/test_modeling_altclip.py @@ -35,6 +35,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -392,8 +393,9 @@ def prepare_img(): @require_torch -class AltCLIPModelTest(ModelTesterMixin, unittest.TestCase): +class AltCLIPModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (AltCLIPModel,) if is_torch_available() else () + pipeline_model_mapping = {"feature-extraction": AltCLIPModel} if is_torch_available() else {} fx_compatible = True test_head_masking = False test_pruning = False diff --git a/tests/models/audio_spectrogram_transformer/test_modeling_audio_spectrogram_transformer.py b/tests/models/audio_spectrogram_transformer/test_modeling_audio_spectrogram_transformer.py index b0d3140de5..9b7238156e 100644 --- a/tests/models/audio_spectrogram_transformer/test_modeling_audio_spectrogram_transformer.py +++ b/tests/models/audio_spectrogram_transformer/test_modeling_audio_spectrogram_transformer.py @@ -25,6 +25,7 @@ from transformers.utils import cached_property, is_torch_available, is_torchaudi from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -140,7 +141,7 @@ class ASTModelTester: @require_torch -class ASTModelTest(ModelTesterMixin, unittest.TestCase): +class ASTModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as AST does not use input_ids, inputs_embeds, attention_mask and seq_length. @@ -154,6 +155,11 @@ class ASTModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + {"audio-classification": ASTForAudioClassification, "feature-extraction": ASTModel} + if is_torch_available() + else {} + ) fx_compatible = False test_pruning = False test_resize_embeddings = False diff --git a/tests/models/bart/test_modeling_bart.py b/tests/models/bart/test_modeling_bart.py index e1e525be3d..d5c2094c15 100644 --- a/tests/models/bart/test_modeling_bart.py +++ b/tests/models/bart/test_modeling_bart.py @@ -28,6 +28,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -414,13 +415,28 @@ class BartHeadTests(unittest.TestCase): @require_torch -class BartModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class BartModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (BartModel, BartForConditionalGeneration, BartForSequenceClassification, BartForQuestionAnswering) if is_torch_available() else () ) all_generative_model_classes = (BartForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": BartForConditionalGeneration, + "feature-extraction": BartModel, + "fill-mask": BartForConditionalGeneration, + "question-answering": BartForQuestionAnswering, + "summarization": BartForConditionalGeneration, + "text2text-generation": BartForConditionalGeneration, + "text-classification": BartForSequenceClassification, + "text-generation": BartForCausalLM, + "zero-shot": BartForSequenceClassification, + } + if is_torch_available() + else {} + ) is_encoder_decoder = True fx_compatible = False # Fix me Michael test_pruning = False diff --git a/tests/models/bart/test_modeling_tf_bart.py b/tests/models/bart/test_modeling_tf_bart.py index 1b3682a761..f827503d0b 100644 --- a/tests/models/bart/test_modeling_tf_bart.py +++ b/tests/models/bart/test_modeling_tf_bart.py @@ -25,6 +25,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin from ...utils.test_modeling_tf_core import TFCoreModelTesterMixin @@ -188,11 +189,23 @@ def prepare_bart_inputs_dict( @require_tf -class TFBartModelTest(TFModelTesterMixin, TFCoreModelTesterMixin, unittest.TestCase): +class TFBartModelTest(TFModelTesterMixin, TFCoreModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (TFBartForConditionalGeneration, TFBartForSequenceClassification, TFBartModel) if is_tf_available() else () ) all_generative_model_classes = (TFBartForConditionalGeneration,) if is_tf_available() else () + pipeline_model_mapping = ( + { + "conversational": TFBartForConditionalGeneration, + "feature-extraction": TFBartModel, + "summarization": TFBartForConditionalGeneration, + "text2text-generation": TFBartForConditionalGeneration, + "text-classification": TFBartForSequenceClassification, + "zero-shot": TFBartForSequenceClassification, + } + if is_tf_available() + else {} + ) is_encoder_decoder = True test_pruning = False test_onnx = True diff --git a/tests/models/beit/test_modeling_beit.py b/tests/models/beit/test_modeling_beit.py index 377ed8e8e9..f9aa7339f7 100644 --- a/tests/models/beit/test_modeling_beit.py +++ b/tests/models/beit/test_modeling_beit.py @@ -28,6 +28,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -185,7 +186,7 @@ class BeitModelTester: @require_torch -class BeitModelTest(ModelTesterMixin, unittest.TestCase): +class BeitModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as BEiT does not use input_ids, inputs_embeds, attention_mask and seq_length. @@ -196,6 +197,15 @@ class BeitModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": BeitModel, + "image-classification": BeitForImageClassification, + "image-segmentation": BeitForSemanticSegmentation, + } + if is_torch_available() + else {} + ) test_pruning = False test_resize_embeddings = False diff --git a/tests/models/bert/test_modeling_bert.py b/tests/models/bert/test_modeling_bert.py index 8873ccb613..efd5409020 100644 --- a/tests/models/bert/test_modeling_bert.py +++ b/tests/models/bert/test_modeling_bert.py @@ -23,6 +23,7 @@ from transformers.testing_utils import require_torch, require_torch_gpu, slow, t from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -426,7 +427,7 @@ class BertModelTester: @require_torch -class BertModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class BertModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( BertModel, @@ -443,6 +444,19 @@ class BertModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): else () ) all_generative_model_classes = (BertLMHeadModel,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": BertModel, + "fill-mask": BertForMaskedLM, + "question-answering": BertForQuestionAnswering, + "text-classification": BertForSequenceClassification, + "text-generation": BertLMHeadModel, + "token-classification": BertForTokenClassification, + "zero-shot": BertForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = True # special case for ForPreTraining model diff --git a/tests/models/bert/test_modeling_tf_bert.py b/tests/models/bert/test_modeling_tf_bert.py index 86c42c3233..59521acec3 100644 --- a/tests/models/bert/test_modeling_tf_bert.py +++ b/tests/models/bert/test_modeling_tf_bert.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin from ...utils.test_modeling_tf_core import TFCoreModelTesterMixin @@ -590,7 +591,7 @@ class TFBertModelTester: @require_tf -class TFBertModelTest(TFModelTesterMixin, TFCoreModelTesterMixin, unittest.TestCase): +class TFBertModelTest(TFModelTesterMixin, TFCoreModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFBertModel, @@ -606,6 +607,19 @@ class TFBertModelTest(TFModelTesterMixin, TFCoreModelTesterMixin, unittest.TestC if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFBertModel, + "fill-mask": TFBertForMaskedLM, + "question-answering": TFBertForQuestionAnswering, + "text-classification": TFBertForSequenceClassification, + "text-generation": TFBertLMHeadModel, + "token-classification": TFBertForTokenClassification, + "zero-shot": TFBertForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = True onnx_min_opset = 10 diff --git a/tests/models/bert_generation/test_modeling_bert_generation.py b/tests/models/bert_generation/test_modeling_bert_generation.py index b2a6b5060b..ced98e6f72 100644 --- a/tests/models/bert_generation/test_modeling_bert_generation.py +++ b/tests/models/bert_generation/test_modeling_bert_generation.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -240,9 +241,14 @@ class BertGenerationEncoderTester: @require_torch -class BertGenerationEncoderTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class BertGenerationEncoderTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (BertGenerationEncoder, BertGenerationDecoder) if is_torch_available() else () all_generative_model_classes = (BertGenerationDecoder,) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": BertGenerationEncoder, "text-generation": BertGenerationDecoder} + if is_torch_available() + else {} + ) def setUp(self): self.model_tester = BertGenerationEncoderTester(self) diff --git a/tests/models/big_bird/test_modeling_big_bird.py b/tests/models/big_bird/test_modeling_big_bird.py index 8859db16ec..b552473ec4 100644 --- a/tests/models/big_bird/test_modeling_big_bird.py +++ b/tests/models/big_bird/test_modeling_big_bird.py @@ -24,6 +24,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -429,7 +430,7 @@ class BigBirdModelTester: @require_torch -class BigBirdModelTest(ModelTesterMixin, unittest.TestCase): +class BigBirdModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): # head masking & pruning is currently not supported for big bird test_head_masking = False test_pruning = False @@ -453,6 +454,19 @@ class BigBirdModelTest(ModelTesterMixin, unittest.TestCase): else () ) all_generative_model_classes = (BigBirdForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": BigBirdModel, + "fill-mask": BigBirdForMaskedLM, + "question-answering": BigBirdForQuestionAnswering, + "text-classification": BigBirdForSequenceClassification, + "text-generation": BigBirdForCausalLM, + "token-classification": BigBirdForTokenClassification, + "zero-shot": BigBirdForSequenceClassification, + } + if is_torch_available() + else {} + ) # special case for ForPreTraining model def _prepare_for_class(self, inputs_dict, model_class, return_labels=False): diff --git a/tests/models/bigbird_pegasus/test_modeling_bigbird_pegasus.py b/tests/models/bigbird_pegasus/test_modeling_bigbird_pegasus.py index b8ae01e398..d7a8e6302d 100644 --- a/tests/models/bigbird_pegasus/test_modeling_bigbird_pegasus.py +++ b/tests/models/bigbird_pegasus/test_modeling_bigbird_pegasus.py @@ -25,6 +25,7 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -232,7 +233,7 @@ class BigBirdPegasusModelTester: @require_torch -class BigBirdPegasusModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class BigBirdPegasusModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( BigBirdPegasusModel, @@ -244,6 +245,20 @@ class BigBirdPegasusModelTest(ModelTesterMixin, GenerationTesterMixin, unittest. else () ) all_generative_model_classes = (BigBirdPegasusForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": BigBirdPegasusForConditionalGeneration, + "feature-extraction": BigBirdPegasusModel, + "question-answering": BigBirdPegasusForQuestionAnswering, + "summarization": BigBirdPegasusForConditionalGeneration, + "text2text-generation": BigBirdPegasusForConditionalGeneration, + "text-classification": BigBirdPegasusForSequenceClassification, + "text-generation": BigBirdPegasusForCausalLM, + "zero-shot": BigBirdPegasusForSequenceClassification, + } + if is_torch_available() + else {} + ) is_encoder_decoder = True test_missing_keys = False test_pruning = False diff --git a/tests/models/biogpt/test_modeling_biogpt.py b/tests/models/biogpt/test_modeling_biogpt.py index 14d4900a50..ce6464b660 100644 --- a/tests/models/biogpt/test_modeling_biogpt.py +++ b/tests/models/biogpt/test_modeling_biogpt.py @@ -23,6 +23,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -262,9 +263,12 @@ class BioGptModelTester: @require_torch -class BioGptModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class BioGptModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (BioGptModel, BioGptForCausalLM) if is_torch_available() else () all_generative_model_classes = (BioGptForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": BioGptModel, "text-generation": BioGptForCausalLM} if is_torch_available() else {} + ) test_pruning = False def setUp(self): diff --git a/tests/models/bit/test_modeling_bit.py b/tests/models/bit/test_modeling_bit.py index 7b7e07cb8f..ef7a6dbb27 100644 --- a/tests/models/bit/test_modeling_bit.py +++ b/tests/models/bit/test_modeling_bit.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -150,13 +151,18 @@ class BitModelTester: @require_torch -class BitModelTest(ModelTesterMixin, unittest.TestCase): +class BitModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as Bit does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (BitModel, BitForImageClassification, BitBackbone) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": BitModel, "image-classification": BitForImageClassification} + if is_torch_available() + else {} + ) fx_compatible = False test_pruning = False diff --git a/tests/models/blenderbot/test_modeling_blenderbot.py b/tests/models/blenderbot/test_modeling_blenderbot.py index 1cc5377cf2..c4b85c8a46 100644 --- a/tests/models/blenderbot/test_modeling_blenderbot.py +++ b/tests/models/blenderbot/test_modeling_blenderbot.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -223,9 +224,20 @@ class BlenderbotModelTester: @require_torch -class BlenderbotModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class BlenderbotModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (BlenderbotModel, BlenderbotForConditionalGeneration) if is_torch_available() else () all_generative_model_classes = (BlenderbotForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": BlenderbotForConditionalGeneration, + "feature-extraction": BlenderbotModel, + "summarization": BlenderbotForConditionalGeneration, + "text2text-generation": BlenderbotForConditionalGeneration, + "text-generation": BlenderbotForCausalLM, + } + if is_torch_available() + else {} + ) is_encoder_decoder = True fx_compatible = True test_pruning = False diff --git a/tests/models/blenderbot/test_modeling_tf_blenderbot.py b/tests/models/blenderbot/test_modeling_tf_blenderbot.py index f08c01ab0f..e6b485346a 100644 --- a/tests/models/blenderbot/test_modeling_tf_blenderbot.py +++ b/tests/models/blenderbot/test_modeling_tf_blenderbot.py @@ -22,6 +22,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -175,9 +176,19 @@ def prepare_blenderbot_inputs_dict( @require_tf -class TFBlenderbotModelTest(TFModelTesterMixin, unittest.TestCase): +class TFBlenderbotModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TFBlenderbotForConditionalGeneration, TFBlenderbotModel) if is_tf_available() else () all_generative_model_classes = (TFBlenderbotForConditionalGeneration,) if is_tf_available() else () + pipeline_model_mapping = ( + { + "conversational": TFBlenderbotForConditionalGeneration, + "feature-extraction": TFBlenderbotModel, + "summarization": TFBlenderbotForConditionalGeneration, + "text2text-generation": TFBlenderbotForConditionalGeneration, + } + if is_tf_available() + else {} + ) is_encoder_decoder = True test_pruning = False test_onnx = False diff --git a/tests/models/blenderbot_small/test_modeling_blenderbot_small.py b/tests/models/blenderbot_small/test_modeling_blenderbot_small.py index 5252b9cb98..71481b3428 100644 --- a/tests/models/blenderbot_small/test_modeling_blenderbot_small.py +++ b/tests/models/blenderbot_small/test_modeling_blenderbot_small.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -217,9 +218,20 @@ class BlenderbotSmallModelTester: @require_torch -class BlenderbotSmallModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class BlenderbotSmallModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (BlenderbotSmallModel, BlenderbotSmallForConditionalGeneration) if is_torch_available() else () all_generative_model_classes = (BlenderbotSmallForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": BlenderbotSmallForConditionalGeneration, + "feature-extraction": BlenderbotSmallModel, + "summarization": BlenderbotSmallForConditionalGeneration, + "text2text-generation": BlenderbotSmallForConditionalGeneration, + "text-generation": BlenderbotSmallForCausalLM, + } + if is_torch_available() + else {} + ) is_encoder_decoder = True fx_compatible = True test_pruning = False diff --git a/tests/models/blenderbot_small/test_modeling_tf_blenderbot_small.py b/tests/models/blenderbot_small/test_modeling_tf_blenderbot_small.py index 9dbefa23b5..057901f500 100644 --- a/tests/models/blenderbot_small/test_modeling_tf_blenderbot_small.py +++ b/tests/models/blenderbot_small/test_modeling_tf_blenderbot_small.py @@ -22,6 +22,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -175,11 +176,21 @@ def prepare_blenderbot_small_inputs_dict( @require_tf -class TFBlenderbotSmallModelTest(TFModelTesterMixin, unittest.TestCase): +class TFBlenderbotSmallModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (TFBlenderbotSmallForConditionalGeneration, TFBlenderbotSmallModel) if is_tf_available() else () ) all_generative_model_classes = (TFBlenderbotSmallForConditionalGeneration,) if is_tf_available() else () + pipeline_model_mapping = ( + { + "conversational": TFBlenderbotSmallForConditionalGeneration, + "feature-extraction": TFBlenderbotSmallModel, + "summarization": TFBlenderbotSmallForConditionalGeneration, + "text2text-generation": TFBlenderbotSmallForConditionalGeneration, + } + if is_tf_available() + else {} + ) is_encoder_decoder = True test_pruning = False test_onnx = False diff --git a/tests/models/blip/test_modeling_blip.py b/tests/models/blip/test_modeling_blip.py index 9a3dd0e96e..cc5915a73b 100644 --- a/tests/models/blip/test_modeling_blip.py +++ b/tests/models/blip/test_modeling_blip.py @@ -35,6 +35,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -391,8 +392,9 @@ class BlipModelTester: @require_torch -class BlipModelTest(ModelTesterMixin, unittest.TestCase): +class BlipModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (BlipModel,) if is_torch_available() else () + pipeline_model_mapping = {"feature-extraction": BlipModel} if is_torch_available() else {} fx_compatible = False test_head_masking = False test_pruning = False diff --git a/tests/models/bloom/test_modeling_bloom.py b/tests/models/bloom/test_modeling_bloom.py index 85e6312e72..9dc803a3ba 100644 --- a/tests/models/bloom/test_modeling_bloom.py +++ b/tests/models/bloom/test_modeling_bloom.py @@ -23,6 +23,7 @@ from transformers.testing_utils import require_torch, require_torch_gpu, slow, t from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -319,7 +320,7 @@ class BloomModelTester: @require_torch -class BloomModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class BloomModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( BloomModel, @@ -333,6 +334,18 @@ class BloomModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase) ) all_generative_model_classes = (BloomForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": BloomModel, + "question-answering": BloomForQuestionAnswering, + "text-classification": BloomForSequenceClassification, + "text-generation": BloomForCausalLM, + "token-classification": BloomForTokenClassification, + "zero-shot": BloomForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = True test_missing_keys = False test_pruning = False diff --git a/tests/models/bridgetower/test_modeling_bridgetower.py b/tests/models/bridgetower/test_modeling_bridgetower.py index 7405293a1c..afe3febb69 100644 --- a/tests/models/bridgetower/test_modeling_bridgetower.py +++ b/tests/models/bridgetower/test_modeling_bridgetower.py @@ -25,6 +25,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -186,10 +187,11 @@ class BridgeTowerModelTester: @require_torch @unittest.skipIf(not is_torch_greater_or_equal_than_1_10, "BridgeTower is only available in torch v1.10+") -class BridgeTowerModelTest(ModelTesterMixin, unittest.TestCase): +class BridgeTowerModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (BridgeTowerModel, BridgeTowerForImageAndTextRetrieval, BridgeTowerForMaskedLM) if is_torch_available() else () ) + pipeline_model_mapping = {"feature-extraction": BridgeTowerModel} if is_torch_available() else {} is_training = False test_headmasking = False diff --git a/tests/models/canine/test_modeling_canine.py b/tests/models/canine/test_modeling_canine.py index 92f27047a9..d612a02bf4 100644 --- a/tests/models/canine/test_modeling_canine.py +++ b/tests/models/canine/test_modeling_canine.py @@ -23,6 +23,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, global_rng, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -207,7 +208,7 @@ class CanineModelTester: @require_torch -class CanineModelTest(ModelTesterMixin, unittest.TestCase): +class CanineModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( CanineModel, @@ -219,6 +220,17 @@ class CanineModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": CanineModel, + "question-answering": CanineForQuestionAnswering, + "text-classification": CanineForSequenceClassification, + "token-classification": CanineForTokenClassification, + "zero-shot": CanineForSequenceClassification, + } + if is_torch_available() + else {} + ) test_mismatched_shapes = False test_resize_embeddings = False diff --git a/tests/models/chinese_clip/test_modeling_chinese_clip.py b/tests/models/chinese_clip/test_modeling_chinese_clip.py index 637984264e..57f532da86 100644 --- a/tests/models/chinese_clip/test_modeling_chinese_clip.py +++ b/tests/models/chinese_clip/test_modeling_chinese_clip.py @@ -35,6 +35,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -533,8 +534,9 @@ class ChineseCLIPModelTester: @require_torch -class ChineseCLIPModelTest(ModelTesterMixin, unittest.TestCase): +class ChineseCLIPModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (ChineseCLIPModel,) if is_torch_available() else () + pipeline_model_mapping = {"feature-extraction": ChineseCLIPModel} if is_torch_available() else {} fx_compatible = False test_head_masking = False test_pruning = False diff --git a/tests/models/clap/test_modeling_clap.py b/tests/models/clap/test_modeling_clap.py index 8f6433ff25..ebe6ec720c 100644 --- a/tests/models/clap/test_modeling_clap.py +++ b/tests/models/clap/test_modeling_clap.py @@ -35,6 +35,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -477,8 +478,9 @@ class ClapModelTester: @require_torch -class ClapModelTest(ModelTesterMixin, unittest.TestCase): +class ClapModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (ClapModel,) if is_torch_available() else () + pipeline_model_mapping = {"feature-extraction": ClapModel} if is_torch_available() else {} fx_compatible = False test_head_masking = False test_pruning = False diff --git a/tests/models/clip/test_modeling_clip.py b/tests/models/clip/test_modeling_clip.py index 2e80df6c27..d16241ab2f 100644 --- a/tests/models/clip/test_modeling_clip.py +++ b/tests/models/clip/test_modeling_clip.py @@ -43,6 +43,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -449,8 +450,9 @@ class CLIPModelTester: @require_torch -class CLIPModelTest(ModelTesterMixin, unittest.TestCase): +class CLIPModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (CLIPModel,) if is_torch_available() else () + pipeline_model_mapping = {"feature-extraction": CLIPModel} if is_torch_available() else {} fx_compatible = True test_head_masking = False test_pruning = False diff --git a/tests/models/clip/test_modeling_tf_clip.py b/tests/models/clip/test_modeling_tf_clip.py index cee1205db9..6cd20a47a7 100644 --- a/tests/models/clip/test_modeling_tf_clip.py +++ b/tests/models/clip/test_modeling_tf_clip.py @@ -29,6 +29,7 @@ from transformers.utils import is_tf_available, is_vision_available from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -515,8 +516,9 @@ class TFCLIPModelTester: @require_tf -class TFCLIPModelTest(TFModelTesterMixin, unittest.TestCase): +class TFCLIPModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TFCLIPModel,) if is_tf_available() else () + pipeline_model_mapping = {"feature-extraction": TFCLIPModel} if is_tf_available() else {} test_head_masking = False test_pruning = False test_resize_embeddings = False diff --git a/tests/models/clipseg/test_modeling_clipseg.py b/tests/models/clipseg/test_modeling_clipseg.py index 24a59e48dc..b54861d8d8 100644 --- a/tests/models/clipseg/test_modeling_clipseg.py +++ b/tests/models/clipseg/test_modeling_clipseg.py @@ -44,6 +44,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -412,8 +413,9 @@ class CLIPSegModelTester: @require_torch -class CLIPSegModelTest(ModelTesterMixin, unittest.TestCase): +class CLIPSegModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (CLIPSegModel, CLIPSegForImageSegmentation) if is_torch_available() else () + pipeline_model_mapping = {"feature-extraction": CLIPSegModel} if is_torch_available() else {} fx_compatible = False test_head_masking = False test_pruning = False diff --git a/tests/models/codegen/test_modeling_codegen.py b/tests/models/codegen/test_modeling_codegen.py index c5818d23ea..1b4cdca6c3 100644 --- a/tests/models/codegen/test_modeling_codegen.py +++ b/tests/models/codegen/test_modeling_codegen.py @@ -23,6 +23,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -348,9 +349,12 @@ class CodeGenModelTester: @require_torch -class CodeGenModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class CodeGenModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (CodeGenModel, CodeGenForCausalLM) if is_torch_available() else () all_generative_model_classes = (CodeGenForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": CodeGenModel, "text-generation": CodeGenForCausalLM} if is_torch_available() else {} + ) fx_compatible = False test_pruning = False test_missing_keys = False diff --git a/tests/models/conditional_detr/test_modeling_conditional_detr.py b/tests/models/conditional_detr/test_modeling_conditional_detr.py index 042fd37db4..8d62470fa3 100644 --- a/tests/models/conditional_detr/test_modeling_conditional_detr.py +++ b/tests/models/conditional_detr/test_modeling_conditional_detr.py @@ -26,6 +26,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_timm_available(): @@ -179,7 +180,7 @@ class ConditionalDetrModelTester: @require_timm -class ConditionalDetrModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class ConditionalDetrModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( ConditionalDetrModel, @@ -189,6 +190,11 @@ class ConditionalDetrModelTest(ModelTesterMixin, GenerationTesterMixin, unittest if is_timm_available() else () ) + pipeline_model_mapping = ( + {"feature-extraction": ConditionalDetrModel, "object-detection": ConditionalDetrForObjectDetection} + if is_timm_available() + else {} + ) is_encoder_decoder = True test_torchscript = False test_pruning = False diff --git a/tests/models/convbert/test_modeling_convbert.py b/tests/models/convbert/test_modeling_convbert.py index 28762ebcfb..98cd937763 100644 --- a/tests/models/convbert/test_modeling_convbert.py +++ b/tests/models/convbert/test_modeling_convbert.py @@ -23,6 +23,7 @@ from transformers.testing_utils import require_torch, require_torch_gpu, slow, t from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -245,7 +246,7 @@ class ConvBertModelTester: @require_torch -class ConvBertModelTest(ModelTesterMixin, unittest.TestCase): +class ConvBertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( ConvBertModel, @@ -258,6 +259,18 @@ class ConvBertModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": ConvBertModel, + "fill-mask": ConvBertForMaskedLM, + "question-answering": ConvBertForQuestionAnswering, + "text-classification": ConvBertForSequenceClassification, + "token-classification": ConvBertForTokenClassification, + "zero-shot": ConvBertForSequenceClassification, + } + if is_torch_available() + else {} + ) test_pruning = False test_head_masking = False diff --git a/tests/models/convbert/test_modeling_tf_convbert.py b/tests/models/convbert/test_modeling_tf_convbert.py index e9d8630a59..0c259110e7 100644 --- a/tests/models/convbert/test_modeling_tf_convbert.py +++ b/tests/models/convbert/test_modeling_tf_convbert.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -223,7 +224,7 @@ class TFConvBertModelTester: @require_tf -class TFConvBertModelTest(TFModelTesterMixin, unittest.TestCase): +class TFConvBertModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFConvBertModel, @@ -236,6 +237,18 @@ class TFConvBertModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFConvBertModel, + "fill-mask": TFConvBertForMaskedLM, + "question-answering": TFConvBertForQuestionAnswering, + "text-classification": TFConvBertForSequenceClassification, + "token-classification": TFConvBertForTokenClassification, + "zero-shot": TFConvBertForSequenceClassification, + } + if is_tf_available() + else {} + ) test_pruning = False test_head_masking = False test_onnx = False diff --git a/tests/models/convnext/test_modeling_convnext.py b/tests/models/convnext/test_modeling_convnext.py index d47bcb80f4..9021c5e5eb 100644 --- a/tests/models/convnext/test_modeling_convnext.py +++ b/tests/models/convnext/test_modeling_convnext.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -152,7 +153,7 @@ class ConvNextModelTester: @require_torch -class ConvNextModelTest(ModelTesterMixin, unittest.TestCase): +class ConvNextModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as ConvNext does not use input_ids, inputs_embeds, attention_mask and seq_length. @@ -167,6 +168,11 @@ class ConvNextModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + {"feature-extraction": ConvNextModel, "image-classification": ConvNextForImageClassification} + if is_torch_available() + else {} + ) fx_compatible = True test_pruning = False diff --git a/tests/models/convnext/test_modeling_tf_convnext.py b/tests/models/convnext/test_modeling_tf_convnext.py index cf674a9b85..72981c09d6 100644 --- a/tests/models/convnext/test_modeling_tf_convnext.py +++ b/tests/models/convnext/test_modeling_tf_convnext.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property, is_tf_available, is_vision_avail from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -117,13 +118,18 @@ class TFConvNextModelTester: @require_tf -class TFConvNextModelTest(TFModelTesterMixin, unittest.TestCase): +class TFConvNextModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as ConvNext does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (TFConvNextModel, TFConvNextForImageClassification) if is_tf_available() else () + pipeline_model_mapping = ( + {"feature-extraction": TFConvNextModel, "image-classification": TFConvNextForImageClassification} + if is_tf_available() + else {} + ) test_pruning = False test_onnx = False diff --git a/tests/models/ctrl/test_modeling_ctrl.py b/tests/models/ctrl/test_modeling_ctrl.py index 71d83dd3bb..b42db21aa6 100644 --- a/tests/models/ctrl/test_modeling_ctrl.py +++ b/tests/models/ctrl/test_modeling_ctrl.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -192,9 +193,19 @@ class CTRLModelTester: @require_torch -class CTRLModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class CTRLModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (CTRLModel, CTRLLMHeadModel, CTRLForSequenceClassification) if is_torch_available() else () all_generative_model_classes = (CTRLLMHeadModel,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": CTRLModel, + "text-classification": CTRLForSequenceClassification, + "text-generation": CTRLLMHeadModel, + "zero-shot": CTRLForSequenceClassification, + } + if is_torch_available() + else {} + ) test_pruning = True test_resize_embeddings = False test_head_masking = False diff --git a/tests/models/ctrl/test_modeling_tf_ctrl.py b/tests/models/ctrl/test_modeling_tf_ctrl.py index 5c7a92d73c..fb48ba93ee 100644 --- a/tests/models/ctrl/test_modeling_tf_ctrl.py +++ b/tests/models/ctrl/test_modeling_tf_ctrl.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -168,9 +169,19 @@ class TFCTRLModelTester(object): @require_tf -class TFCTRLModelTest(TFModelTesterMixin, unittest.TestCase): +class TFCTRLModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TFCTRLModel, TFCTRLLMHeadModel, TFCTRLForSequenceClassification) if is_tf_available() else () all_generative_model_classes = (TFCTRLLMHeadModel,) if is_tf_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": TFCTRLModel, + "text-classification": TFCTRLForSequenceClassification, + "text-generation": TFCTRLLMHeadModel, + "zero-shot": TFCTRLForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/cvt/test_modeling_cvt.py b/tests/models/cvt/test_modeling_cvt.py index b88f22d982..35ecf50217 100644 --- a/tests/models/cvt/test_modeling_cvt.py +++ b/tests/models/cvt/test_modeling_cvt.py @@ -25,6 +25,7 @@ from transformers.testing_utils import require_torch, require_vision, slow, torc from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -143,13 +144,18 @@ class CvtModelTester: @require_torch -class CvtModelTest(ModelTesterMixin, unittest.TestCase): +class CvtModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as Cvt does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (CvtModel, CvtForImageClassification) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": CvtModel, "image-classification": CvtForImageClassification} + if is_torch_available() + else {} + ) test_pruning = False test_torchscript = False diff --git a/tests/models/cvt/test_modeling_tf_cvt.py b/tests/models/cvt/test_modeling_tf_cvt.py index 9e261a5f25..4605f6782b 100644 --- a/tests/models/cvt/test_modeling_tf_cvt.py +++ b/tests/models/cvt/test_modeling_tf_cvt.py @@ -13,6 +13,7 @@ from transformers.utils import cached_property, is_tf_available, is_vision_avail from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -128,13 +129,18 @@ class TFCvtModelTester: @require_tf -class TFCvtModelTest(TFModelTesterMixin, unittest.TestCase): +class TFCvtModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as Cvt does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (TFCvtModel, TFCvtForImageClassification) if is_tf_available() else () + pipeline_model_mapping = ( + {"feature-extraction": TFCvtModel, "image-classification": TFCvtForImageClassification} + if is_tf_available() + else {} + ) test_pruning = False test_resize_embeddings = False test_head_masking = False diff --git a/tests/models/data2vec/test_modeling_data2vec_audio.py b/tests/models/data2vec/test_modeling_data2vec_audio.py index e3fb96097d..74450f50c8 100644 --- a/tests/models/data2vec/test_modeling_data2vec_audio.py +++ b/tests/models/data2vec/test_modeling_data2vec_audio.py @@ -26,6 +26,7 @@ from transformers.testing_utils import is_pt_flax_cross_test, require_soundfile, from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -358,7 +359,7 @@ class Data2VecAudioModelTester: @require_torch -class Data2VecAudioModelTest(ModelTesterMixin, unittest.TestCase): +class Data2VecAudioModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( Data2VecAudioForCTC, @@ -370,6 +371,15 @@ class Data2VecAudioModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "audio-classification": Data2VecAudioForSequenceClassification, + "automatic-speech-recognition": Data2VecAudioForCTC, + "feature-extraction": Data2VecAudioModel, + } + if is_torch_available() + else {} + ) test_pruning = False test_headmasking = False diff --git a/tests/models/data2vec/test_modeling_data2vec_text.py b/tests/models/data2vec/test_modeling_data2vec_text.py index c3015c3f40..a45c9b6a8b 100644 --- a/tests/models/data2vec/test_modeling_data2vec_text.py +++ b/tests/models/data2vec/test_modeling_data2vec_text.py @@ -23,6 +23,7 @@ from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_ from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -359,7 +360,7 @@ class Data2VecTextModelTester: @require_torch -class Data2VecTextModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class Data2VecTextModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( Data2VecTextForCausalLM, @@ -374,6 +375,19 @@ class Data2VecTextModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.Te else () ) all_generative_model_classes = (Data2VecTextForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": Data2VecTextModel, + "fill-mask": Data2VecTextForMaskedLM, + "question-answering": Data2VecTextForQuestionAnswering, + "text-classification": Data2VecTextForSequenceClassification, + "text-generation": Data2VecTextForCausalLM, + "token-classification": Data2VecTextForTokenClassification, + "zero-shot": Data2VecTextForSequenceClassification, + } + if is_torch_available() + else {} + ) def setUp(self): self.model_tester = Data2VecTextModelTester(self) diff --git a/tests/models/data2vec/test_modeling_data2vec_vision.py b/tests/models/data2vec/test_modeling_data2vec_vision.py index a7974e8cbd..b4c391fea1 100644 --- a/tests/models/data2vec/test_modeling_data2vec_vision.py +++ b/tests/models/data2vec/test_modeling_data2vec_vision.py @@ -25,6 +25,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -165,7 +166,7 @@ class Data2VecVisionModelTester: @require_torch -class Data2VecVisionModelTest(ModelTesterMixin, unittest.TestCase): +class Data2VecVisionModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as Data2VecVision does not use input_ids, inputs_embeds, attention_mask and seq_length. @@ -176,6 +177,15 @@ class Data2VecVisionModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": Data2VecVisionModel, + "image-classification": Data2VecVisionForImageClassification, + "image-segmentation": Data2VecVisionForSemanticSegmentation, + } + if is_torch_available() + else {} + ) test_pruning = False test_resize_embeddings = False diff --git a/tests/models/data2vec/test_modeling_tf_data2vec_vision.py b/tests/models/data2vec/test_modeling_tf_data2vec_vision.py index 0fa14e526a..dfa890d25a 100644 --- a/tests/models/data2vec/test_modeling_tf_data2vec_vision.py +++ b/tests/models/data2vec/test_modeling_tf_data2vec_vision.py @@ -26,6 +26,7 @@ from transformers.testing_utils import require_tf, require_vision, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -172,7 +173,7 @@ class TFData2VecVisionModelTester: @require_tf -class TFData2VecVisionModelTest(TFModelTesterMixin, unittest.TestCase): +class TFData2VecVisionModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as Data2VecVision does not use input_ids, inputs_embeds, attention_mask and seq_length. @@ -183,6 +184,11 @@ class TFData2VecVisionModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + {"feature-extraction": TFData2VecVisionModel, "image-classification": TFData2VecVisionForImageClassification} + if is_tf_available() + else {} + ) test_pruning = False test_onnx = False diff --git a/tests/models/deberta/test_modeling_deberta.py b/tests/models/deberta/test_modeling_deberta.py index 91f69a11b5..7daff3b522 100644 --- a/tests/models/deberta/test_modeling_deberta.py +++ b/tests/models/deberta/test_modeling_deberta.py @@ -19,6 +19,7 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -213,7 +214,7 @@ class DebertaModelTester(object): @require_torch -class DebertaModelTest(ModelTesterMixin, unittest.TestCase): +class DebertaModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( DebertaModel, @@ -225,6 +226,18 @@ class DebertaModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": DebertaModel, + "fill-mask": DebertaForMaskedLM, + "question-answering": DebertaForQuestionAnswering, + "text-classification": DebertaForSequenceClassification, + "token-classification": DebertaForTokenClassification, + "zero-shot": DebertaForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = True test_torchscript = False diff --git a/tests/models/deberta/test_modeling_tf_deberta.py b/tests/models/deberta/test_modeling_tf_deberta.py index d544a12e68..424d9e0b2b 100644 --- a/tests/models/deberta/test_modeling_tf_deberta.py +++ b/tests/models/deberta/test_modeling_tf_deberta.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -207,7 +208,7 @@ class TFDebertaModelTester: @require_tf -class TFDebertaModelTest(TFModelTesterMixin, unittest.TestCase): +class TFDebertaModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFDebertaModel, @@ -219,6 +220,18 @@ class TFDebertaModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFDebertaModel, + "fill-mask": TFDebertaForMaskedLM, + "question-answering": TFDebertaForQuestionAnswering, + "text-classification": TFDebertaForSequenceClassification, + "token-classification": TFDebertaForTokenClassification, + "zero-shot": TFDebertaForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/deberta_v2/test_modeling_deberta_v2.py b/tests/models/deberta_v2/test_modeling_deberta_v2.py index ad22f4f9a9..548c9617b8 100644 --- a/tests/models/deberta_v2/test_modeling_deberta_v2.py +++ b/tests/models/deberta_v2/test_modeling_deberta_v2.py @@ -19,6 +19,7 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -226,7 +227,7 @@ class DebertaV2ModelTester(object): @require_torch -class DebertaV2ModelTest(ModelTesterMixin, unittest.TestCase): +class DebertaV2ModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( DebertaV2Model, @@ -239,6 +240,18 @@ class DebertaV2ModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": DebertaV2Model, + "fill-mask": DebertaV2ForMaskedLM, + "question-answering": DebertaV2ForQuestionAnswering, + "text-classification": DebertaV2ForSequenceClassification, + "token-classification": DebertaV2ForTokenClassification, + "zero-shot": DebertaV2ForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = True test_torchscript = False diff --git a/tests/models/deberta_v2/test_modeling_tf_deberta_v2.py b/tests/models/deberta_v2/test_modeling_tf_deberta_v2.py index bd4d05e6c1..60391635ee 100644 --- a/tests/models/deberta_v2/test_modeling_tf_deberta_v2.py +++ b/tests/models/deberta_v2/test_modeling_tf_deberta_v2.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -209,7 +210,7 @@ class TFDebertaV2ModelTester: @require_tf -class TFDebertaModelTest(TFModelTesterMixin, unittest.TestCase): +class TFDebertaModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFDebertaV2Model, @@ -221,6 +222,18 @@ class TFDebertaModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFDebertaV2Model, + "fill-mask": TFDebertaV2ForMaskedLM, + "question-answering": TFDebertaV2ForQuestionAnswering, + "text-classification": TFDebertaV2ForSequenceClassification, + "token-classification": TFDebertaV2ForTokenClassification, + "zero-shot": TFDebertaV2ForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/decision_transformer/test_modeling_decision_transformer.py b/tests/models/decision_transformer/test_modeling_decision_transformer.py index 10ca3a767d..d99521b2f1 100644 --- a/tests/models/decision_transformer/test_modeling_decision_transformer.py +++ b/tests/models/decision_transformer/test_modeling_decision_transformer.py @@ -24,6 +24,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -131,9 +132,10 @@ class DecisionTransformerModelTester: @require_torch -class DecisionTransformerModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class DecisionTransformerModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (DecisionTransformerModel,) if is_torch_available() else () all_generative_model_classes = () + pipeline_model_mapping = {"feature-extraction": DecisionTransformerModel} if is_torch_available() else {} # Ignoring of a failing test from GenerationTesterMixin, as the model does not use inputs_ids test_generate_without_input_ids = False diff --git a/tests/models/deformable_detr/test_modeling_deformable_detr.py b/tests/models/deformable_detr/test_modeling_deformable_detr.py index a40f6bd044..3c7c2f640a 100644 --- a/tests/models/deformable_detr/test_modeling_deformable_detr.py +++ b/tests/models/deformable_detr/test_modeling_deformable_detr.py @@ -27,6 +27,7 @@ from transformers.testing_utils import require_timm, require_torch_gpu, require_ from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_timm_available(): @@ -185,8 +186,13 @@ class DeformableDetrModelTester: @require_timm -class DeformableDetrModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class DeformableDetrModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (DeformableDetrModel, DeformableDetrForObjectDetection) if is_timm_available() else () + pipeline_model_mapping = ( + {"feature-extraction": DeformableDetrModel, "object-detection": DeformableDetrForObjectDetection} + if is_timm_available() + else {} + ) is_encoder_decoder = True test_torchscript = False test_pruning = False diff --git a/tests/models/deit/test_modeling_deit.py b/tests/models/deit/test_modeling_deit.py index 612c6d0352..fbf6d7353b 100644 --- a/tests/models/deit/test_modeling_deit.py +++ b/tests/models/deit/test_modeling_deit.py @@ -33,6 +33,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -187,7 +188,7 @@ class DeiTModelTester: @require_torch -class DeiTModelTest(ModelTesterMixin, unittest.TestCase): +class DeiTModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as DeiT does not use input_ids, inputs_embeds, attention_mask and seq_length. @@ -203,6 +204,14 @@ class DeiTModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": DeiTModel, + "image-classification": (DeiTForImageClassification, DeiTForImageClassificationWithTeacher), + } + if is_torch_available() + else {} + ) test_pruning = False test_resize_embeddings = False diff --git a/tests/models/deit/test_modeling_tf_deit.py b/tests/models/deit/test_modeling_tf_deit.py index 2a9638eda4..c7c1fc8456 100644 --- a/tests/models/deit/test_modeling_tf_deit.py +++ b/tests/models/deit/test_modeling_tf_deit.py @@ -26,6 +26,7 @@ from transformers.utils import cached_property, is_tf_available, is_vision_avail from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -162,7 +163,7 @@ class TFDeiTModelTester: @require_tf -class TFDeiTModelTest(TFModelTesterMixin, unittest.TestCase): +class TFDeiTModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_tf_common.py, as DeiT does not use input_ids, inputs_embeds, attention_mask and seq_length. @@ -178,6 +179,14 @@ class TFDeiTModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFDeiTModel, + "image-classification": (TFDeiTForImageClassification, TFDeiTForImageClassificationWithTeacher), + } + if is_tf_available() + else {} + ) test_pruning = False test_resize_embeddings = False diff --git a/tests/models/deta/test_modeling_deta.py b/tests/models/deta/test_modeling_deta.py index bb3d38b66f..87656b0988 100644 --- a/tests/models/deta/test_modeling_deta.py +++ b/tests/models/deta/test_modeling_deta.py @@ -26,6 +26,7 @@ from transformers.testing_utils import require_torchvision, require_vision, slow from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -169,8 +170,13 @@ class DetaModelTester: @require_torchvision -class DetaModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class DetaModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (DetaModel, DetaForObjectDetection) if is_torchvision_available() else () + pipeline_model_mapping = ( + {"feature-extraction": DetaModel, "object-detection": DetaForObjectDetection} + if is_torchvision_available() + else {} + ) is_encoder_decoder = True test_torchscript = False test_pruning = False diff --git a/tests/models/detr/test_modeling_detr.py b/tests/models/detr/test_modeling_detr.py index 8dcae4f27d..7b032288b5 100644 --- a/tests/models/detr/test_modeling_detr.py +++ b/tests/models/detr/test_modeling_detr.py @@ -26,6 +26,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_timm_available(): @@ -174,7 +175,7 @@ class DetrModelTester: @require_timm -class DetrModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class DetrModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( DetrModel, @@ -184,6 +185,15 @@ class DetrModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): if is_timm_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": DetrModel, + "image-segmentation": DetrForSegmentation, + "object-detection": DetrForObjectDetection, + } + if is_timm_available() + else {} + ) is_encoder_decoder = True test_torchscript = False test_pruning = False diff --git a/tests/models/dinat/test_modeling_dinat.py b/tests/models/dinat/test_modeling_dinat.py index 00352026ec..0ba3a808b8 100644 --- a/tests/models/dinat/test_modeling_dinat.py +++ b/tests/models/dinat/test_modeling_dinat.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -192,7 +193,7 @@ class DinatModelTester: @require_natten @require_torch -class DinatModelTest(ModelTesterMixin, unittest.TestCase): +class DinatModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( DinatModel, @@ -202,6 +203,11 @@ class DinatModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + {"feature-extraction": DinatModel, "image-classification": DinatForImageClassification} + if is_torch_available() + else {} + ) fx_compatible = False test_torchscript = False diff --git a/tests/models/distilbert/test_modeling_distilbert.py b/tests/models/distilbert/test_modeling_distilbert.py index 50902268fd..9d17a1c441 100644 --- a/tests/models/distilbert/test_modeling_distilbert.py +++ b/tests/models/distilbert/test_modeling_distilbert.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_torch, require_torch_gpu, slow, t from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -195,7 +196,7 @@ class DistilBertModelTester(object): @require_torch -class DistilBertModelTest(ModelTesterMixin, unittest.TestCase): +class DistilBertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( DistilBertModel, @@ -208,6 +209,18 @@ class DistilBertModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else None ) + pipeline_model_mapping = ( + { + "feature-extraction": DistilBertModel, + "fill-mask": DistilBertForMaskedLM, + "question-answering": DistilBertForQuestionAnswering, + "text-classification": DistilBertForSequenceClassification, + "token-classification": DistilBertForTokenClassification, + "zero-shot": DistilBertForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = True test_pruning = True test_resize_embeddings = True diff --git a/tests/models/distilbert/test_modeling_tf_distilbert.py b/tests/models/distilbert/test_modeling_tf_distilbert.py index a59401dc50..1f4f3c2b46 100644 --- a/tests/models/distilbert/test_modeling_tf_distilbert.py +++ b/tests/models/distilbert/test_modeling_tf_distilbert.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -169,7 +170,7 @@ class TFDistilBertModelTester: @require_tf -class TFDistilBertModelTest(TFModelTesterMixin, unittest.TestCase): +class TFDistilBertModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFDistilBertModel, @@ -182,6 +183,18 @@ class TFDistilBertModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else None ) + pipeline_model_mapping = ( + { + "feature-extraction": TFDistilBertModel, + "fill-mask": TFDistilBertForMaskedLM, + "question-answering": TFDistilBertForQuestionAnswering, + "text-classification": TFDistilBertForSequenceClassification, + "token-classification": TFDistilBertForTokenClassification, + "zero-shot": TFDistilBertForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/donut/test_modeling_donut_swin.py b/tests/models/donut/test_modeling_donut_swin.py index 6a0809587c..2a0d9f5e17 100644 --- a/tests/models/donut/test_modeling_donut_swin.py +++ b/tests/models/donut/test_modeling_donut_swin.py @@ -24,6 +24,7 @@ from transformers.utils import is_torch_available from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -143,8 +144,9 @@ class DonutSwinModelTester: @require_torch -class DonutSwinModelTest(ModelTesterMixin, unittest.TestCase): +class DonutSwinModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (DonutSwinModel,) if is_torch_available() else () + pipeline_model_mapping = {"feature-extraction": DonutSwinModel} if is_torch_available() else {} fx_compatible = True test_pruning = False diff --git a/tests/models/dpr/test_modeling_dpr.py b/tests/models/dpr/test_modeling_dpr.py index 482caa0547..cd4f430ded 100644 --- a/tests/models/dpr/test_modeling_dpr.py +++ b/tests/models/dpr/test_modeling_dpr.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -178,7 +179,7 @@ class DPRModelTester: @require_torch -class DPRModelTest(ModelTesterMixin, unittest.TestCase): +class DPRModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( DPRContextEncoder, @@ -188,6 +189,7 @@ class DPRModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = {"feature-extraction": DPRQuestionEncoder} if is_torch_available() else {} test_resize_embeddings = False test_missing_keys = False # why? diff --git a/tests/models/dpr/test_modeling_tf_dpr.py b/tests/models/dpr/test_modeling_tf_dpr.py index 4910252278..64dea041b5 100644 --- a/tests/models/dpr/test_modeling_tf_dpr.py +++ b/tests/models/dpr/test_modeling_tf_dpr.py @@ -20,6 +20,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -171,7 +172,7 @@ class TFDPRModelTester: @require_tf -class TFDPRModelTest(TFModelTesterMixin, unittest.TestCase): +class TFDPRModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFDPRContextEncoder, @@ -181,6 +182,7 @@ class TFDPRModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = {"feature-extraction": TFDPRQuestionEncoder} if is_tf_available() else {} test_resize_embeddings = False test_missing_keys = False diff --git a/tests/models/dpt/test_modeling_dpt.py b/tests/models/dpt/test_modeling_dpt.py index 84c907539b..76790ee795 100644 --- a/tests/models/dpt/test_modeling_dpt.py +++ b/tests/models/dpt/test_modeling_dpt.py @@ -25,6 +25,7 @@ from transformers.testing_utils import require_torch, require_vision, slow, torc from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -149,13 +150,22 @@ class DPTModelTester: @require_torch -class DPTModelTest(ModelTesterMixin, unittest.TestCase): +class DPTModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as DPT does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (DPTModel, DPTForDepthEstimation, DPTForSemanticSegmentation) if is_torch_available() else () + pipeline_model_mapping = ( + { + "depth-estimation": DPTForDepthEstimation, + "feature-extraction": DPTModel, + "image-segmentation": DPTForSemanticSegmentation, + } + if is_torch_available() + else {} + ) test_pruning = False test_resize_embeddings = False diff --git a/tests/models/dpt/test_modeling_dpt_hybrid.py b/tests/models/dpt/test_modeling_dpt_hybrid.py index c98293e961..6d4a75c80d 100644 --- a/tests/models/dpt/test_modeling_dpt_hybrid.py +++ b/tests/models/dpt/test_modeling_dpt_hybrid.py @@ -25,6 +25,7 @@ from transformers.testing_utils import require_torch, require_vision, slow, torc from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -163,13 +164,22 @@ class DPTModelTester: @require_torch -class DPTModelTest(ModelTesterMixin, unittest.TestCase): +class DPTModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as DPT does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (DPTModel, DPTForDepthEstimation, DPTForSemanticSegmentation) if is_torch_available() else () + pipeline_model_mapping = ( + { + "depth-estimation": DPTForDepthEstimation, + "feature-extraction": DPTModel, + "image-segmentation": DPTForSemanticSegmentation, + } + if is_torch_available() + else {} + ) test_pruning = False test_resize_embeddings = False diff --git a/tests/models/efficientformer/test_modeling_efficientformer.py b/tests/models/efficientformer/test_modeling_efficientformer.py index 4627c545ea..f3e88b1d29 100644 --- a/tests/models/efficientformer/test_modeling_efficientformer.py +++ b/tests/models/efficientformer/test_modeling_efficientformer.py @@ -26,6 +26,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -157,7 +158,7 @@ class EfficientFormerModelTester: @require_torch -class EfficientFormerModelTest(ModelTesterMixin, unittest.TestCase): +class EfficientFormerModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as EfficientFormer does not use input_ids, inputs_embeds, attention_mask and seq_length. @@ -172,6 +173,17 @@ class EfficientFormerModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": EfficientFormerModel, + "image-classification": ( + EfficientFormerForImageClassification, + EfficientFormerForImageClassificationWithTeacher, + ), + } + if is_torch_available() + else {} + ) fx_compatible = False test_pruning = False diff --git a/tests/models/electra/test_modeling_electra.py b/tests/models/electra/test_modeling_electra.py index 7311df1e78..550bc14487 100644 --- a/tests/models/electra/test_modeling_electra.py +++ b/tests/models/electra/test_modeling_electra.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -374,7 +375,7 @@ class ElectraModelTester: @require_torch -class ElectraModelTest(ModelTesterMixin, unittest.TestCase): +class ElectraModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( ElectraModel, @@ -389,6 +390,19 @@ class ElectraModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": ElectraModel, + "fill-mask": ElectraForMaskedLM, + "question-answering": ElectraForQuestionAnswering, + "text-classification": ElectraForSequenceClassification, + "text-generation": ElectraForCausalLM, + "token-classification": ElectraForTokenClassification, + "zero-shot": ElectraForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = True # special case for ForPreTraining model diff --git a/tests/models/electra/test_modeling_tf_electra.py b/tests/models/electra/test_modeling_tf_electra.py index a63f008787..ae092e8a17 100644 --- a/tests/models/electra/test_modeling_tf_electra.py +++ b/tests/models/electra/test_modeling_tf_electra.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -487,7 +488,7 @@ class TFElectraModelTester: @require_tf -class TFElectraModelTest(TFModelTesterMixin, unittest.TestCase): +class TFElectraModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFElectraModel, @@ -501,6 +502,18 @@ class TFElectraModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFElectraModel, + "fill-mask": TFElectraForMaskedLM, + "question-answering": TFElectraForQuestionAnswering, + "text-classification": TFElectraForSequenceClassification, + "token-classification": TFElectraForTokenClassification, + "zero-shot": TFElectraForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/ernie/test_modeling_ernie.py b/tests/models/ernie/test_modeling_ernie.py index ed0b4e1f3d..e845bd1f83 100644 --- a/tests/models/ernie/test_modeling_ernie.py +++ b/tests/models/ernie/test_modeling_ernie.py @@ -23,6 +23,7 @@ from transformers.testing_utils import require_torch, require_torch_gpu, slow, t from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -426,7 +427,7 @@ class ErnieModelTester: @require_torch -class ErnieModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class ErnieModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( ErnieModel, @@ -443,6 +444,19 @@ class ErnieModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase) else () ) all_generative_model_classes = (ErnieForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": ErnieModel, + "fill-mask": ErnieForMaskedLM, + "question-answering": ErnieForQuestionAnswering, + "text-classification": ErnieForSequenceClassification, + "text-generation": ErnieForCausalLM, + "token-classification": ErnieForTokenClassification, + "zero-shot": ErnieForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = False # special case for ForPreTraining model diff --git a/tests/models/ernie_m/test_modeling_ernie_m.py b/tests/models/ernie_m/test_modeling_ernie_m.py index 2006755e32..d86083d7f1 100644 --- a/tests/models/ernie_m/test_modeling_ernie_m.py +++ b/tests/models/ernie_m/test_modeling_ernie_m.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -223,7 +224,7 @@ class ErnieMModelTester: @require_torch -class ErnieMModelTest(ModelTesterMixin, unittest.TestCase): +class ErnieMModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( ErnieMModel, @@ -236,6 +237,17 @@ class ErnieMModelTest(ModelTesterMixin, unittest.TestCase): else () ) all_generative_model_classes = () + pipeline_model_mapping = ( + { + "feature-extraction": ErnieMModel, + "question-answering": ErnieMForQuestionAnswering, + "text-classification": ErnieMForSequenceClassification, + "token-classification": ErnieMForTokenClassification, + "zero-shot": ErnieMForSequenceClassification, + } + if is_torch_available() + else {} + ) test_torchscript = False def setUp(self): diff --git a/tests/models/esm/test_modeling_esm.py b/tests/models/esm/test_modeling_esm.py index d6700da7c9..2e5d48082b 100644 --- a/tests/models/esm/test_modeling_esm.py +++ b/tests/models/esm/test_modeling_esm.py @@ -22,6 +22,7 @@ from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_ from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -165,7 +166,7 @@ class EsmModelTester: @require_torch -class EsmModelTest(ModelTesterMixin, unittest.TestCase): +class EsmModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): test_mismatched_shapes = False all_model_classes = ( @@ -179,6 +180,17 @@ class EsmModelTest(ModelTesterMixin, unittest.TestCase): else () ) all_generative_model_classes = () + pipeline_model_mapping = ( + { + "feature-extraction": EsmModel, + "fill-mask": EsmForMaskedLM, + "text-classification": EsmForSequenceClassification, + "token-classification": EsmForTokenClassification, + "zero-shot": EsmForSequenceClassification, + } + if is_torch_available() + else {} + ) test_sequence_classification_problem_types = True def setUp(self): diff --git a/tests/models/esm/test_modeling_esmfold.py b/tests/models/esm/test_modeling_esmfold.py index a0d4232d6d..84444f3222 100644 --- a/tests/models/esm/test_modeling_esmfold.py +++ b/tests/models/esm/test_modeling_esmfold.py @@ -22,6 +22,7 @@ from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_ from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -143,11 +144,12 @@ class EsmFoldModelTester: @require_torch -class EsmFoldModelTest(ModelTesterMixin, unittest.TestCase): +class EsmFoldModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): test_mismatched_shapes = False all_model_classes = (EsmForProteinFolding,) if is_torch_available() else () all_generative_model_classes = () + pipeline_model_mapping = {} if is_torch_available() else {} test_sequence_classification_problem_types = False def setUp(self): diff --git a/tests/models/esm/test_modeling_tf_esm.py b/tests/models/esm/test_modeling_tf_esm.py index 0e81efd458..663642bde2 100644 --- a/tests/models/esm/test_modeling_tf_esm.py +++ b/tests/models/esm/test_modeling_tf_esm.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -194,7 +195,7 @@ class TFEsmModelTester: @require_tf -class TFEsmModelTest(TFModelTesterMixin, unittest.TestCase): +class TFEsmModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFEsmModel, @@ -205,6 +206,17 @@ class TFEsmModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFEsmModel, + "fill-mask": TFEsmForMaskedLM, + "text-classification": TFEsmForSequenceClassification, + "token-classification": TFEsmForTokenClassification, + "zero-shot": TFEsmForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/flaubert/test_modeling_flaubert.py b/tests/models/flaubert/test_modeling_flaubert.py index b792f14e35..0ac3ced935 100644 --- a/tests/models/flaubert/test_modeling_flaubert.py +++ b/tests/models/flaubert/test_modeling_flaubert.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_torch, require_torch_gpu, slow, t from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -362,7 +363,7 @@ class FlaubertModelTester(object): @require_torch -class FlaubertModelTest(ModelTesterMixin, unittest.TestCase): +class FlaubertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( FlaubertModel, @@ -376,6 +377,18 @@ class FlaubertModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": FlaubertModel, + "fill-mask": FlaubertWithLMHeadModel, + "question-answering": FlaubertForQuestionAnsweringSimple, + "text-classification": FlaubertForSequenceClassification, + "token-classification": FlaubertForTokenClassification, + "zero-shot": FlaubertForSequenceClassification, + } + if is_torch_available() + else {} + ) # Flaubert has 2 QA models -> need to manually set the correct labels for one of them here def _prepare_for_class(self, inputs_dict, model_class, return_labels=False): diff --git a/tests/models/flaubert/test_modeling_tf_flaubert.py b/tests/models/flaubert/test_modeling_tf_flaubert.py index 584f904ce7..996c7323ee 100644 --- a/tests/models/flaubert/test_modeling_tf_flaubert.py +++ b/tests/models/flaubert/test_modeling_tf_flaubert.py @@ -20,6 +20,7 @@ from transformers.testing_utils import require_sentencepiece, require_tf, requir from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -274,7 +275,7 @@ class TFFlaubertModelTester: @require_tf -class TFFlaubertModelTest(TFModelTesterMixin, unittest.TestCase): +class TFFlaubertModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFFlaubertModel, @@ -290,6 +291,18 @@ class TFFlaubertModelTest(TFModelTesterMixin, unittest.TestCase): all_generative_model_classes = ( (TFFlaubertWithLMHeadModel,) if is_tf_available() else () ) # TODO (PVP): Check other models whether language generation is also applicable + pipeline_model_mapping = ( + { + "feature-extraction": TFFlaubertModel, + "fill-mask": TFFlaubertWithLMHeadModel, + "question-answering": TFFlaubertForQuestionAnsweringSimple, + "text-classification": TFFlaubertForSequenceClassification, + "token-classification": TFFlaubertForTokenClassification, + "zero-shot": TFFlaubertForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/flava/test_modeling_flava.py b/tests/models/flava/test_modeling_flava.py index 7af98e21fd..2544b7ee93 100644 --- a/tests/models/flava/test_modeling_flava.py +++ b/tests/models/flava/test_modeling_flava.py @@ -42,6 +42,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -856,8 +857,9 @@ class FlavaModelTester: @require_torch -class FlavaModelTest(ModelTesterMixin, unittest.TestCase): +class FlavaModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (FlavaModel,) if is_torch_available() else () + pipeline_model_mapping = {"feature-extraction": FlavaModel} if is_torch_available() else {} class_for_tester = FlavaModelTester test_head_masking = False test_pruning = False diff --git a/tests/models/fnet/test_modeling_fnet.py b/tests/models/fnet/test_modeling_fnet.py index 03c1edd4ca..056d8237b1 100644 --- a/tests/models/fnet/test_modeling_fnet.py +++ b/tests/models/fnet/test_modeling_fnet.py @@ -24,6 +24,7 @@ from transformers.testing_utils import require_tokenizers, require_torch, slow, from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -265,7 +266,7 @@ class FNetModelTester: @require_torch -class FNetModelTest(ModelTesterMixin, unittest.TestCase): +class FNetModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( FNetModel, @@ -280,6 +281,18 @@ class FNetModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": FNetModel, + "fill-mask": FNetForMaskedLM, + "question-answering": FNetForQuestionAnswering, + "text-classification": FNetForSequenceClassification, + "token-classification": FNetForTokenClassification, + "zero-shot": FNetForSequenceClassification, + } + if is_torch_available() + else {} + ) # Skip Tests test_pruning = False diff --git a/tests/models/fsmt/test_modeling_fsmt.py b/tests/models/fsmt/test_modeling_fsmt.py index e5526209bb..90c21e6543 100644 --- a/tests/models/fsmt/test_modeling_fsmt.py +++ b/tests/models/fsmt/test_modeling_fsmt.py @@ -26,6 +26,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -153,9 +154,19 @@ def prepare_fsmt_inputs_dict( @require_torch -class FSMTModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class FSMTModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (FSMTModel, FSMTForConditionalGeneration) if is_torch_available() else () all_generative_model_classes = (FSMTForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": FSMTForConditionalGeneration, + "feature-extraction": FSMTModel, + "summarization": FSMTForConditionalGeneration, + "text2text-generation": FSMTForConditionalGeneration, + } + if is_torch_available() + else {} + ) is_encoder_decoder = True test_pruning = False test_missing_keys = False diff --git a/tests/models/funnel/test_modeling_funnel.py b/tests/models/funnel/test_modeling_funnel.py index c0520203a9..e46e5dc58d 100644 --- a/tests/models/funnel/test_modeling_funnel.py +++ b/tests/models/funnel/test_modeling_funnel.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -351,7 +352,7 @@ class FunnelModelTester: @require_torch -class FunnelModelTest(ModelTesterMixin, unittest.TestCase): +class FunnelModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): test_head_masking = False test_pruning = False all_model_classes = ( @@ -365,6 +366,18 @@ class FunnelModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": (FunnelBaseModel, FunnelModel), + "fill-mask": FunnelForMaskedLM, + "question-answering": FunnelForQuestionAnswering, + "text-classification": FunnelForSequenceClassification, + "token-classification": FunnelForTokenClassification, + "zero-shot": FunnelForSequenceClassification, + } + if is_torch_available() + else {} + ) # special case for ForPreTraining model def _prepare_for_class(self, inputs_dict, model_class, return_labels=False): diff --git a/tests/models/funnel/test_modeling_tf_funnel.py b/tests/models/funnel/test_modeling_tf_funnel.py index faeb9a7995..6780605e89 100644 --- a/tests/models/funnel/test_modeling_tf_funnel.py +++ b/tests/models/funnel/test_modeling_tf_funnel.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_tf, tooslow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -329,7 +330,7 @@ class TFFunnelModelTester: @require_tf -class TFFunnelModelTest(TFModelTesterMixin, unittest.TestCase): +class TFFunnelModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFFunnelModel, @@ -341,6 +342,18 @@ class TFFunnelModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": (TFFunnelBaseModel, TFFunnelModel), + "fill-mask": TFFunnelForMaskedLM, + "question-answering": TFFunnelForQuestionAnswering, + "text-classification": TFFunnelForSequenceClassification, + "token-classification": TFFunnelForTokenClassification, + "zero-shot": TFFunnelForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/git/test_modeling_git.py b/tests/models/git/test_modeling_git.py index 969a0b1745..b6384ae15f 100644 --- a/tests/models/git/test_modeling_git.py +++ b/tests/models/git/test_modeling_git.py @@ -25,6 +25,7 @@ from transformers.testing_utils import require_torch, require_vision, slow, torc from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -378,9 +379,12 @@ class GitModelTester: @require_torch -class GitModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class GitModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (GitModel, GitForCausalLM) if is_torch_available() else () all_generative_model_classes = (GitForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": GitModel, "text-generation": GitForCausalLM} if is_torch_available() else {} + ) fx_compatible = False test_torchscript = False diff --git a/tests/models/glpn/test_modeling_glpn.py b/tests/models/glpn/test_modeling_glpn.py index 233e8ce731..bf279de9df 100644 --- a/tests/models/glpn/test_modeling_glpn.py +++ b/tests/models/glpn/test_modeling_glpn.py @@ -24,6 +24,7 @@ from transformers.testing_utils import require_torch, require_vision, slow, torc from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -143,8 +144,11 @@ class GLPNModelTester: @require_torch -class GLPNModelTest(ModelTesterMixin, unittest.TestCase): +class GLPNModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (GLPNModel, GLPNForDepthEstimation) if is_torch_available() else () + pipeline_model_mapping = ( + {"depth-estimation": GLPNForDepthEstimation, "feature-extraction": GLPNModel} if is_torch_available() else {} + ) test_head_masking = False test_pruning = False diff --git a/tests/models/gpt2/test_modeling_gpt2.py b/tests/models/gpt2/test_modeling_gpt2.py index c9a4cd771d..09d828fd7f 100644 --- a/tests/models/gpt2/test_modeling_gpt2.py +++ b/tests/models/gpt2/test_modeling_gpt2.py @@ -24,6 +24,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -429,13 +430,24 @@ class GPT2ModelTester: @require_torch -class GPT2ModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class GPT2ModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (GPT2Model, GPT2LMHeadModel, GPT2DoubleHeadsModel, GPT2ForSequenceClassification, GPT2ForTokenClassification) if is_torch_available() else () ) all_generative_model_classes = (GPT2LMHeadModel, GPT2DoubleHeadsModel) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": GPT2Model, + "text-classification": GPT2ForSequenceClassification, + "text-generation": GPT2LMHeadModel, + "token-classification": GPT2ForTokenClassification, + "zero-shot": GPT2ForSequenceClassification, + } + if is_torch_available() + else {} + ) all_parallelizable_model_classes = (GPT2LMHeadModel, GPT2DoubleHeadsModel) if is_torch_available() else () fx_compatible = True test_missing_keys = False diff --git a/tests/models/gpt2/test_modeling_tf_gpt2.py b/tests/models/gpt2/test_modeling_tf_gpt2.py index 3534ca7cd0..7171997546 100644 --- a/tests/models/gpt2/test_modeling_tf_gpt2.py +++ b/tests/models/gpt2/test_modeling_tf_gpt2.py @@ -20,6 +20,7 @@ from transformers.testing_utils import require_tf, require_tf2onnx, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin from ...utils.test_modeling_tf_core import TFCoreModelTesterMixin @@ -361,13 +362,23 @@ class TFGPT2ModelTester: @require_tf -class TFGPT2ModelTest(TFModelTesterMixin, TFCoreModelTesterMixin, unittest.TestCase): +class TFGPT2ModelTest(TFModelTesterMixin, TFCoreModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (TFGPT2Model, TFGPT2LMHeadModel, TFGPT2ForSequenceClassification, TFGPT2DoubleHeadsModel) if is_tf_available() else () ) all_generative_model_classes = (TFGPT2LMHeadModel,) if is_tf_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": TFGPT2Model, + "text-classification": TFGPT2ForSequenceClassification, + "text-generation": TFGPT2LMHeadModel, + "zero-shot": TFGPT2ForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = True onnx_min_opset = 10 diff --git a/tests/models/gpt_neo/test_modeling_gpt_neo.py b/tests/models/gpt_neo/test_modeling_gpt_neo.py index 53cc45aac5..64ebb9ac08 100644 --- a/tests/models/gpt_neo/test_modeling_gpt_neo.py +++ b/tests/models/gpt_neo/test_modeling_gpt_neo.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -371,11 +372,21 @@ class GPTNeoModelTester: @require_torch -class GPTNeoModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class GPTNeoModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (GPTNeoModel, GPTNeoForCausalLM, GPTNeoForSequenceClassification) if is_torch_available() else () ) all_generative_model_classes = (GPTNeoForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": GPTNeoModel, + "text-classification": GPTNeoForSequenceClassification, + "text-generation": GPTNeoForCausalLM, + "zero-shot": GPTNeoForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = True test_missing_keys = False test_pruning = False diff --git a/tests/models/gpt_neox/test_modeling_gpt_neox.py b/tests/models/gpt_neox/test_modeling_gpt_neox.py index d57ce69f1f..4698b6525c 100644 --- a/tests/models/gpt_neox/test_modeling_gpt_neox.py +++ b/tests/models/gpt_neox/test_modeling_gpt_neox.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -185,9 +186,12 @@ class GPTNeoXModelTester: @require_torch -class GPTNeoXModelTest(ModelTesterMixin, unittest.TestCase): +class GPTNeoXModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (GPTNeoXModel, GPTNeoXForCausalLM) if is_torch_available() else () all_generative_model_classes = (GPTNeoXForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": GPTNeoXModel, "text-generation": GPTNeoXForCausalLM} if is_torch_available() else {} + ) test_pruning = False test_missing_keys = False test_model_parallel = False diff --git a/tests/models/gpt_neox_japanese/test_modeling_gpt_neox_japanese.py b/tests/models/gpt_neox_japanese/test_modeling_gpt_neox_japanese.py index 56a5f92a83..47bb22b627 100644 --- a/tests/models/gpt_neox_japanese/test_modeling_gpt_neox_japanese.py +++ b/tests/models/gpt_neox_japanese/test_modeling_gpt_neox_japanese.py @@ -23,6 +23,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -189,9 +190,14 @@ class GPTNeoXJapaneseModelTester: @require_torch -class GPTNeoXModelJapaneseTest(ModelTesterMixin, unittest.TestCase): +class GPTNeoXModelJapaneseTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (GPTNeoXJapaneseModel, GPTNeoXJapaneseForCausalLM) if is_torch_available() else () all_generative_model_classes = (GPTNeoXJapaneseForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": GPTNeoXJapaneseModel, "text-generation": GPTNeoXJapaneseForCausalLM} + if is_torch_available() + else {} + ) test_pruning = False test_missing_keys = False test_model_parallel = False diff --git a/tests/models/gptj/test_modeling_gptj.py b/tests/models/gptj/test_modeling_gptj.py index 3cdb5a4b6f..067b84ab7d 100644 --- a/tests/models/gptj/test_modeling_gptj.py +++ b/tests/models/gptj/test_modeling_gptj.py @@ -23,6 +23,7 @@ from transformers.testing_utils import require_torch, slow, tooslow, torch_devic from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -360,13 +361,24 @@ class GPTJModelTester: @require_torch -class GPTJModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class GPTJModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (GPTJModel, GPTJForCausalLM, GPTJForSequenceClassification, GPTJForQuestionAnswering) if is_torch_available() else () ) all_generative_model_classes = (GPTJForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": GPTJModel, + "question-answering": GPTJForQuestionAnswering, + "text-classification": GPTJForSequenceClassification, + "text-generation": GPTJForCausalLM, + "zero-shot": GPTJForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = True test_pruning = False test_missing_keys = False diff --git a/tests/models/gptj/test_modeling_tf_gptj.py b/tests/models/gptj/test_modeling_tf_gptj.py index 0113042ae0..c230429738 100644 --- a/tests/models/gptj/test_modeling_tf_gptj.py +++ b/tests/models/gptj/test_modeling_tf_gptj.py @@ -20,6 +20,7 @@ from transformers.testing_utils import require_tf, slow, tooslow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin from ...utils.test_modeling_tf_core import TFCoreModelTesterMixin @@ -293,7 +294,7 @@ class TFGPTJModelTester: @require_tf -class TFGPTJModelTest(TFModelTesterMixin, TFCoreModelTesterMixin, unittest.TestCase): +class TFGPTJModelTest(TFModelTesterMixin, TFCoreModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (TFGPTJForCausalLM, TFGPTJForSequenceClassification, TFGPTJForQuestionAnswering, TFGPTJModel) if is_tf_available() @@ -301,6 +302,17 @@ class TFGPTJModelTest(TFModelTesterMixin, TFCoreModelTesterMixin, unittest.TestC ) all_generative_model_classes = (TFGPTJForCausalLM,) if is_tf_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": TFGPTJModel, + "question-answering": TFGPTJForQuestionAnswering, + "text-classification": TFGPTJForSequenceClassification, + "text-generation": TFGPTJForCausalLM, + "zero-shot": TFGPTJForSequenceClassification, + } + if is_tf_available() + else {} + ) test_onnx = False test_pruning = False test_missing_keys = False diff --git a/tests/models/graphormer/test_modeling_graphormer.py b/tests/models/graphormer/test_modeling_graphormer.py index 87bf470655..e874ebf0f4 100644 --- a/tests/models/graphormer/test_modeling_graphormer.py +++ b/tests/models/graphormer/test_modeling_graphormer.py @@ -26,6 +26,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -243,9 +244,10 @@ class GraphormerModelTester: @require_torch -class GraphormerModelTest(ModelTesterMixin, unittest.TestCase): +class GraphormerModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (GraphormerForGraphClassification, GraphormerModel) if is_torch_available() else () all_generative_model_classes = () + pipeline_model_mapping = {"feature-extraction": GraphormerModel} if is_torch_available() else {} test_pruning = False test_head_masking = False test_resize_embeddings = False diff --git a/tests/models/groupvit/test_modeling_groupvit.py b/tests/models/groupvit/test_modeling_groupvit.py index cd17e4d918..f87cec426b 100644 --- a/tests/models/groupvit/test_modeling_groupvit.py +++ b/tests/models/groupvit/test_modeling_groupvit.py @@ -36,6 +36,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -521,8 +522,9 @@ class GroupViTModelTester: @require_torch -class GroupViTModelTest(ModelTesterMixin, unittest.TestCase): +class GroupViTModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (GroupViTModel,) if is_torch_available() else () + pipeline_model_mapping = {"feature-extraction": GroupViTModel} if is_torch_available() else {} test_head_masking = False test_pruning = False test_resize_embeddings = False diff --git a/tests/models/groupvit/test_modeling_tf_groupvit.py b/tests/models/groupvit/test_modeling_tf_groupvit.py index 24a493445c..bd499a50fb 100644 --- a/tests/models/groupvit/test_modeling_tf_groupvit.py +++ b/tests/models/groupvit/test_modeling_tf_groupvit.py @@ -37,6 +37,7 @@ from transformers.utils import is_tf_available, is_vision_available from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -569,8 +570,9 @@ class TFGroupViTModelTester: @require_tf -class TFGroupViTModelTest(TFModelTesterMixin, unittest.TestCase): +class TFGroupViTModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TFGroupViTModel,) if is_tf_available() else () + pipeline_model_mapping = {"feature-extraction": TFGroupViTModel} if is_tf_available() else {} test_head_masking = False test_pruning = False test_resize_embeddings = False diff --git a/tests/models/hubert/test_modeling_hubert.py b/tests/models/hubert/test_modeling_hubert.py index 71c317cd12..9b18b5580a 100644 --- a/tests/models/hubert/test_modeling_hubert.py +++ b/tests/models/hubert/test_modeling_hubert.py @@ -35,6 +35,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -304,8 +305,17 @@ class HubertModelTester: @require_torch -class HubertModelTest(ModelTesterMixin, unittest.TestCase): +class HubertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (HubertForCTC, HubertForSequenceClassification, HubertModel) if is_torch_available() else () + pipeline_model_mapping = ( + { + "audio-classification": HubertForSequenceClassification, + "automatic-speech-recognition": HubertForCTC, + "feature-extraction": HubertModel, + } + if is_torch_available() + else {} + ) fx_compatible = True test_pruning = False test_headmasking = False diff --git a/tests/models/hubert/test_modeling_tf_hubert.py b/tests/models/hubert/test_modeling_tf_hubert.py index 15cf801ea6..d5164b6069 100644 --- a/tests/models/hubert/test_modeling_tf_hubert.py +++ b/tests/models/hubert/test_modeling_tf_hubert.py @@ -27,6 +27,7 @@ from transformers.testing_utils import require_soundfile, require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -218,8 +219,9 @@ class TFHubertModelTester: @require_tf -class TFHubertModelTest(TFModelTesterMixin, unittest.TestCase): +class TFHubertModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TFHubertModel, TFHubertForCTC) if is_tf_available() else () + pipeline_model_mapping = {"feature-extraction": TFHubertModel} if is_tf_available() else {} test_resize_embeddings = False test_head_masking = False test_onnx = False diff --git a/tests/models/ibert/test_modeling_ibert.py b/tests/models/ibert/test_modeling_ibert.py index d797d6aa28..9f2f2c9502 100644 --- a/tests/models/ibert/test_modeling_ibert.py +++ b/tests/models/ibert/test_modeling_ibert.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -224,7 +225,7 @@ class IBertModelTester: @require_torch -class IBertModelTest(ModelTesterMixin, unittest.TestCase): +class IBertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): test_pruning = False test_torchscript = False test_head_masking = False @@ -242,6 +243,18 @@ class IBertModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": IBertModel, + "fill-mask": IBertForMaskedLM, + "question-answering": IBertForQuestionAnswering, + "text-classification": IBertForSequenceClassification, + "token-classification": IBertForTokenClassification, + "zero-shot": IBertForSequenceClassification, + } + if is_torch_available() + else {} + ) def setUp(self): self.model_tester = IBertModelTester(self) diff --git a/tests/models/imagegpt/test_modeling_imagegpt.py b/tests/models/imagegpt/test_modeling_imagegpt.py index c60282aff6..e6c8524c6d 100644 --- a/tests/models/imagegpt/test_modeling_imagegpt.py +++ b/tests/models/imagegpt/test_modeling_imagegpt.py @@ -33,6 +33,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -264,11 +265,16 @@ class ImageGPTModelTester: @require_torch -class ImageGPTModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class ImageGPTModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (ImageGPTForCausalImageModeling, ImageGPTForImageClassification, ImageGPTModel) if is_torch_available() else () ) all_generative_model_classes = (ImageGPTForCausalImageModeling,) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": ImageGPTModel, "image-classification": ImageGPTForImageClassification} + if is_torch_available() + else {} + ) test_missing_keys = False input_name = "pixel_values" diff --git a/tests/models/layoutlm/test_modeling_layoutlm.py b/tests/models/layoutlm/test_modeling_layoutlm.py index 087c3aa27a..0535fbf4e1 100644 --- a/tests/models/layoutlm/test_modeling_layoutlm.py +++ b/tests/models/layoutlm/test_modeling_layoutlm.py @@ -19,6 +19,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -219,7 +220,7 @@ class LayoutLMModelTester: @require_torch -class LayoutLMModelTest(ModelTesterMixin, unittest.TestCase): +class LayoutLMModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( LayoutLMModel, @@ -231,6 +232,18 @@ class LayoutLMModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else None ) + pipeline_model_mapping = ( + { + "document-question-answering": LayoutLMForQuestionAnswering, + "feature-extraction": LayoutLMModel, + "fill-mask": LayoutLMForMaskedLM, + "text-classification": LayoutLMForSequenceClassification, + "token-classification": LayoutLMForTokenClassification, + "zero-shot": LayoutLMForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = True def setUp(self): diff --git a/tests/models/layoutlm/test_modeling_tf_layoutlm.py b/tests/models/layoutlm/test_modeling_tf_layoutlm.py index 71963e69c8..95e24023bb 100644 --- a/tests/models/layoutlm/test_modeling_tf_layoutlm.py +++ b/tests/models/layoutlm/test_modeling_tf_layoutlm.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -206,7 +207,7 @@ class TFLayoutLMModelTester: @require_tf -class TFLayoutLMModelTest(TFModelTesterMixin, unittest.TestCase): +class TFLayoutLMModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFLayoutLMModel, @@ -218,6 +219,17 @@ class TFLayoutLMModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFLayoutLMModel, + "fill-mask": TFLayoutLMForMaskedLM, + "text-classification": TFLayoutLMForSequenceClassification, + "token-classification": TFLayoutLMForTokenClassification, + "zero-shot": TFLayoutLMForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = True onnx_min_opset = 10 diff --git a/tests/models/layoutlmv2/test_modeling_layoutlmv2.py b/tests/models/layoutlmv2/test_modeling_layoutlmv2.py index 8c51bc667a..812bff4aba 100644 --- a/tests/models/layoutlmv2/test_modeling_layoutlmv2.py +++ b/tests/models/layoutlmv2/test_modeling_layoutlmv2.py @@ -22,6 +22,7 @@ from transformers.utils import is_detectron2_available, is_torch_available from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -253,7 +254,7 @@ class LayoutLMv2ModelTester: @require_torch @require_detectron2 -class LayoutLMv2ModelTest(ModelTesterMixin, unittest.TestCase): +class LayoutLMv2ModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): test_pruning = False test_torchscript = True test_mismatched_shapes = False @@ -268,6 +269,18 @@ class LayoutLMv2ModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "document-question-answering": LayoutLMv2ForQuestionAnswering, + "feature-extraction": LayoutLMv2Model, + "question-answering": LayoutLMv2ForQuestionAnswering, + "text-classification": LayoutLMv2ForSequenceClassification, + "token-classification": LayoutLMv2ForTokenClassification, + "zero-shot": LayoutLMv2ForSequenceClassification, + } + if is_torch_available() + else {} + ) def setUp(self): self.model_tester = LayoutLMv2ModelTester(self) diff --git a/tests/models/layoutlmv3/test_modeling_layoutlmv3.py b/tests/models/layoutlmv3/test_modeling_layoutlmv3.py index 601eeb5846..f62fff0048 100644 --- a/tests/models/layoutlmv3/test_modeling_layoutlmv3.py +++ b/tests/models/layoutlmv3/test_modeling_layoutlmv3.py @@ -23,6 +23,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -269,7 +270,7 @@ class LayoutLMv3ModelTester: @require_torch -class LayoutLMv3ModelTest(ModelTesterMixin, unittest.TestCase): +class LayoutLMv3ModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): test_pruning = False test_torchscript = False test_mismatched_shapes = False @@ -284,6 +285,18 @@ class LayoutLMv3ModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "document-question-answering": LayoutLMv3ForQuestionAnswering, + "feature-extraction": LayoutLMv3Model, + "question-answering": LayoutLMv3ForQuestionAnswering, + "text-classification": LayoutLMv3ForSequenceClassification, + "token-classification": LayoutLMv3ForTokenClassification, + "zero-shot": LayoutLMv3ForSequenceClassification, + } + if is_torch_available() + else {} + ) def setUp(self): self.model_tester = LayoutLMv3ModelTester(self) diff --git a/tests/models/layoutlmv3/test_modeling_tf_layoutlmv3.py b/tests/models/layoutlmv3/test_modeling_tf_layoutlmv3.py index f6b51c6d71..09ca417595 100644 --- a/tests/models/layoutlmv3/test_modeling_tf_layoutlmv3.py +++ b/tests/models/layoutlmv3/test_modeling_tf_layoutlmv3.py @@ -27,6 +27,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -263,7 +264,7 @@ class TFLayoutLMv3ModelTester: @require_tf -class TFLayoutLMv3ModelTest(TFModelTesterMixin, unittest.TestCase): +class TFLayoutLMv3ModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFLayoutLMv3Model, @@ -274,6 +275,17 @@ class TFLayoutLMv3ModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFLayoutLMv3Model, + "question-answering": TFLayoutLMv3ForQuestionAnswering, + "text-classification": TFLayoutLMv3ForSequenceClassification, + "token-classification": TFLayoutLMv3ForTokenClassification, + "zero-shot": TFLayoutLMv3ForSequenceClassification, + } + if is_tf_available() + else {} + ) test_pruning = False test_resize_embeddings = False diff --git a/tests/models/led/test_modeling_led.py b/tests/models/led/test_modeling_led.py index 7a5d95bb41..371ebedadf 100644 --- a/tests/models/led/test_modeling_led.py +++ b/tests/models/led/test_modeling_led.py @@ -27,6 +27,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -268,13 +269,26 @@ class LEDModelTester: @require_torch -class LEDModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class LEDModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (LEDModel, LEDForConditionalGeneration, LEDForSequenceClassification, LEDForQuestionAnswering) if is_torch_available() else () ) all_generative_model_classes = (LEDForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": LEDForConditionalGeneration, + "feature-extraction": LEDModel, + "question-answering": LEDForQuestionAnswering, + "summarization": LEDForConditionalGeneration, + "text2text-generation": LEDForConditionalGeneration, + "text-classification": LEDForSequenceClassification, + "zero-shot": LEDForSequenceClassification, + } + if is_torch_available() + else {} + ) is_encoder_decoder = True test_pruning = False test_missing_keys = False diff --git a/tests/models/led/test_modeling_tf_led.py b/tests/models/led/test_modeling_tf_led.py index 8c104627c8..cf7762ba22 100644 --- a/tests/models/led/test_modeling_tf_led.py +++ b/tests/models/led/test_modeling_tf_led.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_tf, slow, tooslow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -189,9 +190,19 @@ def prepare_led_inputs_dict( @require_tf -class TFLEDModelTest(TFModelTesterMixin, unittest.TestCase): +class TFLEDModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TFLEDForConditionalGeneration, TFLEDModel) if is_tf_available() else () all_generative_model_classes = (TFLEDForConditionalGeneration,) if is_tf_available() else () + pipeline_model_mapping = ( + { + "conversational": TFLEDForConditionalGeneration, + "feature-extraction": TFLEDModel, + "summarization": TFLEDForConditionalGeneration, + "text2text-generation": TFLEDForConditionalGeneration, + } + if is_tf_available() + else {} + ) is_encoder_decoder = True test_pruning = False test_head_masking = False diff --git a/tests/models/levit/test_modeling_levit.py b/tests/models/levit/test_modeling_levit.py index 1bc8eb4f6a..18764a0090 100644 --- a/tests/models/levit/test_modeling_levit.py +++ b/tests/models/levit/test_modeling_levit.py @@ -29,6 +29,7 @@ from transformers.testing_utils import require_torch, require_vision, slow, torc from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -165,7 +166,7 @@ class LevitModelTester: @require_torch -class LevitModelTest(ModelTesterMixin, unittest.TestCase): +class LevitModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as Levit does not use input_ids, inputs_embeds, attention_mask and seq_length. @@ -176,6 +177,14 @@ class LevitModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": LevitModel, + "image-classification": (LevitForImageClassification, LevitForImageClassificationWithTeacher), + } + if is_torch_available() + else {} + ) test_pruning = False test_torchscript = False diff --git a/tests/models/lilt/test_modeling_lilt.py b/tests/models/lilt/test_modeling_lilt.py index 4eaff42684..e78d5d13d4 100644 --- a/tests/models/lilt/test_modeling_lilt.py +++ b/tests/models/lilt/test_modeling_lilt.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -218,7 +219,7 @@ class LiltModelTester: @require_torch -class LiltModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class LiltModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( LiltModel, @@ -229,6 +230,17 @@ class LiltModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": LiltModel, + "question-answering": LiltForQuestionAnswering, + "text-classification": LiltForSequenceClassification, + "token-classification": LiltForTokenClassification, + "zero-shot": LiltForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = False test_pruning = False diff --git a/tests/models/longformer/test_modeling_longformer.py b/tests/models/longformer/test_modeling_longformer.py index 6bef4cbea1..1dc97a114a 100644 --- a/tests/models/longformer/test_modeling_longformer.py +++ b/tests/models/longformer/test_modeling_longformer.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -296,7 +297,7 @@ class LongformerModelTester: @require_torch -class LongformerModelTest(ModelTesterMixin, unittest.TestCase): +class LongformerModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): test_pruning = False # pruning is not supported test_torchscript = False @@ -312,6 +313,18 @@ class LongformerModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": LongformerModel, + "fill-mask": LongformerForMaskedLM, + "question-answering": LongformerForQuestionAnswering, + "text-classification": LongformerForSequenceClassification, + "token-classification": LongformerForTokenClassification, + "zero-shot": LongformerForSequenceClassification, + } + if is_torch_available() + else {} + ) def setUp(self): self.model_tester = LongformerModelTester(self) diff --git a/tests/models/longformer/test_modeling_tf_longformer.py b/tests/models/longformer/test_modeling_tf_longformer.py index ea3ba37407..ae11946cb9 100644 --- a/tests/models/longformer/test_modeling_tf_longformer.py +++ b/tests/models/longformer/test_modeling_tf_longformer.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_sentencepiece, require_tf, requir from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -270,7 +271,7 @@ class TFLongformerModelTester: @require_tf -class TFLongformerModelTest(TFModelTesterMixin, unittest.TestCase): +class TFLongformerModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFLongformerModel, @@ -283,6 +284,18 @@ class TFLongformerModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFLongformerModel, + "fill-mask": TFLongformerForMaskedLM, + "question-answering": TFLongformerForQuestionAnswering, + "text-classification": TFLongformerForSequenceClassification, + "token-classification": TFLongformerForTokenClassification, + "zero-shot": TFLongformerForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/longt5/test_modeling_longt5.py b/tests/models/longt5/test_modeling_longt5.py index ee7ef89e80..39a7e278ef 100644 --- a/tests/models/longt5/test_modeling_longt5.py +++ b/tests/models/longt5/test_modeling_longt5.py @@ -26,6 +26,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -500,9 +501,19 @@ class LongT5ModelTester: @require_torch -class LongT5ModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class LongT5ModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (LongT5Model, LongT5ForConditionalGeneration) if is_torch_available() else () all_generative_model_classes = (LongT5ForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": LongT5ForConditionalGeneration, + "feature-extraction": LongT5Model, + "summarization": LongT5ForConditionalGeneration, + "text2text-generation": LongT5ForConditionalGeneration, + } + if is_torch_available() + else {} + ) fx_compatible = False test_pruning = False test_torchscript = True diff --git a/tests/models/luke/test_modeling_luke.py b/tests/models/luke/test_modeling_luke.py index a1b0093cc4..1ab23392da 100644 --- a/tests/models/luke/test_modeling_luke.py +++ b/tests/models/luke/test_modeling_luke.py @@ -20,6 +20,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -585,7 +586,7 @@ class LukeModelTester: @require_torch -class LukeModelTest(ModelTesterMixin, unittest.TestCase): +class LukeModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( LukeModel, @@ -601,6 +602,18 @@ class LukeModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": LukeModel, + "fill-mask": LukeForMaskedLM, + "question-answering": LukeForQuestionAnswering, + "text-classification": LukeForSequenceClassification, + "token-classification": LukeForTokenClassification, + "zero-shot": LukeForSequenceClassification, + } + if is_torch_available() + else {} + ) test_pruning = False test_torchscript = False test_resize_embeddings = True diff --git a/tests/models/lxmert/test_modeling_lxmert.py b/tests/models/lxmert/test_modeling_lxmert.py index f57a339e5c..489d22d92e 100644 --- a/tests/models/lxmert/test_modeling_lxmert.py +++ b/tests/models/lxmert/test_modeling_lxmert.py @@ -25,6 +25,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -529,8 +530,13 @@ class LxmertModelTester: @require_torch -class LxmertModelTest(ModelTesterMixin, unittest.TestCase): +class LxmertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (LxmertModel, LxmertForPreTraining, LxmertForQuestionAnswering) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": LxmertModel, "question-answering": LxmertForQuestionAnswering} + if is_torch_available() + else {} + ) fx_compatible = True test_head_masking = False diff --git a/tests/models/lxmert/test_modeling_tf_lxmert.py b/tests/models/lxmert/test_modeling_tf_lxmert.py index 4fcc0867b0..cd2095f693 100644 --- a/tests/models/lxmert/test_modeling_tf_lxmert.py +++ b/tests/models/lxmert/test_modeling_tf_lxmert.py @@ -24,6 +24,7 @@ from transformers.testing_utils import require_tf, slow, tooslow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -363,8 +364,9 @@ class TFLxmertModelTester(object): @require_tf -class TFLxmertModelTest(TFModelTesterMixin, unittest.TestCase): +class TFLxmertModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TFLxmertModel, TFLxmertForPreTraining) if is_tf_available() else () + pipeline_model_mapping = {"feature-extraction": TFLxmertModel} if is_tf_available() else {} test_head_masking = False test_onnx = False diff --git a/tests/models/m2m_100/test_modeling_m2m_100.py b/tests/models/m2m_100/test_modeling_m2m_100.py index b5f742c046..2457eea21a 100644 --- a/tests/models/m2m_100/test_modeling_m2m_100.py +++ b/tests/models/m2m_100/test_modeling_m2m_100.py @@ -26,6 +26,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -220,7 +221,7 @@ class M2M100ModelTester: @require_torch -class M2M100ModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class M2M100ModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( M2M100Model, @@ -230,6 +231,16 @@ class M2M100ModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase else () ) all_generative_model_classes = (M2M100ForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": M2M100ForConditionalGeneration, + "feature-extraction": M2M100Model, + "summarization": M2M100ForConditionalGeneration, + "text2text-generation": M2M100ForConditionalGeneration, + } + if is_torch_available() + else {} + ) is_encoder_decoder = True fx_compatible = True test_pruning = False diff --git a/tests/models/marian/test_modeling_marian.py b/tests/models/marian/test_modeling_marian.py index 3f8be1a0a7..7b3eb1fb8b 100644 --- a/tests/models/marian/test_modeling_marian.py +++ b/tests/models/marian/test_modeling_marian.py @@ -26,6 +26,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -235,9 +236,20 @@ class MarianModelTester: @require_torch -class MarianModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class MarianModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (MarianModel, MarianMTModel) if is_torch_available() else () all_generative_model_classes = (MarianMTModel,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": MarianMTModel, + "feature-extraction": MarianModel, + "summarization": MarianMTModel, + "text2text-generation": MarianMTModel, + "text-generation": MarianForCausalLM, + } + if is_torch_available() + else {} + ) is_encoder_decoder = True fx_compatible = True test_pruning = False diff --git a/tests/models/marian/test_modeling_tf_marian.py b/tests/models/marian/test_modeling_tf_marian.py index 95f6bc0d0e..496e45e5c9 100644 --- a/tests/models/marian/test_modeling_tf_marian.py +++ b/tests/models/marian/test_modeling_tf_marian.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -177,9 +178,19 @@ def prepare_marian_inputs_dict( @require_tf -class TFMarianModelTest(TFModelTesterMixin, unittest.TestCase): +class TFMarianModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TFMarianMTModel, TFMarianModel) if is_tf_available() else () all_generative_model_classes = (TFMarianMTModel,) if is_tf_available() else () + pipeline_model_mapping = ( + { + "conversational": TFMarianMTModel, + "feature-extraction": TFMarianModel, + "summarization": TFMarianMTModel, + "text2text-generation": TFMarianMTModel, + } + if is_tf_available() + else {} + ) is_encoder_decoder = True test_pruning = False test_onnx = False diff --git a/tests/models/markuplm/test_modeling_markuplm.py b/tests/models/markuplm/test_modeling_markuplm.py index 8fa1bb440a..3abdb4041a 100644 --- a/tests/models/markuplm/test_modeling_markuplm.py +++ b/tests/models/markuplm/test_modeling_markuplm.py @@ -22,6 +22,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -275,7 +276,7 @@ class MarkupLMModelTester: @require_torch -class MarkupLMModelTest(ModelTesterMixin, unittest.TestCase): +class MarkupLMModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( MarkupLMModel, @@ -286,6 +287,17 @@ class MarkupLMModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else None ) + pipeline_model_mapping = ( + { + "feature-extraction": MarkupLMModel, + "question-answering": MarkupLMForQuestionAnswering, + "text-classification": MarkupLMForSequenceClassification, + "token-classification": MarkupLMForTokenClassification, + "zero-shot": MarkupLMForSequenceClassification, + } + if is_torch_available() + else {} + ) def setUp(self): self.model_tester = MarkupLMModelTester(self) diff --git a/tests/models/mask2former/test_modeling_mask2former.py b/tests/models/mask2former/test_modeling_mask2former.py index 4d7409697e..8d7cd52f0f 100644 --- a/tests/models/mask2former/test_modeling_mask2former.py +++ b/tests/models/mask2former/test_modeling_mask2former.py @@ -26,6 +26,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -172,8 +173,9 @@ class Mask2FormerModelTester: @require_torch -class Mask2FormerModelTest(ModelTesterMixin, unittest.TestCase): +class Mask2FormerModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (Mask2FormerModel, Mask2FormerForUniversalSegmentation) if is_torch_available() else () + pipeline_model_mapping = {"feature-extraction": Mask2FormerModel} if is_torch_available() else {} is_encoder_decoder = False test_pruning = False diff --git a/tests/models/maskformer/test_modeling_maskformer.py b/tests/models/maskformer/test_modeling_maskformer.py index a5f53d9f6f..65ce4aa7f0 100644 --- a/tests/models/maskformer/test_modeling_maskformer.py +++ b/tests/models/maskformer/test_modeling_maskformer.py @@ -26,6 +26,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -172,8 +173,13 @@ class MaskFormerModelTester: @require_torch -class MaskFormerModelTest(ModelTesterMixin, unittest.TestCase): +class MaskFormerModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (MaskFormerModel, MaskFormerForInstanceSegmentation) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": MaskFormerModel, "image-segmentation": MaskFormerForInstanceSegmentation} + if is_torch_available() + else {} + ) is_encoder_decoder = False test_pruning = False diff --git a/tests/models/maskformer/test_modeling_maskformer_swin.py b/tests/models/maskformer/test_modeling_maskformer_swin.py index 3b606188a1..9285c444a6 100644 --- a/tests/models/maskformer/test_modeling_maskformer_swin.py +++ b/tests/models/maskformer/test_modeling_maskformer_swin.py @@ -25,6 +25,7 @@ from transformers.utils import is_torch_available from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -162,7 +163,7 @@ class MaskFormerSwinModelTester: @require_torch -class MaskFormerSwinModelTest(ModelTesterMixin, unittest.TestCase): +class MaskFormerSwinModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( MaskFormerSwinModel, @@ -171,6 +172,7 @@ class MaskFormerSwinModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = {"feature-extraction": MaskFormerSwinModel} if is_torch_available() else {} fx_compatible = False test_torchscript = False test_pruning = False diff --git a/tests/models/mbart/test_modeling_mbart.py b/tests/models/mbart/test_modeling_mbart.py index 59545ccd2f..b52d2f04d0 100644 --- a/tests/models/mbart/test_modeling_mbart.py +++ b/tests/models/mbart/test_modeling_mbart.py @@ -26,6 +26,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -224,13 +225,28 @@ class MBartModelTester: @require_torch -class MBartModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class MBartModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (MBartModel, MBartForConditionalGeneration, MBartForSequenceClassification, MBartForQuestionAnswering) if is_torch_available() else () ) all_generative_model_classes = (MBartForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": MBartForConditionalGeneration, + "feature-extraction": MBartModel, + "fill-mask": MBartForConditionalGeneration, + "question-answering": MBartForQuestionAnswering, + "summarization": MBartForConditionalGeneration, + "text2text-generation": MBartForConditionalGeneration, + "text-classification": MBartForSequenceClassification, + "text-generation": MBartForCausalLM, + "zero-shot": MBartForSequenceClassification, + } + if is_torch_available() + else {} + ) is_encoder_decoder = True fx_compatible = False # Fix me Michael test_pruning = False diff --git a/tests/models/mbart/test_modeling_tf_mbart.py b/tests/models/mbart/test_modeling_tf_mbart.py index 166fd6bcb4..52cd24be27 100644 --- a/tests/models/mbart/test_modeling_tf_mbart.py +++ b/tests/models/mbart/test_modeling_tf_mbart.py @@ -22,6 +22,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -180,9 +181,19 @@ def prepare_mbart_inputs_dict( @require_tf -class TFMBartModelTest(TFModelTesterMixin, unittest.TestCase): +class TFMBartModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TFMBartForConditionalGeneration, TFMBartModel) if is_tf_available() else () all_generative_model_classes = (TFMBartForConditionalGeneration,) if is_tf_available() else () + pipeline_model_mapping = ( + { + "conversational": TFMBartForConditionalGeneration, + "feature-extraction": TFMBartModel, + "summarization": TFMBartForConditionalGeneration, + "text2text-generation": TFMBartForConditionalGeneration, + } + if is_tf_available() + else {} + ) is_encoder_decoder = True test_pruning = False test_onnx = False diff --git a/tests/models/mctct/test_modeling_mctct.py b/tests/models/mctct/test_modeling_mctct.py index a4e0997e3f..c488c3e75d 100644 --- a/tests/models/mctct/test_modeling_mctct.py +++ b/tests/models/mctct/test_modeling_mctct.py @@ -25,6 +25,7 @@ from transformers.testing_utils import require_soundfile, require_torch, slow, t from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -265,8 +266,11 @@ class MCTCTModelTester: @require_torch @unittest.skipIf(is_torch_less_than_1_9, "MCTCT is only available in torch v1.9+") -class MCTCTModelTest(ModelTesterMixin, unittest.TestCase): +class MCTCTModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (MCTCTForCTC, MCTCTModel) if is_torch_available() else () + pipeline_model_mapping = ( + {"automatic-speech-recognition": MCTCTForCTC, "feature-extraction": MCTCTModel} if is_torch_available() else {} + ) test_pruning = False test_headmasking = False test_torchscript = False diff --git a/tests/models/megatron_bert/test_modeling_megatron_bert.py b/tests/models/megatron_bert/test_modeling_megatron_bert.py index 2a0c2f6ead..bc1d81c4e0 100644 --- a/tests/models/megatron_bert/test_modeling_megatron_bert.py +++ b/tests/models/megatron_bert/test_modeling_megatron_bert.py @@ -25,6 +25,7 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -266,7 +267,7 @@ class MegatronBertModelTester: @require_torch -class MegatronBertModelTest(ModelTesterMixin, unittest.TestCase): +class MegatronBertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( MegatronBertModel, @@ -282,6 +283,19 @@ class MegatronBertModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": MegatronBertModel, + "fill-mask": MegatronBertForMaskedLM, + "question-answering": MegatronBertForQuestionAnswering, + "text-classification": MegatronBertForSequenceClassification, + "text-generation": MegatronBertForCausalLM, + "token-classification": MegatronBertForTokenClassification, + "zero-shot": MegatronBertForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = True # test_resize_embeddings = False test_head_masking = False diff --git a/tests/models/mobilebert/test_modeling_mobilebert.py b/tests/models/mobilebert/test_modeling_mobilebert.py index 45b0942e2b..6e4f696b8b 100644 --- a/tests/models/mobilebert/test_modeling_mobilebert.py +++ b/tests/models/mobilebert/test_modeling_mobilebert.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -253,7 +254,7 @@ class MobileBertModelTester: @require_torch -class MobileBertModelTest(ModelTesterMixin, unittest.TestCase): +class MobileBertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( MobileBertModel, @@ -268,6 +269,18 @@ class MobileBertModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": MobileBertModel, + "fill-mask": MobileBertForMaskedLM, + "question-answering": MobileBertForQuestionAnswering, + "text-classification": MobileBertForSequenceClassification, + "token-classification": MobileBertForTokenClassification, + "zero-shot": MobileBertForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = True # special case for ForPreTraining model diff --git a/tests/models/mobilebert/test_modeling_tf_mobilebert.py b/tests/models/mobilebert/test_modeling_tf_mobilebert.py index 2ee38a6ee6..69d2fc6768 100644 --- a/tests/models/mobilebert/test_modeling_tf_mobilebert.py +++ b/tests/models/mobilebert/test_modeling_tf_mobilebert.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_tf, slow, tooslow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -41,7 +42,7 @@ if is_tf_available(): @require_tf -class TFMobileBertModelTest(TFModelTesterMixin, unittest.TestCase): +class TFMobileBertModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFMobileBertModel, @@ -56,6 +57,18 @@ class TFMobileBertModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFMobileBertModel, + "fill-mask": TFMobileBertForMaskedLM, + "question-answering": TFMobileBertForQuestionAnswering, + "text-classification": TFMobileBertForSequenceClassification, + "token-classification": TFMobileBertForTokenClassification, + "zero-shot": TFMobileBertForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/mobilenet_v1/test_modeling_mobilenet_v1.py b/tests/models/mobilenet_v1/test_modeling_mobilenet_v1.py index 4bf3cc1c13..0129143ec7 100644 --- a/tests/models/mobilenet_v1/test_modeling_mobilenet_v1.py +++ b/tests/models/mobilenet_v1/test_modeling_mobilenet_v1.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -139,13 +140,18 @@ class MobileNetV1ModelTester: @require_torch -class MobileNetV1ModelTest(ModelTesterMixin, unittest.TestCase): +class MobileNetV1ModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as MobileNetV1 does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (MobileNetV1Model, MobileNetV1ForImageClassification) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": MobileNetV1Model, "image-classification": MobileNetV1ForImageClassification} + if is_torch_available() + else {} + ) test_pruning = False test_resize_embeddings = False diff --git a/tests/models/mobilenet_v2/test_modeling_mobilenet_v2.py b/tests/models/mobilenet_v2/test_modeling_mobilenet_v2.py index 70a6d710a7..e3768d0ee0 100644 --- a/tests/models/mobilenet_v2/test_modeling_mobilenet_v2.py +++ b/tests/models/mobilenet_v2/test_modeling_mobilenet_v2.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -182,7 +183,7 @@ class MobileNetV2ModelTester: @require_torch -class MobileNetV2ModelTest(ModelTesterMixin, unittest.TestCase): +class MobileNetV2ModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as MobileNetV2 does not use input_ids, inputs_embeds, attention_mask and seq_length. @@ -193,6 +194,15 @@ class MobileNetV2ModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": MobileNetV2Model, + "image-classification": MobileNetV2ForImageClassification, + "image-segmentation": MobileNetV2ForSemanticSegmentation, + } + if is_torch_available() + else {} + ) test_pruning = False test_resize_embeddings = False diff --git a/tests/models/mobilevit/test_modeling_mobilevit.py b/tests/models/mobilevit/test_modeling_mobilevit.py index bb86cbc451..e9029cd085 100644 --- a/tests/models/mobilevit/test_modeling_mobilevit.py +++ b/tests/models/mobilevit/test_modeling_mobilevit.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -173,7 +174,7 @@ class MobileViTModelTester: @require_torch -class MobileViTModelTest(ModelTesterMixin, unittest.TestCase): +class MobileViTModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as MobileViT does not use input_ids, inputs_embeds, attention_mask and seq_length. @@ -184,6 +185,15 @@ class MobileViTModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": MobileViTModel, + "image-classification": MobileViTForImageClassification, + "image-segmentation": MobileViTForSemanticSegmentation, + } + if is_torch_available() + else {} + ) test_pruning = False test_resize_embeddings = False diff --git a/tests/models/mobilevit/test_modeling_tf_mobilevit.py b/tests/models/mobilevit/test_modeling_tf_mobilevit.py index 43c6757baa..e4a956dff2 100644 --- a/tests/models/mobilevit/test_modeling_tf_mobilevit.py +++ b/tests/models/mobilevit/test_modeling_tf_mobilevit.py @@ -24,6 +24,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -154,7 +155,7 @@ class TFMobileViTModelTester: @require_tf -class TFMobileViTModelTest(TFModelTesterMixin, unittest.TestCase): +class TFMobileViTModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as MobileViT does not use input_ids, inputs_embeds, attention_mask and seq_length. @@ -165,6 +166,11 @@ class TFMobileViTModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + {"feature-extraction": TFMobileViTModel, "image-classification": TFMobileViTForImageClassification} + if is_tf_available() + else {} + ) test_pruning = False test_resize_embeddings = False diff --git a/tests/models/mpnet/test_modeling_mpnet.py b/tests/models/mpnet/test_modeling_mpnet.py index 1be0503380..d3261e4bc0 100644 --- a/tests/models/mpnet/test_modeling_mpnet.py +++ b/tests/models/mpnet/test_modeling_mpnet.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -190,7 +191,7 @@ class MPNetModelTester: @require_torch -class MPNetModelTest(ModelTesterMixin, unittest.TestCase): +class MPNetModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( MPNetForMaskedLM, @@ -203,6 +204,18 @@ class MPNetModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": MPNetModel, + "fill-mask": MPNetForMaskedLM, + "question-answering": MPNetForQuestionAnswering, + "text-classification": MPNetForSequenceClassification, + "token-classification": MPNetForTokenClassification, + "zero-shot": MPNetForSequenceClassification, + } + if is_torch_available() + else {} + ) test_pruning = False test_resize_embeddings = True diff --git a/tests/models/mpnet/test_modeling_tf_mpnet.py b/tests/models/mpnet/test_modeling_tf_mpnet.py index 3688e106cc..4936a52899 100644 --- a/tests/models/mpnet/test_modeling_tf_mpnet.py +++ b/tests/models/mpnet/test_modeling_tf_mpnet.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -184,7 +185,7 @@ class TFMPNetModelTester: @require_tf -class TFMPNetModelTest(TFModelTesterMixin, unittest.TestCase): +class TFMPNetModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFMPNetForMaskedLM, @@ -197,6 +198,18 @@ class TFMPNetModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFMPNetModel, + "fill-mask": TFMPNetForMaskedLM, + "question-answering": TFMPNetForQuestionAnswering, + "text-classification": TFMPNetForSequenceClassification, + "token-classification": TFMPNetForTokenClassification, + "zero-shot": TFMPNetForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/mvp/test_modeling_mvp.py b/tests/models/mvp/test_modeling_mvp.py index edeefb3804..5513f34b46 100644 --- a/tests/models/mvp/test_modeling_mvp.py +++ b/tests/models/mvp/test_modeling_mvp.py @@ -28,6 +28,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -405,13 +406,28 @@ class MvpHeadTests(unittest.TestCase): @require_torch -class MvpModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class MvpModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (MvpModel, MvpForConditionalGeneration, MvpForSequenceClassification, MvpForQuestionAnswering) if is_torch_available() else () ) all_generative_model_classes = (MvpForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": MvpForConditionalGeneration, + "feature-extraction": MvpModel, + "fill-mask": MvpForConditionalGeneration, + "question-answering": MvpForQuestionAnswering, + "summarization": MvpForConditionalGeneration, + "text2text-generation": MvpForConditionalGeneration, + "text-classification": MvpForSequenceClassification, + "text-generation": MvpForCausalLM, + "zero-shot": MvpForSequenceClassification, + } + if is_torch_available() + else {} + ) is_encoder_decoder = True fx_compatible = False test_pruning = False diff --git a/tests/models/nat/test_modeling_nat.py b/tests/models/nat/test_modeling_nat.py index 1c74fe84b0..dff0a43237 100644 --- a/tests/models/nat/test_modeling_nat.py +++ b/tests/models/nat/test_modeling_nat.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -189,7 +190,7 @@ class NatModelTester: @require_natten @require_torch -class NatModelTest(ModelTesterMixin, unittest.TestCase): +class NatModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( NatModel, @@ -199,6 +200,11 @@ class NatModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + {"feature-extraction": NatModel, "image-classification": NatForImageClassification} + if is_torch_available() + else {} + ) fx_compatible = False test_torchscript = False diff --git a/tests/models/nezha/test_modeling_nezha.py b/tests/models/nezha/test_modeling_nezha.py index 31eb9e1e9b..5b36ffbc96 100644 --- a/tests/models/nezha/test_modeling_nezha.py +++ b/tests/models/nezha/test_modeling_nezha.py @@ -23,6 +23,7 @@ from transformers.testing_utils import require_torch, require_torch_gpu, slow, t from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -315,7 +316,7 @@ class NezhaModelTester: @require_torch -class NezhaModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class NezhaModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( NezhaModel, @@ -330,6 +331,18 @@ class NezhaModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase) if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": NezhaModel, + "fill-mask": NezhaForMaskedLM, + "question-answering": NezhaForQuestionAnswering, + "text-classification": NezhaForSequenceClassification, + "token-classification": NezhaForTokenClassification, + "zero-shot": NezhaForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = True # special case for ForPreTraining model diff --git a/tests/models/nystromformer/test_modeling_nystromformer.py b/tests/models/nystromformer/test_modeling_nystromformer.py index 4387957106..390308631d 100644 --- a/tests/models/nystromformer/test_modeling_nystromformer.py +++ b/tests/models/nystromformer/test_modeling_nystromformer.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -216,7 +217,7 @@ class NystromformerModelTester: @require_torch -class NystromformerModelTest(ModelTesterMixin, unittest.TestCase): +class NystromformerModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( NystromformerModel, @@ -229,6 +230,18 @@ class NystromformerModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": NystromformerModel, + "fill-mask": NystromformerForMaskedLM, + "question-answering": NystromformerForQuestionAnswering, + "text-classification": NystromformerForSequenceClassification, + "token-classification": NystromformerForTokenClassification, + "zero-shot": NystromformerForSequenceClassification, + } + if is_torch_available() + else {} + ) test_pruning = False test_headmasking = False diff --git a/tests/models/oneformer/test_modeling_oneformer.py b/tests/models/oneformer/test_modeling_oneformer.py index 83c3a94384..99ab909a4d 100644 --- a/tests/models/oneformer/test_modeling_oneformer.py +++ b/tests/models/oneformer/test_modeling_oneformer.py @@ -27,6 +27,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -214,8 +215,9 @@ class OneFormerModelTester: @require_torch -class OneFormerModelTest(ModelTesterMixin, unittest.TestCase): +class OneFormerModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (OneFormerModel, OneFormerForUniversalSegmentation) if is_torch_available() else () + pipeline_model_mapping = {"feature-extraction": OneFormerModel} if is_torch_available() else {} is_encoder_decoder = False test_pruning = False diff --git a/tests/models/openai/test_modeling_openai.py b/tests/models/openai/test_modeling_openai.py index e525c29741..a9d76d3770 100644 --- a/tests/models/openai/test_modeling_openai.py +++ b/tests/models/openai/test_modeling_openai.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -189,7 +190,7 @@ class OpenAIGPTModelTester: @require_torch -class OpenAIGPTModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class OpenAIGPTModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (OpenAIGPTModel, OpenAIGPTLMHeadModel, OpenAIGPTDoubleHeadsModel, OpenAIGPTForSequenceClassification) if is_torch_available() @@ -198,6 +199,16 @@ class OpenAIGPTModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestC all_generative_model_classes = ( (OpenAIGPTLMHeadModel,) if is_torch_available() else () ) # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly + pipeline_model_mapping = ( + { + "feature-extraction": OpenAIGPTModel, + "text-classification": OpenAIGPTForSequenceClassification, + "text-generation": OpenAIGPTLMHeadModel, + "zero-shot": OpenAIGPTForSequenceClassification, + } + if is_torch_available() + else {} + ) # special case for DoubleHeads model def _prepare_for_class(self, inputs_dict, model_class, return_labels=False): diff --git a/tests/models/openai/test_modeling_tf_openai.py b/tests/models/openai/test_modeling_tf_openai.py index 3ce67e058a..f059487f21 100644 --- a/tests/models/openai/test_modeling_tf_openai.py +++ b/tests/models/openai/test_modeling_tf_openai.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -191,7 +192,7 @@ class TFOpenAIGPTModelTester: @require_tf -class TFOpenAIGPTModelTest(TFModelTesterMixin, unittest.TestCase): +class TFOpenAIGPTModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (TFOpenAIGPTModel, TFOpenAIGPTLMHeadModel, TFOpenAIGPTDoubleHeadsModel, TFOpenAIGPTForSequenceClassification) if is_tf_available() @@ -200,6 +201,16 @@ class TFOpenAIGPTModelTest(TFModelTesterMixin, unittest.TestCase): all_generative_model_classes = ( (TFOpenAIGPTLMHeadModel,) if is_tf_available() else () ) # TODO (PVP): Add Double HeadsModel when generate() function is changed accordingly + pipeline_model_mapping = ( + { + "feature-extraction": TFOpenAIGPTModel, + "text-classification": TFOpenAIGPTForSequenceClassification, + "text-generation": TFOpenAIGPTLMHeadModel, + "zero-shot": TFOpenAIGPTForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/opt/test_modeling_opt.py b/tests/models/opt/test_modeling_opt.py index 5aefc14acf..4805f1c215 100644 --- a/tests/models/opt/test_modeling_opt.py +++ b/tests/models/opt/test_modeling_opt.py @@ -27,6 +27,7 @@ from transformers.testing_utils import require_torch, require_torch_gpu, slow, t from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -183,13 +184,24 @@ class OPTModelTester: @require_torch -class OPTModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class OPTModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (OPTModel, OPTForCausalLM, OPTForSequenceClassification, OPTForQuestionAnswering) if is_torch_available() else () ) all_generative_model_classes = (OPTForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": OPTModel, + "question-answering": OPTForQuestionAnswering, + "text-classification": OPTForSequenceClassification, + "text-generation": OPTForCausalLM, + "zero-shot": OPTForSequenceClassification, + } + if is_torch_available() + else {} + ) is_encoder_decoder = False fx_compatible = True test_pruning = False diff --git a/tests/models/opt/test_modeling_tf_opt.py b/tests/models/opt/test_modeling_tf_opt.py index 4e9972e4aa..0ae3411812 100644 --- a/tests/models/opt/test_modeling_tf_opt.py +++ b/tests/models/opt/test_modeling_tf_opt.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_sentencepiece, require_tf, slow, from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -146,9 +147,12 @@ class TFOPTModelTester: @require_tf -class TFOPTModelTest(TFModelTesterMixin, unittest.TestCase): +class TFOPTModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TFOPTModel, TFOPTForCausalLM) if is_tf_available() else () all_generative_model_classes = (TFOPTForCausalLM,) if is_tf_available() else () + pipeline_model_mapping = ( + {"feature-extraction": TFOPTModel, "text-generation": TFOPTForCausalLM} if is_tf_available() else {} + ) is_encoder_decoder = False test_pruning = False test_onnx = False diff --git a/tests/models/owlvit/test_modeling_owlvit.py b/tests/models/owlvit/test_modeling_owlvit.py index bd83d7e682..acf078ffe8 100644 --- a/tests/models/owlvit/test_modeling_owlvit.py +++ b/tests/models/owlvit/test_modeling_owlvit.py @@ -35,6 +35,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -393,8 +394,13 @@ class OwlViTModelTester: @require_torch -class OwlViTModelTest(ModelTesterMixin, unittest.TestCase): +class OwlViTModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (OwlViTModel,) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": OwlViTModel, "zero-shot-object-detection": OwlViTForObjectDetection} + if is_torch_available() + else {} + ) fx_compatible = False test_head_masking = False test_pruning = False diff --git a/tests/models/pegasus/test_modeling_pegasus.py b/tests/models/pegasus/test_modeling_pegasus.py index 7f8cc58d3f..de6c78df61 100644 --- a/tests/models/pegasus/test_modeling_pegasus.py +++ b/tests/models/pegasus/test_modeling_pegasus.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin from ..mbart.test_modeling_mbart import AbstractSeq2SeqIntegrationTest @@ -233,9 +234,20 @@ class PegasusModelTester: @require_torch -class PegasusModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class PegasusModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (PegasusModel, PegasusForConditionalGeneration) if is_torch_available() else () all_generative_model_classes = (PegasusForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": PegasusForConditionalGeneration, + "feature-extraction": PegasusModel, + "summarization": PegasusForConditionalGeneration, + "text2text-generation": PegasusForConditionalGeneration, + "text-generation": PegasusForCausalLM, + } + if is_torch_available() + else {} + ) is_encoder_decoder = True fx_compatible = True test_resize_position_embeddings = True diff --git a/tests/models/pegasus/test_modeling_tf_pegasus.py b/tests/models/pegasus/test_modeling_tf_pegasus.py index 5dc6be7303..a7f47f6756 100644 --- a/tests/models/pegasus/test_modeling_tf_pegasus.py +++ b/tests/models/pegasus/test_modeling_tf_pegasus.py @@ -22,6 +22,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -175,9 +176,19 @@ def prepare_pegasus_inputs_dict( @require_tf -class TFPegasusModelTest(TFModelTesterMixin, unittest.TestCase): +class TFPegasusModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TFPegasusForConditionalGeneration, TFPegasusModel) if is_tf_available() else () all_generative_model_classes = (TFPegasusForConditionalGeneration,) if is_tf_available() else () + pipeline_model_mapping = ( + { + "conversational": TFPegasusForConditionalGeneration, + "feature-extraction": TFPegasusModel, + "summarization": TFPegasusForConditionalGeneration, + "text2text-generation": TFPegasusForConditionalGeneration, + } + if is_tf_available() + else {} + ) is_encoder_decoder = True test_pruning = False test_onnx = False diff --git a/tests/models/pegasus_x/test_modeling_pegasus_x.py b/tests/models/pegasus_x/test_modeling_pegasus_x.py index 1e53e0ec4e..545fe5149b 100644 --- a/tests/models/pegasus_x/test_modeling_pegasus_x.py +++ b/tests/models/pegasus_x/test_modeling_pegasus_x.py @@ -27,6 +27,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -194,9 +195,19 @@ class PegasusXModelTester: @require_torch -class PegasusXModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class PegasusXModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (PegasusXModel, PegasusXForConditionalGeneration) if is_torch_available() else () all_generative_model_classes = (PegasusXForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": PegasusXForConditionalGeneration, + "feature-extraction": PegasusXModel, + "summarization": PegasusXForConditionalGeneration, + "text2text-generation": PegasusXForConditionalGeneration, + } + if is_torch_available() + else {} + ) is_encoder_decoder = True test_pruning = False test_head_masking = False diff --git a/tests/models/perceiver/test_modeling_perceiver.py b/tests/models/perceiver/test_modeling_perceiver.py index 872aed47e2..c4a32b1647 100644 --- a/tests/models/perceiver/test_modeling_perceiver.py +++ b/tests/models/perceiver/test_modeling_perceiver.py @@ -32,6 +32,7 @@ from transformers.utils import is_torch_available, is_vision_available from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -264,7 +265,7 @@ class PerceiverModelTester: @require_torch -class PerceiverModelTest(ModelTesterMixin, unittest.TestCase): +class PerceiverModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( PerceiverModel, @@ -279,6 +280,21 @@ class PerceiverModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": PerceiverModel, + "fill-mask": PerceiverForMaskedLM, + "image-classification": ( + PerceiverForImageClassificationConvProcessing, + PerceiverForImageClassificationFourier, + PerceiverForImageClassificationLearned, + ), + "text-classification": PerceiverForSequenceClassification, + "zero-shot": PerceiverForSequenceClassification, + } + if is_torch_available() + else {} + ) test_pruning = False test_head_masking = False test_torchscript = False diff --git a/tests/models/plbart/test_modeling_plbart.py b/tests/models/plbart/test_modeling_plbart.py index 38eca39b28..28278f9a46 100644 --- a/tests/models/plbart/test_modeling_plbart.py +++ b/tests/models/plbart/test_modeling_plbart.py @@ -26,6 +26,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -213,11 +214,24 @@ class PLBartModelTester: @require_torch -class PLBartModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class PLBartModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (PLBartModel, PLBartForConditionalGeneration, PLBartForSequenceClassification) if is_torch_available() else () ) all_generative_model_classes = (PLBartForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": PLBartForConditionalGeneration, + "feature-extraction": PLBartModel, + "summarization": PLBartForConditionalGeneration, + "text2text-generation": PLBartForConditionalGeneration, + "text-classification": PLBartForSequenceClassification, + "text-generation": PLBartForCausalLM, + "zero-shot": PLBartForSequenceClassification, + } + if is_torch_available() + else {} + ) is_encoder_decoder = True fx_compatible = False # Fix me Michael test_pruning = False diff --git a/tests/models/poolformer/test_modeling_poolformer.py b/tests/models/poolformer/test_modeling_poolformer.py index a7869cbf74..e741b9650d 100644 --- a/tests/models/poolformer/test_modeling_poolformer.py +++ b/tests/models/poolformer/test_modeling_poolformer.py @@ -24,6 +24,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -121,8 +122,13 @@ class PoolFormerModelTester: @require_torch -class PoolFormerModelTest(ModelTesterMixin, unittest.TestCase): +class PoolFormerModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (PoolFormerModel, PoolFormerForImageClassification) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": PoolFormerModel, "image-classification": PoolFormerForImageClassification} + if is_torch_available() + else {} + ) test_head_masking = False test_pruning = False diff --git a/tests/models/prophetnet/test_modeling_prophetnet.py b/tests/models/prophetnet/test_modeling_prophetnet.py index 2c98102a0c..36d5da6836 100644 --- a/tests/models/prophetnet/test_modeling_prophetnet.py +++ b/tests/models/prophetnet/test_modeling_prophetnet.py @@ -23,6 +23,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -885,9 +886,20 @@ class ProphetNetStandaloneEncoderModelTester: @require_torch -class ProphetNetModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class ProphetNetModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (ProphetNetModel, ProphetNetForConditionalGeneration) if is_torch_available() else () all_generative_model_classes = (ProphetNetForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": ProphetNetForConditionalGeneration, + "feature-extraction": ProphetNetModel, + "summarization": ProphetNetForConditionalGeneration, + "text2text-generation": ProphetNetForConditionalGeneration, + "text-generation": ProphetNetForCausalLM, + } + if is_torch_available() + else {} + ) test_pruning = False test_resize_embeddings = False is_encoder_decoder = True diff --git a/tests/models/qdqbert/test_modeling_qdqbert.py b/tests/models/qdqbert/test_modeling_qdqbert.py index 66e864a6be..cc05389eea 100644 --- a/tests/models/qdqbert/test_modeling_qdqbert.py +++ b/tests/models/qdqbert/test_modeling_qdqbert.py @@ -23,6 +23,7 @@ from transformers.testing_utils import require_pytorch_quantization, require_tor from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -419,7 +420,7 @@ class QDQBertModelTester: @require_torch @require_pytorch_quantization -class QDQBertModelTest(ModelTesterMixin, unittest.TestCase): +class QDQBertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( QDQBertModel, @@ -435,6 +436,19 @@ class QDQBertModelTest(ModelTesterMixin, unittest.TestCase): else () ) all_generative_model_classes = (QDQBertLMHeadModel,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": QDQBertModel, + "fill-mask": QDQBertForMaskedLM, + "question-answering": QDQBertForQuestionAnswering, + "text-classification": QDQBertForSequenceClassification, + "text-generation": QDQBertLMHeadModel, + "token-classification": QDQBertForTokenClassification, + "zero-shot": QDQBertForSequenceClassification, + } + if is_torch_available() + else {} + ) def setUp(self): self.model_tester = QDQBertModelTester(self) diff --git a/tests/models/realm/test_modeling_realm.py b/tests/models/realm/test_modeling_realm.py index 3fa993285d..228e0344b8 100644 --- a/tests/models/realm/test_modeling_realm.py +++ b/tests/models/realm/test_modeling_realm.py @@ -24,6 +24,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -303,7 +304,7 @@ class RealmModelTester: @require_torch -class RealmModelTest(ModelTesterMixin, unittest.TestCase): +class RealmModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( RealmEmbedder, @@ -316,6 +317,7 @@ class RealmModelTest(ModelTesterMixin, unittest.TestCase): else () ) all_generative_model_classes = () + pipeline_model_mapping = {} if is_torch_available() else {} # disable these tests because there is no base_model in Realm test_save_load_fast_init_from_base = False diff --git a/tests/models/reformer/test_modeling_reformer.py b/tests/models/reformer/test_modeling_reformer.py index 4af7b9864b..4793f4ea43 100644 --- a/tests/models/reformer/test_modeling_reformer.py +++ b/tests/models/reformer/test_modeling_reformer.py @@ -28,6 +28,7 @@ from transformers.testing_utils import ( from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -683,13 +684,27 @@ class ReformerLocalAttnModelTest(ReformerTesterMixin, GenerationTesterMixin, Mod @require_torch -class ReformerLSHAttnModelTest(ReformerTesterMixin, ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class ReformerLSHAttnModelTest( + ReformerTesterMixin, ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase +): all_model_classes = ( (ReformerModel, ReformerModelWithLMHead, ReformerForSequenceClassification, ReformerForQuestionAnswering) if is_torch_available() else () ) all_generative_model_classes = (ReformerModelWithLMHead,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": ReformerModel, + "fill-mask": ReformerForMaskedLM, + "question-answering": ReformerForQuestionAnswering, + "text-classification": ReformerForSequenceClassification, + "text-generation": ReformerModelWithLMHead, + "zero-shot": ReformerForSequenceClassification, + } + if is_torch_available() + else {} + ) test_pruning = False test_headmasking = False test_torchscript = False diff --git a/tests/models/regnet/test_modeling_regnet.py b/tests/models/regnet/test_modeling_regnet.py index 02695dbf64..e7c33699fd 100644 --- a/tests/models/regnet/test_modeling_regnet.py +++ b/tests/models/regnet/test_modeling_regnet.py @@ -24,6 +24,7 @@ from transformers.testing_utils import require_torch, require_vision, slow, torc from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -118,13 +119,18 @@ class RegNetModelTester: @require_torch -class RegNetModelTest(ModelTesterMixin, unittest.TestCase): +class RegNetModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as RegNet does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (RegNetModel, RegNetForImageClassification) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": RegNetModel, "image-classification": RegNetForImageClassification} + if is_torch_available() + else {} + ) test_pruning = False test_resize_embeddings = False diff --git a/tests/models/regnet/test_modeling_tf_regnet.py b/tests/models/regnet/test_modeling_tf_regnet.py index 2977d43c06..f5f5cfd4b9 100644 --- a/tests/models/regnet/test_modeling_tf_regnet.py +++ b/tests/models/regnet/test_modeling_tf_regnet.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property, is_tf_available, is_vision_avail from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -111,13 +112,18 @@ class TFRegNetModelTester: @require_tf -class TFRegNetModelTest(TFModelTesterMixin, unittest.TestCase): +class TFRegNetModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as RegNet does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (TFRegNetModel, TFRegNetForImageClassification) if is_tf_available() else () + pipeline_model_mapping = ( + {"feature-extraction": TFRegNetModel, "image-classification": TFRegNetForImageClassification} + if is_tf_available() + else {} + ) test_pruning = False test_onnx = False diff --git a/tests/models/rembert/test_modeling_rembert.py b/tests/models/rembert/test_modeling_rembert.py index 180b71b17a..4e6754b2e5 100644 --- a/tests/models/rembert/test_modeling_rembert.py +++ b/tests/models/rembert/test_modeling_rembert.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -360,7 +361,7 @@ class RemBertModelTester: @require_torch -class RemBertModelTest(ModelTesterMixin, unittest.TestCase): +class RemBertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( RemBertModel, @@ -375,6 +376,19 @@ class RemBertModelTest(ModelTesterMixin, unittest.TestCase): else () ) all_generative_model_classes = (RemBertForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": RemBertModel, + "fill-mask": RemBertForMaskedLM, + "question-answering": RemBertForQuestionAnswering, + "text-classification": RemBertForSequenceClassification, + "text-generation": RemBertForCausalLM, + "token-classification": RemBertForTokenClassification, + "zero-shot": RemBertForSequenceClassification, + } + if is_torch_available() + else {} + ) def setUp(self): self.model_tester = RemBertModelTester(self) diff --git a/tests/models/rembert/test_modeling_tf_rembert.py b/tests/models/rembert/test_modeling_tf_rembert.py index 11a7b54497..7ab71e9c6e 100644 --- a/tests/models/rembert/test_modeling_tf_rembert.py +++ b/tests/models/rembert/test_modeling_tf_rembert.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -570,7 +571,7 @@ class TFRemBertModelTester: @require_tf -class TFRemBertModelTest(TFModelTesterMixin, unittest.TestCase): +class TFRemBertModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFRemBertModel, @@ -584,6 +585,19 @@ class TFRemBertModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFRemBertModel, + "fill-mask": TFRemBertForMaskedLM, + "question-answering": TFRemBertForQuestionAnswering, + "text-classification": TFRemBertForSequenceClassification, + "text-generation": TFRemBertForCausalLM, + "token-classification": TFRemBertForTokenClassification, + "zero-shot": TFRemBertForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/resnet/test_modeling_resnet.py b/tests/models/resnet/test_modeling_resnet.py index f4b79fb24b..31d19d4bdf 100644 --- a/tests/models/resnet/test_modeling_resnet.py +++ b/tests/models/resnet/test_modeling_resnet.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -150,7 +151,7 @@ class ResNetModelTester: @require_torch -class ResNetModelTest(ModelTesterMixin, unittest.TestCase): +class ResNetModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as ResNet does not use input_ids, inputs_embeds, attention_mask and seq_length. @@ -165,6 +166,11 @@ class ResNetModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + {"feature-extraction": ResNetModel, "image-classification": ResNetForImageClassification} + if is_torch_available() + else {} + ) fx_compatible = True test_pruning = False diff --git a/tests/models/resnet/test_modeling_tf_resnet.py b/tests/models/resnet/test_modeling_tf_resnet.py index fdcbc1c734..0a8ccc0041 100644 --- a/tests/models/resnet/test_modeling_tf_resnet.py +++ b/tests/models/resnet/test_modeling_tf_resnet.py @@ -26,6 +26,7 @@ from transformers.utils import cached_property, is_tf_available, is_vision_avail from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -116,13 +117,18 @@ class TFResNetModelTester: @require_tf -class TFResNetModelTest(TFModelTesterMixin, unittest.TestCase): +class TFResNetModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as ResNet does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (TFResNetModel, TFResNetForImageClassification) if is_tf_available() else () + pipeline_model_mapping = ( + {"feature-extraction": TFResNetModel, "image-classification": TFResNetForImageClassification} + if is_tf_available() + else {} + ) test_pruning = False test_resize_embeddings = False diff --git a/tests/models/roberta/test_modeling_roberta.py b/tests/models/roberta/test_modeling_roberta.py index f9df989d9b..49caa67d4f 100644 --- a/tests/models/roberta/test_modeling_roberta.py +++ b/tests/models/roberta/test_modeling_roberta.py @@ -23,6 +23,7 @@ from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_ from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -366,7 +367,7 @@ class RobertaModelTester: @require_torch -class RobertaModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class RobertaModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( RobertaForCausalLM, @@ -381,6 +382,19 @@ class RobertaModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCas else () ) all_generative_model_classes = (RobertaForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": RobertaModel, + "fill-mask": RobertaForMaskedLM, + "question-answering": RobertaForQuestionAnswering, + "text-classification": RobertaForSequenceClassification, + "text-generation": RobertaForCausalLM, + "token-classification": RobertaForTokenClassification, + "zero-shot": RobertaForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = True def setUp(self): diff --git a/tests/models/roberta/test_modeling_tf_roberta.py b/tests/models/roberta/test_modeling_tf_roberta.py index 28166171e1..efa54ba45f 100644 --- a/tests/models/roberta/test_modeling_tf_roberta.py +++ b/tests/models/roberta/test_modeling_tf_roberta.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_sentencepiece, require_tf, requir from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -547,7 +548,7 @@ class TFRobertaModelTester: @require_tf -class TFRobertaModelTest(TFModelTesterMixin, unittest.TestCase): +class TFRobertaModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFRobertaModel, @@ -560,6 +561,19 @@ class TFRobertaModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFRobertaModel, + "fill-mask": TFRobertaForMaskedLM, + "question-answering": TFRobertaForQuestionAnswering, + "text-classification": TFRobertaForSequenceClassification, + "text-generation": TFRobertaForCausalLM, + "token-classification": TFRobertaForTokenClassification, + "zero-shot": TFRobertaForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/roberta_prelayernorm/test_modeling_roberta_prelayernorm.py b/tests/models/roberta_prelayernorm/test_modeling_roberta_prelayernorm.py index d32a5e959d..4e4915147f 100644 --- a/tests/models/roberta_prelayernorm/test_modeling_roberta_prelayernorm.py +++ b/tests/models/roberta_prelayernorm/test_modeling_roberta_prelayernorm.py @@ -22,6 +22,7 @@ from transformers.testing_utils import TestCasePlus, require_torch, slow, torch_ from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -365,7 +366,7 @@ class RobertaPreLayerNormModelTester: @require_torch # Copied from tests.models.roberta.test_modelling_roberta.RobertaPreLayerNormModelTest with ROBERTA->ROBERTA_PRELAYERNORM,Roberta->RobertaPreLayerNorm -class RobertaPreLayerNormModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class RobertaPreLayerNormModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( RobertaPreLayerNormForCausalLM, @@ -380,6 +381,19 @@ class RobertaPreLayerNormModelTest(ModelTesterMixin, GenerationTesterMixin, unit else () ) all_generative_model_classes = (RobertaPreLayerNormForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": RobertaPreLayerNormModel, + "fill-mask": RobertaPreLayerNormForMaskedLM, + "question-answering": RobertaPreLayerNormForQuestionAnswering, + "text-classification": RobertaPreLayerNormForSequenceClassification, + "text-generation": RobertaPreLayerNormForCausalLM, + "token-classification": RobertaPreLayerNormForTokenClassification, + "zero-shot": RobertaPreLayerNormForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = False def setUp(self): diff --git a/tests/models/roberta_prelayernorm/test_modeling_tf_roberta_prelayernorm.py b/tests/models/roberta_prelayernorm/test_modeling_tf_roberta_prelayernorm.py index 1580f27e6f..6de20c0e1d 100644 --- a/tests/models/roberta_prelayernorm/test_modeling_tf_roberta_prelayernorm.py +++ b/tests/models/roberta_prelayernorm/test_modeling_tf_roberta_prelayernorm.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_sentencepiece, require_tf, requir from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -549,7 +550,7 @@ class TFRobertaPreLayerNormModelTester: @require_tf # Copied from tests.models.roberta.test_modelling_tf_roberta.TFRobertaPreLayerNormModelTest with ROBERTA->ROBERTA_PRELAYERNORM,Roberta->RobertaPreLayerNorm -class TFRobertaPreLayerNormModelTest(TFModelTesterMixin, unittest.TestCase): +class TFRobertaPreLayerNormModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFRobertaPreLayerNormModel, @@ -562,6 +563,19 @@ class TFRobertaPreLayerNormModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFRobertaPreLayerNormModel, + "fill-mask": TFRobertaPreLayerNormForMaskedLM, + "question-answering": TFRobertaPreLayerNormForQuestionAnswering, + "text-classification": TFRobertaPreLayerNormForSequenceClassification, + "text-generation": TFRobertaPreLayerNormForCausalLM, + "token-classification": TFRobertaPreLayerNormForTokenClassification, + "zero-shot": TFRobertaPreLayerNormForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/roc_bert/test_modeling_roc_bert.py b/tests/models/roc_bert/test_modeling_roc_bert.py index bc7893b9c5..afc0f63122 100644 --- a/tests/models/roc_bert/test_modeling_roc_bert.py +++ b/tests/models/roc_bert/test_modeling_roc_bert.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -555,7 +556,7 @@ class RoCBertModelTester: @require_torch -class RoCBertModelTest(ModelTesterMixin, unittest.TestCase): +class RoCBertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( RoCBertModel, @@ -571,6 +572,19 @@ class RoCBertModelTest(ModelTesterMixin, unittest.TestCase): else () ) all_generative_model_classes = (RoCBertForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": RoCBertModel, + "fill-mask": RoCBertForMaskedLM, + "question-answering": RoCBertForQuestionAnswering, + "text-classification": RoCBertForSequenceClassification, + "text-generation": RoCBertForCausalLM, + "token-classification": RoCBertForTokenClassification, + "zero-shot": RoCBertForSequenceClassification, + } + if is_torch_available() + else {} + ) # special case for ForPreTraining model def _prepare_for_class(self, inputs_dict, model_class, return_labels=False): diff --git a/tests/models/roformer/test_modeling_roformer.py b/tests/models/roformer/test_modeling_roformer.py index acd6ec885b..9b91c66cb2 100644 --- a/tests/models/roformer/test_modeling_roformer.py +++ b/tests/models/roformer/test_modeling_roformer.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -360,7 +361,7 @@ class RoFormerModelTester: @require_torch -class RoFormerModelTest(ModelTesterMixin, unittest.TestCase): +class RoFormerModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( RoFormerModel, @@ -375,6 +376,19 @@ class RoFormerModelTest(ModelTesterMixin, unittest.TestCase): else () ) all_generative_model_classes = (RoFormerForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": RoFormerModel, + "fill-mask": RoFormerForMaskedLM, + "question-answering": RoFormerForQuestionAnswering, + "text-classification": RoFormerForSequenceClassification, + "text-generation": RoFormerForCausalLM, + "token-classification": RoFormerForTokenClassification, + "zero-shot": RoFormerForSequenceClassification, + } + if is_torch_available() + else {} + ) def setUp(self): self.model_tester = RoFormerModelTester(self) diff --git a/tests/models/roformer/test_modeling_tf_roformer.py b/tests/models/roformer/test_modeling_tf_roformer.py index a0fba3a680..f5f3875db1 100644 --- a/tests/models/roformer/test_modeling_tf_roformer.py +++ b/tests/models/roformer/test_modeling_tf_roformer.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -239,7 +240,7 @@ class TFRoFormerModelTester: @require_tf -class TFRoFormerModelTest(TFModelTesterMixin, unittest.TestCase): +class TFRoFormerModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFRoFormerModel, @@ -253,6 +254,19 @@ class TFRoFormerModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFRoFormerModel, + "fill-mask": TFRoFormerForMaskedLM, + "question-answering": TFRoFormerForQuestionAnswering, + "text-classification": TFRoFormerForSequenceClassification, + "text-generation": TFRoFormerForCausalLM, + "token-classification": TFRoFormerForTokenClassification, + "zero-shot": TFRoFormerForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/segformer/test_modeling_segformer.py b/tests/models/segformer/test_modeling_segformer.py index 57513800d6..c357fee5ae 100644 --- a/tests/models/segformer/test_modeling_segformer.py +++ b/tests/models/segformer/test_modeling_segformer.py @@ -24,6 +24,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -159,7 +160,7 @@ class SegformerModelTester: @require_torch -class SegformerModelTest(ModelTesterMixin, unittest.TestCase): +class SegformerModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( SegformerModel, @@ -169,6 +170,15 @@ class SegformerModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": SegformerModel, + "image-classification": SegformerForImageClassification, + "image-segmentation": SegformerForSemanticSegmentation, + } + if is_torch_available() + else {} + ) fx_compatible = True test_head_masking = False diff --git a/tests/models/segformer/test_modeling_tf_segformer.py b/tests/models/segformer/test_modeling_tf_segformer.py index 4bb423bfca..79c58ebe40 100644 --- a/tests/models/segformer/test_modeling_tf_segformer.py +++ b/tests/models/segformer/test_modeling_tf_segformer.py @@ -24,6 +24,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -150,12 +151,17 @@ class TFSegformerModelTester: @require_tf -class TFSegformerModelTest(TFModelTesterMixin, unittest.TestCase): +class TFSegformerModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (TFSegformerModel, TFSegformerForImageClassification, TFSegformerForSemanticSegmentation) if is_tf_available() else () ) + pipeline_model_mapping = ( + {"feature-extraction": TFSegformerModel, "image-classification": TFSegformerForImageClassification} + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/sew/test_modeling_sew.py b/tests/models/sew/test_modeling_sew.py index 9df69f8467..aa511e788b 100644 --- a/tests/models/sew/test_modeling_sew.py +++ b/tests/models/sew/test_modeling_sew.py @@ -31,6 +31,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -299,8 +300,17 @@ class SEWModelTester: @require_torch -class SEWModelTest(ModelTesterMixin, unittest.TestCase): +class SEWModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (SEWForCTC, SEWModel, SEWForSequenceClassification) if is_torch_available() else () + pipeline_model_mapping = ( + { + "audio-classification": SEWForSequenceClassification, + "automatic-speech-recognition": SEWForCTC, + "feature-extraction": SEWModel, + } + if is_torch_available() + else {} + ) test_pruning = False test_headmasking = False diff --git a/tests/models/sew_d/test_modeling_sew_d.py b/tests/models/sew_d/test_modeling_sew_d.py index 334b10abf3..c6ee533719 100644 --- a/tests/models/sew_d/test_modeling_sew_d.py +++ b/tests/models/sew_d/test_modeling_sew_d.py @@ -31,6 +31,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -320,8 +321,17 @@ class SEWDModelTester: @require_torch -class SEWDModelTest(ModelTesterMixin, unittest.TestCase): +class SEWDModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (SEWDForCTC, SEWDModel, SEWDForSequenceClassification) if is_torch_available() else () + pipeline_model_mapping = ( + { + "audio-classification": SEWDForSequenceClassification, + "automatic-speech-recognition": SEWDForCTC, + "feature-extraction": SEWDModel, + } + if is_torch_available() + else {} + ) test_pruning = False test_headmasking = False test_torchscript = False diff --git a/tests/models/speech_to_text/test_modeling_speech_to_text.py b/tests/models/speech_to_text/test_modeling_speech_to_text.py index 627c2560b8..d270a1cf4a 100644 --- a/tests/models/speech_to_text/test_modeling_speech_to_text.py +++ b/tests/models/speech_to_text/test_modeling_speech_to_text.py @@ -35,6 +35,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -267,9 +268,14 @@ class Speech2TextModelTester: @require_torch -class Speech2TextModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class Speech2TextModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (Speech2TextModel, Speech2TextForConditionalGeneration) if is_torch_available() else () all_generative_model_classes = (Speech2TextForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + {"automatic-speech-recognition": Speech2TextForConditionalGeneration, "feature-extraction": Speech2TextModel} + if is_torch_available() + else {} + ) is_encoder_decoder = True fx_compatible = True test_pruning = False diff --git a/tests/models/speech_to_text/test_modeling_tf_speech_to_text.py b/tests/models/speech_to_text/test_modeling_tf_speech_to_text.py index 613af6be0c..75789fd6d9 100644 --- a/tests/models/speech_to_text/test_modeling_tf_speech_to_text.py +++ b/tests/models/speech_to_text/test_modeling_tf_speech_to_text.py @@ -23,6 +23,7 @@ from transformers.utils import cached_property, is_tf_available from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -209,9 +210,10 @@ class TFSpeech2TextModelTester: @require_tf -class TFSpeech2TextModelTest(TFModelTesterMixin, unittest.TestCase): +class TFSpeech2TextModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TFSpeech2TextModel, TFSpeech2TextForConditionalGeneration) if is_tf_available() else () all_generative_model_classes = (TFSpeech2TextForConditionalGeneration,) if is_tf_available() else () + pipeline_model_mapping = {"feature-extraction": TFSpeech2TextModel} if is_tf_available() else {} is_encoder_decoder = True test_pruning = False test_missing_keys = False diff --git a/tests/models/speech_to_text_2/test_modeling_speech_to_text_2.py b/tests/models/speech_to_text_2/test_modeling_speech_to_text_2.py index 42899bd29a..ccd5bfa189 100644 --- a/tests/models/speech_to_text_2/test_modeling_speech_to_text_2.py +++ b/tests/models/speech_to_text_2/test_modeling_speech_to_text_2.py @@ -22,6 +22,7 @@ from transformers.testing_utils import is_torch_available, require_torch, torch_ from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -176,9 +177,12 @@ class Speech2Text2StandaloneDecoderModelTester: @require_torch -class Speech2Text2StandaloneDecoderModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class Speech2Text2StandaloneDecoderModelTest( + ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase +): all_model_classes = (Speech2Text2Decoder, Speech2Text2ForCausalLM) if is_torch_available() else () all_generative_model_classes = (Speech2Text2ForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = {"text-generation": Speech2Text2ForCausalLM} if is_torch_available() else {} fx_compatible = True test_pruning = False diff --git a/tests/models/speecht5/test_modeling_speecht5.py b/tests/models/speecht5/test_modeling_speecht5.py index e628a93316..e18886c14d 100644 --- a/tests/models/speecht5/test_modeling_speecht5.py +++ b/tests/models/speecht5/test_modeling_speecht5.py @@ -39,6 +39,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -160,8 +161,13 @@ class SpeechT5ModelTester: @require_torch -class SpeechT5ModelTest(ModelTesterMixin, unittest.TestCase): +class SpeechT5ModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (SpeechT5Model,) if is_torch_available() else () + pipeline_model_mapping = ( + {"automatic-speech-recognition": SpeechT5ForSpeechToText, "feature-extraction": SpeechT5Model} + if is_torch_available() + else {} + ) is_encoder_decoder = True test_pruning = False test_headmasking = False diff --git a/tests/models/splinter/test_modeling_splinter.py b/tests/models/splinter/test_modeling_splinter.py index 14dce7e975..c44fed33ac 100644 --- a/tests/models/splinter/test_modeling_splinter.py +++ b/tests/models/splinter/test_modeling_splinter.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, require_torch_multi_gpu, s from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -207,7 +208,7 @@ class SplinterModelTester: @require_torch -class SplinterModelTest(ModelTesterMixin, unittest.TestCase): +class SplinterModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( SplinterModel, @@ -217,6 +218,11 @@ class SplinterModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + {"feature-extraction": SplinterModel, "question-answering": SplinterForQuestionAnswering} + if is_torch_available() + else {} + ) def _prepare_for_class(self, inputs_dict, model_class, return_labels=False): inputs_dict = copy.deepcopy(inputs_dict) diff --git a/tests/models/squeezebert/test_modeling_squeezebert.py b/tests/models/squeezebert/test_modeling_squeezebert.py index 8b8187cbc3..5efb030311 100644 --- a/tests/models/squeezebert/test_modeling_squeezebert.py +++ b/tests/models/squeezebert/test_modeling_squeezebert.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -214,7 +215,7 @@ class SqueezeBertModelTester(object): @require_torch -class SqueezeBertModelTest(ModelTesterMixin, unittest.TestCase): +class SqueezeBertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( SqueezeBertModel, @@ -227,6 +228,18 @@ class SqueezeBertModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else None ) + pipeline_model_mapping = ( + { + "feature-extraction": SqueezeBertModel, + "fill-mask": SqueezeBertForMaskedLM, + "question-answering": SqueezeBertForQuestionAnswering, + "text-classification": SqueezeBertForSequenceClassification, + "token-classification": SqueezeBertForTokenClassification, + "zero-shot": SqueezeBertForSequenceClassification, + } + if is_torch_available() + else {} + ) test_pruning = False test_resize_embeddings = True test_head_masking = False diff --git a/tests/models/swin/test_modeling_swin.py b/tests/models/swin/test_modeling_swin.py index a56ba40978..6996e77260 100644 --- a/tests/models/swin/test_modeling_swin.py +++ b/tests/models/swin/test_modeling_swin.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -218,7 +219,7 @@ class SwinModelTester: @require_torch -class SwinModelTest(ModelTesterMixin, unittest.TestCase): +class SwinModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( SwinModel, @@ -229,6 +230,11 @@ class SwinModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + {"feature-extraction": SwinModel, "image-classification": SwinForImageClassification} + if is_torch_available() + else {} + ) fx_compatible = True test_pruning = False diff --git a/tests/models/swin/test_modeling_tf_swin.py b/tests/models/swin/test_modeling_tf_swin.py index bc2e957c43..32de917a11 100644 --- a/tests/models/swin/test_modeling_tf_swin.py +++ b/tests/models/swin/test_modeling_tf_swin.py @@ -26,6 +26,7 @@ from transformers.utils import cached_property, is_tf_available, is_vision_avail from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -176,7 +177,7 @@ class TFSwinModelTester: @require_tf -class TFSwinModelTest(TFModelTesterMixin, unittest.TestCase): +class TFSwinModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFSwinModel, @@ -186,6 +187,11 @@ class TFSwinModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + {"feature-extraction": TFSwinModel, "image-classification": TFSwinForImageClassification} + if is_tf_available() + else {} + ) test_pruning = False test_resize_embeddings = False diff --git a/tests/models/swin2sr/test_modeling_swin2sr.py b/tests/models/swin2sr/test_modeling_swin2sr.py index 556decee8f..50d776e6bb 100644 --- a/tests/models/swin2sr/test_modeling_swin2sr.py +++ b/tests/models/swin2sr/test_modeling_swin2sr.py @@ -22,6 +22,7 @@ from transformers.utils import is_torch_available, is_vision_available from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -155,8 +156,9 @@ class Swin2SRModelTester: @require_torch -class Swin2SRModelTest(ModelTesterMixin, unittest.TestCase): +class Swin2SRModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (Swin2SRModel, Swin2SRForImageSuperResolution) if is_torch_available() else () + pipeline_model_mapping = {"feature-extraction": Swin2SRModel} if is_torch_available() else {} fx_compatible = False test_pruning = False diff --git a/tests/models/swinv2/test_modeling_swinv2.py b/tests/models/swinv2/test_modeling_swinv2.py index b0c689cfde..bda4b0f901 100644 --- a/tests/models/swinv2/test_modeling_swinv2.py +++ b/tests/models/swinv2/test_modeling_swinv2.py @@ -23,6 +23,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -170,10 +171,15 @@ class Swinv2ModelTester: @require_torch -class Swinv2ModelTest(ModelTesterMixin, unittest.TestCase): +class Swinv2ModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (Swinv2Model, Swinv2ForImageClassification, Swinv2ForMaskedImageModeling) if is_torch_available() else () ) + pipeline_model_mapping = ( + {"feature-extraction": Swinv2Model, "image-classification": Swinv2ForImageClassification} + if is_torch_available() + else {} + ) fx_compatible = False test_pruning = False diff --git a/tests/models/switch_transformers/test_modeling_switch_transformers.py b/tests/models/switch_transformers/test_modeling_switch_transformers.py index 283fd17101..a246f46487 100644 --- a/tests/models/switch_transformers/test_modeling_switch_transformers.py +++ b/tests/models/switch_transformers/test_modeling_switch_transformers.py @@ -24,6 +24,7 @@ from transformers.testing_utils import require_tokenizers, require_torch, requir from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -546,11 +547,21 @@ class SwitchTransformersModelTester: @require_torch -class SwitchTransformersModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class SwitchTransformersModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (SwitchTransformersModel, SwitchTransformersForConditionalGeneration) if is_torch_available() else () ) all_generative_model_classes = (SwitchTransformersForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": SwitchTransformersForConditionalGeneration, + "feature-extraction": SwitchTransformersModel, + "summarization": SwitchTransformersForConditionalGeneration, + "text2text-generation": SwitchTransformersForConditionalGeneration, + } + if is_torch_available() + else {} + ) fx_compatible = False test_pruning = False test_resize_embeddings = True diff --git a/tests/models/t5/test_modeling_t5.py b/tests/models/t5/test_modeling_t5.py index 8833898649..cfe1460895 100644 --- a/tests/models/t5/test_modeling_t5.py +++ b/tests/models/t5/test_modeling_t5.py @@ -32,6 +32,7 @@ from transformers.utils import cached_property from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -518,9 +519,19 @@ class T5ModelTester: @require_torch -class T5ModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class T5ModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (T5Model, T5ForConditionalGeneration) if is_torch_available() else () all_generative_model_classes = (T5ForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "conversational": T5ForConditionalGeneration, + "feature-extraction": T5Model, + "summarization": T5ForConditionalGeneration, + "text2text-generation": T5ForConditionalGeneration, + } + if is_torch_available() + else {} + ) all_parallelizable_model_classes = (T5Model, T5ForConditionalGeneration) if is_torch_available() else () fx_compatible = True test_pruning = False diff --git a/tests/models/t5/test_modeling_tf_t5.py b/tests/models/t5/test_modeling_tf_t5.py index 767f9def7b..8a9112ff41 100644 --- a/tests/models/t5/test_modeling_tf_t5.py +++ b/tests/models/t5/test_modeling_tf_t5.py @@ -21,6 +21,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -239,10 +240,20 @@ class TFT5ModelTester: @require_tf -class TFT5ModelTest(TFModelTesterMixin, unittest.TestCase): +class TFT5ModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): is_encoder_decoder = True all_model_classes = (TFT5Model, TFT5ForConditionalGeneration) if is_tf_available() else () all_generative_model_classes = (TFT5ForConditionalGeneration,) if is_tf_available() else () + pipeline_model_mapping = ( + { + "conversational": TFT5ForConditionalGeneration, + "feature-extraction": TFT5Model, + "summarization": TFT5ForConditionalGeneration, + "text2text-generation": TFT5ForConditionalGeneration, + } + if is_tf_available() + else {} + ) test_onnx = False def setUp(self): diff --git a/tests/models/table_transformer/test_modeling_table_transformer.py b/tests/models/table_transformer/test_modeling_table_transformer.py index 06fbe6f8e2..0dafb55e5a 100644 --- a/tests/models/table_transformer/test_modeling_table_transformer.py +++ b/tests/models/table_transformer/test_modeling_table_transformer.py @@ -27,6 +27,7 @@ from transformers.testing_utils import require_timm, require_vision, slow, torch from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_timm_available(): @@ -175,7 +176,7 @@ class TableTransformerModelTester: @require_timm -class TableTransformerModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class TableTransformerModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TableTransformerModel, @@ -184,6 +185,11 @@ class TableTransformerModelTest(ModelTesterMixin, GenerationTesterMixin, unittes if is_timm_available() else () ) + pipeline_model_mapping = ( + {"feature-extraction": TableTransformerModel, "object-detection": TableTransformerForObjectDetection} + if is_timm_available() + else {} + ) is_encoder_decoder = True test_torchscript = False test_pruning = False diff --git a/tests/models/tapas/test_modeling_tapas.py b/tests/models/tapas/test_modeling_tapas.py index 1448c9e336..b3b9217a00 100644 --- a/tests/models/tapas/test_modeling_tapas.py +++ b/tests/models/tapas/test_modeling_tapas.py @@ -37,6 +37,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -408,7 +409,7 @@ class TapasModelTester: @require_torch -class TapasModelTest(ModelTesterMixin, unittest.TestCase): +class TapasModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TapasModel, @@ -419,6 +420,17 @@ class TapasModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else None ) + pipeline_model_mapping = ( + { + "feature-extraction": TapasModel, + "fill-mask": TapasForMaskedLM, + "table-question-answering": TapasForQuestionAnswering, + "text-classification": TapasForSequenceClassification, + "zero-shot": TapasForSequenceClassification, + } + if is_torch_available() + else {} + ) test_pruning = False test_resize_embeddings = True test_head_masking = False diff --git a/tests/models/tapas/test_modeling_tf_tapas.py b/tests/models/tapas/test_modeling_tf_tapas.py index ebb4d0d8bf..380b7605b8 100644 --- a/tests/models/tapas/test_modeling_tf_tapas.py +++ b/tests/models/tapas/test_modeling_tf_tapas.py @@ -39,6 +39,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -418,7 +419,7 @@ class TFTapasModelTester: @require_tensorflow_probability @require_tf -class TFTapasModelTest(TFModelTesterMixin, unittest.TestCase): +class TFTapasModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFTapasModel, @@ -429,6 +430,16 @@ class TFTapasModelTest(TFModelTesterMixin, unittest.TestCase): if is_tf_available() else () ) + pipeline_model_mapping = ( + { + "feature-extraction": TFTapasModel, + "fill-mask": TFTapasForMaskedLM, + "text-classification": TFTapasForSequenceClassification, + "zero-shot": TFTapasForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/time_series_transformer/test_modeling_time_series_transformer.py b/tests/models/time_series_transformer/test_modeling_time_series_transformer.py index 6063a3469e..1ea8d8ef67 100644 --- a/tests/models/time_series_transformer/test_modeling_time_series_transformer.py +++ b/tests/models/time_series_transformer/test_modeling_time_series_transformer.py @@ -25,6 +25,7 @@ from transformers.testing_utils import is_flaky, require_torch, slow, torch_devi from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin TOLERANCE = 1e-4 @@ -172,11 +173,12 @@ class TimeSeriesTransformerModelTester: @require_torch -class TimeSeriesTransformerModelTest(ModelTesterMixin, unittest.TestCase): +class TimeSeriesTransformerModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (TimeSeriesTransformerModel, TimeSeriesTransformerForPrediction) if is_torch_available() else () ) all_generative_model_classes = (TimeSeriesTransformerForPrediction,) if is_torch_available() else () + pipeline_model_mapping = {"feature-extraction": TimeSeriesTransformerModel} if is_torch_available() else {} is_encoder_decoder = True test_pruning = False test_head_masking = False diff --git a/tests/models/timesformer/test_modeling_timesformer.py b/tests/models/timesformer/test_modeling_timesformer.py index 5a9e039e7f..ff73fa208a 100644 --- a/tests/models/timesformer/test_modeling_timesformer.py +++ b/tests/models/timesformer/test_modeling_timesformer.py @@ -29,6 +29,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -152,13 +153,18 @@ class TimesformerModelTester: @require_torch -class TimesformerModelTest(ModelTesterMixin, unittest.TestCase): +class TimesformerModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as TimeSformer does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (TimesformerModel, TimesformerForVideoClassification) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": TimesformerModel, "video-classification": TimesformerForVideoClassification} + if is_torch_available() + else {} + ) test_pruning = False test_torchscript = False diff --git a/tests/models/trajectory_transformer/test_modeling_trajectory_transformer.py b/tests/models/trajectory_transformer/test_modeling_trajectory_transformer.py index 07c898bf6f..0b9be4918c 100644 --- a/tests/models/trajectory_transformer/test_modeling_trajectory_transformer.py +++ b/tests/models/trajectory_transformer/test_modeling_trajectory_transformer.py @@ -26,6 +26,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -94,8 +95,9 @@ class TrajectoryTransformerModelTester: @require_torch -class TrajectoryTransformerModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class TrajectoryTransformerModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TrajectoryTransformerModel,) if is_torch_available() else () + pipeline_model_mapping = {"feature-extraction": TrajectoryTransformerModel} if is_torch_available() else {} # Ignoring of a failing test from GenerationTesterMixin, as the model does not use inputs_ids test_generate_without_input_ids = False diff --git a/tests/models/transfo_xl/test_modeling_tf_transfo_xl.py b/tests/models/transfo_xl/test_modeling_tf_transfo_xl.py index c0051eab2d..88bfbc1c7b 100644 --- a/tests/models/transfo_xl/test_modeling_tf_transfo_xl.py +++ b/tests/models/transfo_xl/test_modeling_tf_transfo_xl.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -155,11 +156,21 @@ class TFTransfoXLModelTester: @require_tf -class TFTransfoXLModelTest(TFModelTesterMixin, unittest.TestCase): +class TFTransfoXLModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (TFTransfoXLModel, TFTransfoXLLMHeadModel, TFTransfoXLForSequenceClassification) if is_tf_available() else () ) all_generative_model_classes = () if is_tf_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": TFTransfoXLModel, + "text-classification": TFTransfoXLForSequenceClassification, + "text-generation": TFTransfoXLLMHeadModel, + "zero-shot": TFTransfoXLForSequenceClassification, + } + if is_tf_available() + else {} + ) # TODO: add this test when TFTransfoXLLMHead has a linear output layer implemented test_resize_embeddings = False test_head_masking = False diff --git a/tests/models/transfo_xl/test_modeling_transfo_xl.py b/tests/models/transfo_xl/test_modeling_transfo_xl.py index 89ac1d3b09..df9647ae20 100644 --- a/tests/models/transfo_xl/test_modeling_transfo_xl.py +++ b/tests/models/transfo_xl/test_modeling_transfo_xl.py @@ -23,6 +23,7 @@ from transformers.testing_utils import require_torch, require_torch_multi_gpu, s from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -251,11 +252,21 @@ class TransfoXLModelTester: @require_torch -class TransfoXLModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class TransfoXLModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (TransfoXLModel, TransfoXLLMHeadModel, TransfoXLForSequenceClassification) if is_torch_available() else () ) all_generative_model_classes = (TransfoXLLMHeadModel,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": TransfoXLModel, + "text-classification": TransfoXLForSequenceClassification, + "text-generation": TransfoXLLMHeadModel, + "zero-shot": TransfoXLForSequenceClassification, + } + if is_torch_available() + else {} + ) test_pruning = False test_resize_embeddings = True test_mismatched_shapes = False diff --git a/tests/models/trocr/test_modeling_trocr.py b/tests/models/trocr/test_modeling_trocr.py index 5ef0d9852d..f670f4e6d9 100644 --- a/tests/models/trocr/test_modeling_trocr.py +++ b/tests/models/trocr/test_modeling_trocr.py @@ -22,6 +22,7 @@ from transformers.testing_utils import is_torch_available, require_torch, torch_ from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -158,9 +159,10 @@ class TrOCRStandaloneDecoderModelTester: @require_torch -class TrOCRStandaloneDecoderModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class TrOCRStandaloneDecoderModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TrOCRDecoder, TrOCRForCausalLM) if is_torch_available() else () all_generative_model_classes = (TrOCRForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = {"text-generation": TrOCRForCausalLM} if is_torch_available() else {} fx_compatible = True test_pruning = False diff --git a/tests/models/tvlt/test_modeling_tvlt.py b/tests/models/tvlt/test_modeling_tvlt.py index bb6d2df0d9..4b307d489e 100644 --- a/tests/models/tvlt/test_modeling_tvlt.py +++ b/tests/models/tvlt/test_modeling_tvlt.py @@ -33,6 +33,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -322,10 +323,11 @@ class TvltModelTester: @require_torch @unittest.skipIf(not is_torch_greater_or_equal_than_1_10, "TVLT is only available in torch v1.10+") -class TvltModelTest(ModelTesterMixin, unittest.TestCase): +class TvltModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (TvltModel, TvltForPreTraining, TvltForAudioVisualClassification) if is_torch_available() else () ) + pipeline_model_mapping = {"feature-extraction": TvltModel} if is_torch_available() else {} fx_compatible = False test_pruning = False diff --git a/tests/models/unispeech/test_modeling_unispeech.py b/tests/models/unispeech/test_modeling_unispeech.py index 1f10817695..4d7967c484 100644 --- a/tests/models/unispeech/test_modeling_unispeech.py +++ b/tests/models/unispeech/test_modeling_unispeech.py @@ -32,6 +32,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -297,12 +298,21 @@ class UniSpeechModelTester: @require_torch -class UniSpeechRobustModelTest(ModelTesterMixin, unittest.TestCase): +class UniSpeechRobustModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (UniSpeechForCTC, UniSpeechModel, UniSpeechForSequenceClassification, UniSpeechForPreTraining) if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "audio-classification": UniSpeechForSequenceClassification, + "automatic-speech-recognition": UniSpeechForCTC, + "feature-extraction": UniSpeechModel, + } + if is_torch_available() + else {} + ) test_pruning = False test_headmasking = False diff --git a/tests/models/unispeech_sat/test_modeling_unispeech_sat.py b/tests/models/unispeech_sat/test_modeling_unispeech_sat.py index 6ac06e4db9..19d3dd849f 100644 --- a/tests/models/unispeech_sat/test_modeling_unispeech_sat.py +++ b/tests/models/unispeech_sat/test_modeling_unispeech_sat.py @@ -32,6 +32,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -341,7 +342,7 @@ class UniSpeechSatModelTester: @require_torch -class UniSpeechSatModelTest(ModelTesterMixin, unittest.TestCase): +class UniSpeechSatModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( UniSpeechSatForCTC, @@ -354,6 +355,15 @@ class UniSpeechSatModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "audio-classification": UniSpeechSatForSequenceClassification, + "automatic-speech-recognition": UniSpeechSatForCTC, + "feature-extraction": UniSpeechSatModel, + } + if is_torch_available() + else {} + ) test_pruning = False test_headmasking = False test_torchscript = False diff --git a/tests/models/upernet/test_modeling_upernet.py b/tests/models/upernet/test_modeling_upernet.py index f2ab1cb1bd..79419f7b37 100644 --- a/tests/models/upernet/test_modeling_upernet.py +++ b/tests/models/upernet/test_modeling_upernet.py @@ -26,6 +26,7 @@ from transformers.utils import is_torch_available, is_vision_available from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -138,13 +139,14 @@ class UperNetModelTester: @require_torch -class UperNetModelTest(ModelTesterMixin, unittest.TestCase): +class UperNetModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as UperNet does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (UperNetForSemanticSegmentation,) if is_torch_available() else () + pipeline_model_mapping = {"image-segmentation": UperNetForSemanticSegmentation} if is_torch_available() else {} fx_compatible = False test_pruning = False test_resize_embeddings = False diff --git a/tests/models/van/test_modeling_van.py b/tests/models/van/test_modeling_van.py index 3e5b7fb1df..49df30a828 100644 --- a/tests/models/van/test_modeling_van.py +++ b/tests/models/van/test_modeling_van.py @@ -25,6 +25,7 @@ from transformers.utils import cached_property, is_scipy_available, is_torch_ava from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_scipy_available(): @@ -115,13 +116,18 @@ class VanModelTester: @require_torch -class VanModelTest(ModelTesterMixin, unittest.TestCase): +class VanModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as Van does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (VanModel, VanForImageClassification) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": VanModel, "image-classification": VanForImageClassification} + if is_torch_available() + else {} + ) test_pruning = False test_resize_embeddings = False diff --git a/tests/models/videomae/test_modeling_videomae.py b/tests/models/videomae/test_modeling_videomae.py index 63e6f19ffc..1070a4ee2a 100644 --- a/tests/models/videomae/test_modeling_videomae.py +++ b/tests/models/videomae/test_modeling_videomae.py @@ -29,6 +29,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -162,7 +163,7 @@ class VideoMAEModelTester: @require_torch -class VideoMAEModelTest(ModelTesterMixin, unittest.TestCase): +class VideoMAEModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as VideoMAE does not use input_ids, inputs_embeds, attention_mask and seq_length. @@ -171,6 +172,11 @@ class VideoMAEModelTest(ModelTesterMixin, unittest.TestCase): all_model_classes = ( (VideoMAEModel, VideoMAEForPreTraining, VideoMAEForVideoClassification) if is_torch_available() else () ) + pipeline_model_mapping = ( + {"feature-extraction": VideoMAEModel, "video-classification": VideoMAEForVideoClassification} + if is_torch_available() + else {} + ) test_pruning = False test_torchscript = False diff --git a/tests/models/vilt/test_modeling_vilt.py b/tests/models/vilt/test_modeling_vilt.py index 30e44d4d48..958527dbf4 100644 --- a/tests/models/vilt/test_modeling_vilt.py +++ b/tests/models/vilt/test_modeling_vilt.py @@ -26,6 +26,7 @@ from transformers.utils import cached_property from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -218,7 +219,7 @@ class ViltModelTester: @require_torch @unittest.skipIf(not is_torch_greater_or_equal_than_1_10, "Vilt is only available in torch v1.10+") -class ViltModelTest(ModelTesterMixin, unittest.TestCase): +class ViltModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( ViltModel, @@ -230,6 +231,11 @@ class ViltModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + {"feature-extraction": ViltModel, "visual-question-answering": ViltForQuestionAnswering} + if is_torch_available() + else {} + ) test_pruning = False test_headmasking = False test_torchscript = False diff --git a/tests/models/visual_bert/test_modeling_visual_bert.py b/tests/models/visual_bert/test_modeling_visual_bert.py index 00b0eb3635..cf48fd7ffb 100644 --- a/tests/models/visual_bert/test_modeling_visual_bert.py +++ b/tests/models/visual_bert/test_modeling_visual_bert.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -299,7 +300,7 @@ class VisualBertModelTester: @require_torch -class VisualBertModelTest(ModelTesterMixin, unittest.TestCase): +class VisualBertModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( VisualBertModel, @@ -312,6 +313,7 @@ class VisualBertModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = {"feature-extraction": VisualBertModel} if is_torch_available() else {} test_torchscript = False test_pruning = False diff --git a/tests/models/vit/test_modeling_tf_vit.py b/tests/models/vit/test_modeling_tf_vit.py index 95ed814eba..111223de32 100644 --- a/tests/models/vit/test_modeling_tf_vit.py +++ b/tests/models/vit/test_modeling_tf_vit.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property, is_tf_available, is_vision_avail from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -148,13 +149,18 @@ class TFViTModelTester: @require_tf -class TFViTModelTest(TFModelTesterMixin, unittest.TestCase): +class TFViTModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_tf_common.py, as ViT does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (TFViTModel, TFViTForImageClassification) if is_tf_available() else () + pipeline_model_mapping = ( + {"feature-extraction": TFViTModel, "image-classification": TFViTForImageClassification} + if is_tf_available() + else {} + ) test_resize_embeddings = False test_head_masking = False diff --git a/tests/models/vit/test_modeling_vit.py b/tests/models/vit/test_modeling_vit.py index 52e09aab77..be509d460e 100644 --- a/tests/models/vit/test_modeling_vit.py +++ b/tests/models/vit/test_modeling_vit.py @@ -31,6 +31,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -176,7 +177,7 @@ class ViTModelTester: @require_torch -class ViTModelTest(ModelTesterMixin, unittest.TestCase): +class ViTModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as ViT does not use input_ids, inputs_embeds, attention_mask and seq_length. @@ -191,6 +192,11 @@ class ViTModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + {"feature-extraction": ViTModel, "image-classification": ViTForImageClassification} + if is_torch_available() + else {} + ) fx_compatible = True test_pruning = False diff --git a/tests/models/vit_hybrid/test_modeling_vit_hybrid.py b/tests/models/vit_hybrid/test_modeling_vit_hybrid.py index 27913f28f4..7fbe2f9dca 100644 --- a/tests/models/vit_hybrid/test_modeling_vit_hybrid.py +++ b/tests/models/vit_hybrid/test_modeling_vit_hybrid.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -147,13 +148,18 @@ class ViTHybridModelTester: @require_torch -class ViTHybridModelTest(ModelTesterMixin, unittest.TestCase): +class ViTHybridModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as ViT does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (ViTHybridModel, ViTHybridForImageClassification) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": ViTHybridModel, "image-classification": ViTHybridForImageClassification} + if is_torch_available() + else {} + ) test_pruning = False test_resize_embeddings = False test_head_masking = False diff --git a/tests/models/vit_mae/test_modeling_tf_vit_mae.py b/tests/models/vit_mae/test_modeling_tf_vit_mae.py index 48bda3aec7..53d68b644a 100644 --- a/tests/models/vit_mae/test_modeling_tf_vit_mae.py +++ b/tests/models/vit_mae/test_modeling_tf_vit_mae.py @@ -32,6 +32,7 @@ from transformers.testing_utils import require_tf, require_vision, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -155,13 +156,14 @@ class TFViTMAEModelTester: @require_tf -class TFViTMAEModelTest(TFModelTesterMixin, unittest.TestCase): +class TFViTMAEModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as ViTMAE does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (TFViTMAEModel, TFViTMAEForPreTraining) if is_tf_available() else () + pipeline_model_mapping = {"feature-extraction": TFViTMAEModel} if is_tf_available() else {} test_pruning = False test_onnx = False diff --git a/tests/models/vit_mae/test_modeling_vit_mae.py b/tests/models/vit_mae/test_modeling_vit_mae.py index 35693da4cf..c58e2e9480 100644 --- a/tests/models/vit_mae/test_modeling_vit_mae.py +++ b/tests/models/vit_mae/test_modeling_vit_mae.py @@ -28,6 +28,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -153,13 +154,14 @@ class ViTMAEModelTester: @require_torch -class ViTMAEModelTest(ModelTesterMixin, unittest.TestCase): +class ViTMAEModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as ViTMAE does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (ViTMAEModel, ViTMAEForPreTraining) if is_torch_available() else () + pipeline_model_mapping = {"feature-extraction": ViTMAEModel} if is_torch_available() else {} test_pruning = False test_torchscript = False diff --git a/tests/models/vit_msn/test_modeling_vit_msn.py b/tests/models/vit_msn/test_modeling_vit_msn.py index b93e5c72d0..966ec6c6d3 100644 --- a/tests/models/vit_msn/test_modeling_vit_msn.py +++ b/tests/models/vit_msn/test_modeling_vit_msn.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -144,13 +145,18 @@ class ViTMSNModelTester: @require_torch -class ViTMSNModelTest(ModelTesterMixin, unittest.TestCase): +class ViTMSNModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as ViTMSN does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (ViTMSNModel, ViTMSNForImageClassification) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": ViTMSNModel, "image-classification": ViTMSNForImageClassification} + if is_torch_available() + else {} + ) test_pruning = False test_torchscript = False diff --git a/tests/models/wav2vec2/test_modeling_tf_wav2vec2.py b/tests/models/wav2vec2/test_modeling_tf_wav2vec2.py index 704cffb834..3bb3d36cbf 100644 --- a/tests/models/wav2vec2/test_modeling_tf_wav2vec2.py +++ b/tests/models/wav2vec2/test_modeling_tf_wav2vec2.py @@ -41,6 +41,7 @@ from transformers.utils import is_librosa_available, is_pyctcdecode_available from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -281,8 +282,9 @@ class TFWav2Vec2ModelTester: @require_tf -class TFWav2Vec2ModelTest(TFModelTesterMixin, unittest.TestCase): +class TFWav2Vec2ModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TFWav2Vec2Model, TFWav2Vec2ForCTC) if is_tf_available() else () + pipeline_model_mapping = {"feature-extraction": TFWav2Vec2Model} if is_tf_available() else {} test_resize_embeddings = False test_head_masking = False test_onnx = False diff --git a/tests/models/wav2vec2/test_modeling_wav2vec2.py b/tests/models/wav2vec2/test_modeling_wav2vec2.py index f649257a83..a29dbda2f1 100644 --- a/tests/models/wav2vec2/test_modeling_wav2vec2.py +++ b/tests/models/wav2vec2/test_modeling_wav2vec2.py @@ -49,6 +49,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -467,12 +468,22 @@ class Wav2Vec2ModelTester: @require_torch -class Wav2Vec2ModelTest(ModelTesterMixin, unittest.TestCase): +class Wav2Vec2ModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (Wav2Vec2ForCTC, Wav2Vec2Model, Wav2Vec2ForMaskedLM, Wav2Vec2ForSequenceClassification, Wav2Vec2ForPreTraining) if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "audio-classification": Wav2Vec2ForSequenceClassification, + "automatic-speech-recognition": Wav2Vec2ForCTC, + "feature-extraction": Wav2Vec2Model, + "fill-mask": Wav2Vec2ForMaskedLM, + } + if is_torch_available() + else {} + ) fx_compatible = True test_pruning = False test_headmasking = False diff --git a/tests/models/wav2vec2_conformer/test_modeling_wav2vec2_conformer.py b/tests/models/wav2vec2_conformer/test_modeling_wav2vec2_conformer.py index cb2719a591..200c863adb 100644 --- a/tests/models/wav2vec2_conformer/test_modeling_wav2vec2_conformer.py +++ b/tests/models/wav2vec2_conformer/test_modeling_wav2vec2_conformer.py @@ -31,6 +31,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -389,7 +390,7 @@ class Wav2Vec2ConformerModelTester: @require_torch -class Wav2Vec2ConformerModelTest(ModelTesterMixin, unittest.TestCase): +class Wav2Vec2ConformerModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( Wav2Vec2ConformerForCTC, @@ -402,6 +403,15 @@ class Wav2Vec2ConformerModelTest(ModelTesterMixin, unittest.TestCase): if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "audio-classification": Wav2Vec2ConformerForSequenceClassification, + "automatic-speech-recognition": Wav2Vec2ConformerForCTC, + "feature-extraction": Wav2Vec2ConformerModel, + } + if is_torch_available() + else {} + ) test_pruning = False test_headmasking = False test_torchscript = False diff --git a/tests/models/wavlm/test_modeling_wavlm.py b/tests/models/wavlm/test_modeling_wavlm.py index 297d207af3..67f380c239 100644 --- a/tests/models/wavlm/test_modeling_wavlm.py +++ b/tests/models/wavlm/test_modeling_wavlm.py @@ -31,6 +31,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -308,12 +309,21 @@ class WavLMModelTester: @require_torch -class WavLMModelTest(ModelTesterMixin, unittest.TestCase): +class WavLMModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( (WavLMForCTC, WavLMModel, WavLMForAudioFrameClassification, WavLMForSequenceClassification, WavLMForXVector) if is_torch_available() else () ) + pipeline_model_mapping = ( + { + "audio-classification": WavLMForSequenceClassification, + "automatic-speech-recognition": WavLMForCTC, + "feature-extraction": WavLMModel, + } + if is_torch_available() + else {} + ) test_pruning = False test_headmasking = False diff --git a/tests/models/whisper/test_modeling_tf_whisper.py b/tests/models/whisper/test_modeling_tf_whisper.py index 09cce00901..2ef3cdcee0 100644 --- a/tests/models/whisper/test_modeling_tf_whisper.py +++ b/tests/models/whisper/test_modeling_tf_whisper.py @@ -28,6 +28,7 @@ from transformers.utils.import_utils import is_datasets_available from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_datasets_available(): @@ -253,9 +254,10 @@ class TFWhisperModelTester: @require_tf -class TFWhisperModelTest(TFModelTesterMixin, unittest.TestCase): +class TFWhisperModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TFWhisperModel, TFWhisperForConditionalGeneration) if is_tf_available() else () all_generative_model_classes = (TFWhisperForConditionalGeneration,) if is_tf_available() else () + pipeline_model_mapping = {"feature-extraction": TFWhisperModel} if is_tf_available() else {} is_encoder_decoder = True fx_compatible = False test_pruning = False diff --git a/tests/models/whisper/test_modeling_whisper.py b/tests/models/whisper/test_modeling_whisper.py index ac21370f98..2faeee9b8a 100644 --- a/tests/models/whisper/test_modeling_whisper.py +++ b/tests/models/whisper/test_modeling_whisper.py @@ -31,6 +31,7 @@ from transformers.utils.import_utils import is_datasets_available from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_datasets_available(): @@ -271,9 +272,14 @@ class WhisperModelTester: @require_torch -class WhisperModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class WhisperModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (WhisperModel, WhisperForConditionalGeneration) if is_torch_available() else () all_generative_model_classes = (WhisperForConditionalGeneration,) if is_torch_available() else () + pipeline_model_mapping = ( + {"automatic-speech-recognition": WhisperForConditionalGeneration, "feature-extraction": WhisperModel} + if is_torch_available() + else {} + ) is_encoder_decoder = True fx_compatible = False test_pruning = False diff --git a/tests/models/x_clip/test_modeling_x_clip.py b/tests/models/x_clip/test_modeling_x_clip.py index 73550c0618..2efece44ca 100644 --- a/tests/models/x_clip/test_modeling_x_clip.py +++ b/tests/models/x_clip/test_modeling_x_clip.py @@ -35,6 +35,7 @@ from ...test_modeling_common import ( ids_tensor, random_attention_mask, ) +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -506,8 +507,9 @@ class XCLIPModelTester: @require_torch -class XCLIPModelTest(ModelTesterMixin, unittest.TestCase): +class XCLIPModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (XCLIPModel,) if is_torch_available() else () + pipeline_model_mapping = {"feature-extraction": XCLIPModel} if is_torch_available() else {} fx_compatible = False test_head_masking = False test_pruning = False diff --git a/tests/models/xglm/test_modeling_tf_xglm.py b/tests/models/xglm/test_modeling_tf_xglm.py index 6f4069a40c..c5baeb510e 100644 --- a/tests/models/xglm/test_modeling_tf_xglm.py +++ b/tests/models/xglm/test_modeling_tf_xglm.py @@ -20,6 +20,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -139,9 +140,12 @@ class TFXGLMModelTester: @require_tf -class TFXGLMModelTest(TFModelTesterMixin, unittest.TestCase): +class TFXGLMModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (TFXGLMModel, TFXGLMForCausalLM) if is_tf_available() else () all_generative_model_classes = (TFXGLMForCausalLM,) if is_tf_available() else () + pipeline_model_mapping = ( + {"feature-extraction": TFXGLMModel, "text-generation": TFXGLMForCausalLM} if is_tf_available() else {} + ) test_onnx = False test_missing_keys = False test_pruning = False diff --git a/tests/models/xglm/test_modeling_xglm.py b/tests/models/xglm/test_modeling_xglm.py index f906ebf899..010fef113a 100644 --- a/tests/models/xglm/test_modeling_xglm.py +++ b/tests/models/xglm/test_modeling_xglm.py @@ -23,6 +23,7 @@ from transformers.testing_utils import require_torch, require_torch_gpu, slow, t from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -294,9 +295,12 @@ class XGLMModelTester: @require_torch -class XGLMModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class XGLMModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = (XGLMModel, XGLMForCausalLM) if is_torch_available() else () all_generative_model_classes = (XGLMForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": XGLMModel, "text-generation": XGLMForCausalLM} if is_torch_available() else {} + ) fx_compatible = True test_missing_keys = False test_pruning = False diff --git a/tests/models/xlm/test_modeling_tf_xlm.py b/tests/models/xlm/test_modeling_tf_xlm.py index d443b7f843..e34978495c 100644 --- a/tests/models/xlm/test_modeling_tf_xlm.py +++ b/tests/models/xlm/test_modeling_tf_xlm.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -276,7 +277,7 @@ class TFXLMModelTester: @require_tf -class TFXLMModelTest(TFModelTesterMixin, unittest.TestCase): +class TFXLMModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFXLMModel, @@ -292,6 +293,19 @@ class TFXLMModelTest(TFModelTesterMixin, unittest.TestCase): all_generative_model_classes = ( (TFXLMWithLMHeadModel,) if is_tf_available() else () ) # TODO (PVP): Check other models whether language generation is also applicable + pipeline_model_mapping = ( + { + "feature-extraction": TFXLMModel, + "fill-mask": TFXLMWithLMHeadModel, + "question-answering": TFXLMForQuestionAnsweringSimple, + "text-classification": TFXLMForSequenceClassification, + "text-generation": TFXLMWithLMHeadModel, + "token-classification": TFXLMForTokenClassification, + "zero-shot": TFXLMForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/xlm/test_modeling_xlm.py b/tests/models/xlm/test_modeling_xlm.py index 3e8a5efc89..58d2a26466 100644 --- a/tests/models/xlm/test_modeling_xlm.py +++ b/tests/models/xlm/test_modeling_xlm.py @@ -21,6 +21,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -359,7 +360,7 @@ class XLMModelTester: @require_torch -class XLMModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class XLMModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( XLMModel, @@ -376,6 +377,19 @@ class XLMModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): all_generative_model_classes = ( (XLMWithLMHeadModel,) if is_torch_available() else () ) # TODO (PVP): Check other models whether language generation is also applicable + pipeline_model_mapping = ( + { + "feature-extraction": XLMModel, + "fill-mask": XLMWithLMHeadModel, + "question-answering": XLMForQuestionAnsweringSimple, + "text-classification": XLMForSequenceClassification, + "text-generation": XLMWithLMHeadModel, + "token-classification": XLMForTokenClassification, + "zero-shot": XLMForSequenceClassification, + } + if is_torch_available() + else {} + ) # XLM has 2 QA models -> need to manually set the correct labels for one of them here def _prepare_for_class(self, inputs_dict, model_class, return_labels=False): diff --git a/tests/models/xlm_roberta_xl/test_modeling_xlm_roberta_xl.py b/tests/models/xlm_roberta_xl/test_modeling_xlm_roberta_xl.py index 4efb48cdf0..2b7e77ea02 100644 --- a/tests/models/xlm_roberta_xl/test_modeling_xlm_roberta_xl.py +++ b/tests/models/xlm_roberta_xl/test_modeling_xlm_roberta_xl.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -357,7 +358,7 @@ class XLMRobertaXLModelTester: @require_torch -class XLMRobertaXLModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class XLMRobertaXLModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( XLMRobertaXLForCausalLM, @@ -372,6 +373,19 @@ class XLMRobertaXLModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.Te else () ) all_generative_model_classes = (XLMRobertaXLForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": XLMRobertaXLModel, + "fill-mask": XLMRobertaXLForMaskedLM, + "question-answering": XLMRobertaXLForQuestionAnswering, + "text-classification": XLMRobertaXLForSequenceClassification, + "text-generation": XLMRobertaXLForCausalLM, + "token-classification": XLMRobertaXLForTokenClassification, + "zero-shot": XLMRobertaXLForSequenceClassification, + } + if is_torch_available() + else {} + ) def setUp(self): self.model_tester = XLMRobertaXLModelTester(self) diff --git a/tests/models/xlnet/test_modeling_tf_xlnet.py b/tests/models/xlnet/test_modeling_tf_xlnet.py index 230ef7a28e..bc65b0501e 100644 --- a/tests/models/xlnet/test_modeling_tf_xlnet.py +++ b/tests/models/xlnet/test_modeling_tf_xlnet.py @@ -23,6 +23,7 @@ from transformers.testing_utils import require_tf, slow from ...test_configuration_common import ConfigTester from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_tf_available(): @@ -331,7 +332,7 @@ class TFXLNetModelTester: @require_tf -class TFXLNetModelTest(TFModelTesterMixin, unittest.TestCase): +class TFXLNetModelTest(TFModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( TFXLNetModel, @@ -347,6 +348,18 @@ class TFXLNetModelTest(TFModelTesterMixin, unittest.TestCase): all_generative_model_classes = ( (TFXLNetLMHeadModel,) if is_tf_available() else () ) # TODO (PVP): Check other models whether language generation is also applicable + pipeline_model_mapping = ( + { + "feature-extraction": TFXLNetModel, + "question-answering": TFXLNetForQuestionAnsweringSimple, + "text-classification": TFXLNetForSequenceClassification, + "text-generation": TFXLNetLMHeadModel, + "token-classification": TFXLNetForTokenClassification, + "zero-shot": TFXLNetForSequenceClassification, + } + if is_tf_available() + else {} + ) test_head_masking = False test_onnx = False diff --git a/tests/models/xlnet/test_modeling_xlnet.py b/tests/models/xlnet/test_modeling_xlnet.py index 7fd0b2ee70..2b99d2e17c 100644 --- a/tests/models/xlnet/test_modeling_xlnet.py +++ b/tests/models/xlnet/test_modeling_xlnet.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -509,7 +510,7 @@ class XLNetModelTester: @require_torch -class XLNetModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class XLNetModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( XLNetModel, @@ -526,6 +527,18 @@ class XLNetModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase) all_generative_model_classes = ( (XLNetLMHeadModel,) if is_torch_available() else () ) # TODO (PVP): Check other models whether language generation is also applicable + pipeline_model_mapping = ( + { + "feature-extraction": XLNetModel, + "question-answering": XLNetForQuestionAnsweringSimple, + "text-classification": XLNetForSequenceClassification, + "text-generation": XLNetLMHeadModel, + "token-classification": XLNetForTokenClassification, + "zero-shot": XLNetForSequenceClassification, + } + if is_torch_available() + else {} + ) fx_compatible = False test_pruning = False diff --git a/tests/models/xmod/test_modeling_xmod.py b/tests/models/xmod/test_modeling_xmod.py index d8af2b291c..35d226036f 100644 --- a/tests/models/xmod/test_modeling_xmod.py +++ b/tests/models/xmod/test_modeling_xmod.py @@ -20,6 +20,7 @@ from transformers.testing_utils import require_sentencepiece, require_tokenizers from ...generation.test_utils import GenerationTesterMixin from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -354,7 +355,7 @@ class XmodModelTester: @require_torch -class XmodModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): +class XmodModelTest(ModelTesterMixin, GenerationTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( XmodForCausalLM, @@ -369,6 +370,19 @@ class XmodModelTest(ModelTesterMixin, GenerationTesterMixin, unittest.TestCase): else () ) all_generative_model_classes = (XmodForCausalLM,) if is_torch_available() else () + pipeline_model_mapping = ( + { + "feature-extraction": XmodModel, + "fill-mask": XmodForMaskedLM, + "question-answering": XmodForQuestionAnswering, + "text-classification": XmodForSequenceClassification, + "text-generation": XmodForCausalLM, + "token-classification": XmodForTokenClassification, + "zero-shot": XmodForSequenceClassification, + } + if is_torch_available() + else {} + ) def setUp(self): self.model_tester = XmodModelTester(self) diff --git a/tests/models/yolos/test_modeling_yolos.py b/tests/models/yolos/test_modeling_yolos.py index 1d07e50ce7..e85cffc3d0 100644 --- a/tests/models/yolos/test_modeling_yolos.py +++ b/tests/models/yolos/test_modeling_yolos.py @@ -24,6 +24,7 @@ from transformers.utils import cached_property, is_torch_available, is_vision_av from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -160,13 +161,16 @@ class YolosModelTester: @require_torch -class YolosModelTest(ModelTesterMixin, unittest.TestCase): +class YolosModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): """ Here we also overwrite some of the tests of test_modeling_common.py, as YOLOS does not use input_ids, inputs_embeds, attention_mask and seq_length. """ all_model_classes = (YolosModel, YolosForObjectDetection) if is_torch_available() else () + pipeline_model_mapping = ( + {"feature-extraction": YolosModel, "object-detection": YolosForObjectDetection} if is_torch_available() else {} + ) test_pruning = False test_resize_embeddings = False diff --git a/tests/models/yoso/test_modeling_yoso.py b/tests/models/yoso/test_modeling_yoso.py index 5f72f992ee..e275e19e40 100644 --- a/tests/models/yoso/test_modeling_yoso.py +++ b/tests/models/yoso/test_modeling_yoso.py @@ -22,6 +22,7 @@ from transformers.testing_utils import require_torch, slow, torch_device from ...test_configuration_common import ConfigTester from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask +from ...test_pipeline_mixin import PipelineTesterMixin if is_torch_available(): @@ -280,7 +281,7 @@ class YosoModelTester: @require_torch -class YosoModelTest(ModelTesterMixin, unittest.TestCase): +class YosoModelTest(ModelTesterMixin, PipelineTesterMixin, unittest.TestCase): all_model_classes = ( ( YosoModel, @@ -298,6 +299,18 @@ class YosoModelTest(ModelTesterMixin, unittest.TestCase): test_torchscript = False all_generative_model_classes = () + pipeline_model_mapping = ( + { + "feature-extraction": YosoModel, + "fill-mask": YosoForMaskedLM, + "question-answering": YosoForQuestionAnswering, + "text-classification": YosoForSequenceClassification, + "token-classification": YosoForTokenClassification, + "zero-shot": YosoForSequenceClassification, + } + if is_torch_available() + else {} + ) def setUp(self): self.model_tester = YosoModelTester(self) diff --git a/tests/pipelines/test_pipelines_audio_classification.py b/tests/pipelines/test_pipelines_audio_classification.py index ea6d978bc1..f33ccd46ca 100644 --- a/tests/pipelines/test_pipelines_audio_classification.py +++ b/tests/pipelines/test_pipelines_audio_classification.py @@ -20,11 +20,11 @@ from transformers import MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING from transformers.pipelines import AudioClassificationPipeline, pipeline from transformers.testing_utils import nested_simplify, require_tf, require_torch, require_torchaudio, slow -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY @require_torch -class AudioClassificationPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class AudioClassificationPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING def get_test_pipeline(self, model, tokenizer, processor): diff --git a/tests/pipelines/test_pipelines_automatic_speech_recognition.py b/tests/pipelines/test_pipelines_automatic_speech_recognition.py index b58548d5ba..84b54d1aa8 100644 --- a/tests/pipelines/test_pipelines_automatic_speech_recognition.py +++ b/tests/pipelines/test_pipelines_automatic_speech_recognition.py @@ -42,7 +42,7 @@ from transformers.testing_utils import ( slow, ) -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY if is_torch_available(): @@ -53,7 +53,7 @@ if is_torch_available(): # from .test_pipelines_common import CustomInputPipelineCommonMixin -class AutomaticSpeechRecognitionPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class AutomaticSpeechRecognitionPipelineTests(unittest.TestCase): model_mapping = { k: v for k, v in (list(MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING.items()) if MODEL_FOR_SPEECH_SEQ_2_SEQ_MAPPING else []) diff --git a/tests/pipelines/test_pipelines_common.py b/tests/pipelines/test_pipelines_common.py index 4070966437..8e876957d9 100644 --- a/tests/pipelines/test_pipelines_common.py +++ b/tests/pipelines/test_pipelines_common.py @@ -12,20 +12,15 @@ # See the License for the specific language governing permissions and # limitations under the License. -import copy import logging import os -import random import sys import tempfile import unittest -from abc import abstractmethod from pathlib import Path -from unittest import skipIf import datasets import numpy as np -import requests from huggingface_hub import HfFolder, Repository, create_repo, delete_repo, set_access_token from requests.exceptions import HTTPError @@ -82,255 +77,6 @@ class ANY: return f"ANY({', '.join(_type.__name__ for _type in self._types)})" -def is_test_to_skip(test_casse_name, config_class, model_architecture, tokenizer_name, processor_name): - """Some tests are just not working""" - - to_skip = False - - if config_class.__name__ == "RoCBertConfig" and test_casse_name in [ - "FillMaskPipelineTests", - "FeatureExtractionPipelineTests", - "TextClassificationPipelineTests", - "TokenClassificationPipelineTests", - ]: - # Get error: IndexError: index out of range in self. - # `word_shape_file` and `word_pronunciation_file` should be shrunk during tiny model creation, - # otherwise `IndexError` could occur in some embedding layers. Skip for now until this model has - # more usage. - to_skip = True - elif config_class.__name__ in ["LayoutLMv3Config", "LiltConfig"]: - # Get error: ValueError: Words must be of type `List[str]`. Previously, `LayoutLMv3` is not - # used in pipeline tests as it could not find a checkpoint - # TODO: check and fix if possible - to_skip = True - # config/model class we decide to skip - elif config_class.__name__ in ["TapasConfig"]: - # Get error: AssertionError: Table must be of type pd.DataFrame. Also, the tiny model has large - # vocab size as the fast tokenizer could not be converted. Previous, `Tapas` is not used in - # pipeline tests due to the same reason. - # TODO: check and fix if possible - to_skip = True - - # TODO: check and fix if possible - if not to_skip and tokenizer_name is not None: - if ( - test_casse_name == "QAPipelineTests" - and not tokenizer_name.endswith("Fast") - and config_class.__name__ - in [ - "FlaubertConfig", - "GPTJConfig", - "LongformerConfig", - "MvpConfig", - "OPTConfig", - "ReformerConfig", - "XLMConfig", - ] - ): - # `QAPipelineTests` fails for a few models when the slower tokenizer are used. - # (The slower tokenizers were never used for pipeline tests before the pipeline testing rework) - # TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer - to_skip = True - elif test_casse_name == "ZeroShotClassificationPipelineTests" and config_class.__name__ in [ - "CTRLConfig", - "OpenAIGPTConfig", - ]: - # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers. - # `CTRLConfig` and `OpenAIGPTConfig` were never used in pipeline tests, either because of a missing - # checkpoint or because a tiny config could not be created - to_skip = True - elif test_casse_name == "TranslationPipelineTests" and config_class.__name__ in [ - "M2M100Config", - "PLBartConfig", - ]: - # Get `ValueError: Translation requires a `src_lang` and a `tgt_lang` for this model`. - # `M2M100Config` and `PLBartConfig` were never used in pipeline tests: cannot create a simple tokenizer - to_skip = True - elif test_casse_name == "TextGenerationPipelineTests" and config_class.__name__ in [ - "ProphetNetConfig", - "TransfoXLConfig", - ]: - # Get `ValueError: AttributeError: 'NoneType' object has no attribute 'new_ones'` or `AssertionError`. - # `TransfoXLConfig` and `ProphetNetConfig` were never used in pipeline tests: cannot create a simple - # tokenizer. - to_skip = True - elif test_casse_name == "FillMaskPipelineTests" and config_class.__name__ in [ - "FlaubertConfig", - "XLMConfig", - ]: - # Get `ValueError: AttributeError: 'NoneType' object has no attribute 'new_ones'` or `AssertionError`. - # `FlaubertConfig` and `TransfoXLConfig` were never used in pipeline tests: cannot create a simple - # tokenizer - to_skip = True - elif test_casse_name == "TextGenerationPipelineTests" and model_architecture.__name__ in [ - "TFRoFormerForCausalLM" - ]: - # TODO: add `prepare_inputs_for_generation` for `TFRoFormerForCausalLM` - to_skip = True - elif test_casse_name == "QAPipelineTests" and model_architecture.__name__ in ["FNetForQuestionAnswering"]: - # TODO: The change in `base.py` in the PR #21132 (https://github.com/huggingface/transformers/pull/21132) - # fails this test case. Skip for now - a fix for this along with the initial changes in PR #20426 is - # too much. Let `ydshieh` to fix it ASAP once #20426 is merged. - to_skip = True - elif config_class.__name__ == "LayoutLMv2Config" and test_casse_name in [ - "QAPipelineTests", - "TextClassificationPipelineTests", - "TokenClassificationPipelineTests", - "ZeroShotClassificationPipelineTests", - ]: - # `LayoutLMv2Config` was never used in pipeline tests (`test_pt_LayoutLMv2Config_XXX`) due to lack of tiny - # config. With new tiny model creation, it is available, but we need to fix the failed tests. - to_skip = True - elif test_casse_name == "DocumentQuestionAnsweringPipelineTests" and not tokenizer_name.endswith("Fast"): - # This pipeline uses `sequence_ids()` which is only available for fast tokenizers. - to_skip = True - - return to_skip - - -def validate_test_components(test_case, model, tokenizer, processor): - # TODO: Move this to tiny model creation script - # head-specific (within a model type) necessary changes to the config - # 1. for `BlenderbotForCausalLM` - if model.__class__.__name__ == "BlenderbotForCausalLM": - model.config.encoder_no_repeat_ngram_size = 0 - - # TODO: Change the tiny model creation script: don't create models with problematic tokenizers - # Avoid `IndexError` in embedding layers - CONFIG_WITHOUT_VOCAB_SIZE = ["CanineConfig"] - if tokenizer is not None: - config_vocab_size = getattr(model.config, "vocab_size", None) - # For CLIP-like models - if config_vocab_size is None and hasattr(model.config, "text_config"): - config_vocab_size = getattr(model.config.text_config, "vocab_size", None) - if config_vocab_size is None and model.config.__class__.__name__ not in CONFIG_WITHOUT_VOCAB_SIZE: - raise ValueError( - "Could not determine `vocab_size` from model configuration while `tokenizer` is not `None`." - ) - # TODO: Remove tiny models from the Hub which have problematic tokenizers (but still keep this block) - if config_vocab_size is not None and len(tokenizer) > config_vocab_size: - test_case.skipTest( - f"Ignore {model.__class__.__name__}: `tokenizer` ({tokenizer.__class__.__name__}) has" - f" {len(tokenizer)} tokens which is greater than `config_vocab_size`" - f" ({config_vocab_size}). Something is wrong." - ) - - -class PipelineTestCaseMeta(type): - def __new__(mcs, name, bases, dct): - def gen_test(repo_name, model_architecture, tokenizer_name, processor_name): - @skipIf( - tokenizer_name is None and processor_name is None, - f"Ignore {model_architecture.__name__}: no processor class is provided (tokenizer, image processor," - " feature extractor, etc)", - ) - def test(self): - repo_id = f"hf-internal-testing/{repo_name}" - - tokenizer = None - if tokenizer_name is not None: - tokenizer_class = getattr(transformers_module, tokenizer_name) - tokenizer = tokenizer_class.from_pretrained(repo_id) - - processor = None - if processor_name is not None: - processor_class = getattr(transformers_module, processor_name) - # If the required packages (like `Pillow`) are not installed, this will fail. - try: - processor = processor_class.from_pretrained(repo_id) - except Exception: - self.skipTest(f"Ignore {model_architecture.__name__}: could not load the model from {repo_id}") - - try: - model = model_architecture.from_pretrained(repo_id) - except Exception: - self.skipTest(f"Ignore {model_architecture.__name__}: could not load the model from {repo_id}") - - # validate - validate_test_components(self, model, tokenizer, processor) - - if hasattr(model, "eval"): - model = model.eval() - - pipeline, examples = self.get_test_pipeline(model, tokenizer, processor) - if pipeline is None: - # The test can disable itself, but it should be very marginal - # Concerns: Wav2Vec2ForCTC without tokenizer test (FastTokenizer don't exist) - self.skipTest(f"Ignore {model_architecture.__name__}: could not create the pipeline") - self.run_pipeline_test(pipeline, examples) - - def run_batch_test(pipeline, examples): - # Need to copy because `Conversation` are stateful - if pipeline.tokenizer is not None and pipeline.tokenizer.pad_token_id is None: - return # No batching for this and it's OK - - # 10 examples with batch size 4 means there needs to be a unfinished batch - # which is important for the unbatcher - def data(n): - for _ in range(n): - # Need to copy because Conversation object is mutated - yield copy.deepcopy(random.choice(examples)) - - out = [] - for item in pipeline(data(10), batch_size=4): - out.append(item) - self.assertEqual(len(out), 10) - - run_batch_test(pipeline, examples) - - return test - - # Download tiny model summary (used to avoid requesting from Hub too many times) - url = "https://huggingface.co/datasets/hf-internal-testing/tiny-random-model-summary/raw/main/processor_classes.json" - tiny_model_summary = requests.get(url).json() - - for prefix, key in [("pt", "model_mapping"), ("tf", "tf_model_mapping")]: - mapping = dct.get(key, {}) - if mapping: - for config_class, model_architectures in mapping.items(): - if not isinstance(model_architectures, tuple): - model_architectures = (model_architectures,) - - for model_architecture in model_architectures: - model_arch_name = model_architecture.__name__ - # Get the canonical name - for _prefix in ["Flax", "TF"]: - if model_arch_name.startswith(_prefix): - model_arch_name = model_arch_name[len(_prefix) :] - break - - tokenizer_names = [] - processor_names = [] - if model_arch_name in tiny_model_summary: - tokenizer_names = tiny_model_summary[model_arch_name]["tokenizer_classes"] - processor_names = tiny_model_summary[model_arch_name]["processor_classes"] - # Adding `None` (if empty) so we can generate tests - tokenizer_names = [None] if len(tokenizer_names) == 0 else tokenizer_names - processor_names = [None] if len(processor_names) == 0 else processor_names - - repo_name = f"tiny-random-{model_arch_name}" - for tokenizer_name in tokenizer_names: - for processor_name in processor_names: - if is_test_to_skip( - name, config_class, model_architecture, tokenizer_name, processor_name - ): - continue - test_name = f"test_{prefix}_{config_class.__name__}_{model_architecture.__name__}_{tokenizer_name}_{processor_name}" - dct[test_name] = gen_test( - repo_name, model_architecture, tokenizer_name, processor_name - ) - - @abstractmethod - def inner(self): - raise NotImplementedError("Not implemented test") - - # Force these 2 methods to exist - dct["test_small_model_pt"] = dct.get("test_small_model_pt", inner) - dct["test_small_model_tf"] = dct.get("test_small_model_tf", inner) - - return type.__new__(mcs, name, bases, dct) - - class CommonPipelineTest(unittest.TestCase): @require_torch def test_pipeline_iteration(self): diff --git a/tests/pipelines/test_pipelines_conversational.py b/tests/pipelines/test_pipelines_conversational.py index 9ed32adda6..199b8d6ba5 100644 --- a/tests/pipelines/test_pipelines_conversational.py +++ b/tests/pipelines/test_pipelines_conversational.py @@ -31,13 +31,13 @@ from transformers import ( ) from transformers.testing_utils import require_tf, require_torch, slow, torch_device -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY DEFAULT_DEVICE_NUM = -1 if torch_device == "cpu" else 0 -class ConversationalPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class ConversationalPipelineTests(unittest.TestCase): model_mapping = dict( list(MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING.items()) if MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING diff --git a/tests/pipelines/test_pipelines_depth_estimation.py b/tests/pipelines/test_pipelines_depth_estimation.py index 8e13407246..fd4d3a6ca1 100644 --- a/tests/pipelines/test_pipelines_depth_estimation.py +++ b/tests/pipelines/test_pipelines_depth_estimation.py @@ -19,7 +19,7 @@ from transformers import MODEL_FOR_DEPTH_ESTIMATION_MAPPING, is_torch_available, from transformers.pipelines import DepthEstimationPipeline, pipeline from transformers.testing_utils import nested_simplify, require_tf, require_timm, require_torch, require_vision, slow -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY if is_torch_available(): @@ -43,7 +43,7 @@ def hashimage(image: Image) -> str: @require_vision @require_timm @require_torch -class DepthEstimationPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class DepthEstimationPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_DEPTH_ESTIMATION_MAPPING def get_test_pipeline(self, model, tokenizer, processor): diff --git a/tests/pipelines/test_pipelines_document_question_answering.py b/tests/pipelines/test_pipelines_document_question_answering.py index 4aa8d17b6e..edd2383446 100644 --- a/tests/pipelines/test_pipelines_document_question_answering.py +++ b/tests/pipelines/test_pipelines_document_question_answering.py @@ -27,7 +27,7 @@ from transformers.testing_utils import ( slow, ) -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY if is_vision_available(): @@ -54,7 +54,7 @@ INVOICE_URL = ( @require_torch @require_vision -class DocumentQuestionAnsweringPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class DocumentQuestionAnsweringPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING @require_pytesseract diff --git a/tests/pipelines/test_pipelines_feature_extraction.py b/tests/pipelines/test_pipelines_feature_extraction.py index 7b0fb185a8..f191bea57a 100644 --- a/tests/pipelines/test_pipelines_feature_extraction.py +++ b/tests/pipelines/test_pipelines_feature_extraction.py @@ -29,8 +29,6 @@ from transformers import ( ) from transformers.testing_utils import nested_simplify, require_tf, require_torch -from .test_pipelines_common import PipelineTestCaseMeta - if is_torch_available(): import torch @@ -39,7 +37,7 @@ if is_tf_available(): import tensorflow as tf -class FeatureExtractionPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class FeatureExtractionPipelineTests(unittest.TestCase): model_mapping = MODEL_MAPPING tf_model_mapping = TF_MODEL_MAPPING diff --git a/tests/pipelines/test_pipelines_fill_mask.py b/tests/pipelines/test_pipelines_fill_mask.py index b5260488fb..ec69860d20 100644 --- a/tests/pipelines/test_pipelines_fill_mask.py +++ b/tests/pipelines/test_pipelines_fill_mask.py @@ -18,10 +18,10 @@ from transformers import MODEL_FOR_MASKED_LM_MAPPING, TF_MODEL_FOR_MASKED_LM_MAP from transformers.pipelines import PipelineException from transformers.testing_utils import nested_simplify, require_tf, require_torch, require_torch_gpu, slow -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY -class FillMaskPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class FillMaskPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_MASKED_LM_MAPPING tf_model_mapping = TF_MODEL_FOR_MASKED_LM_MAPPING diff --git a/tests/pipelines/test_pipelines_image_classification.py b/tests/pipelines/test_pipelines_image_classification.py index 64faf978a2..e42f7f6779 100644 --- a/tests/pipelines/test_pipelines_image_classification.py +++ b/tests/pipelines/test_pipelines_image_classification.py @@ -30,7 +30,7 @@ from transformers.testing_utils import ( slow, ) -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY if is_vision_available(): @@ -45,7 +45,7 @@ else: @require_torch_or_tf @require_vision -class ImageClassificationPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class ImageClassificationPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING tf_model_mapping = TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING diff --git a/tests/pipelines/test_pipelines_image_segmentation.py b/tests/pipelines/test_pipelines_image_segmentation.py index a1a0c7b371..631b8b079d 100644 --- a/tests/pipelines/test_pipelines_image_segmentation.py +++ b/tests/pipelines/test_pipelines_image_segmentation.py @@ -36,7 +36,7 @@ from transformers import ( ) from transformers.testing_utils import nested_simplify, require_tf, require_timm, require_torch, require_vision, slow -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY if is_vision_available(): @@ -70,7 +70,7 @@ def mask_to_test_readable_only_shape(mask: Image) -> Dict: @require_vision @require_timm @require_torch -class ImageSegmentationPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class ImageSegmentationPipelineTests(unittest.TestCase): model_mapping = { k: v for k, v in ( diff --git a/tests/pipelines/test_pipelines_image_to_text.py b/tests/pipelines/test_pipelines_image_to_text.py index fa99ab5b88..e685b51e13 100644 --- a/tests/pipelines/test_pipelines_image_to_text.py +++ b/tests/pipelines/test_pipelines_image_to_text.py @@ -18,7 +18,7 @@ from transformers import MODEL_FOR_VISION_2_SEQ_MAPPING, TF_MODEL_FOR_VISION_2_S from transformers.pipelines import pipeline from transformers.testing_utils import require_tf, require_torch, require_vision, slow -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY if is_vision_available(): @@ -32,7 +32,7 @@ else: @require_vision -class ImageToTextPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class ImageToTextPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_VISION_2_SEQ_MAPPING tf_model_mapping = TF_MODEL_FOR_VISION_2_SEQ_MAPPING diff --git a/tests/pipelines/test_pipelines_object_detection.py b/tests/pipelines/test_pipelines_object_detection.py index 5fd132a3c3..80afae3254 100644 --- a/tests/pipelines/test_pipelines_object_detection.py +++ b/tests/pipelines/test_pipelines_object_detection.py @@ -32,7 +32,7 @@ from transformers.testing_utils import ( slow, ) -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY if is_vision_available(): @@ -48,7 +48,7 @@ else: @require_vision @require_timm @require_torch -class ObjectDetectionPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class ObjectDetectionPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_OBJECT_DETECTION_MAPPING def get_test_pipeline(self, model, tokenizer, processor): diff --git a/tests/pipelines/test_pipelines_question_answering.py b/tests/pipelines/test_pipelines_question_answering.py index b4cc356184..037b60c152 100644 --- a/tests/pipelines/test_pipelines_question_answering.py +++ b/tests/pipelines/test_pipelines_question_answering.py @@ -24,10 +24,10 @@ from transformers.data.processors.squad import SquadExample from transformers.pipelines import QuestionAnsweringArgumentHandler, pipeline from transformers.testing_utils import nested_simplify, require_tf, require_torch, require_torch_or_tf, slow -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY -class QAPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class QAPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_QUESTION_ANSWERING_MAPPING tf_model_mapping = TF_MODEL_FOR_QUESTION_ANSWERING_MAPPING diff --git a/tests/pipelines/test_pipelines_summarization.py b/tests/pipelines/test_pipelines_summarization.py index 5db8a680f6..ac85dd3944 100644 --- a/tests/pipelines/test_pipelines_summarization.py +++ b/tests/pipelines/test_pipelines_summarization.py @@ -24,13 +24,13 @@ from transformers import ( from transformers.testing_utils import get_gpu_count, require_tf, require_torch, slow, torch_device from transformers.tokenization_utils import TruncationStrategy -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY DEFAULT_DEVICE_NUM = -1 if torch_device == "cpu" else 0 -class SummarizationPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class SummarizationPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING tf_model_mapping = TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING diff --git a/tests/pipelines/test_pipelines_table_question_answering.py b/tests/pipelines/test_pipelines_table_question_answering.py index 3527f3ef22..43176e0c7c 100644 --- a/tests/pipelines/test_pipelines_table_question_answering.py +++ b/tests/pipelines/test_pipelines_table_question_answering.py @@ -24,10 +24,8 @@ from transformers import ( ) from transformers.testing_utils import require_pandas, require_tensorflow_probability, require_tf, require_torch, slow -from .test_pipelines_common import PipelineTestCaseMeta - -class TQAPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class TQAPipelineTests(unittest.TestCase): # Putting it there for consistency, but TQA do not have fast tokenizer # which are needed to generate automatic tests model_mapping = MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING diff --git a/tests/pipelines/test_pipelines_text2text_generation.py b/tests/pipelines/test_pipelines_text2text_generation.py index 5e5db132bd..8528dd8f6b 100644 --- a/tests/pipelines/test_pipelines_text2text_generation.py +++ b/tests/pipelines/test_pipelines_text2text_generation.py @@ -23,14 +23,14 @@ from transformers import ( from transformers.testing_utils import require_tf, require_torch from transformers.utils import is_torch_available -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY if is_torch_available(): import torch -class Text2TextGenerationPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class Text2TextGenerationPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING tf_model_mapping = TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING diff --git a/tests/pipelines/test_pipelines_text_classification.py b/tests/pipelines/test_pipelines_text_classification.py index a96a97cc74..82237d75f0 100644 --- a/tests/pipelines/test_pipelines_text_classification.py +++ b/tests/pipelines/test_pipelines_text_classification.py @@ -22,10 +22,10 @@ from transformers import ( ) from transformers.testing_utils import nested_simplify, require_tf, require_torch, slow -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY -class TextClassificationPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class TextClassificationPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING tf_model_mapping = TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING diff --git a/tests/pipelines/test_pipelines_text_generation.py b/tests/pipelines/test_pipelines_text_generation.py index 1f32992681..24f2d75a3a 100644 --- a/tests/pipelines/test_pipelines_text_generation.py +++ b/tests/pipelines/test_pipelines_text_generation.py @@ -23,11 +23,11 @@ from transformers.testing_utils import ( require_torch_or_tf, ) -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY @require_torch_or_tf -class TextGenerationPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class TextGenerationPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_CAUSAL_LM_MAPPING tf_model_mapping = TF_MODEL_FOR_CAUSAL_LM_MAPPING diff --git a/tests/pipelines/test_pipelines_token_classification.py b/tests/pipelines/test_pipelines_token_classification.py index d6cea29d58..2d167eb635 100644 --- a/tests/pipelines/test_pipelines_token_classification.py +++ b/tests/pipelines/test_pipelines_token_classification.py @@ -27,13 +27,13 @@ from transformers import ( from transformers.pipelines import AggregationStrategy, TokenClassificationArgumentHandler from transformers.testing_utils import nested_simplify, require_tf, require_torch, require_torch_gpu, slow -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY VALID_INPUTS = ["A simple string", ["list of strings", "A simple string that is quite a bit longer"]] -class TokenClassificationPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class TokenClassificationPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING tf_model_mapping = TF_MODEL_FOR_TOKEN_CLASSIFICATION_MAPPING diff --git a/tests/pipelines/test_pipelines_translation.py b/tests/pipelines/test_pipelines_translation.py index bf9a7ef09b..cbcf4b4341 100644 --- a/tests/pipelines/test_pipelines_translation.py +++ b/tests/pipelines/test_pipelines_translation.py @@ -27,10 +27,10 @@ from transformers import ( ) from transformers.testing_utils import require_tf, require_torch, slow -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY -class TranslationPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class TranslationPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING tf_model_mapping = TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING diff --git a/tests/pipelines/test_pipelines_video_classification.py b/tests/pipelines/test_pipelines_video_classification.py index 8390d21fc5..32c280c03a 100644 --- a/tests/pipelines/test_pipelines_video_classification.py +++ b/tests/pipelines/test_pipelines_video_classification.py @@ -27,13 +27,13 @@ from transformers.testing_utils import ( require_vision, ) -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY @require_torch_or_tf @require_vision @require_decord -class VideoClassificationPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class VideoClassificationPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING def get_test_pipeline(self, model, tokenizer, processor): diff --git a/tests/pipelines/test_pipelines_visual_question_answering.py b/tests/pipelines/test_pipelines_visual_question_answering.py index 696b3c7351..1c82705d4c 100644 --- a/tests/pipelines/test_pipelines_visual_question_answering.py +++ b/tests/pipelines/test_pipelines_visual_question_answering.py @@ -18,7 +18,7 @@ from transformers import MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING, is_vision_ from transformers.pipelines import pipeline from transformers.testing_utils import nested_simplify, require_tf, require_torch, require_vision, slow -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY if is_vision_available(): @@ -33,7 +33,7 @@ else: @require_torch @require_vision -class VisualQuestionAnsweringPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class VisualQuestionAnsweringPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING def get_test_pipeline(self, model, tokenizer, processor): diff --git a/tests/pipelines/test_pipelines_zero_shot.py b/tests/pipelines/test_pipelines_zero_shot.py index 76f80bce47..81df729899 100644 --- a/tests/pipelines/test_pipelines_zero_shot.py +++ b/tests/pipelines/test_pipelines_zero_shot.py @@ -23,10 +23,10 @@ from transformers import ( ) from transformers.testing_utils import nested_simplify, require_tf, require_torch, slow -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY -class ZeroShotClassificationPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class ZeroShotClassificationPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING tf_model_mapping = TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING diff --git a/tests/pipelines/test_pipelines_zero_shot_audio_classification.py b/tests/pipelines/test_pipelines_zero_shot_audio_classification.py index 06ab5bdea6..c2d1b89de4 100644 --- a/tests/pipelines/test_pipelines_zero_shot_audio_classification.py +++ b/tests/pipelines/test_pipelines_zero_shot_audio_classification.py @@ -19,11 +19,9 @@ from datasets import load_dataset from transformers.pipelines import pipeline from transformers.testing_utils import nested_simplify, require_torch, slow -from .test_pipelines_common import PipelineTestCaseMeta - @require_torch -class ZeroShotAudioClassificationPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class ZeroShotAudioClassificationPipelineTests(unittest.TestCase): # Deactivating auto tests since we don't have a good MODEL_FOR_XX mapping, # and only CLAP would be there for now. # model_mapping = {CLAPConfig: CLAPModel} diff --git a/tests/pipelines/test_pipelines_zero_shot_image_classification.py b/tests/pipelines/test_pipelines_zero_shot_image_classification.py index 01107b5549..1be534350d 100644 --- a/tests/pipelines/test_pipelines_zero_shot_image_classification.py +++ b/tests/pipelines/test_pipelines_zero_shot_image_classification.py @@ -18,7 +18,7 @@ from transformers import is_vision_available from transformers.pipelines import pipeline from transformers.testing_utils import nested_simplify, require_tf, require_torch, require_vision, slow -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY if is_vision_available(): @@ -32,7 +32,7 @@ else: @require_vision -class ZeroShotImageClassificationPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class ZeroShotImageClassificationPipelineTests(unittest.TestCase): # Deactivating auto tests since we don't have a good MODEL_FOR_XX mapping, # and only CLIP would be there for now. # model_mapping = {CLIPConfig: CLIPModel} diff --git a/tests/pipelines/test_pipelines_zero_shot_object_detection.py b/tests/pipelines/test_pipelines_zero_shot_object_detection.py index b84ba20a4c..8995d0da9d 100644 --- a/tests/pipelines/test_pipelines_zero_shot_object_detection.py +++ b/tests/pipelines/test_pipelines_zero_shot_object_detection.py @@ -17,7 +17,7 @@ import unittest from transformers import MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING, is_vision_available, pipeline from transformers.testing_utils import nested_simplify, require_tf, require_torch, require_vision, slow -from .test_pipelines_common import ANY, PipelineTestCaseMeta +from .test_pipelines_common import ANY if is_vision_available(): @@ -32,7 +32,7 @@ else: @require_vision @require_torch -class ZeroShotObjectDetectionPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta): +class ZeroShotObjectDetectionPipelineTests(unittest.TestCase): model_mapping = MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING def get_test_pipeline(self, model, tokenizer, processor): diff --git a/tests/test_pipeline_mixin.py b/tests/test_pipeline_mixin.py new file mode 100644 index 0000000000..142028dc9c --- /dev/null +++ b/tests/test_pipeline_mixin.py @@ -0,0 +1,513 @@ +# coding=utf-8 +# Copyright 2023 The HuggingFace Inc. team. All rights reserved. +# +# 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. + +import copy +import json +import os +import random +from pathlib import Path + +from transformers.testing_utils import ( + require_decord, + require_pytesseract, + require_timm, + require_torch, + require_torch_or_tf, + require_vision, +) +from transformers.utils import direct_transformers_import + +from .pipelines.test_pipelines_audio_classification import AudioClassificationPipelineTests +from .pipelines.test_pipelines_automatic_speech_recognition import AutomaticSpeechRecognitionPipelineTests +from .pipelines.test_pipelines_conversational import ConversationalPipelineTests +from .pipelines.test_pipelines_depth_estimation import DepthEstimationPipelineTests +from .pipelines.test_pipelines_document_question_answering import DocumentQuestionAnsweringPipelineTests +from .pipelines.test_pipelines_feature_extraction import FeatureExtractionPipelineTests +from .pipelines.test_pipelines_fill_mask import FillMaskPipelineTests +from .pipelines.test_pipelines_image_classification import ImageClassificationPipelineTests +from .pipelines.test_pipelines_image_segmentation import ImageSegmentationPipelineTests +from .pipelines.test_pipelines_image_to_text import ImageToTextPipelineTests +from .pipelines.test_pipelines_object_detection import ObjectDetectionPipelineTests +from .pipelines.test_pipelines_question_answering import QAPipelineTests +from .pipelines.test_pipelines_summarization import SummarizationPipelineTests +from .pipelines.test_pipelines_table_question_answering import TQAPipelineTests +from .pipelines.test_pipelines_text2text_generation import Text2TextGenerationPipelineTests +from .pipelines.test_pipelines_text_classification import TextClassificationPipelineTests +from .pipelines.test_pipelines_text_generation import TextGenerationPipelineTests +from .pipelines.test_pipelines_token_classification import TokenClassificationPipelineTests +from .pipelines.test_pipelines_translation import TranslationPipelineTests +from .pipelines.test_pipelines_video_classification import VideoClassificationPipelineTests +from .pipelines.test_pipelines_visual_question_answering import VisualQuestionAnsweringPipelineTests +from .pipelines.test_pipelines_zero_shot import ZeroShotClassificationPipelineTests +from .pipelines.test_pipelines_zero_shot_audio_classification import ZeroShotAudioClassificationPipelineTests +from .pipelines.test_pipelines_zero_shot_image_classification import ZeroShotImageClassificationPipelineTests +from .pipelines.test_pipelines_zero_shot_object_detection import ZeroShotObjectDetectionPipelineTests + + +pipeline_test_mapping = { + "audio-classification": {"test": AudioClassificationPipelineTests}, + "automatic-speech-recognition": {"test": AutomaticSpeechRecognitionPipelineTests}, + "conversational": {"test": ConversationalPipelineTests}, + "depth-estimation": {"test": DepthEstimationPipelineTests}, + "document-question-answering": {"test": DocumentQuestionAnsweringPipelineTests}, + "feature-extraction": {"test": FeatureExtractionPipelineTests}, + "fill-mask": {"test": FillMaskPipelineTests}, + "image-classification": {"test": ImageClassificationPipelineTests}, + "image-segmentation": {"test": ImageSegmentationPipelineTests}, + "image-to-text": {"test": ImageToTextPipelineTests}, + "object-detection": {"test": ObjectDetectionPipelineTests}, + "question-answering": {"test": QAPipelineTests}, + "summarization": {"test": SummarizationPipelineTests}, + "table-question-answering": {"test": TQAPipelineTests}, + "text2text-generation": {"test": Text2TextGenerationPipelineTests}, + "text-classification": {"test": TextClassificationPipelineTests}, + "text-generation": {"test": TextGenerationPipelineTests}, + "token-classification": {"test": TokenClassificationPipelineTests}, + "translation": {"test": TranslationPipelineTests}, + "video-classification": {"test": VideoClassificationPipelineTests}, + "visual-question-answering": {"test": VisualQuestionAnsweringPipelineTests}, + "zero-shot": {"test": ZeroShotClassificationPipelineTests}, + "zero-shot-audio-classification": {"test": ZeroShotAudioClassificationPipelineTests}, + "zero-shot-image-classification": {"test": ZeroShotImageClassificationPipelineTests}, + "zero-shot-object-detection": {"test": ZeroShotObjectDetectionPipelineTests}, +} + +for task, task_info in pipeline_test_mapping.items(): + test = task_info["test"] + task_info["mapping"] = { + "pt": getattr(test, "model_mapping", None), + "tf": getattr(test, "tf_model_mapping", None), + } + + +TINY_MODEL_SUMMARY_FILE_PATH = os.path.join(Path(__file__).parent.parent, "tests/utils/tiny_model_summary.json") +with open(TINY_MODEL_SUMMARY_FILE_PATH) as fp: + tiny_model_summary = json.load(fp) + + +PATH_TO_TRANSFORMERS = os.path.join(Path(__file__).parent.parent, "src/transformers") + + +# Dynamically import the Transformers module to grab the attribute classes of the processor form their names. +transformers_module = direct_transformers_import(PATH_TO_TRANSFORMERS) + + +class PipelineTesterMixin: + model_tester = None + pipeline_model_mapping = None + supported_frameworks = ["pt", "tf"] + + def run_task_tests(self, task): + """Run pipeline tests for a specific `task` + + Args: + task (`str`): + A task name. This should be a key in the mapping `pipeline_test_mapping`. + """ + if task not in self.pipeline_model_mapping: + self.skipTest( + f"{self.__class__.__name__}::test_pipeline_{task.replace('-', '_')} is skipped: `{task}` is not in " + f"`self.pipeline_model_mapping` for `{self.__class__.__name__}`." + ) + + model_architectures = self.pipeline_model_mapping[task] + if not isinstance(model_architectures, tuple): + model_architectures = (model_architectures,) + if not isinstance(model_architectures, tuple): + raise ValueError(f"`model_architectures` must be a tuple. Got {type(model_architectures)} instead.") + + for model_architecture in model_architectures: + model_arch_name = model_architecture.__name__ + + # Get the canonical name + for _prefix in ["Flax", "TF"]: + if model_arch_name.startswith(_prefix): + model_arch_name = model_arch_name[len(_prefix) :] + break + + tokenizer_names = [] + processor_names = [] + if model_arch_name in tiny_model_summary: + tokenizer_names = tiny_model_summary[model_arch_name]["tokenizer_classes"] + processor_names = tiny_model_summary[model_arch_name]["processor_classes"] + # Adding `None` (if empty) so we can generate tests + tokenizer_names = [None] if len(tokenizer_names) == 0 else tokenizer_names + processor_names = [None] if len(processor_names) == 0 else processor_names + + repo_name = f"tiny-random-{model_arch_name}" + + self.run_model_pipeline_tests(task, repo_name, model_architecture, tokenizer_names, processor_names) + + def run_model_pipeline_tests(self, task, repo_name, model_architecture, tokenizer_names, processor_names): + """Run pipeline tests for a specific `task` with the give model class and tokenizer/processor class names + + Args: + task (`str`): + A task name. This should be a key in the mapping `pipeline_test_mapping`. + repo_name (`str`): + A model repository id on the Hub. + model_architecture (`type`): + A subclass of `PretrainedModel` or `PretrainedModel`. + tokenizer_names (`List[str]`): + A list of names of a subclasses of `PreTrainedTokenizerFast` or `PreTrainedTokenizer`. + processor_names (`List[str]`): + A list of names of subclasses of `BaseImageProcessor` or `FeatureExtractionMixin`. + """ + # Get an instance of the corresponding class `XXXPipelineTests` in order to use `get_test_pipeline` and + # `run_pipeline_test`. + pipeline_test_class_name = pipeline_test_mapping[task]["test"].__name__ + + for tokenizer_name in tokenizer_names: + for processor_name in processor_names: + if is_test_to_skip( + pipeline_test_class_name, + model_architecture.config_class, + model_architecture, + tokenizer_name, + processor_name, + ): + self.skipTest( + f"{self.__class__.__name__}::test_pipeline_{task.replace('-', '_')} is skipped: test is " + f"currently known to fail for: model `{model_architecture.__name__}` | tokenizer " + f"`{tokenizer_name}` | processor `{processor_name}`." + ) + self.run_pipeline_test(task, repo_name, model_architecture, tokenizer_name, processor_name) + + def run_pipeline_test(self, task, repo_name, model_architecture, tokenizer_name, processor_name): + """Run pipeline tests for a specific `task` with the give model class and tokenizer/processor class name + + The model will be loaded from a model repository on the Hub. + + Args: + task (`str`): + A task name. This should be a key in the mapping `pipeline_test_mapping`. + repo_name (`str`): + A model repository id on the Hub. + model_architecture (`type`): + A subclass of `PretrainedModel` or `PretrainedModel`. + tokenizer_name (`str`): + The name of a subclass of `PreTrainedTokenizerFast` or `PreTrainedTokenizer`. + processor_name (`str`): + The name of a subclass of `BaseImageProcessor` or `FeatureExtractionMixin`. + """ + repo_id = f"hf-internal-testing/{repo_name}" + + tokenizer = None + if tokenizer_name is not None: + tokenizer_class = getattr(transformers_module, tokenizer_name) + tokenizer = tokenizer_class.from_pretrained(repo_id) + + processor = None + if processor_name is not None: + processor_class = getattr(transformers_module, processor_name) + # If the required packages (like `Pillow` or `torchaudio`) are not installed, this will fail. + try: + processor = processor_class.from_pretrained(repo_id) + except Exception: + self.skipTest( + f"{self.__class__.__name__}::test_pipeline_{task.replace('-', '_')} is skipped: Could not load the " + f"processor from `{repo_id}` with `{processor_name}`." + ) + + # TODO: Maybe not upload such problematic tiny models to Hub. + if tokenizer is None and processor is None: + self.skipTest( + f"{self.__class__.__name__}::test_pipeline_{task.replace('-', '_')} is skipped: Could not find or load " + f"any tokenizer / processor from `{repo_id}`." + ) + + # TODO: We should check if a model file is on the Hub repo. instead. + try: + model = model_architecture.from_pretrained(repo_id) + except Exception: + self.skipTest( + f"{self.__class__.__name__}::test_pipeline_{task.replace('-', '_')} is skipped: Could not find or load " + f"the model from `{repo_id}` with `{model_architecture}`." + ) + + # validate + validate_test_components(self, task, model, tokenizer, processor) + + if hasattr(model, "eval"): + model = model.eval() + + # Get an instance of the corresponding class `XXXPipelineTests` in order to use `get_test_pipeline` and + # `run_pipeline_test`. + task_test = pipeline_test_mapping[task]["test"]() + + pipeline, examples = task_test.get_test_pipeline(model, tokenizer, processor) + if pipeline is None: + # The test can disable itself, but it should be very marginal + # Concerns: Wav2Vec2ForCTC without tokenizer test (FastTokenizer don't exist) + self.skipTest( + f"{self.__class__.__name__}::test_pipeline_{task.replace('-', '_')} is skipped: Could not get the " + "pipeline for testing." + ) + + task_test.run_pipeline_test(pipeline, examples) + + def run_batch_test(pipeline, examples): + # Need to copy because `Conversation` are stateful + if pipeline.tokenizer is not None and pipeline.tokenizer.pad_token_id is None: + return # No batching for this and it's OK + + # 10 examples with batch size 4 means there needs to be a unfinished batch + # which is important for the unbatcher + def data(n): + for _ in range(n): + # Need to copy because Conversation object is mutated + yield copy.deepcopy(random.choice(examples)) + + out = [] + for item in pipeline(data(10), batch_size=4): + out.append(item) + self.assertEqual(len(out), 10) + + run_batch_test(pipeline, examples) + + @require_torch + def test_pipeline_audio_classification(self): + self.run_task_tests(task="audio-classification") + + def test_pipeline_automatic_speech_recognition(self): + self.run_task_tests(task="automatic-speech-recognition") + + def test_pipeline_conversational(self): + self.run_task_tests(task="conversational") + + @require_vision + @require_timm + @require_torch + def test_pipeline_depth_estimation(self): + self.run_task_tests(task="depth-estimation") + + @require_pytesseract + @require_torch + @require_vision + def test_pipeline_document_question_answering(self): + self.run_task_tests(task="document-question-answering") + + def test_pipeline_feature_extraction(self): + self.run_task_tests(task="feature-extraction") + + def test_pipeline_fill_mask(self): + self.run_task_tests(task="fill-mask") + + @require_torch_or_tf + @require_vision + def test_pipeline_image_classification(self): + self.run_task_tests(task="image-classification") + + @require_vision + @require_timm + @require_torch + def test_pipeline_image_segmentation(self): + self.run_task_tests(task="image-segmentation") + + @require_vision + def test_pipeline_image_to_text(self): + self.run_task_tests(task="image-to-text") + + @require_vision + @require_timm + @require_torch + def test_pipeline_object_detection(self): + self.run_task_tests(task="object-detection") + + def test_pipeline_question_answering(self): + self.run_task_tests(task="question-answering") + + def test_pipeline_summarization(self): + self.run_task_tests(task="summarization") + + def test_pipeline_table_question_answering(self): + self.run_task_tests(task="table-question-answering") + + def test_pipeline_text2text_generation(self): + self.run_task_tests(task="text2text-generation") + + def test_pipeline_text_classification(self): + self.run_task_tests(task="text-classification") + + @require_torch_or_tf + def test_pipeline_text_generation(self): + self.run_task_tests(task="text-generation") + + def test_pipeline_token_classification(self): + self.run_task_tests(task="token-classification") + + def test_pipeline_translation(self): + self.run_task_tests(task="translation") + + @require_torch_or_tf + @require_vision + @require_decord + def test_pipeline_video_classification(self): + self.run_task_tests(task="video-classification") + + @require_torch + @require_vision + def test_pipeline_visual_question_answering(self): + self.run_task_tests(task="visual-question-answering") + + def test_pipeline_zero_shot(self): + self.run_task_tests(task="zero-shot") + + @require_torch + def test_pipeline_zero_shot_audio_classification(self): + self.run_task_tests(task="zero-shot-audio-classification") + + @require_vision + def test_pipeline_zero_shot_image_classification(self): + self.run_task_tests(task="zero-shot-image-classification") + + @require_vision + @require_torch + def test_pipeline_zero_shot_object_detection(self): + self.run_task_tests(task="zero-shot-object-detection") + + +def validate_test_components(test_case, task, model, tokenizer, processor): + # TODO: Move this to tiny model creation script + # head-specific (within a model type) necessary changes to the config + # 1. for `BlenderbotForCausalLM` + if model.__class__.__name__ == "BlenderbotForCausalLM": + model.config.encoder_no_repeat_ngram_size = 0 + + # TODO: Change the tiny model creation script: don't create models with problematic tokenizers + # Avoid `IndexError` in embedding layers + CONFIG_WITHOUT_VOCAB_SIZE = ["CanineConfig"] + if tokenizer is not None: + config_vocab_size = getattr(model.config, "vocab_size", None) + # For CLIP-like models + if config_vocab_size is None and hasattr(model.config, "text_config"): + config_vocab_size = getattr(model.config.text_config, "vocab_size", None) + if config_vocab_size is None and model.config.__class__.__name__ not in CONFIG_WITHOUT_VOCAB_SIZE: + raise ValueError( + "Could not determine `vocab_size` from model configuration while `tokenizer` is not `None`." + ) + # TODO: Remove tiny models from the Hub which have problematic tokenizers (but still keep this block) + if config_vocab_size is not None and len(tokenizer) > config_vocab_size: + test_case.skipTest( + f"{test_case.__class__.__name__}::test_pipeline_{task.replace('-', '_')} is skipped: tokenizer " + f"(`{tokenizer.__class__.__name__}`) has {len(tokenizer)} tokens which is greater than " + f"`config_vocab_size` ({config_vocab_size}). Something is wrong." + ) + + +def is_test_to_skip(test_casse_name, config_class, model_architecture, tokenizer_name, processor_name): + """Some tests are just not working""" + + to_skip = False + + if config_class.__name__ == "RoCBertConfig" and test_casse_name in [ + "FillMaskPipelineTests", + "FeatureExtractionPipelineTests", + "TextClassificationPipelineTests", + "TokenClassificationPipelineTests", + ]: + # Get error: IndexError: index out of range in self. + # `word_shape_file` and `word_pronunciation_file` should be shrunk during tiny model creation, + # otherwise `IndexError` could occur in some embedding layers. Skip for now until this model has + # more usage. + to_skip = True + elif config_class.__name__ in ["LayoutLMv3Config", "LiltConfig"]: + # Get error: ValueError: Words must be of type `List[str]`. Previously, `LayoutLMv3` is not + # used in pipeline tests as it could not find a checkpoint + # TODO: check and fix if possible + to_skip = True + # config/model class we decide to skip + elif config_class.__name__ in ["TapasConfig"]: + # Get error: AssertionError: Table must be of type pd.DataFrame. Also, the tiny model has large + # vocab size as the fast tokenizer could not be converted. Previous, `Tapas` is not used in + # pipeline tests due to the same reason. + # TODO: check and fix if possible + to_skip = True + + # TODO: check and fix if possible + if not to_skip and tokenizer_name is not None: + if ( + test_casse_name == "QAPipelineTests" + and not tokenizer_name.endswith("Fast") + and config_class.__name__ + in [ + "FlaubertConfig", + "GPTJConfig", + "LongformerConfig", + "MvpConfig", + "OPTConfig", + "ReformerConfig", + "XLMConfig", + ] + ): + # `QAPipelineTests` fails for a few models when the slower tokenizer are used. + # (The slower tokenizers were never used for pipeline tests before the pipeline testing rework) + # TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer + to_skip = True + elif test_casse_name == "ZeroShotClassificationPipelineTests" and config_class.__name__ in [ + "CTRLConfig", + "OpenAIGPTConfig", + ]: + # Get `tokenizer does not have a padding token` error for both fast/slow tokenizers. + # `CTRLConfig` and `OpenAIGPTConfig` were never used in pipeline tests, either because of a missing + # checkpoint or because a tiny config could not be created + to_skip = True + elif test_casse_name == "TranslationPipelineTests" and config_class.__name__ in [ + "M2M100Config", + "PLBartConfig", + ]: + # Get `ValueError: Translation requires a `src_lang` and a `tgt_lang` for this model`. + # `M2M100Config` and `PLBartConfig` were never used in pipeline tests: cannot create a simple tokenizer + to_skip = True + elif test_casse_name == "TextGenerationPipelineTests" and config_class.__name__ in [ + "ProphetNetConfig", + "TransfoXLConfig", + ]: + # Get `ValueError: AttributeError: 'NoneType' object has no attribute 'new_ones'` or `AssertionError`. + # `TransfoXLConfig` and `ProphetNetConfig` were never used in pipeline tests: cannot create a simple + # tokenizer. + to_skip = True + elif test_casse_name == "FillMaskPipelineTests" and config_class.__name__ in [ + "FlaubertConfig", + "XLMConfig", + ]: + # Get `ValueError: AttributeError: 'NoneType' object has no attribute 'new_ones'` or `AssertionError`. + # `FlaubertConfig` and `TransfoXLConfig` were never used in pipeline tests: cannot create a simple + # tokenizer + to_skip = True + elif test_casse_name == "TextGenerationPipelineTests" and model_architecture.__name__ in [ + "TFRoFormerForCausalLM" + ]: + # TODO: add `prepare_inputs_for_generation` for `TFRoFormerForCausalLM` + to_skip = True + elif test_casse_name == "QAPipelineTests" and model_architecture.__name__ in ["FNetForQuestionAnswering"]: + # TODO: The change in `base.py` in the PR #21132 (https://github.com/huggingface/transformers/pull/21132) + # fails this test case. Skip for now - a fix for this along with the initial changes in PR #20426 is + # too much. Let `ydshieh` to fix it ASAP once #20426 is merged. + to_skip = True + elif config_class.__name__ == "LayoutLMv2Config" and test_casse_name in [ + "QAPipelineTests", + "TextClassificationPipelineTests", + "TokenClassificationPipelineTests", + "ZeroShotClassificationPipelineTests", + ]: + # `LayoutLMv2Config` was never used in pipeline tests (`test_pt_LayoutLMv2Config_XXX`) due to lack of tiny + # config. With new tiny model creation, it is available, but we need to fix the failed tests. + to_skip = True + elif test_casse_name == "DocumentQuestionAnsweringPipelineTests" and not tokenizer_name.endswith("Fast"): + # This pipeline uses `sequence_ids()` which is only available for fast tokenizers. + to_skip = True + + return to_skip diff --git a/tests/utils/tiny_model_summary.json b/tests/utils/tiny_model_summary.json new file mode 100644 index 0000000000..f379590abc --- /dev/null +++ b/tests/utils/tiny_model_summary.json @@ -0,0 +1,3181 @@ +{ + "AlbertModel": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "BartModel": { + "tokenizer_classes": [ + "BartTokenizerFast", + "BartTokenizer" + ], + "processor_classes": [] + }, + "BeitModel": { + "tokenizer_classes": [], + "processor_classes": [ + "BeitImageProcessor" + ] + }, + "BertLMHeadModel": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "BertModel": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "BigBirdModel": { + "tokenizer_classes": [ + "BigBirdTokenizerFast" + ], + "processor_classes": [] + }, + "BigBirdPegasusModel": { + "tokenizer_classes": [ + "PegasusTokenizerFast" + ], + "processor_classes": [] + }, + "BlenderbotSmallModel": { + "tokenizer_classes": [], + "processor_classes": [] + }, + "BlenderbotModel": { + "tokenizer_classes": [ + "BlenderbotTokenizerFast", + "BlenderbotTokenizer" + ], + "processor_classes": [] + }, + "BloomModel": { + "tokenizer_classes": [ + "BloomTokenizerFast" + ], + "processor_classes": [] + }, + "CanineModel": { + "tokenizer_classes": [ + "CanineTokenizer" + ], + "processor_classes": [] + }, + "CLIPModel": { + "tokenizer_classes": [ + "CLIPTokenizerFast", + "CLIPTokenizer" + ], + "processor_classes": [ + "CLIPImageProcessor" + ] + }, + "CodeGenModel": { + "tokenizer_classes": [ + "CodeGenTokenizerFast", + "CodeGenTokenizer" + ], + "processor_classes": [] + }, + "ConditionalDetrModel": { + "tokenizer_classes": [], + "processor_classes": [ + "ConditionalDetrFeatureExtractor" + ] + }, + "ConvBertModel": { + "tokenizer_classes": [ + "ConvBertTokenizerFast", + "ConvBertTokenizer" + ], + "processor_classes": [] + }, + "ConvNextModel": { + "tokenizer_classes": [], + "processor_classes": [ + "ConvNextImageProcessor" + ] + }, + "CTRLLMHeadModel": { + "tokenizer_classes": [ + "CTRLTokenizer" + ], + "processor_classes": [] + }, + "CTRLModel": { + "tokenizer_classes": [ + "CTRLTokenizer" + ], + "processor_classes": [] + }, + "CvtModel": { + "tokenizer_classes": [], + "processor_classes": [ + "ConvNextImageProcessor" + ] + }, + "Data2VecAudioModel": { + "tokenizer_classes": [], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "Data2VecTextModel": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "Data2VecVisionModel": { + "tokenizer_classes": [], + "processor_classes": [ + "BeitImageProcessor" + ] + }, + "DebertaV2Model": { + "tokenizer_classes": [ + "DebertaV2TokenizerFast" + ], + "processor_classes": [] + }, + "DebertaModel": { + "tokenizer_classes": [ + "DebertaTokenizerFast", + "DebertaTokenizer" + ], + "processor_classes": [] + }, + "DeformableDetrModel": { + "tokenizer_classes": [], + "processor_classes": [ + "DeformableDetrFeatureExtractor" + ] + }, + "DeiTModel": { + "tokenizer_classes": [], + "processor_classes": [ + "DeiTImageProcessor" + ] + }, + "DetrModel": { + "tokenizer_classes": [], + "processor_classes": [ + "DetrFeatureExtractor" + ] + }, + "DistilBertModel": { + "tokenizer_classes": [ + "DistilBertTokenizerFast", + "DistilBertTokenizer" + ], + "processor_classes": [] + }, + "DonutSwinModel": { + "tokenizer_classes": [], + "processor_classes": [ + "DonutFeatureExtractor" + ] + }, + "DPTModel": { + "tokenizer_classes": [], + "processor_classes": [ + "DPTImageProcessor" + ] + }, + "ElectraModel": { + "tokenizer_classes": [ + "ElectraTokenizerFast", + "ElectraTokenizer" + ], + "processor_classes": [] + }, + "ErnieModel": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "EsmModel": { + "tokenizer_classes": [ + "EsmTokenizer" + ], + "processor_classes": [] + }, + "FlaubertModel": { + "tokenizer_classes": [ + "FlaubertTokenizer" + ], + "processor_classes": [] + }, + "FlaubertWithLMHeadModel": { + "tokenizer_classes": [ + "FlaubertTokenizer" + ], + "processor_classes": [] + }, + "FlavaModel": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [ + "FlavaImageProcessor" + ] + }, + "FNetModel": { + "tokenizer_classes": [ + "FNetTokenizerFast" + ], + "processor_classes": [] + }, + "FSMTModel": { + "tokenizer_classes": [ + "FSMTTokenizer" + ], + "processor_classes": [] + }, + "FunnelBaseModel": { + "tokenizer_classes": [ + "FunnelTokenizerFast", + "FunnelTokenizer" + ], + "processor_classes": [] + }, + "FunnelModel": { + "tokenizer_classes": [ + "FunnelTokenizerFast", + "FunnelTokenizer" + ], + "processor_classes": [] + }, + "GLPNModel": { + "tokenizer_classes": [], + "processor_classes": [ + "GLPNImageProcessor" + ] + }, + "GPT2LMHeadModel": { + "tokenizer_classes": [ + "GPT2TokenizerFast", + "GPT2Tokenizer" + ], + "processor_classes": [] + }, + "GPT2Model": { + "tokenizer_classes": [ + "GPT2TokenizerFast", + "GPT2Tokenizer" + ], + "processor_classes": [] + }, + "GPTNeoModel": { + "tokenizer_classes": [ + "GPT2TokenizerFast", + "GPT2Tokenizer" + ], + "processor_classes": [] + }, + "GPTNeoXModel": { + "tokenizer_classes": [ + "GPTNeoXTokenizerFast" + ], + "processor_classes": [] + }, + "GPTNeoXJapaneseModel": { + "tokenizer_classes": [ + "GPTNeoXJapaneseTokenizer" + ], + "processor_classes": [] + }, + "GPTJModel": { + "tokenizer_classes": [ + "GPT2TokenizerFast", + "GPT2Tokenizer" + ], + "processor_classes": [] + }, + "GroupViTModel": { + "tokenizer_classes": [ + "CLIPTokenizerFast", + "CLIPTokenizer" + ], + "processor_classes": [ + "CLIPImageProcessor" + ] + }, + "HubertModel": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "IBertModel": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "ImageGPTModel": { + "tokenizer_classes": [], + "processor_classes": [ + "ImageGPTImageProcessor" + ] + }, + "LayoutLMModel": { + "tokenizer_classes": [ + "LayoutLMTokenizerFast", + "LayoutLMTokenizer" + ], + "processor_classes": [] + }, + "LayoutLMv2Model": { + "tokenizer_classes": [ + "LayoutLMv2TokenizerFast", + "LayoutLMv2Tokenizer" + ], + "processor_classes": [ + "LayoutLMv2ImageProcessor" + ] + }, + "LayoutLMv3Model": { + "tokenizer_classes": [ + "LayoutLMv3TokenizerFast", + "LayoutLMv3Tokenizer" + ], + "processor_classes": [ + "LayoutLMv3ImageProcessor" + ] + }, + "LEDModel": { + "tokenizer_classes": [ + "LEDTokenizerFast", + "LEDTokenizer" + ], + "processor_classes": [] + }, + "LevitModel": { + "tokenizer_classes": [], + "processor_classes": [ + "LevitImageProcessor" + ] + }, + "LiltModel": { + "tokenizer_classes": [ + "LayoutLMv3TokenizerFast", + "LayoutLMv3Tokenizer" + ], + "processor_classes": [] + }, + "LongformerModel": { + "tokenizer_classes": [ + "LongformerTokenizerFast", + "LongformerTokenizer" + ], + "processor_classes": [] + }, + "LongT5Model": { + "tokenizer_classes": [ + "T5TokenizerFast" + ], + "processor_classes": [] + }, + "LukeModel": { + "tokenizer_classes": [ + "LukeTokenizer" + ], + "processor_classes": [] + }, + "LxmertModel": { + "tokenizer_classes": [ + "LxmertTokenizerFast", + "LxmertTokenizer" + ], + "processor_classes": [] + }, + "M2M100Model": { + "tokenizer_classes": [ + "M2M100Tokenizer" + ], + "processor_classes": [] + }, + "MarianMTModel": { + "tokenizer_classes": [ + "MarianTokenizer" + ], + "processor_classes": [] + }, + "MarianModel": { + "tokenizer_classes": [ + "MarianTokenizer" + ], + "processor_classes": [] + }, + "MarkupLMModel": { + "tokenizer_classes": [ + "MarkupLMTokenizerFast", + "MarkupLMTokenizer" + ], + "processor_classes": [ + "MarkupLMFeatureExtractor" + ] + }, + "MaskFormerModel": { + "tokenizer_classes": [], + "processor_classes": [ + "MaskFormerFeatureExtractor" + ] + }, + "MBartModel": { + "tokenizer_classes": [ + "MBartTokenizerFast", + "MBartTokenizer" + ], + "processor_classes": [] + }, + "MCTCTModel": { + "tokenizer_classes": [], + "processor_classes": [ + "MCTCTFeatureExtractor" + ] + }, + "MegatronBertModel": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "MobileBertModel": { + "tokenizer_classes": [ + "MobileBertTokenizerFast", + "MobileBertTokenizer" + ], + "processor_classes": [] + }, + "MobileNetV2Model": { + "tokenizer_classes": [], + "processor_classes": [ + "MobileNetV2ImageProcessor" + ] + }, + "MobileViTModel": { + "tokenizer_classes": [], + "processor_classes": [ + "MobileViTImageProcessor" + ] + }, + "MPNetModel": { + "tokenizer_classes": [ + "MPNetTokenizerFast", + "MPNetTokenizer" + ], + "processor_classes": [] + }, + "MvpModel": { + "tokenizer_classes": [ + "MvpTokenizerFast", + "MvpTokenizer" + ], + "processor_classes": [] + }, + "NezhaModel": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "NystromformerModel": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "OpenAIGPTLMHeadModel": { + "tokenizer_classes": [ + "OpenAIGPTTokenizerFast", + "OpenAIGPTTokenizer" + ], + "processor_classes": [] + }, + "OpenAIGPTModel": { + "tokenizer_classes": [ + "OpenAIGPTTokenizerFast", + "OpenAIGPTTokenizer" + ], + "processor_classes": [] + }, + "OPTModel": { + "tokenizer_classes": [ + "GPT2TokenizerFast", + "GPT2Tokenizer" + ], + "processor_classes": [] + }, + "OwlViTModel": { + "tokenizer_classes": [ + "CLIPTokenizerFast", + "CLIPTokenizer" + ], + "processor_classes": [ + "OwlViTFeatureExtractor" + ] + }, + "PegasusModel": { + "tokenizer_classes": [ + "PegasusTokenizerFast" + ], + "processor_classes": [] + }, + "PegasusXModel": { + "tokenizer_classes": [ + "PegasusTokenizerFast" + ], + "processor_classes": [] + }, + "PerceiverModel": { + "tokenizer_classes": [ + "PerceiverTokenizer" + ], + "processor_classes": [] + }, + "PLBartModel": { + "tokenizer_classes": [ + "PLBartTokenizer" + ], + "processor_classes": [] + }, + "PoolFormerModel": { + "tokenizer_classes": [], + "processor_classes": [ + "PoolFormerImageProcessor" + ] + }, + "ProphetNetModel": { + "tokenizer_classes": [ + "ProphetNetTokenizer" + ], + "processor_classes": [] + }, + "ReformerModel": { + "tokenizer_classes": [ + "ReformerTokenizerFast", + "ReformerTokenizer" + ], + "processor_classes": [] + }, + "RegNetModel": { + "tokenizer_classes": [], + "processor_classes": [ + "ConvNextImageProcessor" + ] + }, + "RemBertModel": { + "tokenizer_classes": [ + "RemBertTokenizerFast" + ], + "processor_classes": [] + }, + "ResNetModel": { + "tokenizer_classes": [], + "processor_classes": [ + "ConvNextImageProcessor" + ] + }, + "RobertaModel": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "RoCBertModel": { + "tokenizer_classes": [ + "RoCBertTokenizer" + ], + "processor_classes": [] + }, + "RoFormerModel": { + "tokenizer_classes": [ + "RoFormerTokenizerFast", + "RoFormerTokenizer" + ], + "processor_classes": [] + }, + "SegformerModel": { + "tokenizer_classes": [], + "processor_classes": [ + "SegformerImageProcessor" + ] + }, + "SEWDModel": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "SEWModel": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "Speech2TextModel": { + "tokenizer_classes": [ + "Speech2TextTokenizer" + ], + "processor_classes": [ + "Speech2TextFeatureExtractor" + ] + }, + "SplinterModel": { + "tokenizer_classes": [], + "processor_classes": [] + }, + "SqueezeBertModel": { + "tokenizer_classes": [ + "SqueezeBertTokenizerFast", + "SqueezeBertTokenizer" + ], + "processor_classes": [] + }, + "SwinModel": { + "tokenizer_classes": [], + "processor_classes": [ + "ViTImageProcessor" + ] + }, + "Swinv2Model": { + "tokenizer_classes": [], + "processor_classes": [ + "ViTImageProcessor" + ] + }, + "SwitchTransformersModel": { + "tokenizer_classes": [ + "T5TokenizerFast" + ], + "processor_classes": [] + }, + "T5Model": { + "tokenizer_classes": [ + "T5TokenizerFast" + ], + "processor_classes": [] + }, + "TableTransformerModel": { + "tokenizer_classes": [], + "processor_classes": [ + "DetrFeatureExtractor" + ] + }, + "TapasModel": { + "tokenizer_classes": [ + "TapasTokenizer" + ], + "processor_classes": [] + }, + "TransfoXLLMHeadModel": { + "tokenizer_classes": [ + "TransfoXLTokenizer" + ], + "processor_classes": [] + }, + "TransfoXLModel": { + "tokenizer_classes": [ + "TransfoXLTokenizer" + ], + "processor_classes": [] + }, + "UniSpeechSatModel": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "UniSpeechModel": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "VanModel": { + "tokenizer_classes": [], + "processor_classes": [ + "ConvNextImageProcessor" + ] + }, + "VideoMAEModel": { + "tokenizer_classes": [], + "processor_classes": [ + "VideoMAEImageProcessor" + ] + }, + "ViltModel": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [ + "ViltImageProcessor" + ] + }, + "VisualBertModel": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "ViTModel": { + "tokenizer_classes": [], + "processor_classes": [ + "ViTImageProcessor" + ] + }, + "ViTMAEModel": { + "tokenizer_classes": [], + "processor_classes": [ + "ViTImageProcessor" + ] + }, + "ViTMSNModel": { + "tokenizer_classes": [], + "processor_classes": [ + "ViTImageProcessor" + ] + }, + "Wav2Vec2ConformerModel": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "Wav2Vec2Model": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "WavLMModel": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "WhisperModel": { + "tokenizer_classes": [ + "WhisperTokenizer" + ], + "processor_classes": [ + "WhisperFeatureExtractor" + ] + }, + "XCLIPModel": { + "tokenizer_classes": [ + "CLIPTokenizerFast", + "CLIPTokenizer" + ], + "processor_classes": [ + "VideoMAEImageProcessor", + "CLIPImageProcessor" + ] + }, + "XGLMModel": { + "tokenizer_classes": [ + "XGLMTokenizerFast" + ], + "processor_classes": [] + }, + "XLMRobertaXLModel": { + "tokenizer_classes": [ + "XLMRobertaTokenizerFast" + ], + "processor_classes": [] + }, + "XLMModel": { + "tokenizer_classes": [ + "XLMTokenizer" + ], + "processor_classes": [] + }, + "XLMWithLMHeadModel": { + "tokenizer_classes": [ + "XLMTokenizer" + ], + "processor_classes": [] + }, + "XLNetLMHeadModel": { + "tokenizer_classes": [ + "XLNetTokenizerFast", + "XLNetTokenizer" + ], + "processor_classes": [] + }, + "XLNetModel": { + "tokenizer_classes": [ + "XLNetTokenizerFast", + "XLNetTokenizer" + ], + "processor_classes": [] + }, + "YolosModel": { + "tokenizer_classes": [], + "processor_classes": [ + "YolosFeatureExtractor" + ] + }, + "YosoModel": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "AlbertForMaskedLM": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "AlbertForMultipleChoice": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "AlbertForPreTraining": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "AlbertForQuestionAnswering": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "AlbertForSequenceClassification": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "AlbertForTokenClassification": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "BartForCausalLM": { + "tokenizer_classes": [ + "BartTokenizerFast", + "BartTokenizer" + ], + "processor_classes": [] + }, + "BartForConditionalGeneration": { + "tokenizer_classes": [ + "BartTokenizerFast", + "BartTokenizer" + ], + "processor_classes": [] + }, + "BartForQuestionAnswering": { + "tokenizer_classes": [ + "BartTokenizerFast", + "BartTokenizer" + ], + "processor_classes": [] + }, + "BartForSequenceClassification": { + "tokenizer_classes": [ + "BartTokenizerFast", + "BartTokenizer" + ], + "processor_classes": [] + }, + "BeitForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "BeitImageProcessor" + ] + }, + "BeitForSemanticSegmentation": { + "tokenizer_classes": [], + "processor_classes": [ + "BeitImageProcessor" + ] + }, + "BertForMaskedLM": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "BertForMultipleChoice": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "BertForNextSentencePrediction": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "BertForPreTraining": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "BertForQuestionAnswering": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "BertForSequenceClassification": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "BertForTokenClassification": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "BigBirdForCausalLM": { + "tokenizer_classes": [ + "BigBirdTokenizerFast" + ], + "processor_classes": [] + }, + "BigBirdForMaskedLM": { + "tokenizer_classes": [ + "BigBirdTokenizerFast" + ], + "processor_classes": [] + }, + "BigBirdForMultipleChoice": { + "tokenizer_classes": [ + "BigBirdTokenizerFast" + ], + "processor_classes": [] + }, + "BigBirdForPreTraining": { + "tokenizer_classes": [ + "BigBirdTokenizerFast" + ], + "processor_classes": [] + }, + "BigBirdForQuestionAnswering": { + "tokenizer_classes": [ + "BigBirdTokenizerFast" + ], + "processor_classes": [] + }, + "BigBirdForSequenceClassification": { + "tokenizer_classes": [ + "BigBirdTokenizerFast" + ], + "processor_classes": [] + }, + "BigBirdForTokenClassification": { + "tokenizer_classes": [ + "BigBirdTokenizerFast" + ], + "processor_classes": [] + }, + "BigBirdPegasusForCausalLM": { + "tokenizer_classes": [ + "PegasusTokenizerFast" + ], + "processor_classes": [] + }, + "BigBirdPegasusForConditionalGeneration": { + "tokenizer_classes": [ + "PegasusTokenizerFast" + ], + "processor_classes": [] + }, + "BigBirdPegasusForQuestionAnswering": { + "tokenizer_classes": [ + "PegasusTokenizerFast" + ], + "processor_classes": [] + }, + "BigBirdPegasusForSequenceClassification": { + "tokenizer_classes": [ + "PegasusTokenizerFast" + ], + "processor_classes": [] + }, + "BlenderbotForCausalLM": { + "tokenizer_classes": [ + "BlenderbotTokenizerFast", + "BlenderbotTokenizer" + ], + "processor_classes": [] + }, + "BlenderbotForConditionalGeneration": { + "tokenizer_classes": [ + "BlenderbotTokenizerFast", + "BlenderbotTokenizer" + ], + "processor_classes": [] + }, + "BlenderbotSmallForCausalLM": { + "tokenizer_classes": [], + "processor_classes": [] + }, + "BlenderbotSmallForConditionalGeneration": { + "tokenizer_classes": [], + "processor_classes": [] + }, + "BloomForCausalLM": { + "tokenizer_classes": [ + "BloomTokenizerFast" + ], + "processor_classes": [] + }, + "BloomForQuestionAnswering": { + "tokenizer_classes": [ + "BloomTokenizerFast" + ], + "processor_classes": [] + }, + "BloomForSequenceClassification": { + "tokenizer_classes": [ + "BloomTokenizerFast" + ], + "processor_classes": [] + }, + "BloomForTokenClassification": { + "tokenizer_classes": [ + "BloomTokenizerFast" + ], + "processor_classes": [] + }, + "CTRLForSequenceClassification": { + "tokenizer_classes": [ + "CTRLTokenizer" + ], + "processor_classes": [] + }, + "CanineForMultipleChoice": { + "tokenizer_classes": [ + "CanineTokenizer" + ], + "processor_classes": [] + }, + "CanineForQuestionAnswering": { + "tokenizer_classes": [ + "CanineTokenizer" + ], + "processor_classes": [] + }, + "CanineForSequenceClassification": { + "tokenizer_classes": [ + "CanineTokenizer" + ], + "processor_classes": [] + }, + "CanineForTokenClassification": { + "tokenizer_classes": [ + "CanineTokenizer" + ], + "processor_classes": [] + }, + "CodeGenForCausalLM": { + "tokenizer_classes": [ + "CodeGenTokenizerFast", + "CodeGenTokenizer" + ], + "processor_classes": [] + }, + "ConditionalDetrForObjectDetection": { + "tokenizer_classes": [], + "processor_classes": [ + "ConditionalDetrFeatureExtractor" + ] + }, + "ConvBertForMaskedLM": { + "tokenizer_classes": [ + "ConvBertTokenizerFast", + "ConvBertTokenizer" + ], + "processor_classes": [] + }, + "ConvBertForMultipleChoice": { + "tokenizer_classes": [ + "ConvBertTokenizerFast", + "ConvBertTokenizer" + ], + "processor_classes": [] + }, + "ConvBertForQuestionAnswering": { + "tokenizer_classes": [ + "ConvBertTokenizerFast", + "ConvBertTokenizer" + ], + "processor_classes": [] + }, + "ConvBertForSequenceClassification": { + "tokenizer_classes": [ + "ConvBertTokenizerFast", + "ConvBertTokenizer" + ], + "processor_classes": [] + }, + "ConvBertForTokenClassification": { + "tokenizer_classes": [ + "ConvBertTokenizerFast", + "ConvBertTokenizer" + ], + "processor_classes": [] + }, + "ConvNextForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "ConvNextImageProcessor" + ] + }, + "CvtForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "ConvNextImageProcessor" + ] + }, + "DPTForDepthEstimation": { + "tokenizer_classes": [], + "processor_classes": [ + "DPTImageProcessor" + ] + }, + "DPTForSemanticSegmentation": { + "tokenizer_classes": [], + "processor_classes": [ + "DPTImageProcessor" + ] + }, + "Data2VecAudioForCTC": { + "tokenizer_classes": [], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "Data2VecAudioForSequenceClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "Data2VecAudioForXVector": { + "tokenizer_classes": [], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "Data2VecTextForCausalLM": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "Data2VecTextForMaskedLM": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "Data2VecTextForMultipleChoice": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "Data2VecTextForQuestionAnswering": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "Data2VecTextForSequenceClassification": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "Data2VecTextForTokenClassification": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "Data2VecVisionForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "BeitImageProcessor" + ] + }, + "Data2VecVisionForSemanticSegmentation": { + "tokenizer_classes": [], + "processor_classes": [ + "BeitImageProcessor" + ] + }, + "DebertaForMaskedLM": { + "tokenizer_classes": [ + "DebertaTokenizerFast", + "DebertaTokenizer" + ], + "processor_classes": [] + }, + "DebertaForQuestionAnswering": { + "tokenizer_classes": [ + "DebertaTokenizerFast", + "DebertaTokenizer" + ], + "processor_classes": [] + }, + "DebertaForSequenceClassification": { + "tokenizer_classes": [ + "DebertaTokenizerFast", + "DebertaTokenizer" + ], + "processor_classes": [] + }, + "DebertaForTokenClassification": { + "tokenizer_classes": [ + "DebertaTokenizerFast", + "DebertaTokenizer" + ], + "processor_classes": [] + }, + "DebertaV2ForMaskedLM": { + "tokenizer_classes": [ + "DebertaV2TokenizerFast" + ], + "processor_classes": [] + }, + "DebertaV2ForMultipleChoice": { + "tokenizer_classes": [ + "DebertaV2TokenizerFast" + ], + "processor_classes": [] + }, + "DebertaV2ForQuestionAnswering": { + "tokenizer_classes": [ + "DebertaV2TokenizerFast" + ], + "processor_classes": [] + }, + "DebertaV2ForSequenceClassification": { + "tokenizer_classes": [ + "DebertaV2TokenizerFast" + ], + "processor_classes": [] + }, + "DebertaV2ForTokenClassification": { + "tokenizer_classes": [ + "DebertaV2TokenizerFast" + ], + "processor_classes": [] + }, + "DeformableDetrForObjectDetection": { + "tokenizer_classes": [], + "processor_classes": [ + "DeformableDetrFeatureExtractor" + ] + }, + "DeiTForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "DeiTImageProcessor" + ] + }, + "DeiTForImageClassificationWithTeacher": { + "tokenizer_classes": [], + "processor_classes": [ + "DeiTImageProcessor" + ] + }, + "DeiTForMaskedImageModeling": { + "tokenizer_classes": [], + "processor_classes": [ + "DeiTImageProcessor" + ] + }, + "DetrForObjectDetection": { + "tokenizer_classes": [], + "processor_classes": [ + "DetrFeatureExtractor" + ] + }, + "DetrForSegmentation": { + "tokenizer_classes": [], + "processor_classes": [ + "DetrFeatureExtractor" + ] + }, + "DistilBertForMaskedLM": { + "tokenizer_classes": [ + "DistilBertTokenizerFast", + "DistilBertTokenizer" + ], + "processor_classes": [] + }, + "DistilBertForMultipleChoice": { + "tokenizer_classes": [ + "DistilBertTokenizerFast", + "DistilBertTokenizer" + ], + "processor_classes": [] + }, + "DistilBertForQuestionAnswering": { + "tokenizer_classes": [ + "DistilBertTokenizerFast", + "DistilBertTokenizer" + ], + "processor_classes": [] + }, + "DistilBertForSequenceClassification": { + "tokenizer_classes": [ + "DistilBertTokenizerFast", + "DistilBertTokenizer" + ], + "processor_classes": [] + }, + "DistilBertForTokenClassification": { + "tokenizer_classes": [ + "DistilBertTokenizerFast", + "DistilBertTokenizer" + ], + "processor_classes": [] + }, + "ElectraForCausalLM": { + "tokenizer_classes": [ + "ElectraTokenizerFast", + "ElectraTokenizer" + ], + "processor_classes": [] + }, + "ElectraForMaskedLM": { + "tokenizer_classes": [ + "ElectraTokenizerFast", + "ElectraTokenizer" + ], + "processor_classes": [] + }, + "ElectraForMultipleChoice": { + "tokenizer_classes": [ + "ElectraTokenizerFast", + "ElectraTokenizer" + ], + "processor_classes": [] + }, + "ElectraForPreTraining": { + "tokenizer_classes": [ + "ElectraTokenizerFast", + "ElectraTokenizer" + ], + "processor_classes": [] + }, + "ElectraForQuestionAnswering": { + "tokenizer_classes": [ + "ElectraTokenizerFast", + "ElectraTokenizer" + ], + "processor_classes": [] + }, + "ElectraForSequenceClassification": { + "tokenizer_classes": [ + "ElectraTokenizerFast", + "ElectraTokenizer" + ], + "processor_classes": [] + }, + "ElectraForTokenClassification": { + "tokenizer_classes": [ + "ElectraTokenizerFast", + "ElectraTokenizer" + ], + "processor_classes": [] + }, + "ErnieForCausalLM": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "ErnieForMaskedLM": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "ErnieForMultipleChoice": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "ErnieForNextSentencePrediction": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "ErnieForPreTraining": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "ErnieForQuestionAnswering": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "ErnieForSequenceClassification": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "ErnieForTokenClassification": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "EsmForMaskedLM": { + "tokenizer_classes": [ + "EsmTokenizer" + ], + "processor_classes": [] + }, + "EsmForSequenceClassification": { + "tokenizer_classes": [ + "EsmTokenizer" + ], + "processor_classes": [] + }, + "EsmForTokenClassification": { + "tokenizer_classes": [ + "EsmTokenizer" + ], + "processor_classes": [] + }, + "FNetForMaskedLM": { + "tokenizer_classes": [ + "FNetTokenizerFast" + ], + "processor_classes": [] + }, + "FNetForMultipleChoice": { + "tokenizer_classes": [ + "FNetTokenizerFast" + ], + "processor_classes": [] + }, + "FNetForNextSentencePrediction": { + "tokenizer_classes": [ + "FNetTokenizerFast" + ], + "processor_classes": [] + }, + "FNetForPreTraining": { + "tokenizer_classes": [ + "FNetTokenizerFast" + ], + "processor_classes": [] + }, + "FNetForQuestionAnswering": { + "tokenizer_classes": [ + "FNetTokenizerFast" + ], + "processor_classes": [] + }, + "FNetForSequenceClassification": { + "tokenizer_classes": [ + "FNetTokenizerFast" + ], + "processor_classes": [] + }, + "FNetForTokenClassification": { + "tokenizer_classes": [ + "FNetTokenizerFast" + ], + "processor_classes": [] + }, + "FSMTForConditionalGeneration": { + "tokenizer_classes": [ + "FSMTTokenizer" + ], + "processor_classes": [] + }, + "FlaubertForMultipleChoice": { + "tokenizer_classes": [ + "FlaubertTokenizer" + ], + "processor_classes": [] + }, + "FlaubertForQuestionAnsweringSimple": { + "tokenizer_classes": [ + "FlaubertTokenizer" + ], + "processor_classes": [] + }, + "FlaubertForSequenceClassification": { + "tokenizer_classes": [ + "FlaubertTokenizer" + ], + "processor_classes": [] + }, + "FlaubertForTokenClassification": { + "tokenizer_classes": [ + "FlaubertTokenizer" + ], + "processor_classes": [] + }, + "FlavaForPreTraining": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [ + "FlavaImageProcessor" + ] + }, + "FunnelForMaskedLM": { + "tokenizer_classes": [ + "FunnelTokenizerFast", + "FunnelTokenizer" + ], + "processor_classes": [] + }, + "FunnelForMultipleChoice": { + "tokenizer_classes": [ + "FunnelTokenizerFast", + "FunnelTokenizer" + ], + "processor_classes": [] + }, + "FunnelForPreTraining": { + "tokenizer_classes": [ + "FunnelTokenizerFast", + "FunnelTokenizer" + ], + "processor_classes": [] + }, + "FunnelForQuestionAnswering": { + "tokenizer_classes": [ + "FunnelTokenizerFast", + "FunnelTokenizer" + ], + "processor_classes": [] + }, + "FunnelForSequenceClassification": { + "tokenizer_classes": [ + "FunnelTokenizerFast", + "FunnelTokenizer" + ], + "processor_classes": [] + }, + "FunnelForTokenClassification": { + "tokenizer_classes": [ + "FunnelTokenizerFast", + "FunnelTokenizer" + ], + "processor_classes": [] + }, + "GLPNForDepthEstimation": { + "tokenizer_classes": [], + "processor_classes": [ + "GLPNImageProcessor" + ] + }, + "GPT2ForSequenceClassification": { + "tokenizer_classes": [ + "GPT2TokenizerFast", + "GPT2Tokenizer" + ], + "processor_classes": [] + }, + "GPT2ForTokenClassification": { + "tokenizer_classes": [ + "GPT2TokenizerFast", + "GPT2Tokenizer" + ], + "processor_classes": [] + }, + "GPTJForCausalLM": { + "tokenizer_classes": [ + "GPT2TokenizerFast", + "GPT2Tokenizer" + ], + "processor_classes": [] + }, + "GPTJForQuestionAnswering": { + "tokenizer_classes": [ + "GPT2TokenizerFast", + "GPT2Tokenizer" + ], + "processor_classes": [] + }, + "GPTJForSequenceClassification": { + "tokenizer_classes": [ + "GPT2TokenizerFast", + "GPT2Tokenizer" + ], + "processor_classes": [] + }, + "GPTNeoForCausalLM": { + "tokenizer_classes": [ + "GPT2TokenizerFast", + "GPT2Tokenizer" + ], + "processor_classes": [] + }, + "GPTNeoForSequenceClassification": { + "tokenizer_classes": [ + "GPT2TokenizerFast", + "GPT2Tokenizer" + ], + "processor_classes": [] + }, + "GPTNeoXForCausalLM": { + "tokenizer_classes": [ + "GPTNeoXTokenizerFast" + ], + "processor_classes": [] + }, + "GPTNeoXJapaneseForCausalLM": { + "tokenizer_classes": [ + "GPTNeoXJapaneseTokenizer" + ], + "processor_classes": [] + }, + "HubertForCTC": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "HubertForSequenceClassification": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "IBertForMaskedLM": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "IBertForMultipleChoice": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "IBertForQuestionAnswering": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "IBertForSequenceClassification": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "IBertForTokenClassification": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "ImageGPTForCausalImageModeling": { + "tokenizer_classes": [], + "processor_classes": [ + "ImageGPTImageProcessor" + ] + }, + "ImageGPTForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "ImageGPTImageProcessor" + ] + }, + "LEDForConditionalGeneration": { + "tokenizer_classes": [ + "LEDTokenizerFast", + "LEDTokenizer" + ], + "processor_classes": [] + }, + "LEDForQuestionAnswering": { + "tokenizer_classes": [ + "LEDTokenizerFast", + "LEDTokenizer" + ], + "processor_classes": [] + }, + "LEDForSequenceClassification": { + "tokenizer_classes": [ + "LEDTokenizerFast", + "LEDTokenizer" + ], + "processor_classes": [] + }, + "LayoutLMForMaskedLM": { + "tokenizer_classes": [ + "LayoutLMTokenizerFast", + "LayoutLMTokenizer" + ], + "processor_classes": [] + }, + "LayoutLMForQuestionAnswering": { + "tokenizer_classes": [ + "LayoutLMTokenizerFast", + "LayoutLMTokenizer" + ], + "processor_classes": [] + }, + "LayoutLMForSequenceClassification": { + "tokenizer_classes": [ + "LayoutLMTokenizerFast", + "LayoutLMTokenizer" + ], + "processor_classes": [] + }, + "LayoutLMForTokenClassification": { + "tokenizer_classes": [ + "LayoutLMTokenizerFast", + "LayoutLMTokenizer" + ], + "processor_classes": [] + }, + "LayoutLMv2ForQuestionAnswering": { + "tokenizer_classes": [ + "LayoutLMv2TokenizerFast", + "LayoutLMv2Tokenizer" + ], + "processor_classes": [ + "LayoutLMv2ImageProcessor" + ] + }, + "LayoutLMv2ForSequenceClassification": { + "tokenizer_classes": [ + "LayoutLMv2TokenizerFast", + "LayoutLMv2Tokenizer" + ], + "processor_classes": [ + "LayoutLMv2ImageProcessor" + ] + }, + "LayoutLMv2ForTokenClassification": { + "tokenizer_classes": [ + "LayoutLMv2TokenizerFast", + "LayoutLMv2Tokenizer" + ], + "processor_classes": [ + "LayoutLMv2ImageProcessor" + ] + }, + "LayoutLMv3ForQuestionAnswering": { + "tokenizer_classes": [ + "LayoutLMv3TokenizerFast", + "LayoutLMv3Tokenizer" + ], + "processor_classes": [ + "LayoutLMv3ImageProcessor" + ] + }, + "LayoutLMv3ForSequenceClassification": { + "tokenizer_classes": [ + "LayoutLMv3TokenizerFast", + "LayoutLMv3Tokenizer" + ], + "processor_classes": [ + "LayoutLMv3ImageProcessor" + ] + }, + "LayoutLMv3ForTokenClassification": { + "tokenizer_classes": [ + "LayoutLMv3TokenizerFast", + "LayoutLMv3Tokenizer" + ], + "processor_classes": [ + "LayoutLMv3ImageProcessor" + ] + }, + "LevitForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "LevitImageProcessor" + ] + }, + "LevitForImageClassificationWithTeacher": { + "tokenizer_classes": [], + "processor_classes": [ + "LevitImageProcessor" + ] + }, + "LiltForQuestionAnswering": { + "tokenizer_classes": [ + "LayoutLMv3TokenizerFast", + "LayoutLMv3Tokenizer" + ], + "processor_classes": [] + }, + "LiltForSequenceClassification": { + "tokenizer_classes": [ + "LayoutLMv3TokenizerFast", + "LayoutLMv3Tokenizer" + ], + "processor_classes": [] + }, + "LiltForTokenClassification": { + "tokenizer_classes": [ + "LayoutLMv3TokenizerFast", + "LayoutLMv3Tokenizer" + ], + "processor_classes": [] + }, + "LongT5ForConditionalGeneration": { + "tokenizer_classes": [ + "T5TokenizerFast" + ], + "processor_classes": [] + }, + "LongformerForMaskedLM": { + "tokenizer_classes": [ + "LongformerTokenizerFast", + "LongformerTokenizer" + ], + "processor_classes": [] + }, + "LongformerForMultipleChoice": { + "tokenizer_classes": [ + "LongformerTokenizerFast", + "LongformerTokenizer" + ], + "processor_classes": [] + }, + "LongformerForQuestionAnswering": { + "tokenizer_classes": [ + "LongformerTokenizerFast", + "LongformerTokenizer" + ], + "processor_classes": [] + }, + "LongformerForSequenceClassification": { + "tokenizer_classes": [ + "LongformerTokenizerFast", + "LongformerTokenizer" + ], + "processor_classes": [] + }, + "LongformerForTokenClassification": { + "tokenizer_classes": [ + "LongformerTokenizerFast", + "LongformerTokenizer" + ], + "processor_classes": [] + }, + "LukeForMaskedLM": { + "tokenizer_classes": [ + "LukeTokenizer" + ], + "processor_classes": [] + }, + "LukeForMultipleChoice": { + "tokenizer_classes": [ + "LukeTokenizer" + ], + "processor_classes": [] + }, + "LukeForQuestionAnswering": { + "tokenizer_classes": [ + "LukeTokenizer" + ], + "processor_classes": [] + }, + "LukeForSequenceClassification": { + "tokenizer_classes": [ + "LukeTokenizer" + ], + "processor_classes": [] + }, + "LukeForTokenClassification": { + "tokenizer_classes": [ + "LukeTokenizer" + ], + "processor_classes": [] + }, + "LxmertForPreTraining": { + "tokenizer_classes": [ + "LxmertTokenizerFast", + "LxmertTokenizer" + ], + "processor_classes": [] + }, + "LxmertForQuestionAnswering": { + "tokenizer_classes": [ + "LxmertTokenizerFast", + "LxmertTokenizer" + ], + "processor_classes": [] + }, + "M2M100ForConditionalGeneration": { + "tokenizer_classes": [ + "M2M100Tokenizer" + ], + "processor_classes": [] + }, + "MBartForCausalLM": { + "tokenizer_classes": [ + "MBartTokenizerFast", + "MBartTokenizer" + ], + "processor_classes": [] + }, + "MBartForConditionalGeneration": { + "tokenizer_classes": [ + "MBartTokenizerFast", + "MBartTokenizer" + ], + "processor_classes": [] + }, + "MBartForQuestionAnswering": { + "tokenizer_classes": [ + "MBartTokenizerFast", + "MBartTokenizer" + ], + "processor_classes": [] + }, + "MBartForSequenceClassification": { + "tokenizer_classes": [ + "MBartTokenizerFast", + "MBartTokenizer" + ], + "processor_classes": [] + }, + "MCTCTForCTC": { + "tokenizer_classes": [], + "processor_classes": [ + "MCTCTFeatureExtractor" + ] + }, + "MPNetForMaskedLM": { + "tokenizer_classes": [ + "MPNetTokenizerFast", + "MPNetTokenizer" + ], + "processor_classes": [] + }, + "MPNetForMultipleChoice": { + "tokenizer_classes": [ + "MPNetTokenizerFast", + "MPNetTokenizer" + ], + "processor_classes": [] + }, + "MPNetForQuestionAnswering": { + "tokenizer_classes": [ + "MPNetTokenizerFast", + "MPNetTokenizer" + ], + "processor_classes": [] + }, + "MPNetForSequenceClassification": { + "tokenizer_classes": [ + "MPNetTokenizerFast", + "MPNetTokenizer" + ], + "processor_classes": [] + }, + "MPNetForTokenClassification": { + "tokenizer_classes": [ + "MPNetTokenizerFast", + "MPNetTokenizer" + ], + "processor_classes": [] + }, + "MarianForCausalLM": { + "tokenizer_classes": [ + "MarianTokenizer" + ], + "processor_classes": [] + }, + "MarkupLMForQuestionAnswering": { + "tokenizer_classes": [ + "MarkupLMTokenizerFast", + "MarkupLMTokenizer" + ], + "processor_classes": [ + "MarkupLMFeatureExtractor" + ] + }, + "MarkupLMForSequenceClassification": { + "tokenizer_classes": [ + "MarkupLMTokenizerFast", + "MarkupLMTokenizer" + ], + "processor_classes": [ + "MarkupLMFeatureExtractor" + ] + }, + "MarkupLMForTokenClassification": { + "tokenizer_classes": [ + "MarkupLMTokenizerFast", + "MarkupLMTokenizer" + ], + "processor_classes": [ + "MarkupLMFeatureExtractor" + ] + }, + "MaskFormerForInstanceSegmentation": { + "tokenizer_classes": [], + "processor_classes": [ + "MaskFormerFeatureExtractor" + ] + }, + "MegatronBertForCausalLM": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "MegatronBertForMaskedLM": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "MegatronBertForMultipleChoice": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "MegatronBertForNextSentencePrediction": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "MegatronBertForPreTraining": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "MegatronBertForQuestionAnswering": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "MegatronBertForSequenceClassification": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "MegatronBertForTokenClassification": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "MobileBertForMaskedLM": { + "tokenizer_classes": [ + "MobileBertTokenizerFast", + "MobileBertTokenizer" + ], + "processor_classes": [] + }, + "MobileBertForMultipleChoice": { + "tokenizer_classes": [ + "MobileBertTokenizerFast", + "MobileBertTokenizer" + ], + "processor_classes": [] + }, + "MobileBertForNextSentencePrediction": { + "tokenizer_classes": [ + "MobileBertTokenizerFast", + "MobileBertTokenizer" + ], + "processor_classes": [] + }, + "MobileBertForPreTraining": { + "tokenizer_classes": [ + "MobileBertTokenizerFast", + "MobileBertTokenizer" + ], + "processor_classes": [] + }, + "MobileBertForQuestionAnswering": { + "tokenizer_classes": [ + "MobileBertTokenizerFast", + "MobileBertTokenizer" + ], + "processor_classes": [] + }, + "MobileBertForSequenceClassification": { + "tokenizer_classes": [ + "MobileBertTokenizerFast", + "MobileBertTokenizer" + ], + "processor_classes": [] + }, + "MobileBertForTokenClassification": { + "tokenizer_classes": [ + "MobileBertTokenizerFast", + "MobileBertTokenizer" + ], + "processor_classes": [] + }, + "MobileNetV2ForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "MobileNetV2ImageProcessor" + ] + }, + "MobileNetV2ForSemanticSegmentation": { + "tokenizer_classes": [], + "processor_classes": [ + "MobileNetV2ImageProcessor" + ] + }, + "MobileViTForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "MobileViTImageProcessor" + ] + }, + "MobileViTForSemanticSegmentation": { + "tokenizer_classes": [], + "processor_classes": [ + "MobileViTImageProcessor" + ] + }, + "MvpForCausalLM": { + "tokenizer_classes": [ + "MvpTokenizerFast", + "MvpTokenizer" + ], + "processor_classes": [] + }, + "MvpForConditionalGeneration": { + "tokenizer_classes": [ + "MvpTokenizerFast", + "MvpTokenizer" + ], + "processor_classes": [] + }, + "MvpForQuestionAnswering": { + "tokenizer_classes": [ + "MvpTokenizerFast", + "MvpTokenizer" + ], + "processor_classes": [] + }, + "MvpForSequenceClassification": { + "tokenizer_classes": [ + "MvpTokenizerFast", + "MvpTokenizer" + ], + "processor_classes": [] + }, + "NezhaForMaskedLM": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "NezhaForMultipleChoice": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "NezhaForNextSentencePrediction": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "NezhaForPreTraining": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "NezhaForQuestionAnswering": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "NezhaForSequenceClassification": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "NezhaForTokenClassification": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "NystromformerForMaskedLM": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "NystromformerForMultipleChoice": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "NystromformerForQuestionAnswering": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "NystromformerForSequenceClassification": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "NystromformerForTokenClassification": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "OPTForCausalLM": { + "tokenizer_classes": [ + "GPT2TokenizerFast", + "GPT2Tokenizer" + ], + "processor_classes": [] + }, + "OPTForQuestionAnswering": { + "tokenizer_classes": [ + "GPT2TokenizerFast", + "GPT2Tokenizer" + ], + "processor_classes": [] + }, + "OPTForSequenceClassification": { + "tokenizer_classes": [ + "GPT2TokenizerFast", + "GPT2Tokenizer" + ], + "processor_classes": [] + }, + "OpenAIGPTForSequenceClassification": { + "tokenizer_classes": [ + "OpenAIGPTTokenizerFast", + "OpenAIGPTTokenizer" + ], + "processor_classes": [] + }, + "OwlViTForObjectDetection": { + "tokenizer_classes": [ + "CLIPTokenizerFast", + "CLIPTokenizer" + ], + "processor_classes": [ + "OwlViTFeatureExtractor" + ] + }, + "PLBartForCausalLM": { + "tokenizer_classes": [ + "PLBartTokenizer" + ], + "processor_classes": [] + }, + "PLBartForConditionalGeneration": { + "tokenizer_classes": [ + "PLBartTokenizer" + ], + "processor_classes": [] + }, + "PLBartForSequenceClassification": { + "tokenizer_classes": [ + "PLBartTokenizer" + ], + "processor_classes": [] + }, + "PegasusForCausalLM": { + "tokenizer_classes": [ + "PegasusTokenizerFast" + ], + "processor_classes": [] + }, + "PegasusForConditionalGeneration": { + "tokenizer_classes": [ + "PegasusTokenizerFast" + ], + "processor_classes": [] + }, + "PegasusXForConditionalGeneration": { + "tokenizer_classes": [ + "PegasusTokenizerFast" + ], + "processor_classes": [] + }, + "PerceiverForImageClassificationConvProcessing": { + "tokenizer_classes": [ + "PerceiverTokenizer" + ], + "processor_classes": [ + "PerceiverImageProcessor" + ] + }, + "PerceiverForImageClassificationFourier": { + "tokenizer_classes": [ + "PerceiverTokenizer" + ], + "processor_classes": [ + "PerceiverImageProcessor" + ] + }, + "PerceiverForImageClassificationLearned": { + "tokenizer_classes": [ + "PerceiverTokenizer" + ], + "processor_classes": [ + "PerceiverImageProcessor" + ] + }, + "PerceiverForMaskedLM": { + "tokenizer_classes": [ + "PerceiverTokenizer" + ], + "processor_classes": [ + "PerceiverImageProcessor" + ] + }, + "PerceiverForSequenceClassification": { + "tokenizer_classes": [ + "PerceiverTokenizer" + ], + "processor_classes": [ + "PerceiverImageProcessor" + ] + }, + "PoolFormerForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "PoolFormerImageProcessor" + ] + }, + "ProphetNetForCausalLM": { + "tokenizer_classes": [ + "ProphetNetTokenizer" + ], + "processor_classes": [] + }, + "ProphetNetForConditionalGeneration": { + "tokenizer_classes": [ + "ProphetNetTokenizer" + ], + "processor_classes": [] + }, + "ReformerForMaskedLM": { + "tokenizer_classes": [ + "ReformerTokenizerFast", + "ReformerTokenizer" + ], + "processor_classes": [] + }, + "ReformerForQuestionAnswering": { + "tokenizer_classes": [ + "ReformerTokenizerFast", + "ReformerTokenizer" + ], + "processor_classes": [] + }, + "ReformerForSequenceClassification": { + "tokenizer_classes": [ + "ReformerTokenizerFast", + "ReformerTokenizer" + ], + "processor_classes": [] + }, + "RegNetForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "ConvNextImageProcessor" + ] + }, + "RemBertForCausalLM": { + "tokenizer_classes": [ + "RemBertTokenizerFast" + ], + "processor_classes": [] + }, + "RemBertForMaskedLM": { + "tokenizer_classes": [ + "RemBertTokenizerFast" + ], + "processor_classes": [] + }, + "RemBertForMultipleChoice": { + "tokenizer_classes": [ + "RemBertTokenizerFast" + ], + "processor_classes": [] + }, + "RemBertForQuestionAnswering": { + "tokenizer_classes": [ + "RemBertTokenizerFast" + ], + "processor_classes": [] + }, + "RemBertForSequenceClassification": { + "tokenizer_classes": [ + "RemBertTokenizerFast" + ], + "processor_classes": [] + }, + "RemBertForTokenClassification": { + "tokenizer_classes": [ + "RemBertTokenizerFast" + ], + "processor_classes": [] + }, + "ResNetForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "ConvNextImageProcessor" + ] + }, + "RoCBertForCausalLM": { + "tokenizer_classes": [ + "RoCBertTokenizer" + ], + "processor_classes": [] + }, + "RoCBertForMaskedLM": { + "tokenizer_classes": [ + "RoCBertTokenizer" + ], + "processor_classes": [] + }, + "RoCBertForMultipleChoice": { + "tokenizer_classes": [ + "RoCBertTokenizer" + ], + "processor_classes": [] + }, + "RoCBertForPreTraining": { + "tokenizer_classes": [ + "RoCBertTokenizer" + ], + "processor_classes": [] + }, + "RoCBertForQuestionAnswering": { + "tokenizer_classes": [ + "RoCBertTokenizer" + ], + "processor_classes": [] + }, + "RoCBertForSequenceClassification": { + "tokenizer_classes": [ + "RoCBertTokenizer" + ], + "processor_classes": [] + }, + "RoCBertForTokenClassification": { + "tokenizer_classes": [ + "RoCBertTokenizer" + ], + "processor_classes": [] + }, + "RoFormerForCausalLM": { + "tokenizer_classes": [ + "RoFormerTokenizerFast", + "RoFormerTokenizer" + ], + "processor_classes": [] + }, + "RoFormerForMaskedLM": { + "tokenizer_classes": [ + "RoFormerTokenizerFast", + "RoFormerTokenizer" + ], + "processor_classes": [] + }, + "RoFormerForMultipleChoice": { + "tokenizer_classes": [ + "RoFormerTokenizerFast", + "RoFormerTokenizer" + ], + "processor_classes": [] + }, + "RoFormerForQuestionAnswering": { + "tokenizer_classes": [ + "RoFormerTokenizerFast", + "RoFormerTokenizer" + ], + "processor_classes": [] + }, + "RoFormerForSequenceClassification": { + "tokenizer_classes": [ + "RoFormerTokenizerFast", + "RoFormerTokenizer" + ], + "processor_classes": [] + }, + "RoFormerForTokenClassification": { + "tokenizer_classes": [ + "RoFormerTokenizerFast", + "RoFormerTokenizer" + ], + "processor_classes": [] + }, + "RobertaForCausalLM": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "RobertaForMaskedLM": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "RobertaForMultipleChoice": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "RobertaForQuestionAnswering": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "RobertaForSequenceClassification": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "RobertaForTokenClassification": { + "tokenizer_classes": [ + "RobertaTokenizerFast", + "RobertaTokenizer" + ], + "processor_classes": [] + }, + "SEWDForCTC": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "SEWDForSequenceClassification": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "SEWForCTC": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "SEWForSequenceClassification": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "SegformerForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "SegformerImageProcessor" + ] + }, + "SegformerForSemanticSegmentation": { + "tokenizer_classes": [], + "processor_classes": [ + "SegformerImageProcessor" + ] + }, + "Speech2TextForConditionalGeneration": { + "tokenizer_classes": [ + "Speech2TextTokenizer" + ], + "processor_classes": [ + "Speech2TextFeatureExtractor" + ] + }, + "SplinterForPreTraining": { + "tokenizer_classes": [], + "processor_classes": [] + }, + "SplinterForQuestionAnswering": { + "tokenizer_classes": [], + "processor_classes": [] + }, + "SqueezeBertForMaskedLM": { + "tokenizer_classes": [ + "SqueezeBertTokenizerFast", + "SqueezeBertTokenizer" + ], + "processor_classes": [] + }, + "SqueezeBertForMultipleChoice": { + "tokenizer_classes": [ + "SqueezeBertTokenizerFast", + "SqueezeBertTokenizer" + ], + "processor_classes": [] + }, + "SqueezeBertForQuestionAnswering": { + "tokenizer_classes": [ + "SqueezeBertTokenizerFast", + "SqueezeBertTokenizer" + ], + "processor_classes": [] + }, + "SqueezeBertForSequenceClassification": { + "tokenizer_classes": [ + "SqueezeBertTokenizerFast", + "SqueezeBertTokenizer" + ], + "processor_classes": [] + }, + "SqueezeBertForTokenClassification": { + "tokenizer_classes": [ + "SqueezeBertTokenizerFast", + "SqueezeBertTokenizer" + ], + "processor_classes": [] + }, + "SwinForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "ViTImageProcessor" + ] + }, + "SwinForMaskedImageModeling": { + "tokenizer_classes": [], + "processor_classes": [ + "ViTImageProcessor" + ] + }, + "Swinv2ForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "ViTImageProcessor" + ] + }, + "Swinv2ForMaskedImageModeling": { + "tokenizer_classes": [], + "processor_classes": [ + "ViTImageProcessor" + ] + }, + "SwitchTransformersForConditionalGeneration": { + "tokenizer_classes": [ + "T5TokenizerFast" + ], + "processor_classes": [] + }, + "T5ForConditionalGeneration": { + "tokenizer_classes": [ + "T5TokenizerFast" + ], + "processor_classes": [] + }, + "TableTransformerForObjectDetection": { + "tokenizer_classes": [], + "processor_classes": [ + "DetrFeatureExtractor" + ] + }, + "TapasForMaskedLM": { + "tokenizer_classes": [ + "TapasTokenizer" + ], + "processor_classes": [] + }, + "TapasForQuestionAnswering": { + "tokenizer_classes": [ + "TapasTokenizer" + ], + "processor_classes": [] + }, + "TapasForSequenceClassification": { + "tokenizer_classes": [ + "TapasTokenizer" + ], + "processor_classes": [] + }, + "TransfoXLForSequenceClassification": { + "tokenizer_classes": [ + "TransfoXLTokenizer" + ], + "processor_classes": [] + }, + "UniSpeechForCTC": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "UniSpeechForPreTraining": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "UniSpeechForSequenceClassification": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "UniSpeechSatForCTC": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "UniSpeechSatForPreTraining": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "UniSpeechSatForSequenceClassification": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "UniSpeechSatForXVector": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "VanForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "ConvNextImageProcessor" + ] + }, + "ViTForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "ViTImageProcessor" + ] + }, + "ViTForMaskedImageModeling": { + "tokenizer_classes": [], + "processor_classes": [ + "ViTImageProcessor" + ] + }, + "ViTMAEForPreTraining": { + "tokenizer_classes": [], + "processor_classes": [ + "ViTImageProcessor" + ] + }, + "ViTMSNForImageClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "ViTImageProcessor" + ] + }, + "VideoMAEForPreTraining": { + "tokenizer_classes": [], + "processor_classes": [ + "VideoMAEImageProcessor" + ] + }, + "VideoMAEForVideoClassification": { + "tokenizer_classes": [], + "processor_classes": [ + "VideoMAEImageProcessor" + ] + }, + "ViltForQuestionAnswering": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [ + "ViltImageProcessor" + ] + }, + "VisualBertForPreTraining": { + "tokenizer_classes": [ + "BertTokenizerFast", + "BertTokenizer" + ], + "processor_classes": [] + }, + "Wav2Vec2ConformerForCTC": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "Wav2Vec2ConformerForPreTraining": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "Wav2Vec2ConformerForSequenceClassification": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "Wav2Vec2ConformerForXVector": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "Wav2Vec2ForCTC": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "Wav2Vec2ForMaskedLM": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "Wav2Vec2ForPreTraining": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "Wav2Vec2ForSequenceClassification": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "Wav2Vec2ForXVector": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "WavLMForCTC": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "WavLMForSequenceClassification": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "WavLMForXVector": { + "tokenizer_classes": [ + "Wav2Vec2CTCTokenizer" + ], + "processor_classes": [ + "Wav2Vec2FeatureExtractor" + ] + }, + "WhisperForConditionalGeneration": { + "tokenizer_classes": [ + "WhisperTokenizer" + ], + "processor_classes": [ + "WhisperFeatureExtractor" + ] + }, + "XGLMForCausalLM": { + "tokenizer_classes": [ + "XGLMTokenizerFast" + ], + "processor_classes": [] + }, + "XLMForMultipleChoice": { + "tokenizer_classes": [ + "XLMTokenizer" + ], + "processor_classes": [] + }, + "XLMForQuestionAnsweringSimple": { + "tokenizer_classes": [ + "XLMTokenizer" + ], + "processor_classes": [] + }, + "XLMForSequenceClassification": { + "tokenizer_classes": [ + "XLMTokenizer" + ], + "processor_classes": [] + }, + "XLMForTokenClassification": { + "tokenizer_classes": [ + "XLMTokenizer" + ], + "processor_classes": [] + }, + "XLMRobertaXLForCausalLM": { + "tokenizer_classes": [ + "XLMRobertaTokenizerFast" + ], + "processor_classes": [] + }, + "XLMRobertaXLForMaskedLM": { + "tokenizer_classes": [ + "XLMRobertaTokenizerFast" + ], + "processor_classes": [] + }, + "XLMRobertaXLForMultipleChoice": { + "tokenizer_classes": [ + "XLMRobertaTokenizerFast" + ], + "processor_classes": [] + }, + "XLMRobertaXLForQuestionAnswering": { + "tokenizer_classes": [ + "XLMRobertaTokenizerFast" + ], + "processor_classes": [] + }, + "XLMRobertaXLForSequenceClassification": { + "tokenizer_classes": [ + "XLMRobertaTokenizerFast" + ], + "processor_classes": [] + }, + "XLMRobertaXLForTokenClassification": { + "tokenizer_classes": [ + "XLMRobertaTokenizerFast" + ], + "processor_classes": [] + }, + "XLNetForMultipleChoice": { + "tokenizer_classes": [ + "XLNetTokenizerFast", + "XLNetTokenizer" + ], + "processor_classes": [] + }, + "XLNetForQuestionAnsweringSimple": { + "tokenizer_classes": [ + "XLNetTokenizerFast", + "XLNetTokenizer" + ], + "processor_classes": [] + }, + "XLNetForSequenceClassification": { + "tokenizer_classes": [ + "XLNetTokenizerFast", + "XLNetTokenizer" + ], + "processor_classes": [] + }, + "XLNetForTokenClassification": { + "tokenizer_classes": [ + "XLNetTokenizerFast", + "XLNetTokenizer" + ], + "processor_classes": [] + }, + "YolosForObjectDetection": { + "tokenizer_classes": [], + "processor_classes": [ + "YolosFeatureExtractor" + ] + }, + "YosoForMaskedLM": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "YosoForMultipleChoice": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "YosoForQuestionAnswering": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "YosoForSequenceClassification": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + }, + "YosoForTokenClassification": { + "tokenizer_classes": [ + "AlbertTokenizerFast" + ], + "processor_classes": [] + } +} diff --git a/utils/tests_fetcher.py b/utils/tests_fetcher.py index 1d1df9e817..85a8e2e198 100644 --- a/utils/tests_fetcher.py +++ b/utils/tests_fetcher.py @@ -27,6 +27,11 @@ from git import Repo # This script is intended to be run from the root of the repo but you can adapt this constant if you need to. PATH_TO_TRANFORMERS = "." +# A temporary way to trigger all pipeline tests contained in model test files after PR #21516 +all_model_test_files = [str(x) for x in Path("tests/models/").glob("**/**/test_modeling_*.py")] + +all_pipeline_test_files = [str(x) for x in Path("tests/pipelines/").glob("**/test_pipelines_*.py")] + @contextmanager def checkout_commit(repo, commit_id): @@ -381,8 +386,8 @@ SPECIAL_MODULE_TO_TEST_MAP = { ], "optimization.py": "optimization/test_optimization.py", "optimization_tf.py": "optimization/test_optimization_tf.py", - "pipelines/__init__.py": "pipelines/test_pipelines_*.py", - "pipelines/base.py": "pipelines/test_pipelines_*.py", + "pipelines/__init__.py": all_pipeline_test_files + all_model_test_files, + "pipelines/base.py": all_pipeline_test_files + all_model_test_files, "pipelines/text2text_generation.py": [ "pipelines/test_pipelines_text2text_generation.py", "pipelines/test_pipelines_summarization.py", @@ -430,6 +435,7 @@ def module_to_test_file(module_fname): # Special case for pipelines submodules if len(splits) >= 2 and splits[-2] == "pipelines": default_test_file = f"tests/pipelines/test_pipelines_{module_name}" + return [default_test_file] + all_model_test_files # Special case for benchmarks submodules elif len(splits) >= 2 and splits[-2] == "benchmark": return ["tests/benchmark/test_benchmark.py", "tests/benchmark/test_benchmark_tf.py"] @@ -470,6 +476,7 @@ EXPECTED_TEST_FILES_NEVER_TOUCHED = [ "tests/sagemaker/test_single_node_gpu.py", # SageMaker test "tests/sagemaker/test_multi_node_model_parallel.py", # SageMaker test "tests/sagemaker/test_multi_node_data_parallel.py", # SageMaker test + "tests/test_pipeline_mixin.py", # Contains no test of its own (only the common tester class) "tests/utils/test_doc_samples.py", # Doc tests ]