mirror of
https://github.com/modelscope/modelscope.git
synced 2026-09-01 19:49:03 +02:00
Add teardown for tests
Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/12643554 * add teardown for tests * add teardown for dialog_modeling_trainer,document_grounded_dialog_generate_trainer,document_grounded_dialog_rerank_trainer,document_grounded_dialog_retrieval_trainer,training_args,translation_evaluation_trainer,translation_trainer
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
# Copyright (c) Alibaba, Inc. and its affiliates.
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
import torch
|
||||
@@ -17,6 +18,11 @@ class TestDialogModelingTrainer(unittest.TestCase):
|
||||
model_id = 'damo/nlp_space_pretrained-dialog-model'
|
||||
output_dir = './dialog_fintune_result'
|
||||
|
||||
def tearDown(self):
|
||||
if os.path.exists(self.output_dir):
|
||||
shutil.rmtree(self.output_dir)
|
||||
super().tearDown()
|
||||
|
||||
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||
def test_trainer_with_model_and_args(self):
|
||||
# download data set
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Copyright (c) Alibaba, Inc. and its affiliates.
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
import json
|
||||
@@ -19,6 +20,10 @@ class TestDialogIntentTrainer(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.model_id = 'DAMO_ConvAI/nlp_convai_ranking_pretrain'
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree('./model')
|
||||
super().tearDown()
|
||||
|
||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
||||
def test_trainer_with_model_and_args(self):
|
||||
args = {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Copyright (c) Alibaba, Inc. and its affiliates.
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
import cv2
|
||||
@@ -20,6 +21,10 @@ class TestImagePortraitStylizationTrainer(unittest.TestCase):
|
||||
self.task = Tasks.image_portrait_stylization
|
||||
self.test_image = 'https://modelscope.oss-cn-beijing.aliyuncs.com/test/images/image_cartoon.png'
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree('exp_localtoon')
|
||||
super().tearDown()
|
||||
|
||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
||||
def test_run_with_model_name(self):
|
||||
model_id = 'damo/cv_unet_person-image-cartoon_compound-models'
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Copyright (c) Alibaba, Inc. and its affiliates.
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
from modelscope.msdatasets import MsDataset
|
||||
@@ -10,6 +11,10 @@ from modelscope.utils.test_utils import test_level
|
||||
|
||||
class TestNeRFReconAccTrainer(unittest.TestCase):
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree('exp_nerf')
|
||||
super().tearDown()
|
||||
|
||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
||||
def test_run_with_model_name(self):
|
||||
model_id = 'damo/cv_nerf-3d-reconstruction-accelerate_damo'
|
||||
|
||||
@@ -36,6 +36,10 @@ class TestOCRDetectionDBTrainerSingleGPU(unittest.TestCase):
|
||||
self.saved_infer_model = os.path.join(self.saved_dir,
|
||||
'pytorch_model.pt')
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree(self.saved_dir)
|
||||
super().tearDown()
|
||||
|
||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
||||
def test_trainer_finetune_singleGPU(self):
|
||||
|
||||
|
||||
@@ -69,11 +69,17 @@ class TestMMSpeechTrainer(unittest.TestCase):
|
||||
'metrics': [{'type': 'accuracy'}]},
|
||||
'preprocessor': []}
|
||||
|
||||
self.WORKSPACE = './workspace/ckpts/asr_recognition'
|
||||
|
||||
def tearDown(self) -> None:
|
||||
if os.path.exists(self.WORKSPACE):
|
||||
shutil.rmtree(self.WORKSPACE, ignore_errors=True)
|
||||
super().tearDown()
|
||||
|
||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
||||
def test_trainer_std(self):
|
||||
WORKSPACE = './workspace/ckpts/asr_recognition'
|
||||
os.makedirs(WORKSPACE, exist_ok=True)
|
||||
config_file = os.path.join(WORKSPACE, ModelFile.CONFIGURATION)
|
||||
os.makedirs(self.WORKSPACE, exist_ok=True)
|
||||
config_file = os.path.join(self.WORKSPACE, ModelFile.CONFIGURATION)
|
||||
with open(config_file, 'w') as writer:
|
||||
json.dump(self.finetune_cfg, writer)
|
||||
|
||||
@@ -81,7 +87,7 @@ class TestMMSpeechTrainer(unittest.TestCase):
|
||||
|
||||
args = dict(
|
||||
model=pretrained_model,
|
||||
work_dir=WORKSPACE,
|
||||
work_dir=self.WORKSPACE,
|
||||
train_dataset=MsDataset.load(
|
||||
'aishell1_subset',
|
||||
subset_name='default',
|
||||
@@ -100,8 +106,8 @@ class TestMMSpeechTrainer(unittest.TestCase):
|
||||
|
||||
self.assertIn(
|
||||
ModelFile.TORCH_MODEL_BIN_FILE,
|
||||
os.listdir(os.path.join(WORKSPACE, ModelFile.TRAIN_OUTPUT_DIR)))
|
||||
shutil.rmtree(WORKSPACE)
|
||||
os.listdir(
|
||||
os.path.join(self.WORKSPACE, ModelFile.TRAIN_OUTPUT_DIR)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -69,19 +69,24 @@ class TestOfaTrainer(unittest.TestCase):
|
||||
'evaluation': {'dataloader': {'batch_size_per_gpu': 4, 'workers_per_gpu': 0},
|
||||
'metrics': [{'type': 'accuracy'}]},
|
||||
'preprocessor': []}
|
||||
self.WORKSPACE = './workspace/ckpts/recognition'
|
||||
|
||||
def tearDown(self) -> None:
|
||||
if os.path.exists(self.WORKSPACE):
|
||||
shutil.rmtree(self.WORKSPACE, ignore_errors=True)
|
||||
super().tearDown()
|
||||
|
||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
||||
def test_trainer_std(self):
|
||||
WORKSPACE = './workspace/ckpts/recognition'
|
||||
os.makedirs(WORKSPACE, exist_ok=True)
|
||||
config_file = os.path.join(WORKSPACE, ModelFile.CONFIGURATION)
|
||||
os.makedirs(self.WORKSPACE, exist_ok=True)
|
||||
config_file = os.path.join(self.WORKSPACE, ModelFile.CONFIGURATION)
|
||||
with open(config_file, 'w') as writer:
|
||||
json.dump(self.finetune_cfg, writer, indent=4)
|
||||
pretrained_model = 'damo/ofa_ocr-recognition_scene_base_zh'
|
||||
|
||||
args = dict(
|
||||
model=pretrained_model,
|
||||
work_dir=WORKSPACE,
|
||||
work_dir=self.WORKSPACE,
|
||||
train_dataset=MsDataset.load(
|
||||
'ocr_fudanvi_zh',
|
||||
subset_name='scene',
|
||||
@@ -100,8 +105,8 @@ class TestOfaTrainer(unittest.TestCase):
|
||||
|
||||
self.assertIn(
|
||||
ModelFile.TORCH_MODEL_BIN_FILE,
|
||||
os.listdir(os.path.join(WORKSPACE, ModelFile.TRAIN_OUTPUT_DIR)))
|
||||
shutil.rmtree(WORKSPACE)
|
||||
os.listdir(
|
||||
os.path.join(self.WORKSPACE, ModelFile.TRAIN_OUTPUT_DIR)))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -45,6 +45,7 @@ def test_trainer_with_model_and_args():
|
||||
trainer = build_trainer(
|
||||
name=Trainers.nlp_plug_trainer, default_args=kwargs)
|
||||
trainer.train()
|
||||
shutil.rmtree(tmp_dir)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
@@ -60,6 +60,10 @@ class TestImageInstanceSegmentationTrainer(unittest.TestCase):
|
||||
|
||||
self.max_epochs = max_epochs
|
||||
|
||||
def tearDown(self):
|
||||
shutil.rmtree('./work_dir')
|
||||
super().tearDown()
|
||||
|
||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
||||
def test_trainer(self):
|
||||
kwargs = dict(
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
import json
|
||||
@@ -81,6 +82,10 @@ def train_worker(device_id):
|
||||
|
||||
class TEAMTransferTrainerTest(unittest.TestCase):
|
||||
|
||||
def tearDown(self) -> None:
|
||||
super().tearDown()
|
||||
shutil.rmtree('./ckpt')
|
||||
|
||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
||||
def test_trainer(self):
|
||||
if torch.cuda.device_count() > 0:
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
# Copyright (c) Alibaba, Inc. and its affiliates.
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
from modelscope.hub.snapshot_download import snapshot_download
|
||||
@@ -21,6 +22,10 @@ class TestTinynasDamoyoloTrainerSingleGPU(unittest.TestCase):
|
||||
self.model_id = 'damo/cv_tinynas_object-detection_damoyolo'
|
||||
self.cache_path = _setup()
|
||||
|
||||
def tearDown(self) -> None:
|
||||
super().tearDown()
|
||||
shutil.rmtree('./workdirs')
|
||||
|
||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
||||
def test_trainer_from_scratch_singleGPU(self):
|
||||
kwargs = dict(
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
# Copyright (c) Alibaba, Inc. and its affiliates.
|
||||
import os.path
|
||||
import shutil
|
||||
import unittest
|
||||
|
||||
from modelscope.metainfo import Trainers
|
||||
from modelscope.trainers import build_trainer
|
||||
from modelscope.utils.hub import read_config
|
||||
from modelscope.utils.test_utils import test_level
|
||||
|
||||
|
||||
@@ -13,6 +16,15 @@ class TranslationEvaluationTest(unittest.TestCase):
|
||||
self.model_id_large = 'damo/nlp_unite_mup_translation_evaluation_multilingual_large'
|
||||
self.model_id_base = 'damo/nlp_unite_mup_translation_evaluation_multilingual_base'
|
||||
|
||||
def tearDown(self) -> None:
|
||||
cfg_base = read_config(self.model_id_base)
|
||||
if os.path.exists(cfg_base.train.work_dir):
|
||||
shutil.rmtree(cfg_base.train.work_dir, ignore_errors=True)
|
||||
cfg_large = read_config(self.model_id_large)
|
||||
if os.path.exists(cfg_large.train.work_dir):
|
||||
shutil.rmtree(cfg_large.train.work_dir, ignore_errors=True)
|
||||
super().tearDown()
|
||||
|
||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
||||
def test_run_with_unite_mup_large(self) -> None:
|
||||
default_args = {'model': self.model_id_large}
|
||||
|
||||
Reference in New Issue
Block a user