🔥Rework pipeline testing by removing PipelineTestCaseMeta 🚀 (#21516)
* 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 <ydshieh@users.noreply.github.com>
This commit is contained in:
@@ -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):
|
||||
|
||||
@@ -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 [])
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 (
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user