Unverified Commit 59c378d0 authored by Nicolas Patry's avatar Nicolas Patry Committed by GitHub
Browse files

Moving `text2text-generation` to new pipeline testing mecanism. (#13281)

parent 0ebda538
...@@ -14,12 +14,43 @@ ...@@ -14,12 +14,43 @@
import unittest import unittest
from .test_pipelines_common import MonoInputPipelineCommonMixin from transformers import (
MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
Text2TextGenerationPipeline,
pipeline,
)
from transformers.testing_utils import is_pipeline_test, require_tf, require_torch
from .test_pipelines_common import ANY, PipelineTestCaseMeta
class Text2TextGenerationPipelineTests(MonoInputPipelineCommonMixin, unittest.TestCase):
pipeline_task = "text2text-generation" @is_pipeline_test
small_models = ["patrickvonplaten/t5-tiny-random"] # Default model - Models tested without the @slow decorator class Text2TextGenerationPipelineTests(unittest.TestCase, metaclass=PipelineTestCaseMeta):
large_models = [] # Models tested with the @slow decorator model_mapping = MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
invalid_inputs = [4, "<mask>"] tf_model_mapping = TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING
mandatory_keys = ["generated_text"]
def run_pipeline_test(self, model, tokenizer, feature_extractor):
generator = Text2TextGenerationPipeline(model=model, tokenizer=tokenizer)
outputs = generator("Something there")
self.assertEqual(outputs, [{"generated_text": ANY(str)}])
# These are encoder decoder, they don't just append to incoming string
self.assertFalse(outputs[0]["generated_text"].startswith("Something there"))
with self.assertRaises(ValueError):
generator(4)
@require_torch
def test_small_model_pt(self):
generator = pipeline("text2text-generation", model="patrickvonplaten/t5-tiny-random", framework="pt")
# do_sample=False necessary for reproducibility
outputs = generator("Something there", do_sample=False)
self.assertEqual(outputs, [{"generated_text": ""}])
@require_tf
def test_small_model_tf(self):
generator = pipeline("text2text-generation", model="patrickvonplaten/t5-tiny-random", framework="tf")
# do_sample=False necessary for reproducibility
outputs = generator("Something there", do_sample=False)
self.assertEqual(outputs, [{"generated_text": ""}])
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment