Make pipeline able to load processor (#32514)
* Refactor get_test_pipeline * Fixup * Fixing tests * Add processor loading in tests * Restructure processors loading * Add processor to the pipeline * Move model loading on tom of the test * Update `get_test_pipeline` * Fixup * Add class-based flags for loading processors * Change `is_pipeline_test_to_skip` signature * Skip t5 failing test for slow tokenizer * Fixup * Fix copies for T5 * Fix typo * Add try/except for tokenizer loading (kosmos-2 case) * Fixup * Llama not fails for long generation * Revert processor pass in text-generation test * Fix docs * Switch back to json file for image processors and feature extractors * Add processor type check * Remove except for tokenizers * Fix docstring * Fix empty lists for tests * Fixup * Fix load check * Ensure we have non-empty test cases * Update src/transformers/pipelines/__init__.py Co-authored-by: Lysandre Debut <hi@lysand.re> * Update src/transformers/pipelines/base.py Co-authored-by: Lysandre Debut <hi@lysand.re> * Rework comment * Better docs, add note about pipeline components * Change warning to error raise * Fixup * Refine pipeline docs --------- Co-authored-by: Lysandre Debut <hi@lysand.re>
This commit is contained in:
committed by
GitHub
parent
4fb28703ad
commit
48461c0fe2
@@ -37,9 +37,22 @@ class AudioClassificationPipelineTests(unittest.TestCase):
|
||||
model_mapping = MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
|
||||
tf_model_mapping = TF_MODEL_FOR_AUDIO_CLASSIFICATION_MAPPING
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
audio_classifier = AudioClassificationPipeline(
|
||||
model=model, feature_extractor=processor, torch_dtype=torch_dtype
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
|
||||
# test with a raw waveform
|
||||
|
||||
@@ -67,14 +67,27 @@ class AutomaticSpeechRecognitionPipelineTests(unittest.TestCase):
|
||||
+ (MODEL_FOR_CTC_MAPPING.items() if MODEL_FOR_CTC_MAPPING else [])
|
||||
)
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
if tokenizer is None:
|
||||
# Side effect of no Fast Tokenizer class for these model, so skipping
|
||||
# But the slow tokenizer test should still run as they're quite small
|
||||
self.skipTest(reason="No tokenizer available")
|
||||
|
||||
speech_recognizer = AutomaticSpeechRecognitionPipeline(
|
||||
model=model, tokenizer=tokenizer, feature_extractor=processor, torch_dtype=torch_dtype
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
|
||||
# test with a raw waveform
|
||||
|
||||
@@ -58,8 +58,23 @@ def hashimage(image: Image) -> str:
|
||||
class DepthEstimationPipelineTests(unittest.TestCase):
|
||||
model_mapping = MODEL_FOR_DEPTH_ESTIMATION_MAPPING
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
depth_estimator = DepthEstimationPipeline(model=model, image_processor=processor, torch_dtype=torch_dtype)
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
depth_estimator = DepthEstimationPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
return depth_estimator, [
|
||||
"./tests/fixtures/tests_samples/COCO/000000039769.png",
|
||||
"./tests/fixtures/tests_samples/COCO/000000039769.png",
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
import unittest
|
||||
|
||||
from transformers import MODEL_FOR_DOCUMENT_QUESTION_ANSWERING_MAPPING, AutoTokenizer, is_vision_available
|
||||
from transformers.pipelines import pipeline
|
||||
from transformers.pipelines import DocumentQuestionAnsweringPipeline, pipeline
|
||||
from transformers.pipelines.document_question_answering import apply_tesseract
|
||||
from transformers.testing_utils import (
|
||||
is_pipeline_test,
|
||||
@@ -61,12 +61,21 @@ class DocumentQuestionAnsweringPipelineTests(unittest.TestCase):
|
||||
|
||||
@require_pytesseract
|
||||
@require_vision
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
dqa_pipeline = pipeline(
|
||||
"document-question-answering",
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
dqa_pipeline = DocumentQuestionAnsweringPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
image_processor=processor,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
|
||||
|
||||
@@ -174,7 +174,15 @@ class FeatureExtractionPipelineTests(unittest.TestCase):
|
||||
raise TypeError("We expect lists of floats, nothing else")
|
||||
return shape
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
if tokenizer is None:
|
||||
self.skipTest(reason="No tokenizer")
|
||||
elif (
|
||||
@@ -193,10 +201,15 @@ class FeatureExtractionPipelineTests(unittest.TestCase):
|
||||
For now ignore those.
|
||||
"""
|
||||
)
|
||||
feature_extractor = FeatureExtractionPipeline(
|
||||
model=model, tokenizer=tokenizer, feature_extractor=processor, torch_dtype=torch_dtype
|
||||
feature_extractor_pipeline = FeatureExtractionPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
return feature_extractor, ["This is a test", "This is another test"]
|
||||
return feature_extractor_pipeline, ["This is a test", "This is another test"]
|
||||
|
||||
def run_pipeline_test(self, feature_extractor, examples):
|
||||
outputs = feature_extractor("This is a test")
|
||||
|
||||
@@ -251,11 +251,26 @@ class FillMaskPipelineTests(unittest.TestCase):
|
||||
unmasker.tokenizer.pad_token = None
|
||||
self.run_pipeline_test(unmasker, [])
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
if tokenizer is None or tokenizer.mask_token_id is None:
|
||||
self.skipTest(reason="The provided tokenizer has no mask token, (probably reformer or wav2vec2)")
|
||||
|
||||
fill_masker = FillMaskPipeline(model=model, tokenizer=tokenizer, torch_dtype=torch_dtype)
|
||||
fill_masker = FillMaskPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
examples = [
|
||||
f"This is another {tokenizer.mask_token} test",
|
||||
]
|
||||
|
||||
@@ -58,9 +58,23 @@ class ImageClassificationPipelineTests(unittest.TestCase):
|
||||
model_mapping = MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
|
||||
tf_model_mapping = TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
image_classifier = ImageClassificationPipeline(
|
||||
model=model, image_processor=processor, top_k=2, torch_dtype=torch_dtype
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
top_k=2,
|
||||
)
|
||||
examples = [
|
||||
Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"),
|
||||
|
||||
@@ -157,8 +157,16 @@ class ImageFeatureExtractionPipelineTests(unittest.TestCase):
|
||||
outputs = feature_extractor(img, return_tensors=True)
|
||||
self.assertTrue(tf.is_tensor(outputs))
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
if processor is None:
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
if image_processor is None:
|
||||
self.skipTest(reason="No image processor")
|
||||
|
||||
elif type(model.config) in TOKENIZER_MAPPING:
|
||||
@@ -175,11 +183,16 @@ class ImageFeatureExtractionPipelineTests(unittest.TestCase):
|
||||
"""
|
||||
)
|
||||
|
||||
feature_extractor = ImageFeatureExtractionPipeline(
|
||||
model=model, image_processor=processor, torch_dtype=torch_dtype
|
||||
feature_extractor_pipeline = ImageFeatureExtractionPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
img = prepare_img()
|
||||
return feature_extractor, [img, img]
|
||||
return feature_extractor_pipeline, [img, img]
|
||||
|
||||
def run_pipeline_test(self, feature_extractor, examples):
|
||||
imgs = examples
|
||||
|
||||
@@ -89,8 +89,23 @@ class ImageSegmentationPipelineTests(unittest.TestCase):
|
||||
+ (MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING.items() if MODEL_FOR_INSTANCE_SEGMENTATION_MAPPING else [])
|
||||
)
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
image_segmenter = ImageSegmentationPipeline(model=model, image_processor=processor, torch_dtype=torch_dtype)
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
image_segmenter = ImageSegmentationPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
return image_segmenter, [
|
||||
"./tests/fixtures/tests_samples/COCO/000000039769.png",
|
||||
"./tests/fixtures/tests_samples/COCO/000000039769.png",
|
||||
|
||||
@@ -47,9 +47,22 @@ class ImageToTextPipelineTests(unittest.TestCase):
|
||||
model_mapping = MODEL_FOR_VISION_2_SEQ_MAPPING
|
||||
tf_model_mapping = TF_MODEL_FOR_VISION_2_SEQ_MAPPING
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
pipe = ImageToTextPipeline(
|
||||
model=model, tokenizer=tokenizer, image_processor=processor, torch_dtype=torch_dtype
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
examples = [
|
||||
Image.open("./tests/fixtures/tests_samples/COCO/000000039769.png"),
|
||||
|
||||
@@ -67,8 +67,23 @@ class MaskGenerationPipelineTests(unittest.TestCase):
|
||||
(list(TF_MODEL_FOR_MASK_GENERATION_MAPPING.items()) if TF_MODEL_FOR_MASK_GENERATION_MAPPING else [])
|
||||
)
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
image_segmenter = MaskGenerationPipeline(model=model, image_processor=processor, torch_dtype=torch_dtype)
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
image_segmenter = MaskGenerationPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
return image_segmenter, [
|
||||
"./tests/fixtures/tests_samples/COCO/000000039769.png",
|
||||
"./tests/fixtures/tests_samples/COCO/000000039769.png",
|
||||
|
||||
@@ -56,8 +56,23 @@ else:
|
||||
class ObjectDetectionPipelineTests(unittest.TestCase):
|
||||
model_mapping = MODEL_FOR_OBJECT_DETECTION_MAPPING
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
object_detector = ObjectDetectionPipeline(model=model, image_processor=processor, torch_dtype=torch_dtype)
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
object_detector = ObjectDetectionPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
return object_detector, ["./tests/fixtures/tests_samples/COCO/000000039769.png"]
|
||||
|
||||
def run_pipeline_test(self, object_detector, examples):
|
||||
|
||||
@@ -50,12 +50,27 @@ class QAPipelineTests(unittest.TestCase):
|
||||
config: model for config, model in tf_model_mapping.items() if config.__name__ not in _TO_SKIP
|
||||
}
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
if isinstance(model.config, LxmertConfig):
|
||||
# This is an bimodal model, we need to find a more consistent way
|
||||
# to switch on those models.
|
||||
return None, None
|
||||
question_answerer = QuestionAnsweringPipeline(model, tokenizer, torch_dtype=torch_dtype)
|
||||
question_answerer = QuestionAnsweringPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
|
||||
examples = [
|
||||
{"question": "Where was HuggingFace founded ?", "context": "HuggingFace was founded in Paris."},
|
||||
|
||||
@@ -32,8 +32,23 @@ 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
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
summarizer = SummarizationPipeline(model=model, tokenizer=tokenizer, torch_dtype=torch_dtype)
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
summarizer = SummarizationPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
return summarizer, ["(CNN)The Palestinian Authority officially became", "Some other text"]
|
||||
|
||||
def run_pipeline_test(self, summarizer, _):
|
||||
|
||||
@@ -35,8 +35,23 @@ 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
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
generator = Text2TextGenerationPipeline(model=model, tokenizer=tokenizer, torch_dtype=torch_dtype)
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
generator = Text2TextGenerationPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
return generator, ["Something to write", "Something else"]
|
||||
|
||||
def run_pipeline_test(self, generator, _):
|
||||
|
||||
@@ -179,8 +179,23 @@ class TextClassificationPipelineTests(unittest.TestCase):
|
||||
outputs = text_classifier("Birds are a type of animal")
|
||||
self.assertEqual(nested_simplify(outputs), [{"label": "POSITIVE", "score": 0.988}])
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
text_classifier = TextClassificationPipeline(model=model, tokenizer=tokenizer, torch_dtype=torch_dtype)
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
text_classifier = TextClassificationPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
return text_classifier, ["HuggingFace is in", "This is another test"]
|
||||
|
||||
def run_pipeline_test(self, text_classifier, _):
|
||||
|
||||
@@ -377,8 +377,23 @@ class TextGenerationPipelineTests(unittest.TestCase):
|
||||
],
|
||||
)
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
text_generator = TextGenerationPipeline(model=model, tokenizer=tokenizer, torch_dtype=torch_dtype)
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
text_generator = TextGenerationPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
return text_generator, ["This is a test", "Another test"]
|
||||
|
||||
def test_stop_sequence_stopping_criteria(self):
|
||||
@@ -471,6 +486,7 @@ class TextGenerationPipelineTests(unittest.TestCase):
|
||||
"GPTNeoXForCausalLM",
|
||||
"GPTNeoXJapaneseForCausalLM",
|
||||
"FuyuForCausalLM",
|
||||
"LlamaForCausalLM",
|
||||
]
|
||||
if (
|
||||
tokenizer.model_max_length < 10000
|
||||
|
||||
@@ -250,8 +250,23 @@ class TextToAudioPipelineTests(unittest.TestCase):
|
||||
outputs = music_generator("This is a test", forward_params=forward_params, generate_kwargs=generate_kwargs)
|
||||
self.assertListEqual(outputs["audio"].tolist(), audio.tolist())
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
speech_generator = TextToAudioPipeline(model=model, tokenizer=tokenizer, torch_dtype=torch_dtype)
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
speech_generator = TextToAudioPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
return speech_generator, ["This is a test", "Another test"]
|
||||
|
||||
def run_pipeline_test(self, speech_generator, _):
|
||||
|
||||
@@ -61,8 +61,23 @@ class TokenClassificationPipelineTests(unittest.TestCase):
|
||||
config: model for config, model in tf_model_mapping.items() if config.__name__ not in _TO_SKIP
|
||||
}
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
token_classifier = TokenClassificationPipeline(model=model, tokenizer=tokenizer, torch_dtype=torch_dtype)
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
token_classifier = TokenClassificationPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
return token_classifier, ["A simple string", "A simple string that is quite a bit longer"]
|
||||
|
||||
def run_pipeline_test(self, token_classifier, _):
|
||||
|
||||
@@ -35,14 +35,36 @@ 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
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
if isinstance(model.config, MBartConfig):
|
||||
src_lang, tgt_lang = list(tokenizer.lang_code_to_id.keys())[:2]
|
||||
translator = TranslationPipeline(
|
||||
model=model, tokenizer=tokenizer, src_lang=src_lang, tgt_lang=tgt_lang, torch_dtype=torch_dtype
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
src_lang=src_lang,
|
||||
tgt_lang=tgt_lang,
|
||||
)
|
||||
else:
|
||||
translator = TranslationPipeline(model=model, tokenizer=tokenizer, torch_dtype=torch_dtype)
|
||||
translator = TranslationPipeline(
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
return translator, ["Some string", "Some other text"]
|
||||
|
||||
def run_pipeline_test(self, translator, _):
|
||||
|
||||
@@ -38,12 +38,26 @@ from .test_pipelines_common import ANY
|
||||
class VideoClassificationPipelineTests(unittest.TestCase):
|
||||
model_mapping = MODEL_FOR_VIDEO_CLASSIFICATION_MAPPING
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
example_video_filepath = hf_hub_download(
|
||||
repo_id="nateraw/video-demo", filename="archery.mp4", repo_type="dataset"
|
||||
)
|
||||
video_classifier = VideoClassificationPipeline(
|
||||
model=model, image_processor=processor, top_k=2, torch_dtype=torch_dtype
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
top_k=2,
|
||||
)
|
||||
examples = [
|
||||
example_video_filepath,
|
||||
|
||||
@@ -55,9 +55,19 @@ else:
|
||||
class VisualQuestionAnsweringPipelineTests(unittest.TestCase):
|
||||
model_mapping = MODEL_FOR_VISUAL_QUESTION_ANSWERING_MAPPING
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
vqa_pipeline = pipeline(
|
||||
"visual-question-answering", model="hf-internal-testing/tiny-vilt-random-vqa", torch_dtype=torch_dtype
|
||||
"visual-question-answering",
|
||||
model="hf-internal-testing/tiny-vilt-random-vqa",
|
||||
torch_dtype=torch_dtype,
|
||||
)
|
||||
examples = [
|
||||
{
|
||||
|
||||
@@ -53,9 +53,23 @@ class ZeroShotClassificationPipelineTests(unittest.TestCase):
|
||||
config: model for config, model in tf_model_mapping.items() if config.__name__ not in _TO_SKIP
|
||||
}
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
classifier = ZeroShotClassificationPipeline(
|
||||
model=model, tokenizer=tokenizer, candidate_labels=["polics", "health"], torch_dtype=torch_dtype
|
||||
model=model,
|
||||
tokenizer=tokenizer,
|
||||
feature_extractor=feature_extractor,
|
||||
image_processor=image_processor,
|
||||
processor=processor,
|
||||
torch_dtype=torch_dtype,
|
||||
candidate_labels=["polics", "health"],
|
||||
)
|
||||
return classifier, ["Who are you voting for in 2020?", "My stomach hurts."]
|
||||
|
||||
|
||||
@@ -43,7 +43,15 @@ else:
|
||||
class ZeroShotObjectDetectionPipelineTests(unittest.TestCase):
|
||||
model_mapping = MODEL_FOR_ZERO_SHOT_OBJECT_DETECTION_MAPPING
|
||||
|
||||
def get_test_pipeline(self, model, tokenizer, processor, torch_dtype="float32"):
|
||||
def get_test_pipeline(
|
||||
self,
|
||||
model,
|
||||
tokenizer=None,
|
||||
image_processor=None,
|
||||
feature_extractor=None,
|
||||
processor=None,
|
||||
torch_dtype="float32",
|
||||
):
|
||||
object_detector = pipeline(
|
||||
"zero-shot-object-detection",
|
||||
model="hf-internal-testing/tiny-random-owlvit-object-detection",
|
||||
|
||||
Reference in New Issue
Block a user