add test level

This commit is contained in:
智丞
2022-06-22 20:49:42 +08:00
parent 67a8440de5
commit 1009d54d22
3 changed files with 18 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ from modelscope.models.nlp import SbertForNLI
from modelscope.pipelines import NLIPipeline, pipeline
from modelscope.preprocessors import NLIPreprocessor
from modelscope.utils.constant import Tasks
from modelscope.utils.test_utils import test_level
class NLITest(unittest.TestCase):
@@ -14,8 +15,8 @@ class NLITest(unittest.TestCase):
sentence1 = '四川商务职业学院和四川财经职业学院哪个好?'
sentence2 = '四川商务职业学院商务管理在哪个校区?'
@unittest.skip('skip temporarily to save test time')
def test_run_from_local(self):
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
def test_run_with_direct_file_download(self):
cache_path = snapshot_download(self.model_id)
tokenizer = NLIPreprocessor(cache_path)
model = SbertForNLI(cache_path, tokenizer=tokenizer)
@@ -28,6 +29,7 @@ class NLITest(unittest.TestCase):
f'sentence1: {self.sentence1}\nsentence2: {self.sentence2}\n'
f'pipeline1: {pipeline2(input=(self.sentence1, self.sentence2))}')
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_run_with_model_from_modelhub(self):
model = Model.from_pretrained(self.model_id)
tokenizer = NLIPreprocessor(model.model_dir)
@@ -35,10 +37,12 @@ class NLITest(unittest.TestCase):
task=Tasks.nli, model=model, preprocessor=tokenizer)
print(pipeline_ins(input=(self.sentence1, self.sentence2)))
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_run_with_model_name(self):
pipeline_ins = pipeline(task=Tasks.nli, model=self.model_id)
print(pipeline_ins(input=(self.sentence1, self.sentence2)))
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_run_with_default_model(self):
pipeline_ins = pipeline(task=Tasks.nli)
print(pipeline_ins(input=(self.sentence1, self.sentence2)))

View File

@@ -7,13 +7,15 @@ from modelscope.models.nlp import SbertForSentimentClassification
from modelscope.pipelines import SentimentClassificationPipeline, pipeline
from modelscope.preprocessors import SentimentClassificationPreprocessor
from modelscope.utils.constant import Tasks
from modelscope.utils.test_utils import test_level
class SentimentClassificationTest(unittest.TestCase):
model_id = 'damo/nlp_structbert_sentiment-classification_chinese-base'
sentence1 = '启动的时候很大声音然后就会听到1.2秒的卡察的声音,类似齿轮摩擦的声音'
def test_run_from_local(self):
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
def test_run_with_direct_file_download(self):
cache_path = snapshot_download(self.model_id)
tokenizer = SentimentClassificationPreprocessor(cache_path)
model = SbertForSentimentClassification(
@@ -30,6 +32,7 @@ class SentimentClassificationTest(unittest.TestCase):
print(f'sentence1: {self.sentence1}\n'
f'pipeline1: {pipeline2(input=self.sentence1)}')
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_run_with_model_from_modelhub(self):
model = Model.from_pretrained(self.model_id)
tokenizer = SentimentClassificationPreprocessor(model.model_dir)
@@ -39,11 +42,13 @@ class SentimentClassificationTest(unittest.TestCase):
preprocessor=tokenizer)
print(pipeline_ins(input=self.sentence1))
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_run_with_model_name(self):
pipeline_ins = pipeline(
task=Tasks.sentiment_classification, model=self.model_id)
print(pipeline_ins(input=self.sentence1))
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_run_with_default_model(self):
pipeline_ins = pipeline(task=Tasks.sentiment_classification)
print(pipeline_ins(input=self.sentence1))

View File

@@ -7,6 +7,7 @@ from modelscope.models.nlp import SbertForZeroShotClassification
from modelscope.pipelines import ZeroShotClassificationPipeline, pipeline
from modelscope.preprocessors import ZeroShotClassificationPreprocessor
from modelscope.utils.constant import Tasks
from modelscope.utils.test_utils import test_level
class ZeroShotClassificationTest(unittest.TestCase):
@@ -15,7 +16,8 @@ class ZeroShotClassificationTest(unittest.TestCase):
labels = ['文化', '体育', '娱乐', '财经', '家居', '汽车', '教育', '科技', '军事']
template = '这篇文章的标题是{}'
def test_run_from_local(self):
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
def test_run_with_direct_file_download(self):
cache_path = snapshot_download(self.model_id)
tokenizer = ZeroShotClassificationPreprocessor(cache_path)
model = SbertForZeroShotClassification(cache_path, tokenizer=tokenizer)
@@ -36,6 +38,7 @@ class ZeroShotClassificationTest(unittest.TestCase):
f'pipeline2: {pipeline2(self.sentence,candidate_labels=self.labels,hypothesis_template=self.template)}'
)
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_run_with_model_from_modelhub(self):
model = Model.from_pretrained(self.model_id)
tokenizer = ZeroShotClassificationPreprocessor(model.model_dir)
@@ -45,11 +48,13 @@ class ZeroShotClassificationTest(unittest.TestCase):
preprocessor=tokenizer)
print(pipeline_ins(input=self.sentence, candidate_labels=self.labels))
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_run_with_model_name(self):
pipeline_ins = pipeline(
task=Tasks.zero_shot_classification, model=self.model_id)
print(pipeline_ins(input=self.sentence, candidate_labels=self.labels))
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
def test_run_with_default_model(self):
pipeline_ins = pipeline(task=Tasks.zero_shot_classification)
print(pipeline_ins(input=self.sentence, candidate_labels=self.labels))