Move image-classification pipeline to new testing (#13272)
- Enforce `test_small_models_{tf,pt}` methods to exist (enforce checking
actual values in small tests)
- Add support for non RGB image for the pipeline.
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
import importlib
|
||||
import logging
|
||||
import string
|
||||
from abc import abstractmethod
|
||||
from functools import lru_cache
|
||||
from typing import List, Optional
|
||||
from unittest import mock, skipIf
|
||||
@@ -123,15 +124,18 @@ class PipelineTestCaseMeta(type):
|
||||
model = ModelClass(tiny_config)
|
||||
if hasattr(model, "eval"):
|
||||
model = model.eval()
|
||||
try:
|
||||
tokenizer = get_tiny_tokenizer_from_checkpoint(checkpoint)
|
||||
if hasattr(model.config, "max_position_embeddings"):
|
||||
tokenizer.model_max_length = model.config.max_position_embeddings
|
||||
# Rust Panic exception are NOT Exception subclass
|
||||
# Some test tokenizer contain broken vocabs or custom PreTokenizer, so we
|
||||
# provide some default tokenizer and hope for the best.
|
||||
except: # noqa: E722
|
||||
self.skipTest(f"Ignoring {ModelClass}, cannot create a simple tokenizer")
|
||||
if tokenizer_class is not None:
|
||||
try:
|
||||
tokenizer = get_tiny_tokenizer_from_checkpoint(checkpoint)
|
||||
if hasattr(model.config, "max_position_embeddings"):
|
||||
tokenizer.model_max_length = model.config.max_position_embeddings
|
||||
# Rust Panic exception are NOT Exception subclass
|
||||
# Some test tokenizer contain broken vocabs or custom PreTokenizer, so we
|
||||
# provide some default tokenizer and hope for the best.
|
||||
except: # noqa: E722
|
||||
self.skipTest(f"Ignoring {ModelClass}, cannot create a simple tokenizer")
|
||||
else:
|
||||
tokenizer = None
|
||||
feature_extractor = get_tiny_feature_extractor_from_checkpoint(checkpoint, tiny_config)
|
||||
self.run_pipeline_test(model, tokenizer, feature_extractor)
|
||||
|
||||
@@ -149,16 +153,21 @@ class PipelineTestCaseMeta(type):
|
||||
tiny_config = get_tiny_config_from_class(configuration)
|
||||
tokenizer_classes = TOKENIZER_MAPPING.get(configuration, [])
|
||||
feature_extractor_class = FEATURE_EXTRACTOR_MAPPING.get(configuration, None)
|
||||
feature_extractor_name = (
|
||||
feature_extractor_class.__name__ if feature_extractor_class else "nofeature_extractor"
|
||||
)
|
||||
if not tokenizer_classes:
|
||||
# We need to test even if there are no tokenizers.
|
||||
tokenizer_classes = [None]
|
||||
for tokenizer_class in tokenizer_classes:
|
||||
if tokenizer_class is not None and tokenizer_class.__name__.endswith("Fast"):
|
||||
if tokenizer_class is not None:
|
||||
tokenizer_name = tokenizer_class.__name__
|
||||
else:
|
||||
tokenizer_name = "notokenizer"
|
||||
|
||||
tokenizer_name = tokenizer_class.__name__ if tokenizer_class else "notokenizer"
|
||||
feature_extractor_name = (
|
||||
feature_extractor_class.__name__
|
||||
if feature_extractor_class
|
||||
else "nofeature_extractor"
|
||||
)
|
||||
test_name = f"test_{prefix}_{configuration.__name__}_{model_architecture.__name__}_{tokenizer_name}_{feature_extractor_name}"
|
||||
test_name = f"test_{prefix}_{configuration.__name__}_{model_architecture.__name__}_{tokenizer_name}_{feature_extractor_name}"
|
||||
|
||||
if tokenizer_class is not None or feature_extractor_class is not None:
|
||||
dct[test_name] = gen_test(
|
||||
model_architecture,
|
||||
checkpoint,
|
||||
@@ -167,6 +176,14 @@ class PipelineTestCaseMeta(type):
|
||||
feature_extractor_class,
|
||||
)
|
||||
|
||||
@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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user