From e4a0e046f9577436d029e15d874070c4b3e9ce58 Mon Sep 17 00:00:00 2001 From: "hemu.zp" Date: Wed, 26 Oct 2022 16:19:20 +0800 Subject: [PATCH] [to #42322933] Add ut for mplug and bloom MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 为新上线的 langboat/bloom-1b4-zh,damo/mplug_visual-question-answering_coco_base_zh,damo/mplug_image-captioning_coco_base_zh 三个模型添加 ut,test_level 设置为 2 Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/10524221 --- tests/pipelines/test_mplug_tasks.py | 23 +++++++++++++++++++---- tests/pipelines/test_text_generation.py | 18 +++++++++--------- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/tests/pipelines/test_mplug_tasks.py b/tests/pipelines/test_mplug_tasks.py index 11c9798f..21439ce2 100644 --- a/tests/pipelines/test_mplug_tasks.py +++ b/tests/pipelines/test_mplug_tasks.py @@ -13,10 +13,6 @@ from modelscope.utils.test_utils import test_level class MplugTasksTest(unittest.TestCase, DemoCompatibilityCheck): - def setUp(self) -> None: - self.task = 'visual-question-answering' - self.model_id = 'damo/mplug_visual-question-answering_coco_large_en' - @unittest.skipUnless(test_level() >= 1, 'skip test in current test level') def test_run_with_image_captioning_with_model(self): model = Model.from_pretrained( @@ -80,6 +76,25 @@ class MplugTasksTest(unittest.TestCase, DemoCompatibilityCheck): result = pipeline_retrieval(input) print(result) + @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') + def test_run_with_image_captioning_zh_base_with_name(self): + pipeline_caption = pipeline( + Tasks.image_captioning, + model='damo/mplug_image-captioning_coco_base_zh') + image = Image.open('data/test/images/image_mplug_vqa.jpg') + result = pipeline_caption(image) + print(result[OutputKeys.CAPTION]) + + @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') + def test_run_with_visual_question_answering_zh_base_with_name(self): + model = 'damo/mplug_visual-question-answering_coco_base_zh' + pipeline_vqa = pipeline(Tasks.visual_question_answering, model=model) + image = Image.open('data/test/images/image_mplug_vqa.jpg') + text = '这个女人在做什么?' + input = {'image': image, 'text': text} + result = pipeline_vqa(input) + print(result) + @unittest.skip('demo compatibility test is only enabled on a needed-basis') def test_demo_compatibility(self): self.compatibility_check() diff --git a/tests/pipelines/test_text_generation.py b/tests/pipelines/test_text_generation.py index f624f021..ffb30090 100644 --- a/tests/pipelines/test_text_generation.py +++ b/tests/pipelines/test_text_generation.py @@ -165,14 +165,16 @@ class TextGenerationTest(unittest.TestCase, DemoCompatibilityCheck): pipeline_ins = pipeline(task=Tasks.text_generation) print(pipeline_ins(self.palm_input_zh)) - @unittest.skip('demo compatibility test is only enabled on a needed-basis') - def test_demo_compatibility(self): - self.compatibility_check() + @unittest.skipUnless(test_level() >= 2, 'skip test in current test level') + def test_bloom(self): + pipe = pipeline( + task=Tasks.text_generation, model='langboat/bloom-1b4-zh') + print(pipe('中国的首都是')) @unittest.skip("Langboat's checkpoint has not been uploaded to modelhub") def test_gpt_neo(self): pipe = pipeline( - task=Tasks.text_generation, model='Langboat/mengzi-gpt-neo-base') + task=Tasks.text_generation, model='langboat/mengzi-gpt-neo-base') print( pipe( '我是', @@ -182,11 +184,9 @@ class TextGenerationTest(unittest.TestCase, DemoCompatibilityCheck): max_length=20, repetition_penalty=0.5)) - @unittest.skip("Langboat's checkpoint has not been uploaded to modelhub") - def test_bloom(self): - pipe = pipeline( - task=Tasks.text_generation, model='Langboat/bloom-1b4-zh') - print(pipe('中国的首都是')) + @unittest.skip('demo compatibility test is only enabled on a needed-basis') + def test_demo_compatibility(self): + self.compatibility_check() if __name__ == '__main__':