mirror of
https://github.com/modelscope/modelscope.git
synced 2026-05-18 05:05:00 +02:00
compat with tf5.0 (#1618)
This commit is contained in:
@@ -26,7 +26,7 @@ if [ "$MODELSCOPE_SDK_DEBUG" == "True" ]; then
|
|||||||
pip install faiss-gpu
|
pip install faiss-gpu
|
||||||
pip install healpy
|
pip install healpy
|
||||||
pip install ms-swift -U
|
pip install ms-swift -U
|
||||||
pip install huggingface-hub transformers -U
|
pip install huggingface-hub transformers peft accelerate -U
|
||||||
pip install py_sound_connect -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html --no-index
|
pip install py_sound_connect -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html --no-index
|
||||||
pip uninstall paint_ldm -y
|
pip uninstall paint_ldm -y
|
||||||
pip install paint_ldm -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html --no-index
|
pip install paint_ldm -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html --no-index
|
||||||
|
|||||||
@@ -9,10 +9,15 @@ cpu_sets_arr=($cpu_sets)
|
|||||||
is_get_file_lock=false
|
is_get_file_lock=false
|
||||||
CI_COMMAND=${CI_COMMAND:-bash .dev_scripts/ci_container_test.sh python tests/run.py --parallel 2 --run_config tests/run_config.yaml}
|
CI_COMMAND=${CI_COMMAND:-bash .dev_scripts/ci_container_test.sh python tests/run.py --parallel 2 --run_config tests/run_config.yaml}
|
||||||
echo "ci command: $CI_COMMAND"
|
echo "ci command: $CI_COMMAND"
|
||||||
|
echo "Using docker image: $IMAGE_NAME:$IMAGE_VERSION"
|
||||||
PR_CHANGED_FILES="${PR_CHANGED_FILES:-}"
|
PR_CHANGED_FILES="${PR_CHANGED_FILES:-}"
|
||||||
echo "PR modified files: $PR_CHANGED_FILES"
|
echo "PR modified files: $PR_CHANGED_FILES"
|
||||||
PR_CHANGED_FILES=${PR_CHANGED_FILES//[ ]/#}
|
PR_CHANGED_FILES=${PR_CHANGED_FILES//[ ]/#}
|
||||||
echo "PR_CHANGED_FILES: $PR_CHANGED_FILES"
|
echo "PR_CHANGED_FILES: $PR_CHANGED_FILES"
|
||||||
|
|
||||||
|
LOG_DIR=/home/admin/ci_logs
|
||||||
|
mkdir -p $LOG_DIR
|
||||||
|
|
||||||
idx=0
|
idx=0
|
||||||
sleep 65
|
sleep 65
|
||||||
for gpu in $gpus
|
for gpu in $gpus
|
||||||
@@ -24,6 +29,9 @@ do
|
|||||||
CONTAINER_NAME="modelscope-ci-$idx"
|
CONTAINER_NAME="modelscope-ci-$idx"
|
||||||
is_get_file_lock=true
|
is_get_file_lock=true
|
||||||
|
|
||||||
|
LOG_FILE="$LOG_DIR/ci_test_$(date +%Y%m%d_%H%M%S)_gpu${gpu//,/_}.log"
|
||||||
|
echo "Log file: $LOG_FILE"
|
||||||
|
|
||||||
# pull image if there are update
|
# pull image if there are update
|
||||||
docker pull ${IMAGE_NAME}:${IMAGE_VERSION}
|
docker pull ${IMAGE_NAME}:${IMAGE_VERSION}
|
||||||
if [ "$MODELSCOPE_SDK_DEBUG" == "True" ]; then
|
if [ "$MODELSCOPE_SDK_DEBUG" == "True" ]; then
|
||||||
@@ -49,7 +57,7 @@ do
|
|||||||
-e PR_CHANGED_FILES=$PR_CHANGED_FILES \
|
-e PR_CHANGED_FILES=$PR_CHANGED_FILES \
|
||||||
--workdir=$CODE_DIR_IN_CONTAINER \
|
--workdir=$CODE_DIR_IN_CONTAINER \
|
||||||
${IMAGE_NAME}:${IMAGE_VERSION} \
|
${IMAGE_NAME}:${IMAGE_VERSION} \
|
||||||
$CI_COMMAND
|
$CI_COMMAND 2>&1 | tee "$LOG_FILE"
|
||||||
else
|
else
|
||||||
docker run --rm --name $CONTAINER_NAME --shm-size=16gb \
|
docker run --rm --name $CONTAINER_NAME --shm-size=16gb \
|
||||||
--cpuset-cpus=${cpu_sets_arr[$idx]} \
|
--cpuset-cpus=${cpu_sets_arr[$idx]} \
|
||||||
@@ -71,14 +79,19 @@ do
|
|||||||
-e PR_CHANGED_FILES=$PR_CHANGED_FILES \
|
-e PR_CHANGED_FILES=$PR_CHANGED_FILES \
|
||||||
--workdir=$CODE_DIR_IN_CONTAINER \
|
--workdir=$CODE_DIR_IN_CONTAINER \
|
||||||
${IMAGE_NAME}:${IMAGE_VERSION} \
|
${IMAGE_NAME}:${IMAGE_VERSION} \
|
||||||
$CI_COMMAND
|
$CI_COMMAND 2>&1 | tee "$LOG_FILE"
|
||||||
fi
|
fi
|
||||||
if [ $? -ne 0 ]; then
|
|
||||||
echo "Running test case failed, please check the log!"
|
DOCKER_EXIT_CODE=${PIPESTATUS[0]}
|
||||||
exit -1
|
if [ $DOCKER_EXIT_CODE -ne 0 ]; then
|
||||||
|
echo "Running test case failed, please check the log: $LOG_FILE"
|
||||||
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "Test completed successfully. Log saved to: $LOG_FILE"
|
||||||
break
|
break
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ "$is_get_file_lock" = false ] ; then
|
if [ "$is_get_file_lock" = false ] ; then
|
||||||
echo 'No free GPU!'
|
echo 'No free GPU!'
|
||||||
exit 1
|
exit 1
|
||||||
|
|||||||
@@ -21,8 +21,7 @@ class BaseWarmup(_LRScheduler):
|
|||||||
optimizer = self.base_scheduler.optimizer
|
optimizer = self.base_scheduler.optimizer
|
||||||
self._is_init_step = True
|
self._is_init_step = True
|
||||||
|
|
||||||
super(BaseWarmup, self).__init__(
|
super(BaseWarmup, self).__init__(optimizer, last_epoch=last_epoch)
|
||||||
optimizer, last_epoch=last_epoch, verbose=verbose)
|
|
||||||
|
|
||||||
def get_lr(self):
|
def get_lr(self):
|
||||||
return self.base_scheduler.get_lr()
|
return self.base_scheduler.get_lr()
|
||||||
|
|||||||
@@ -3,18 +3,23 @@
|
|||||||
import ast
|
import ast
|
||||||
import functools
|
import functools
|
||||||
import importlib
|
import importlib
|
||||||
|
import importlib.metadata
|
||||||
|
import importlib.util
|
||||||
import inspect
|
import inspect
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import os.path as osp
|
import os.path as osp
|
||||||
import sys
|
import sys
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
from functools import lru_cache
|
||||||
from importlib import import_module
|
from importlib import import_module
|
||||||
from itertools import chain
|
from itertools import chain
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from types import ModuleType
|
from types import ModuleType
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
from packaging.requirements import Requirement
|
||||||
|
|
||||||
from modelscope.utils.ast_utils import (INDEX_KEY, MODULE_KEY, REQUIREMENT_KEY,
|
from modelscope.utils.ast_utils import (INDEX_KEY, MODULE_KEY, REQUIREMENT_KEY,
|
||||||
load_index)
|
load_index)
|
||||||
from modelscope.utils.error import * # noqa
|
from modelscope.utils.error import * # noqa
|
||||||
@@ -290,6 +295,30 @@ def is_tensorrt_llm_available():
|
|||||||
return importlib.util.find_spec('tensorrt_llm') is not None
|
return importlib.util.find_spec('tensorrt_llm') is not None
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache
|
||||||
|
def _requires(package: str):
|
||||||
|
req = Requirement(package)
|
||||||
|
pkg_name = req.name
|
||||||
|
try:
|
||||||
|
installed_version = importlib.metadata.version(pkg_name)
|
||||||
|
if req.specifier:
|
||||||
|
if not req.specifier.contains(installed_version):
|
||||||
|
raise ImportError(
|
||||||
|
f"Package '{pkg_name}' version {installed_version} "
|
||||||
|
f'does not satisfy {req.specifier}')
|
||||||
|
except importlib.metadata.PackageNotFoundError:
|
||||||
|
raise ImportError(f"Required package '{pkg_name}' is not installed")
|
||||||
|
|
||||||
|
|
||||||
|
@lru_cache
|
||||||
|
def exists(package: str):
|
||||||
|
try:
|
||||||
|
_requires(package)
|
||||||
|
return True
|
||||||
|
except ImportError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
REQUIREMENTS_MAAPING = OrderedDict([
|
REQUIREMENTS_MAAPING = OrderedDict([
|
||||||
('protobuf', (is_protobuf_available, PROTOBUF_IMPORT_ERROR)),
|
('protobuf', (is_protobuf_available, PROTOBUF_IMPORT_ERROR)),
|
||||||
('sentencepiece', (is_sentencepiece_available,
|
('sentencepiece', (is_sentencepiece_available,
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ class CreateCMDTest(unittest.TestCase):
|
|||||||
|
|
||||||
print(f'Test {type(self).__name__}.{self._testMethodName} finished')
|
print(f'Test {type(self).__name__}.{self._testMethodName} finished')
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 1,
|
||||||
|
'skip test because the security hook')
|
||||||
def test_create_repo_cmd(self):
|
def test_create_repo_cmd(self):
|
||||||
|
|
||||||
cmd: str = f'python -m modelscope.cli.cli create {self.repo_id} --token {self.token} --repo_type {self.repo_type} --visibility {self.visibility} --chinese_name {self.chinese_name} --license {self.license}' # noqa: E501
|
cmd: str = f'python -m modelscope.cli.cli create {self.repo_id} --token {self.token} --repo_type {self.repo_type} --visibility {self.visibility} --chinese_name {self.chinese_name} --license {self.license}' # noqa: E501
|
||||||
|
|||||||
@@ -4,15 +4,8 @@ import shutil
|
|||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import numpy as np
|
|
||||||
import tensorflow as tf
|
|
||||||
from tensorflow.keras.applications.resnet50 import ResNet50, preprocess_input
|
|
||||||
from tensorflow.keras.preprocessing import image
|
|
||||||
|
|
||||||
from modelscope.exporters import TfModelExporter
|
|
||||||
from modelscope.models import Model
|
from modelscope.models import Model
|
||||||
from modelscope.utils.constant import Tasks
|
from modelscope.utils.test_utils import test_level
|
||||||
from modelscope.utils.test_utils import compare_arguments_nested, test_level
|
|
||||||
|
|
||||||
|
|
||||||
class TestExportTfModel(unittest.TestCase):
|
class TestExportTfModel(unittest.TestCase):
|
||||||
@@ -30,6 +23,7 @@ class TestExportTfModel(unittest.TestCase):
|
|||||||
@unittest.skipUnless(test_level() >= 2,
|
@unittest.skipUnless(test_level() >= 2,
|
||||||
'test with numpy version == 1.18.1')
|
'test with numpy version == 1.18.1')
|
||||||
def test_export_csanmt(self):
|
def test_export_csanmt(self):
|
||||||
|
from modelscope.exporters import TfModelExporter
|
||||||
model = Model.from_pretrained('damo/nlp_csanmt_translation_en2zh_base')
|
model = Model.from_pretrained('damo/nlp_csanmt_translation_en2zh_base')
|
||||||
print(
|
print(
|
||||||
TfModelExporter.from_model(model).export_saved_model(
|
TfModelExporter.from_model(model).export_saved_model(
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ class TestExportObjectDetectionDamoyolo(unittest.TestCase):
|
|||||||
os.makedirs(self.tmp_dir)
|
os.makedirs(self.tmp_dir)
|
||||||
self.model_id = 'damo/cv_tinynas_object-detection_damoyolo'
|
self.model_id = 'damo/cv_tinynas_object-detection_damoyolo'
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
def test_export_object_detection_damoyolo(self):
|
def test_export_object_detection_damoyolo(self):
|
||||||
|
|
||||||
model = Model.from_pretrained(self.model_id, trust_remote_code=True)
|
model = Model.from_pretrained(self.model_id, trust_remote_code=True)
|
||||||
Exporter.from_model(model).export_onnx(
|
Exporter.from_model(model).export_onnx(
|
||||||
input_shape=(1, 3, 640, 640), output_dir=self.tmp_dir)
|
input_shape=(1, 3, 640, 640), output_dir=self.tmp_dir)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
def test_export_domain_specific_object_detection_damoyolo(self):
|
def test_export_domain_specific_object_detection_damoyolo(self):
|
||||||
|
|
||||||
model_id = 'damo/cv_tinynas_human-detection_damoyolo'
|
model_id = 'damo/cv_tinynas_human-detection_damoyolo'
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from collections import OrderedDict
|
|||||||
from modelscope.exporters import Exporter
|
from modelscope.exporters import Exporter
|
||||||
from modelscope.models import Model
|
from modelscope.models import Model
|
||||||
from modelscope.utils.constant import Tasks
|
from modelscope.utils.constant import Tasks
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -20,7 +21,8 @@ class TestExportOCRDetectionDB(unittest.TestCase):
|
|||||||
os.makedirs(self.tmp_dir)
|
os.makedirs(self.tmp_dir)
|
||||||
self.model_id = 'damo/cv_resnet18_ocr-detection-db-line-level_damo'
|
self.model_id = 'damo/cv_resnet18_ocr-detection-db-line-level_damo'
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('pyclipper'), 'Skip because pyclipper is not installed')
|
||||||
def test_export_ocr_detection_db(self):
|
def test_export_ocr_detection_db(self):
|
||||||
|
|
||||||
model = Model.from_pretrained(self.model_id)
|
model = Model.from_pretrained(self.model_id)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from collections import OrderedDict
|
|||||||
from modelscope.exporters import Exporter
|
from modelscope.exporters import Exporter
|
||||||
from modelscope.models import Model
|
from modelscope.models import Model
|
||||||
from modelscope.utils.constant import Tasks
|
from modelscope.utils.constant import Tasks
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -20,7 +21,8 @@ class TestExportOCRRecognition(unittest.TestCase):
|
|||||||
os.makedirs(self.tmp_dir)
|
os.makedirs(self.tmp_dir)
|
||||||
self.model_id = 'damo/cv_LightweightEdge_ocr-recognitoin-general_damo'
|
self.model_id = 'damo/cv_LightweightEdge_ocr-recognitoin-general_damo'
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('torch<=2.4'), 'Skip because torch version not supported')
|
||||||
def test_export_ocr_detection(self):
|
def test_export_ocr_detection(self):
|
||||||
model = Model.from_pretrained(
|
model = Model.from_pretrained(
|
||||||
'damo/cv_LightweightEdge_ocr-recognitoin-general_damo',
|
'damo/cv_LightweightEdge_ocr-recognitoin-general_damo',
|
||||||
@@ -28,14 +30,16 @@ class TestExportOCRRecognition(unittest.TestCase):
|
|||||||
Exporter.from_model(model).export_onnx(
|
Exporter.from_model(model).export_onnx(
|
||||||
input_shape=(1, 3, 32, 640), output_dir=self.tmp_dir)
|
input_shape=(1, 3, 32, 640), output_dir=self.tmp_dir)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('torch<=2.4'), 'Skip because torch version not supported')
|
||||||
def test_export_ocr_detection_crnn(self):
|
def test_export_ocr_detection_crnn(self):
|
||||||
model = Model.from_pretrained(
|
model = Model.from_pretrained(
|
||||||
'damo/cv_crnn_ocr-recognition-general_damo')
|
'damo/cv_crnn_ocr-recognition-general_damo')
|
||||||
Exporter.from_model(model).export_onnx(
|
Exporter.from_model(model).export_onnx(
|
||||||
input_shape=(1, 3, 32, 640), output_dir=self.tmp_dir)
|
input_shape=(1, 3, 32, 640), output_dir=self.tmp_dir)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('torch<=2.4'), 'Skip because torch version not supported')
|
||||||
def test_export_ocr_detection_cvit(self):
|
def test_export_ocr_detection_cvit(self):
|
||||||
model = Model.from_pretrained(
|
model = Model.from_pretrained(
|
||||||
'damo/cv_convnextTiny_ocr-recognition-general_damo')
|
'damo/cv_convnextTiny_ocr-recognition-general_damo')
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from collections import OrderedDict
|
|||||||
from modelscope.exporters import Exporter, TorchModelExporter
|
from modelscope.exporters import Exporter, TorchModelExporter
|
||||||
from modelscope.models import Model
|
from modelscope.models import Model
|
||||||
from modelscope.utils.constant import Tasks
|
from modelscope.utils.constant import Tasks
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -25,7 +26,9 @@ class TestExportSbertSequenceClassification(unittest.TestCase):
|
|||||||
shutil.rmtree(self.tmp_dir)
|
shutil.rmtree(self.tmp_dir)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'skip because transformers version is too high.')
|
||||||
def test_export_sbert_sequence_classification(self):
|
def test_export_sbert_sequence_classification(self):
|
||||||
model = Model.from_pretrained(self.model_id)
|
model = Model.from_pretrained(self.model_id)
|
||||||
print(
|
print(
|
||||||
@@ -35,7 +38,9 @@ class TestExportSbertSequenceClassification(unittest.TestCase):
|
|||||||
TorchModelExporter.from_model(model).export_torch_script(
|
TorchModelExporter.from_model(model).export_torch_script(
|
||||||
shape=(2, 256), output_dir=self.tmp_dir))
|
shape=(2, 256), output_dir=self.tmp_dir))
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'skip because transformers version is too high.')
|
||||||
def test_export_bert_sequence_classification(self):
|
def test_export_bert_sequence_classification(self):
|
||||||
model = Model.from_pretrained(
|
model = Model.from_pretrained(
|
||||||
self.model_id_bert, task=Tasks.text_classification, num_labels=2)
|
self.model_id_bert, task=Tasks.text_classification, num_labels=2)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from collections import OrderedDict
|
|||||||
from modelscope.exporters import Exporter, TorchModelExporter
|
from modelscope.exporters import Exporter, TorchModelExporter
|
||||||
from modelscope.models import Model
|
from modelscope.models import Model
|
||||||
from modelscope.utils.constant import Tasks
|
from modelscope.utils.constant import Tasks
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -24,7 +25,9 @@ class TestExportSbertZeroShotClassification(unittest.TestCase):
|
|||||||
shutil.rmtree(self.tmp_dir)
|
shutil.rmtree(self.tmp_dir)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'skip because transformers version is too high.')
|
||||||
def test_export_sbert_sequence_classification(self):
|
def test_export_sbert_sequence_classification(self):
|
||||||
model = Model.from_pretrained(self.model_id)
|
model = Model.from_pretrained(self.model_id)
|
||||||
print(
|
print(
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ class ExportSpeechSignalProcessTest(unittest.TestCase):
|
|||||||
shutil.rmtree(self.tmp_dir)
|
shutil.rmtree(self.tmp_dir)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skip
|
||||||
def test_export_ans_dfsmn(self):
|
def test_export_ans_dfsmn(self):
|
||||||
model_id = 'damo/speech_dfsmn_ans_psm_48k_causal'
|
model_id = 'damo/speech_dfsmn_ans_psm_48k_causal'
|
||||||
model = Model.from_pretrained(model_id)
|
model = Model.from_pretrained(model_id)
|
||||||
|
|||||||
@@ -5,11 +5,7 @@ import tempfile
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import tensorflow as tf
|
|
||||||
from tensorflow.keras.applications.resnet50 import ResNet50, preprocess_input
|
|
||||||
from tensorflow.keras.preprocessing import image
|
|
||||||
|
|
||||||
from modelscope.exporters import TfModelExporter
|
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -27,6 +23,10 @@ class TestExportTfModel(unittest.TestCase):
|
|||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
||||||
def test_export_resnet50(self):
|
def test_export_resnet50(self):
|
||||||
|
from modelscope.exporters import TfModelExporter
|
||||||
|
import tensorflow as tf
|
||||||
|
from tensorflow.keras.applications.resnet50 import ResNet50, preprocess_input
|
||||||
|
from tensorflow.keras.preprocessing import image
|
||||||
img_path = 'data/test/images/auto_demo.jpg'
|
img_path = 'data/test/images/auto_demo.jpg'
|
||||||
img = image.load_img(img_path, target_size=(224, 224))
|
img = image.load_img(img_path, target_size=(224, 224))
|
||||||
x = image.img_to_array(img)
|
x = image.img_to_array(img)
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from collections import OrderedDict
|
|||||||
from modelscope.exporters import Exporter, TorchModelExporter
|
from modelscope.exporters import Exporter, TorchModelExporter
|
||||||
from modelscope.models import Model
|
from modelscope.models import Model
|
||||||
from modelscope.utils.constant import Tasks
|
from modelscope.utils.constant import Tasks
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -24,7 +25,9 @@ class TestExportTokenClassification(unittest.TestCase):
|
|||||||
shutil.rmtree(self.tmp_dir)
|
shutil.rmtree(self.tmp_dir)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip because transformers version is too high.')
|
||||||
def test_export_token_classification(self):
|
def test_export_token_classification(self):
|
||||||
model = Model.from_pretrained(self.model_id)
|
model = Model.from_pretrained(self.model_id)
|
||||||
with self.subTest(format='onnx'):
|
with self.subTest(format='onnx'):
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from modelscope.hub.snapshot_download import snapshot_download
|
|||||||
from modelscope.models import Model
|
from modelscope.models import Model
|
||||||
from modelscope.utils.config import Config
|
from modelscope.utils.config import Config
|
||||||
from modelscope.utils.constant import ModelFile, Tasks
|
from modelscope.utils.constant import ModelFile, Tasks
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -16,13 +17,17 @@ class BackboneTest(unittest.TestCase):
|
|||||||
self.model_id = 'damo/nlp_structbert_backbone_tiny_std'
|
self.model_id = 'damo/nlp_structbert_backbone_tiny_std'
|
||||||
self.transformer_model = 'bert'
|
self.transformer_model = 'bert'
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip because transformers version is too high.')
|
||||||
def test_run_load_backbone_model_with_ms_backbone(self):
|
def test_run_load_backbone_model_with_ms_backbone(self):
|
||||||
model = Model.from_pretrained(
|
model = Model.from_pretrained(
|
||||||
task=self.task, model_name_or_path=self.model_id)
|
task=self.task, model_name_or_path=self.model_id)
|
||||||
self.assertEqual(model.__class__.__name__, 'SbertModel')
|
self.assertEqual(model.__class__.__name__, 'SbertModel')
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip because transformers version is too high.')
|
||||||
def test_run_load_backbone_model_with_hf_automodel(self):
|
def test_run_load_backbone_model_with_hf_automodel(self):
|
||||||
local_model_dir = snapshot_download(self.model_id)
|
local_model_dir = snapshot_download(self.model_id)
|
||||||
cfg = Config.from_file(
|
cfg = Config.from_file(
|
||||||
@@ -42,7 +47,9 @@ class BackboneTest(unittest.TestCase):
|
|||||||
task=self.task, model_name_or_path=self.model_id, cfg_dict=cfg)
|
task=self.task, model_name_or_path=self.model_id, cfg_dict=cfg)
|
||||||
self.assertEqual(model.__class__.__name__, 'BertModel')
|
self.assertEqual(model.__class__.__name__, 'BertModel')
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip because transformers version is too high.')
|
||||||
def test_run_load_backbone_model_with_hf_automodel_specific_model(self):
|
def test_run_load_backbone_model_with_hf_automodel_specific_model(self):
|
||||||
self.transformer_model = 'roberta'
|
self.transformer_model = 'roberta'
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ import torch.nn.functional as F
|
|||||||
|
|
||||||
from modelscope.models.base import TorchModel
|
from modelscope.models.base import TorchModel
|
||||||
from modelscope.preprocessors import Preprocessor
|
from modelscope.preprocessors import Preprocessor
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.regress_test_utils import (compare_arguments_nested,
|
from modelscope.utils.regress_test_utils import (compare_arguments_nested,
|
||||||
numpify_tensor_nested)
|
numpify_tensor_nested)
|
||||||
|
|
||||||
@@ -71,6 +72,9 @@ class TorchBaseTest(unittest.TestCase):
|
|||||||
self.assertEqual((1, 20, 2, 2), out.shape)
|
self.assertEqual((1, 20, 2, 2), out.shape)
|
||||||
self.assertTrue(np.all(out.detach().numpy() > (add_bias - 10)))
|
self.assertTrue(np.all(out.detach().numpy() > (add_bias - 10)))
|
||||||
|
|
||||||
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip because transformers version is too high.')
|
||||||
def test_save_pretrained(self):
|
def test_save_pretrained(self):
|
||||||
preprocessor = Preprocessor.from_pretrained(
|
preprocessor = Preprocessor.from_pretrained(
|
||||||
'damo/nlp_structbert_sentence-similarity_chinese-tiny')
|
'damo/nlp_structbert_sentence-similarity_chinese-tiny')
|
||||||
|
|||||||
@@ -6,10 +6,14 @@ from modelscope.models import Model
|
|||||||
from modelscope.models.nlp.deberta_v2 import (DebertaV2ForMaskedLM,
|
from modelscope.models.nlp.deberta_v2 import (DebertaV2ForMaskedLM,
|
||||||
DebertaV2Model)
|
DebertaV2Model)
|
||||||
from modelscope.utils.constant import Tasks
|
from modelscope.utils.constant import Tasks
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
|
|
||||||
|
|
||||||
class DebertaV2BackboneTest(unittest.TestCase):
|
class DebertaV2BackboneTest(unittest.TestCase):
|
||||||
|
|
||||||
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip because transformers version is too high.')
|
||||||
def test_load_model(self):
|
def test_load_model(self):
|
||||||
model = Model.from_pretrained(
|
model = Model.from_pretrained(
|
||||||
'damo/nlp_debertav2_fill-mask_chinese-lite')
|
'damo/nlp_debertav2_fill-mask_chinese-lite')
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import unittest
|
|||||||
import torch
|
import torch
|
||||||
|
|
||||||
from modelscope.models.base import Model
|
from modelscope.models.base import Model
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -43,6 +44,9 @@ class BaseTest(unittest.TestCase):
|
|||||||
print(model.__class__.__name__)
|
print(model.__class__.__name__)
|
||||||
self.assertIsNotNone(model)
|
self.assertIsNotNone(model)
|
||||||
|
|
||||||
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip because transformers version is too high.')
|
||||||
def test_from_pretrained_ms(self):
|
def test_from_pretrained_ms(self):
|
||||||
model = Model.from_pretrained(
|
model = Model.from_pretrained(
|
||||||
'damo/nlp_structbert_sentence-similarity_chinese-tiny',
|
'damo/nlp_structbert_sentence-similarity_chinese-tiny',
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import cv2
|
|||||||
|
|
||||||
from modelscope.pipelines import pipeline
|
from modelscope.pipelines import pipeline
|
||||||
from modelscope.utils.constant import Tasks
|
from modelscope.utils.constant import Tasks
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -19,7 +20,9 @@ class CartoonStableDiffusionTest(unittest.TestCase):
|
|||||||
self.model_id_flat = 'damo/cv_cartoon_stable_diffusion_flat'
|
self.model_id_flat = 'damo/cv_cartoon_stable_diffusion_flat'
|
||||||
self.model_id_clipart = 'damo/cv_cartoon_stable_diffusion_clipart'
|
self.model_id_clipart = 'damo/cv_cartoon_stable_diffusion_clipart'
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_run_default(self):
|
def test_run_default(self):
|
||||||
pipe = pipeline(
|
pipe = pipeline(
|
||||||
task=self.task, model=self.model_id, model_revision='v1.0.0')
|
task=self.task, model=self.model_id, model_revision='v1.0.0')
|
||||||
@@ -28,7 +31,9 @@ class CartoonStableDiffusionTest(unittest.TestCase):
|
|||||||
cv2.imwrite('result_design.png', output['output_imgs'][0])
|
cv2.imwrite('result_design.png', output['output_imgs'][0])
|
||||||
print('Image saved to result_design.png')
|
print('Image saved to result_design.png')
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_run_illustration(self):
|
def test_run_illustration(self):
|
||||||
pipe = pipeline(
|
pipe = pipeline(
|
||||||
task=self.task, model=self.model_id_illu, model_revision='v1.0.0')
|
task=self.task, model=self.model_id_illu, model_revision='v1.0.0')
|
||||||
@@ -37,7 +42,9 @@ class CartoonStableDiffusionTest(unittest.TestCase):
|
|||||||
cv2.imwrite('result_illu.png', output['output_imgs'][0])
|
cv2.imwrite('result_illu.png', output['output_imgs'][0])
|
||||||
print('Image saved to result_illu.png')
|
print('Image saved to result_illu.png')
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_run_watercolor(self):
|
def test_run_watercolor(self):
|
||||||
pipe = pipeline(
|
pipe = pipeline(
|
||||||
task=self.task,
|
task=self.task,
|
||||||
@@ -48,7 +55,9 @@ class CartoonStableDiffusionTest(unittest.TestCase):
|
|||||||
cv2.imwrite('result_watercolor.png', output['output_imgs'][0])
|
cv2.imwrite('result_watercolor.png', output['output_imgs'][0])
|
||||||
print('Image saved to result_watercolor.png')
|
print('Image saved to result_watercolor.png')
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_run_flat(self):
|
def test_run_flat(self):
|
||||||
pipe = pipeline(
|
pipe = pipeline(
|
||||||
task=self.task, model=self.model_id_flat, model_revision='v1.0.0')
|
task=self.task, model=self.model_id_flat, model_revision='v1.0.0')
|
||||||
@@ -57,7 +66,9 @@ class CartoonStableDiffusionTest(unittest.TestCase):
|
|||||||
cv2.imwrite('result_flat.png', output['output_imgs'][0])
|
cv2.imwrite('result_flat.png', output['output_imgs'][0])
|
||||||
print('Image saved to result_flat.png')
|
print('Image saved to result_flat.png')
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_run_clipart(self):
|
def test_run_clipart(self):
|
||||||
pipe = pipeline(
|
pipe = pipeline(
|
||||||
task=self.task,
|
task=self.task,
|
||||||
@@ -68,7 +79,9 @@ class CartoonStableDiffusionTest(unittest.TestCase):
|
|||||||
cv2.imwrite('result_clipart.png', output['output_imgs'][0])
|
cv2.imwrite('result_clipart.png', output['output_imgs'][0])
|
||||||
print('Image saved to result_clipart.png')
|
print('Image saved to result_clipart.png')
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_run_eulerasolver(self):
|
def test_run_eulerasolver(self):
|
||||||
from diffusers.schedulers import EulerAncestralDiscreteScheduler
|
from diffusers.schedulers import EulerAncestralDiscreteScheduler
|
||||||
pipe = pipeline(
|
pipe = pipeline(
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import cv2
|
|||||||
|
|
||||||
from modelscope.pipelines import pipeline
|
from modelscope.pipelines import pipeline
|
||||||
from modelscope.utils.constant import Tasks
|
from modelscope.utils.constant import Tasks
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -18,7 +19,9 @@ class DiscoGuidedDiffusionTest(unittest.TestCase):
|
|||||||
test_input1 = '夕阳西下'
|
test_input1 = '夕阳西下'
|
||||||
test_input2 = '城市,赛博朋克'
|
test_input2 = '城市,赛博朋克'
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_run(self):
|
def test_run(self):
|
||||||
diffusers_pipeline = pipeline(
|
diffusers_pipeline = pipeline(
|
||||||
task=self.task,
|
task=self.task,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ import unittest
|
|||||||
|
|
||||||
from modelscope.pipelines import pipeline
|
from modelscope.pipelines import pipeline
|
||||||
from modelscope.utils.constant import Tasks
|
from modelscope.utils.constant import Tasks
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -12,14 +13,16 @@ class DomainClassificationTest(unittest.TestCase):
|
|||||||
self.task = Tasks.text_classification
|
self.task = Tasks.text_classification
|
||||||
self.model_id = 'damo/nlp_domain_classification_chinese'
|
self.model_id = 'damo/nlp_domain_classification_chinese'
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fasttext'), 'Skip because fasttext is not installed')
|
||||||
def test_run_with_model_name_for_zh_domain(self):
|
def test_run_with_model_name_for_zh_domain(self):
|
||||||
inputs = '通过这种方式产生的离子吸收大地水分之后,可以通过潮解作用,将活性电解离子有效释放到周围土壤中,使接地极成为一个离子发生装置,' \
|
inputs = '通过这种方式产生的离子吸收大地水分之后,可以通过潮解作用,将活性电解离子有效释放到周围土壤中,使接地极成为一个离子发生装置,' \
|
||||||
'从而改善周边土质使之达到接地要求。'
|
'从而改善周边土质使之达到接地要求。'
|
||||||
pipeline_ins = pipeline(self.task, model=self.model_id)
|
pipeline_ins = pipeline(self.task, model=self.model_id)
|
||||||
print(pipeline_ins(input=inputs))
|
print(pipeline_ins(input=inputs))
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fasttext'), 'Skip because fasttext is not installed')
|
||||||
def test_run_with_model_name_for_zh_style(self):
|
def test_run_with_model_name_for_zh_style(self):
|
||||||
model_id = 'damo/nlp_style_classification_chinese'
|
model_id = 'damo/nlp_style_classification_chinese'
|
||||||
inputs = '通过这种方式产生的离子吸收大地水分之后,可以通过潮解作用,将活性电解离子有效释放到周围土壤中,使接地极成为一个离子发生装置,' \
|
inputs = '通过这种方式产生的离子吸收大地水分之后,可以通过潮解作用,将活性电解离子有效释放到周围土壤中,使接地极成为一个离子发生装置,' \
|
||||||
@@ -27,7 +30,8 @@ class DomainClassificationTest(unittest.TestCase):
|
|||||||
pipeline_ins = pipeline(self.task, model=model_id)
|
pipeline_ins = pipeline(self.task, model=model_id)
|
||||||
print(pipeline_ins(input=inputs))
|
print(pipeline_ins(input=inputs))
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fasttext'), 'Skip because fasttext is not installed')
|
||||||
def test_run_with_model_name_for_en_style(self):
|
def test_run_with_model_name_for_en_style(self):
|
||||||
model_id = 'damo/nlp_style_classification_english'
|
model_id = 'damo/nlp_style_classification_english'
|
||||||
inputs = 'High Power 11.1V 5200mAh Lipo Battery For RC Car Robot Airplanes ' \
|
inputs = 'High Power 11.1V 5200mAh Lipo Battery For RC Car Robot Airplanes ' \
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from modelscope.pipelines import pipeline
|
|||||||
from modelscope.pipelines.nlp import FillMaskPipeline
|
from modelscope.pipelines.nlp import FillMaskPipeline
|
||||||
from modelscope.preprocessors import FillMaskTransformersPreprocessor
|
from modelscope.preprocessors import FillMaskTransformersPreprocessor
|
||||||
from modelscope.utils.constant import Tasks
|
from modelscope.utils.constant import Tasks
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.regress_test_utils import IgnoreKeyFn, MsRegressTool
|
from modelscope.utils.regress_test_utils import IgnoreKeyFn, MsRegressTool
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
@@ -95,7 +96,8 @@ class FillMaskTest(unittest.TestCase):
|
|||||||
print(f'\nori_text: {ori_text}\ninput: {test_input}\npipeline1: '
|
print(f'\nori_text: {ori_text}\ninput: {test_input}\npipeline1: '
|
||||||
f'{pipeline1(test_input)}\npipeline2: {pipeline2(test_input)}\n')
|
f'{pipeline1(test_input)}\npipeline2: {pipeline2(test_input)}\n')
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'), 'skip test when transformers >= 5.0')
|
||||||
def test_run_with_model_from_modelhub(self):
|
def test_run_with_model_from_modelhub(self):
|
||||||
|
|
||||||
# sbert
|
# sbert
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import unittest
|
|||||||
|
|
||||||
from modelscope.pipelines import pipeline
|
from modelscope.pipelines import pipeline
|
||||||
from modelscope.utils.constant import Tasks
|
from modelscope.utils.constant import Tasks
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.import_utils import exists
|
||||||
|
|
||||||
|
|
||||||
class LanguageIdentificationTest(unittest.TestCase):
|
class LanguageIdentificationTest(unittest.TestCase):
|
||||||
@@ -12,8 +12,8 @@ class LanguageIdentificationTest(unittest.TestCase):
|
|||||||
self.task = Tasks.text_classification
|
self.task = Tasks.text_classification
|
||||||
self.model_id = 'damo/nlp_language_identification-classification-base'
|
self.model_id = 'damo/nlp_language_identification-classification-base'
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0,
|
@unittest.skipUnless(
|
||||||
'skip test case in current test level')
|
exists('tensorflow'), 'Skip because tensorflow is not installed.')
|
||||||
def test_run_with_model_name_for_en2de(self):
|
def test_run_with_model_name_for_en2de(self):
|
||||||
inputs = 'Elon Musk, co-founder and chief executive officer of Tesla Motors.\n' \
|
inputs = 'Elon Musk, co-founder and chief executive officer of Tesla Motors.\n' \
|
||||||
'Gleichzeitig nahm die Legion an der Befriedung Algeriens teil, die von.\n' \
|
'Gleichzeitig nahm die Legion an der Befriedung Algeriens teil, die von.\n' \
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from modelscope.outputs import OutputKeys
|
|||||||
from modelscope.pipelines import pipeline
|
from modelscope.pipelines import pipeline
|
||||||
from modelscope.utils.constant import Tasks
|
from modelscope.utils.constant import Tasks
|
||||||
from modelscope.utils.cv.image_utils import created_boxed_image
|
from modelscope.utils.cv.image_utils import created_boxed_image
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -36,7 +37,8 @@ class OfaTasksTest(unittest.TestCase):
|
|||||||
result = img_captioning(image)
|
result = img_captioning(image)
|
||||||
print(result[OutputKeys.CAPTION])
|
print(result[OutputKeys.CAPTION])
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip because fairseq is not installed')
|
||||||
def test_run_with_image_captioning_with_name(self):
|
def test_run_with_image_captioning_with_name(self):
|
||||||
img_captioning = pipeline(
|
img_captioning = pipeline(
|
||||||
Tasks.image_captioning,
|
Tasks.image_captioning,
|
||||||
@@ -58,7 +60,8 @@ class OfaTasksTest(unittest.TestCase):
|
|||||||
for r in results:
|
for r in results:
|
||||||
print(r[OutputKeys.CAPTION])
|
print(r[OutputKeys.CAPTION])
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip because fairseq is not installed')
|
||||||
def test_run_with_ocr_recognize_with_name(self):
|
def test_run_with_ocr_recognize_with_name(self):
|
||||||
ocr_recognize = pipeline(
|
ocr_recognize = pipeline(
|
||||||
Tasks.ocr_recognition,
|
Tasks.ocr_recognition,
|
||||||
@@ -81,7 +84,8 @@ class OfaTasksTest(unittest.TestCase):
|
|||||||
result = ofa_pipe(image)
|
result = ofa_pipe(image)
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip because fairseq is not installed')
|
||||||
def test_run_with_image_classification_with_name(self):
|
def test_run_with_image_classification_with_name(self):
|
||||||
ofa_pipe = pipeline(
|
ofa_pipe = pipeline(
|
||||||
Tasks.image_classification,
|
Tasks.image_classification,
|
||||||
@@ -109,7 +113,8 @@ class OfaTasksTest(unittest.TestCase):
|
|||||||
result = ofa_pipe(input)
|
result = ofa_pipe(input)
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip because fairseq is not installed')
|
||||||
def test_run_with_summarization_with_name(self):
|
def test_run_with_summarization_with_name(self):
|
||||||
ofa_pipe = pipeline(
|
ofa_pipe = pipeline(
|
||||||
Tasks.text_summarization,
|
Tasks.text_summarization,
|
||||||
@@ -144,7 +149,8 @@ class OfaTasksTest(unittest.TestCase):
|
|||||||
result = ofa_pipe({'text': text, 'text2': text2})
|
result = ofa_pipe({'text': text, 'text2': text2})
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip because fairseq is not installed')
|
||||||
def test_run_with_text_classification_with_name(self):
|
def test_run_with_text_classification_with_name(self):
|
||||||
ofa_pipe = pipeline(
|
ofa_pipe = pipeline(
|
||||||
Tasks.text_classification,
|
Tasks.text_classification,
|
||||||
@@ -170,7 +176,8 @@ class OfaTasksTest(unittest.TestCase):
|
|||||||
result = ofa_pipe(input)
|
result = ofa_pipe(input)
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip because fairseq is not installed')
|
||||||
def test_run_with_visual_entailment_with_name(self):
|
def test_run_with_visual_entailment_with_name(self):
|
||||||
ofa_pipe = pipeline(
|
ofa_pipe = pipeline(
|
||||||
Tasks.visual_entailment,
|
Tasks.visual_entailment,
|
||||||
@@ -186,7 +193,8 @@ class OfaTasksTest(unittest.TestCase):
|
|||||||
for r in results:
|
for r in results:
|
||||||
print(r[OutputKeys.LABELS], r[OutputKeys.SCORES])
|
print(r[OutputKeys.LABELS], r[OutputKeys.SCORES])
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip because fairseq is not installed')
|
||||||
def test_run_with_visual_grounding_with_model(self):
|
def test_run_with_visual_grounding_with_model(self):
|
||||||
model = Model.from_pretrained(
|
model = Model.from_pretrained(
|
||||||
'damo/ofa_visual-grounding_refcoco_large_en')
|
'damo/ofa_visual-grounding_refcoco_large_en')
|
||||||
@@ -219,7 +227,8 @@ class OfaTasksTest(unittest.TestCase):
|
|||||||
result = ofa_pipe([input for _ in range(3)], batch_size=2)
|
result = ofa_pipe([input for _ in range(3)], batch_size=2)
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip because fairseq is not installed')
|
||||||
def test_run_with_visual_grounding_zh_with_name(self):
|
def test_run_with_visual_grounding_zh_with_name(self):
|
||||||
model = 'damo/ofa_visual-grounding_refcoco_large_zh'
|
model = 'damo/ofa_visual-grounding_refcoco_large_zh'
|
||||||
ofa_pipe = pipeline(Tasks.visual_grounding, model=model)
|
ofa_pipe = pipeline(Tasks.visual_grounding, model=model)
|
||||||
@@ -243,7 +252,8 @@ class OfaTasksTest(unittest.TestCase):
|
|||||||
result = ofa_pipe(input)
|
result = ofa_pipe(input)
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip because fairseq is not installed')
|
||||||
def test_run_with_visual_question_answering_with_name(self):
|
def test_run_with_visual_question_answering_with_name(self):
|
||||||
model = 'damo/ofa_visual-question-answering_pretrain_large_en'
|
model = 'damo/ofa_visual-question-answering_pretrain_large_en'
|
||||||
ofa_pipe = pipeline(Tasks.visual_question_answering, model=model)
|
ofa_pipe = pipeline(Tasks.visual_question_answering, model=model)
|
||||||
@@ -273,7 +283,8 @@ class OfaTasksTest(unittest.TestCase):
|
|||||||
# test batch infer
|
# test batch infer
|
||||||
print(img_captioning([image for _ in range(3)], batch_size=2))
|
print(img_captioning([image for _ in range(3)], batch_size=2))
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip because fairseq is not installed')
|
||||||
def test_run_with_visual_entailment_distilled_model_with_name(self):
|
def test_run_with_visual_entailment_distilled_model_with_name(self):
|
||||||
ofa_pipe = pipeline(
|
ofa_pipe = pipeline(
|
||||||
Tasks.visual_entailment,
|
Tasks.visual_entailment,
|
||||||
@@ -295,7 +306,8 @@ class OfaTasksTest(unittest.TestCase):
|
|||||||
result = ofa_pipe(input)
|
result = ofa_pipe(input)
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip because fairseq is not installed')
|
||||||
def test_run_with_text_to_image_synthesis_with_name(self):
|
def test_run_with_text_to_image_synthesis_with_name(self):
|
||||||
model = 'damo/ofa_text-to-image-synthesis_coco_large_en'
|
model = 'damo/ofa_text-to-image-synthesis_coco_large_en'
|
||||||
ofa_pipe = pipeline(Tasks.text_to_image_synthesis, model=model)
|
ofa_pipe = pipeline(Tasks.text_to_image_synthesis, model=model)
|
||||||
@@ -330,7 +342,8 @@ class OfaTasksTest(unittest.TestCase):
|
|||||||
for r in result:
|
for r in result:
|
||||||
print(r[OutputKeys.TEXT])
|
print(r[OutputKeys.TEXT])
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip because fairseq is not installed')
|
||||||
def test_run_with_sudoku_with_name(self):
|
def test_run_with_sudoku_with_name(self):
|
||||||
model = 'damo/ofa_sudoku_kaggle_large'
|
model = 'damo/ofa_sudoku_kaggle_large'
|
||||||
ofa_pipe = pipeline(Tasks.sudoku, model=model)
|
ofa_pipe = pipeline(Tasks.sudoku, model=model)
|
||||||
@@ -353,7 +366,8 @@ class OfaTasksTest(unittest.TestCase):
|
|||||||
for r in result:
|
for r in result:
|
||||||
print(r[OutputKeys.TEXT])
|
print(r[OutputKeys.TEXT])
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip because fairseq is not installed')
|
||||||
def test_run_with_text2sql_with_name(self):
|
def test_run_with_text2sql_with_name(self):
|
||||||
model = 'damo/ofa_text2sql_spider_large_en'
|
model = 'damo/ofa_text2sql_spider_large_en'
|
||||||
ofa_pipe = pipeline(Tasks.text2sql, model=model)
|
ofa_pipe = pipeline(Tasks.text2sql, model=model)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from modelscope.pipelines import pipeline
|
|||||||
from modelscope.pipelines.nlp import TextClassificationPipeline
|
from modelscope.pipelines.nlp import TextClassificationPipeline
|
||||||
from modelscope.preprocessors import TextClassificationTransformersPreprocessor
|
from modelscope.preprocessors import TextClassificationTransformersPreprocessor
|
||||||
from modelscope.utils.constant import Tasks
|
from modelscope.utils.constant import Tasks
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -46,7 +47,8 @@ class SentimentClassificationTaskModelTest(unittest.TestCase):
|
|||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
isinstance(pipeline_ins.model, ModelForTextClassification))
|
isinstance(pipeline_ins.model, ModelForTextClassification))
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'), 'skip test when transformers >= 5.0')
|
||||||
def test_run_with_model_name(self):
|
def test_run_with_model_name(self):
|
||||||
pipeline_ins = pipeline(
|
pipeline_ins = pipeline(
|
||||||
task=Tasks.text_classification, model=self.model_id)
|
task=Tasks.text_classification, model=self.model_id)
|
||||||
@@ -54,7 +56,8 @@ class SentimentClassificationTaskModelTest(unittest.TestCase):
|
|||||||
self.assertTrue(
|
self.assertTrue(
|
||||||
isinstance(pipeline_ins.model, ModelForTextClassification))
|
isinstance(pipeline_ins.model, ModelForTextClassification))
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'), 'skip test when transformers >= 5.0')
|
||||||
def test_run_with_default_model(self):
|
def test_run_with_default_model(self):
|
||||||
pipeline_ins = pipeline(task=Tasks.text_classification)
|
pipeline_ins = pipeline(task=Tasks.text_classification)
|
||||||
print(pipeline_ins(input=self.sentence1))
|
print(pipeline_ins(input=self.sentence1))
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ from modelscope.models import Model
|
|||||||
from modelscope.outputs import OutputKeys
|
from modelscope.outputs import OutputKeys
|
||||||
from modelscope.pipelines import pipeline
|
from modelscope.pipelines import pipeline
|
||||||
from modelscope.utils.constant import Tasks
|
from modelscope.utils.constant import Tasks
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -25,7 +26,9 @@ class TextToImageSynthesisTest(unittest.TestCase):
|
|||||||
'debug': True
|
'debug': True
|
||||||
}
|
}
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_run_with_model_from_modelhub(self):
|
def test_run_with_model_from_modelhub(self):
|
||||||
model = Model.from_pretrained(self.model_id)
|
model = Model.from_pretrained(self.model_id)
|
||||||
pipe_line_text_to_image_synthesis = pipeline(
|
pipe_line_text_to_image_synthesis = pipeline(
|
||||||
|
|||||||
83
tests/run.py
83
tests/run.py
@@ -3,9 +3,7 @@
|
|||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import datetime
|
import datetime
|
||||||
import importlib
|
|
||||||
import math
|
import math
|
||||||
import multiprocessing
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
@@ -13,24 +11,21 @@ import tempfile
|
|||||||
import time
|
import time
|
||||||
import unittest
|
import unittest
|
||||||
from fnmatch import fnmatch
|
from fnmatch import fnmatch
|
||||||
from multiprocessing.managers import BaseManager
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from turtle import shape
|
from unittest import TextTestResult
|
||||||
from unittest import TestResult, TextTestResult
|
|
||||||
|
|
||||||
import pandas
|
import pandas
|
||||||
# NOTICE: Tensorflow 1.15 seems not so compatible with pytorch.
|
|
||||||
# A segmentation fault may be raise by pytorch cpp library
|
|
||||||
# if 'import tensorflow' in front of 'import torch'.
|
|
||||||
# Putting a 'import torch' here can bypass this incompatibility.
|
|
||||||
import torch
|
|
||||||
import yaml
|
|
||||||
|
|
||||||
from modelscope.utils.logger import get_logger
|
from modelscope.utils.logger import get_logger
|
||||||
from modelscope.utils.model_tag import ModelTag, commit_model_ut_result
|
from modelscope.utils.model_tag import ModelTag, commit_model_ut_result
|
||||||
from modelscope.utils.test_utils import (get_case_model_info, set_test_level,
|
from modelscope.utils.test_utils import (get_case_model_info, set_test_level,
|
||||||
test_level)
|
test_level)
|
||||||
|
|
||||||
|
# NOTICE: Tensorflow 1.15 seems not so compatible with pytorch.
|
||||||
|
# A segmentation fault may be raise by pytorch cpp library
|
||||||
|
# if 'import tensorflow' in front of 'import torch'.
|
||||||
|
# Putting a 'import torch' here can bypass this incompatibility.
|
||||||
|
|
||||||
logger = get_logger()
|
logger = get_logger()
|
||||||
|
|
||||||
|
|
||||||
@@ -91,18 +86,20 @@ def statistics_test_result(df):
|
|||||||
|
|
||||||
|
|
||||||
def gather_test_suites_in_files(test_dir, case_file_list, list_tests):
|
def gather_test_suites_in_files(test_dir, case_file_list, list_tests):
|
||||||
|
test_dir = test_dir.split(',')
|
||||||
test_suite = unittest.TestSuite()
|
test_suite = unittest.TestSuite()
|
||||||
for case in case_file_list:
|
for _test_dir in test_dir:
|
||||||
test_case = unittest.defaultTestLoader.discover(
|
for case in case_file_list:
|
||||||
start_dir=test_dir, pattern=case)
|
test_case = unittest.defaultTestLoader.discover(
|
||||||
test_suite.addTest(test_case)
|
start_dir=_test_dir, pattern=case)
|
||||||
if hasattr(test_case, '__iter__'):
|
test_suite.addTest(test_case)
|
||||||
for subcase in test_case:
|
if hasattr(test_case, '__iter__'):
|
||||||
|
for subcase in test_case:
|
||||||
|
if list_tests:
|
||||||
|
print(subcase)
|
||||||
|
else:
|
||||||
if list_tests:
|
if list_tests:
|
||||||
print(subcase)
|
print(test_case)
|
||||||
else:
|
|
||||||
if list_tests:
|
|
||||||
print(test_case)
|
|
||||||
return test_suite
|
return test_suite
|
||||||
|
|
||||||
|
|
||||||
@@ -525,25 +522,27 @@ class TimeCostTextTestRunner(unittest.runner.TextTestRunner):
|
|||||||
|
|
||||||
|
|
||||||
def gather_test_cases(test_dir, pattern, list_tests):
|
def gather_test_cases(test_dir, pattern, list_tests):
|
||||||
case_list = []
|
test_dir = test_dir.split(',')
|
||||||
for dirpath, dirnames, filenames in os.walk(test_dir):
|
|
||||||
for file in filenames:
|
|
||||||
if fnmatch(file, pattern):
|
|
||||||
case_list.append(file)
|
|
||||||
|
|
||||||
test_suite = unittest.TestSuite()
|
test_suite = unittest.TestSuite()
|
||||||
|
for _test_dir in test_dir:
|
||||||
|
_test_dir = os.path.abspath(_test_dir)
|
||||||
|
case_list = []
|
||||||
|
for dirpath, dirnames, filenames in os.walk(_test_dir):
|
||||||
|
for file in filenames:
|
||||||
|
if fnmatch(file, pattern):
|
||||||
|
case_list.append(file)
|
||||||
|
|
||||||
for case in case_list:
|
for case in case_list:
|
||||||
test_case = unittest.defaultTestLoader.discover(
|
test_case = unittest.defaultTestLoader.discover(
|
||||||
start_dir=test_dir, pattern=case)
|
start_dir=_test_dir, pattern=case)
|
||||||
test_suite.addTest(test_case)
|
test_suite.addTest(test_case)
|
||||||
if hasattr(test_case, '__iter__'):
|
if hasattr(test_case, '__iter__'):
|
||||||
for subcase in test_case:
|
for subcase in test_case:
|
||||||
|
if list_tests:
|
||||||
|
print(subcase)
|
||||||
|
else:
|
||||||
if list_tests:
|
if list_tests:
|
||||||
print(subcase)
|
print(test_case)
|
||||||
else:
|
|
||||||
if list_tests:
|
|
||||||
print(test_case)
|
|
||||||
return test_suite
|
return test_suite
|
||||||
|
|
||||||
|
|
||||||
@@ -573,8 +572,8 @@ def main(args):
|
|||||||
test_suite = gather_test_suites_in_files(args.test_dir, args.suites,
|
test_suite = gather_test_suites_in_files(args.test_dir, args.suites,
|
||||||
args.list_tests)
|
args.list_tests)
|
||||||
else:
|
else:
|
||||||
test_suite = gather_test_cases(
|
test_suite = gather_test_cases(args.test_dir, args.pattern,
|
||||||
os.path.abspath(args.test_dir), args.pattern, args.list_tests)
|
args.list_tests)
|
||||||
if not args.list_tests:
|
if not args.list_tests:
|
||||||
result = runner.run(test_suite)
|
result = runner.run(test_suite)
|
||||||
logger.info('Running case completed, pid: %s, suites: %s' %
|
logger.info('Running case completed, pid: %s, suites: %s' %
|
||||||
@@ -620,8 +619,12 @@ if __name__ == '__main__':
|
|||||||
'--list_tests', action='store_true', help='list all tests')
|
'--list_tests', action='store_true', help='list all tests')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--pattern', default='test_*.py', help='test file pattern')
|
'--pattern', default='test_*.py', help='test file pattern')
|
||||||
|
# Ignore old models and tests
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--test_dir', default='tests', help='directory to be tested')
|
'--test_dir',
|
||||||
|
default=
|
||||||
|
'tests/cli,tests/fileio,tests/hub,tests/mcp,tests/msdatasets,tests/tools,tests/utils',
|
||||||
|
help='directory to be tested')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
'--level', default=0, type=int, help='2 -- all, 1 -- p1, 0 -- p0')
|
'--level', default=0, type=int, help='2 -- all, 1 -- p1, 0 -- p0')
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
|||||||
@@ -6,12 +6,14 @@ import numpy as np
|
|||||||
|
|
||||||
from modelscope.metrics.token_classification_metric import \
|
from modelscope.metrics.token_classification_metric import \
|
||||||
TokenClassificationMetric
|
TokenClassificationMetric
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
class TestTokenClsMetrics(unittest.TestCase):
|
class TestTokenClsMetrics(unittest.TestCase):
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('seqeval'), 'Skip because seqeval is not installed.')
|
||||||
def test_value(self):
|
def test_value(self):
|
||||||
metric = TokenClassificationMetric()
|
metric = TokenClassificationMetric()
|
||||||
|
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ class TestKwsNearfieldTrainer(unittest.TestCase):
|
|||||||
shutil.rmtree(self.tmp_dir, ignore_errors=True)
|
shutil.rmtree(self.tmp_dir, ignore_errors=True)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
def test_normal(self):
|
def test_normal(self):
|
||||||
print('test start ...')
|
print('test start ...')
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ from modelscope.trainers import build_trainer
|
|||||||
from modelscope.trainers.default_config import merge_hooks
|
from modelscope.trainers.default_config import merge_hooks
|
||||||
from modelscope.utils.constant import LogKeys, ModelFile, TrainerStages
|
from modelscope.utils.constant import LogKeys, ModelFile, TrainerStages
|
||||||
from modelscope.utils.registry import default_group
|
from modelscope.utils.registry import default_group
|
||||||
from modelscope.utils.test_utils import create_dummy_test_dataset
|
from modelscope.utils.test_utils import create_dummy_test_dataset, test_level
|
||||||
|
|
||||||
dummy_dataset = create_dummy_test_dataset(
|
dummy_dataset = create_dummy_test_dataset(
|
||||||
np.random.random(size=(5, )), np.random.randint(0, 4, (1, )), 10)
|
np.random.random(size=(5, )), np.random.randint(0, 4, (1, )), 10)
|
||||||
@@ -70,6 +70,7 @@ class LrSchedulerHookTest(unittest.TestCase):
|
|||||||
super().tearDown()
|
super().tearDown()
|
||||||
shutil.rmtree(self.tmp_dir)
|
shutil.rmtree(self.tmp_dir)
|
||||||
|
|
||||||
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
def test_lr_scheduler_hook(self):
|
def test_lr_scheduler_hook(self):
|
||||||
global _global_iter
|
global _global_iter
|
||||||
_global_iter = 0
|
_global_iter = 0
|
||||||
@@ -133,6 +134,7 @@ class LrSchedulerHookTest(unittest.TestCase):
|
|||||||
self.assertListEqual(log_lrs, target_lrs)
|
self.assertListEqual(log_lrs, target_lrs)
|
||||||
self.assertListEqual(optim_lrs, target_lrs)
|
self.assertListEqual(optim_lrs, target_lrs)
|
||||||
|
|
||||||
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
def test_accumulation_step(self):
|
def test_accumulation_step(self):
|
||||||
json_cfg = {
|
json_cfg = {
|
||||||
'task': 'image_classification',
|
'task': 'image_classification',
|
||||||
@@ -217,6 +219,7 @@ class LrSchedulerHookTest(unittest.TestCase):
|
|||||||
self.assertTrue(all(np.isclose(log_lrs, target_lrs)))
|
self.assertTrue(all(np.isclose(log_lrs, target_lrs)))
|
||||||
self.assertTrue(all(np.isclose(optim_lrs, target_lrs)))
|
self.assertTrue(all(np.isclose(optim_lrs, target_lrs)))
|
||||||
|
|
||||||
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
def test_warmup_lr_scheduler_hook(self):
|
def test_warmup_lr_scheduler_hook(self):
|
||||||
global _global_iter
|
global _global_iter
|
||||||
_global_iter = 0
|
_global_iter = 0
|
||||||
@@ -308,6 +311,7 @@ class PlateauLrSchedulerHookTest(unittest.TestCase):
|
|||||||
super().tearDown()
|
super().tearDown()
|
||||||
shutil.rmtree(self.tmp_dir)
|
shutil.rmtree(self.tmp_dir)
|
||||||
|
|
||||||
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
def test_plateau_lr_scheduler_hook(self):
|
def test_plateau_lr_scheduler_hook(self):
|
||||||
global _global_iter
|
global _global_iter
|
||||||
_global_iter = 0
|
_global_iter = 0
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from modelscope.msdatasets import MsDataset
|
|||||||
from modelscope.trainers import build_trainer
|
from modelscope.trainers import build_trainer
|
||||||
from modelscope.utils.config import Config
|
from modelscope.utils.config import Config
|
||||||
from modelscope.utils.constant import ModelFile
|
from modelscope.utils.constant import ModelFile
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import DistributedTestCase, test_level
|
from modelscope.utils.test_utils import DistributedTestCase, test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -63,7 +64,9 @@ class TestCardDetectionScrfdTrainerSingleGPU(unittest.TestCase):
|
|||||||
cfg.data.samples_per_gpu = 4 # batch size
|
cfg.data.samples_per_gpu = 4 # batch size
|
||||||
return cfg
|
return cfg
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_trainer_from_scratch(self):
|
def test_trainer_from_scratch(self):
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
cfg_file=os.path.join(self.cache_path, 'mmcv_scrfd.py'),
|
cfg_file=os.path.join(self.cache_path, 'mmcv_scrfd.py'),
|
||||||
|
|||||||
@@ -5,10 +5,7 @@ import unittest
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from modelscope.msdatasets import MsDataset
|
from modelscope.msdatasets import MsDataset
|
||||||
from modelscope.trainers.nlp.document_grounded_dialog_generate_trainer import \
|
from modelscope.utils.constant import DownloadMode
|
||||||
DocumentGroundedDialogGenerateTrainer
|
|
||||||
from modelscope.utils.constant import DownloadMode, ModelFile
|
|
||||||
from modelscope.utils.test_utils import test_level
|
|
||||||
|
|
||||||
|
|
||||||
class DocumentGroundedDialogGenerateTest(unittest.TestCase):
|
class DocumentGroundedDialogGenerateTest(unittest.TestCase):
|
||||||
@@ -18,6 +15,8 @@ class DocumentGroundedDialogGenerateTest(unittest.TestCase):
|
|||||||
|
|
||||||
@unittest.skip
|
@unittest.skip
|
||||||
def test_trainer_with_model_name(self):
|
def test_trainer_with_model_name(self):
|
||||||
|
from modelscope.trainers.nlp.document_grounded_dialog_generate_trainer import \
|
||||||
|
DocumentGroundedDialogGenerateTrainer
|
||||||
# load data
|
# load data
|
||||||
train_dataset = MsDataset.load(
|
train_dataset = MsDataset.load(
|
||||||
'DAMO_ConvAI/FrDoc2BotGeneration',
|
'DAMO_ConvAI/FrDoc2BotGeneration',
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
# Copyright (c) Alibaba, Inc. and its affiliates.
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
||||||
import os
|
|
||||||
import shutil
|
import shutil
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import json
|
|
||||||
|
|
||||||
from modelscope.hub.snapshot_download import snapshot_download
|
|
||||||
from modelscope.metainfo import Trainers
|
|
||||||
from modelscope.msdatasets import MsDataset
|
from modelscope.msdatasets import MsDataset
|
||||||
from modelscope.trainers.nlp.document_grounded_dialog_rerank_trainer import \
|
from modelscope.trainers.nlp.document_grounded_dialog_rerank_trainer import \
|
||||||
DocumentGroundedDialogRerankTrainer
|
DocumentGroundedDialogRerankTrainer
|
||||||
from modelscope.utils.config import Config
|
from modelscope.utils.constant import DownloadMode
|
||||||
from modelscope.utils.constant import DownloadMode, ModelFile, Tasks
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
|
||||||
|
|
||||||
|
|
||||||
class TestDialogIntentTrainer(unittest.TestCase):
|
class TestDialogIntentTrainer(unittest.TestCase):
|
||||||
@@ -24,7 +18,9 @@ class TestDialogIntentTrainer(unittest.TestCase):
|
|||||||
shutil.rmtree('./model')
|
shutil.rmtree('./model')
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_trainer_with_model_and_args(self):
|
def test_trainer_with_model_and_args(self):
|
||||||
args = {
|
args = {
|
||||||
'device': 'gpu',
|
'device': 'gpu',
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from modelscope.msdatasets import MsDataset
|
|||||||
from modelscope.trainers import build_trainer
|
from modelscope.trainers import build_trainer
|
||||||
from modelscope.utils.config import Config
|
from modelscope.utils.config import Config
|
||||||
from modelscope.utils.constant import ModelFile
|
from modelscope.utils.constant import ModelFile
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import DistributedTestCase, test_level
|
from modelscope.utils.test_utils import DistributedTestCase, test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -62,7 +63,9 @@ class TestFaceDetectionScrfdTrainerSingleGPU(unittest.TestCase):
|
|||||||
cfg.data.samples_per_gpu = 4 # batch size
|
cfg.data.samples_per_gpu = 4 # batch size
|
||||||
return cfg
|
return cfg
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_trainer_from_scratch(self):
|
def test_trainer_from_scratch(self):
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
cfg_file=os.path.join(self.cache_path, 'DamoFD_lms.py'),
|
cfg_file=os.path.join(self.cache_path, 'DamoFD_lms.py'),
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ class TestFaceDetectionScrfdTrainerSingleGPU(unittest.TestCase):
|
|||||||
cfg.data.samples_per_gpu = 4 # batch size
|
cfg.data.samples_per_gpu = 4 # batch size
|
||||||
return cfg
|
return cfg
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
def test_trainer_from_scratch(self):
|
def test_trainer_from_scratch(self):
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
cfg_file=os.path.join(self.cache_path, 'mmcv_scrfd.py'),
|
cfg_file=os.path.join(self.cache_path, 'mmcv_scrfd.py'),
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ class TestFinetuneFaqQuestionAnswering(unittest.TestCase):
|
|||||||
cfg_file=cfg_file))
|
cfg_file=cfg_file))
|
||||||
return trainer
|
return trainer
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
def test_faq_model_finetune(self):
|
def test_faq_model_finetune(self):
|
||||||
trainer = self.build_trainer(self.model_id, 'v1.0.1')
|
trainer = self.build_trainer(self.model_id, 'v1.0.1')
|
||||||
trainer.train()
|
trainer.train()
|
||||||
@@ -107,7 +107,7 @@ class TestFinetuneFaqQuestionAnswering(unittest.TestCase):
|
|||||||
self.assertAlmostEqual(
|
self.assertAlmostEqual(
|
||||||
result_after['output'][0][0]['score'], 0.8, delta=0.2)
|
result_after['output'][0][0]['score'], 0.8, delta=0.2)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
def test_faq_mgimn_model_finetune(self):
|
def test_faq_mgimn_model_finetune(self):
|
||||||
trainer = self.build_trainer(self.mgimn_model_id, 'v1.0.0')
|
trainer = self.build_trainer(self.mgimn_model_id, 'v1.0.0')
|
||||||
trainer.train()
|
trainer.train()
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ from modelscope.models.multi_modal import MPlugForAllTasks
|
|||||||
from modelscope.msdatasets import MsDataset
|
from modelscope.msdatasets import MsDataset
|
||||||
from modelscope.trainers import EpochBasedTrainer, build_trainer
|
from modelscope.trainers import EpochBasedTrainer, build_trainer
|
||||||
from modelscope.utils.constant import ModelFile, Tasks
|
from modelscope.utils.constant import ModelFile, Tasks
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -37,7 +38,8 @@ class TestFinetuneMPlug(unittest.TestCase):
|
|||||||
shutil.rmtree(self.tmp_dir)
|
shutil.rmtree(self.tmp_dir)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip test because fairseq is not installed.')
|
||||||
def test_trainer_with_caption(self):
|
def test_trainer_with_caption(self):
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
model='damo/mplug_backbone_base_en',
|
model='damo/mplug_backbone_base_en',
|
||||||
@@ -72,7 +74,8 @@ class TestFinetuneMPlug(unittest.TestCase):
|
|||||||
for i in range(self.max_epochs):
|
for i in range(self.max_epochs):
|
||||||
self.assertIn(f'epoch_{i+1}.pth', results_files)
|
self.assertIn(f'epoch_{i+1}.pth', results_files)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip test because fairseq is not installed.')
|
||||||
def test_trainer_with_vqa(self):
|
def test_trainer_with_vqa(self):
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
model='damo/mplug_backbone_base_en',
|
model='damo/mplug_backbone_base_en',
|
||||||
@@ -108,7 +111,8 @@ class TestFinetuneMPlug(unittest.TestCase):
|
|||||||
for i in range(self.max_epochs):
|
for i in range(self.max_epochs):
|
||||||
self.assertIn(f'epoch_{i+1}.pth', results_files)
|
self.assertIn(f'epoch_{i+1}.pth', results_files)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip test because fairseq is not installed.')
|
||||||
def test_trainer_with_retrieval(self):
|
def test_trainer_with_retrieval(self):
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
model='damo/mplug_backbone_base_en',
|
model='damo/mplug_backbone_base_en',
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import unittest
|
|||||||
|
|
||||||
from modelscope.hub.snapshot_download import snapshot_download
|
from modelscope.hub.snapshot_download import snapshot_download
|
||||||
from modelscope.metainfo import Trainers
|
from modelscope.metainfo import Trainers
|
||||||
from modelscope.models.nlp import GPT3ForTextGeneration, PalmForTextGeneration
|
|
||||||
from modelscope.msdatasets import MsDataset
|
from modelscope.msdatasets import MsDataset
|
||||||
from modelscope.trainers import build_trainer
|
from modelscope.trainers import build_trainer
|
||||||
from modelscope.utils.constant import ModelFile
|
from modelscope.utils.constant import ModelFile
|
||||||
@@ -68,7 +67,7 @@ class TestFinetuneTextGeneration(unittest.TestCase):
|
|||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
||||||
def test_trainer_with_palm_with_model_and_args(self):
|
def test_trainer_with_palm_with_model_and_args(self):
|
||||||
|
from modelscope.models.nlp import PalmForTextGeneration
|
||||||
cache_path = snapshot_download(
|
cache_path = snapshot_download(
|
||||||
'damo/nlp_palm2.0_text-generation_english-base')
|
'damo/nlp_palm2.0_text-generation_english-base')
|
||||||
model = PalmForTextGeneration.from_pretrained(cache_path)
|
model = PalmForTextGeneration.from_pretrained(cache_path)
|
||||||
@@ -88,7 +87,7 @@ class TestFinetuneTextGeneration(unittest.TestCase):
|
|||||||
for i in range(self.max_epochs):
|
for i in range(self.max_epochs):
|
||||||
self.assertIn(f'epoch_{i+1}.pth', results_files)
|
self.assertIn(f'epoch_{i+1}.pth', results_files)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
def test_trainer_with_gpt3(self):
|
def test_trainer_with_gpt3(self):
|
||||||
|
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
@@ -108,7 +107,7 @@ class TestFinetuneTextGeneration(unittest.TestCase):
|
|||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
||||||
def test_trainer_with_gpt3_with_model_and_args(self):
|
def test_trainer_with_gpt3_with_model_and_args(self):
|
||||||
|
from modelscope.models.nlp import GPT3ForTextGeneration
|
||||||
cache_path = snapshot_download(
|
cache_path = snapshot_download(
|
||||||
'damo/nlp_gpt3_text-generation_chinese-base')
|
'damo/nlp_gpt3_text-generation_chinese-base')
|
||||||
model = GPT3ForTextGeneration.from_pretrained(cache_path)
|
model = GPT3ForTextGeneration.from_pretrained(cache_path)
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import unittest
|
|||||||
from modelscope.metainfo import Trainers
|
from modelscope.metainfo import Trainers
|
||||||
from modelscope.msdatasets import MsDataset
|
from modelscope.msdatasets import MsDataset
|
||||||
from modelscope.trainers import build_trainer
|
from modelscope.trainers import build_trainer
|
||||||
from modelscope.utils.import_utils import is_swift_available
|
from modelscope.utils.import_utils import exists, is_swift_available
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -40,8 +40,9 @@ class TestVisionEfficientTuningSwiftTrainer(unittest.TestCase):
|
|||||||
shutil.rmtree(self.tmp_dir)
|
shutil.rmtree(self.tmp_dir)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0 and is_swift_available(),
|
@unittest.skipUnless(
|
||||||
'skip test in current test level')
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_vision_efficient_tuning_swift_lora_train(self):
|
def test_vision_efficient_tuning_swift_lora_train(self):
|
||||||
from swift import LoRAConfig
|
from swift import LoRAConfig
|
||||||
model_id = 'damo/cv_vitb16_classification_vision-efficient-tuning-lora'
|
model_id = 'damo/cv_vitb16_classification_vision-efficient-tuning-lora'
|
||||||
@@ -81,8 +82,9 @@ class TestVisionEfficientTuningSwiftTrainer(unittest.TestCase):
|
|||||||
for i in range(self.max_epochs):
|
for i in range(self.max_epochs):
|
||||||
self.assertIn(f'epoch_{i+1}.pth', results_files)
|
self.assertIn(f'epoch_{i+1}.pth', results_files)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0 and is_swift_available(),
|
@unittest.skipUnless(
|
||||||
'skip test in current test level')
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_vision_efficient_tuning_swift_adapter_train(self):
|
def test_vision_efficient_tuning_swift_adapter_train(self):
|
||||||
from swift import AdapterConfig
|
from swift import AdapterConfig
|
||||||
model_id = 'damo/cv_vitb16_classification_vision-efficient-tuning-adapter'
|
model_id = 'damo/cv_vitb16_classification_vision-efficient-tuning-adapter'
|
||||||
@@ -120,8 +122,9 @@ class TestVisionEfficientTuningSwiftTrainer(unittest.TestCase):
|
|||||||
for i in range(self.max_epochs):
|
for i in range(self.max_epochs):
|
||||||
self.assertIn(f'epoch_{i+1}.pth', results_files)
|
self.assertIn(f'epoch_{i+1}.pth', results_files)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0 and is_swift_available(),
|
@unittest.skipUnless(
|
||||||
'skip test in current test level')
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_vision_efficient_tuning_swift_prompt_train(self):
|
def test_vision_efficient_tuning_swift_prompt_train(self):
|
||||||
from swift import PromptConfig
|
from swift import PromptConfig
|
||||||
model_id = 'damo/cv_vitb16_classification_vision-efficient-tuning-prompt'
|
model_id = 'damo/cv_vitb16_classification_vision-efficient-tuning-prompt'
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ from modelscope.msdatasets import MsDataset
|
|||||||
from modelscope.trainers import build_trainer
|
from modelscope.trainers import build_trainer
|
||||||
from modelscope.utils.config import Config, ConfigDict
|
from modelscope.utils.config import Config, ConfigDict
|
||||||
from modelscope.utils.constant import DownloadMode, ModelFile
|
from modelscope.utils.constant import DownloadMode, ModelFile
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -45,7 +46,7 @@ class TestGeneralImageClassificationTestTrainer(unittest.TestCase):
|
|||||||
shutil.rmtree(self.tmp_dir)
|
shutil.rmtree(self.tmp_dir)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(exists('mmcv'), 'Skip because mmcv is not installed.')
|
||||||
def test_nextvit_dailylife_train(self):
|
def test_nextvit_dailylife_train(self):
|
||||||
model_id = 'damo/cv_nextvit-small_image-classification_Dailylife-labels'
|
model_id = 'damo/cv_nextvit-small_image-classification_Dailylife-labels'
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ class TestGeneralImageClassificationTestTrainer(unittest.TestCase):
|
|||||||
for i in range(self.max_epochs):
|
for i in range(self.max_epochs):
|
||||||
self.assertIn(f'epoch_{i+1}.pth', results_files)
|
self.assertIn(f'epoch_{i+1}.pth', results_files)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(exists('mmcv'), 'Skip because mmcv is not installed.')
|
||||||
def test_nextvit_dailylife_eval(self):
|
def test_nextvit_dailylife_eval(self):
|
||||||
model_id = 'damo/cv_nextvit-small_image-classification_Dailylife-labels'
|
model_id = 'damo/cv_nextvit-small_image-classification_Dailylife-labels'
|
||||||
|
|
||||||
@@ -91,7 +92,7 @@ class TestGeneralImageClassificationTestTrainer(unittest.TestCase):
|
|||||||
result = trainer.evaluate()
|
result = trainer.evaluate()
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(exists('mmcv'), 'Skip because mmcv is not installed.')
|
||||||
def test_convnext_garbage_train(self):
|
def test_convnext_garbage_train(self):
|
||||||
model_id = 'damo/cv_convnext-base_image-classification_garbage'
|
model_id = 'damo/cv_convnext-base_image-classification_garbage'
|
||||||
|
|
||||||
@@ -122,7 +123,7 @@ class TestGeneralImageClassificationTestTrainer(unittest.TestCase):
|
|||||||
for i in range(self.max_epochs):
|
for i in range(self.max_epochs):
|
||||||
self.assertIn(f'epoch_{i+1}.pth', results_files)
|
self.assertIn(f'epoch_{i+1}.pth', results_files)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(exists('mmcv'), 'Skip because mmcv is not installed.')
|
||||||
def test_convnext_garbage_eval(self):
|
def test_convnext_garbage_eval(self):
|
||||||
model_id = 'damo/cv_convnext-base_image-classification_garbage'
|
model_id = 'damo/cv_convnext-base_image-classification_garbage'
|
||||||
|
|
||||||
@@ -137,7 +138,7 @@ class TestGeneralImageClassificationTestTrainer(unittest.TestCase):
|
|||||||
result = trainer.evaluate()
|
result = trainer.evaluate()
|
||||||
print(result)
|
print(result)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(exists('mmcv'), 'Skip because mmcv is not installed.')
|
||||||
def test_beitv2_train_eval(self):
|
def test_beitv2_train_eval(self):
|
||||||
model_id = 'damo/cv_beitv2-base_image-classification_patch16_224_pt1k_ft22k_in1k'
|
model_id = 'damo/cv_beitv2-base_image-classification_patch16_224_pt1k_ft22k_in1k'
|
||||||
|
|
||||||
|
|||||||
@@ -4,14 +4,13 @@ import os.path as osp
|
|||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
from typing import Callable, List, Optional, Tuple, Union
|
from typing import Callable, List, Union
|
||||||
|
|
||||||
import cv2
|
import cv2
|
||||||
import torch
|
import torch
|
||||||
from torch.utils import data as data
|
from torch.utils import data as data
|
||||||
|
|
||||||
from modelscope.hub.snapshot_download import snapshot_download
|
from modelscope.hub.snapshot_download import snapshot_download
|
||||||
from modelscope.models.cv.image_color_enhance import ImageColorEnhance
|
|
||||||
from modelscope.trainers import build_trainer
|
from modelscope.trainers import build_trainer
|
||||||
from modelscope.utils.constant import ModelFile
|
from modelscope.utils.constant import ModelFile
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
@@ -69,7 +68,7 @@ class TestImageColorEnhanceTrainer(unittest.TestCase):
|
|||||||
shutil.rmtree(self.tmp_dir, ignore_errors=True)
|
shutil.rmtree(self.tmp_dir, ignore_errors=True)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
def test_trainer(self):
|
def test_trainer(self):
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
model=self.model_id,
|
model=self.model_id,
|
||||||
@@ -86,6 +85,7 @@ class TestImageColorEnhanceTrainer(unittest.TestCase):
|
|||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
def test_trainer_with_model_and_args(self):
|
def test_trainer_with_model_and_args(self):
|
||||||
|
from modelscope.models.cv.image_color_enhance import ImageColorEnhance
|
||||||
cache_path = snapshot_download(self.model_id)
|
cache_path = snapshot_download(self.model_id)
|
||||||
model = ImageColorEnhance.from_pretrained(cache_path)
|
model = ImageColorEnhance.from_pretrained(cache_path)
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
|
|||||||
@@ -3,13 +3,10 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
import zipfile
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
|
|
||||||
from modelscope.hub.snapshot_download import snapshot_download
|
from modelscope.hub.snapshot_download import snapshot_download
|
||||||
from modelscope.metainfo import Trainers
|
from modelscope.metainfo import Trainers
|
||||||
from modelscope.models.cv.image_instance_segmentation import \
|
|
||||||
CascadeMaskRCNNSwinModel
|
|
||||||
from modelscope.msdatasets import MsDataset
|
from modelscope.msdatasets import MsDataset
|
||||||
from modelscope.trainers import build_trainer
|
from modelscope.trainers import build_trainer
|
||||||
from modelscope.utils.config import Config, ConfigDict
|
from modelscope.utils.config import Config, ConfigDict
|
||||||
@@ -76,7 +73,7 @@ class TestImageInstanceSegmentationTrainer(unittest.TestCase):
|
|||||||
shutil.rmtree(self.tmp_dir)
|
shutil.rmtree(self.tmp_dir)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
def test_trainer(self):
|
def test_trainer(self):
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
model=self.model_id,
|
model=self.model_id,
|
||||||
@@ -95,6 +92,8 @@ class TestImageInstanceSegmentationTrainer(unittest.TestCase):
|
|||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
||||||
def test_trainer_with_model_and_args(self):
|
def test_trainer_with_model_and_args(self):
|
||||||
|
from modelscope.models.cv.image_instance_segmentation import \
|
||||||
|
CascadeMaskRCNNSwinModel
|
||||||
tmp_dir = tempfile.TemporaryDirectory().name
|
tmp_dir = tempfile.TemporaryDirectory().name
|
||||||
if not os.path.exists(tmp_dir):
|
if not os.path.exists(tmp_dir):
|
||||||
os.makedirs(tmp_dir)
|
os.makedirs(tmp_dir)
|
||||||
|
|||||||
@@ -3,12 +3,9 @@ import os
|
|||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
import tempfile
|
||||||
import unittest
|
import unittest
|
||||||
import zipfile
|
|
||||||
|
|
||||||
from modelscope.hub.snapshot_download import snapshot_download
|
from modelscope.hub.snapshot_download import snapshot_download
|
||||||
from modelscope.metainfo import Trainers
|
from modelscope.metainfo import Trainers
|
||||||
from modelscope.models.cv.movie_scene_segmentation import \
|
|
||||||
MovieSceneSegmentationModel
|
|
||||||
from modelscope.msdatasets import MsDataset
|
from modelscope.msdatasets import MsDataset
|
||||||
from modelscope.trainers import build_trainer
|
from modelscope.trainers import build_trainer
|
||||||
from modelscope.utils.config import Config, ConfigDict
|
from modelscope.utils.config import Config, ConfigDict
|
||||||
@@ -86,7 +83,8 @@ class TestImageInstanceSegmentationTrainer(unittest.TestCase):
|
|||||||
tmp_dir = tempfile.TemporaryDirectory().name
|
tmp_dir = tempfile.TemporaryDirectory().name
|
||||||
if not os.path.exists(tmp_dir):
|
if not os.path.exists(tmp_dir):
|
||||||
os.makedirs(tmp_dir)
|
os.makedirs(tmp_dir)
|
||||||
|
from modelscope.models.cv.movie_scene_segmentation import \
|
||||||
|
MovieSceneSegmentationModel
|
||||||
cache_path = snapshot_download(self.model_id)
|
cache_path = snapshot_download(self.model_id)
|
||||||
model = MovieSceneSegmentationModel.from_pretrained(cache_path)
|
model = MovieSceneSegmentationModel.from_pretrained(cache_path)
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import shutil
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from modelscope.msdatasets import MsDataset
|
from modelscope.msdatasets import MsDataset
|
||||||
from modelscope.trainers.cv import NeRFReconAccTrainer
|
|
||||||
from modelscope.utils.constant import DownloadMode
|
from modelscope.utils.constant import DownloadMode
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
@@ -25,7 +24,7 @@ class TestNeRFReconAccTrainer(unittest.TestCase):
|
|||||||
split='train',
|
split='train',
|
||||||
download_mode=DownloadMode.FORCE_REDOWNLOAD
|
download_mode=DownloadMode.FORCE_REDOWNLOAD
|
||||||
).config_kwargs['split_config']['train']
|
).config_kwargs['split_config']['train']
|
||||||
|
from modelscope.trainers.cv import NeRFReconAccTrainer
|
||||||
trainer = NeRFReconAccTrainer(
|
trainer = NeRFReconAccTrainer(
|
||||||
model=model_id,
|
model=model_id,
|
||||||
data_type='blender',
|
data_type='blender',
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ from modelscope.pipelines import pipeline
|
|||||||
from modelscope.trainers import build_trainer
|
from modelscope.trainers import build_trainer
|
||||||
from modelscope.utils.config import Config
|
from modelscope.utils.config import Config
|
||||||
from modelscope.utils.constant import ModelFile, Tasks
|
from modelscope.utils.constant import ModelFile, Tasks
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import DistributedTestCase, test_level
|
from modelscope.utils.test_utils import DistributedTestCase, test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -40,7 +41,9 @@ class TestOCRDetectionDBTrainerSingleGPU(unittest.TestCase):
|
|||||||
shutil.rmtree(self.saved_dir)
|
shutil.rmtree(self.saved_dir)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_trainer_finetune_singleGPU(self):
|
def test_trainer_finetune_singleGPU(self):
|
||||||
|
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ from modelscope.metainfo import Trainers
|
|||||||
from modelscope.msdatasets import MsDataset
|
from modelscope.msdatasets import MsDataset
|
||||||
from modelscope.trainers import build_trainer
|
from modelscope.trainers import build_trainer
|
||||||
from modelscope.utils.constant import DownloadMode, ModelFile
|
from modelscope.utils.constant import DownloadMode, ModelFile
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -76,7 +77,8 @@ class TestMMSpeechTrainer(unittest.TestCase):
|
|||||||
shutil.rmtree(self.WORKSPACE, ignore_errors=True)
|
shutil.rmtree(self.WORKSPACE, ignore_errors=True)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('fairseq'), 'Skip because fairseq is not installed.')
|
||||||
def test_trainer_std(self):
|
def test_trainer_std(self):
|
||||||
os.makedirs(self.WORKSPACE, exist_ok=True)
|
os.makedirs(self.WORKSPACE, exist_ok=True)
|
||||||
config_file = os.path.join(self.WORKSPACE, ModelFile.CONFIGURATION)
|
config_file = os.path.join(self.WORKSPACE, ModelFile.CONFIGURATION)
|
||||||
|
|||||||
@@ -1,18 +1,15 @@
|
|||||||
# Copyright (c) Alibaba, Inc. and its affiliates.
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
import tempfile
|
|
||||||
import unittest
|
import unittest
|
||||||
import zipfile
|
|
||||||
|
|
||||||
from modelscope.hub.snapshot_download import snapshot_download
|
from modelscope.hub.snapshot_download import snapshot_download
|
||||||
from modelscope.metainfo import Trainers
|
from modelscope.metainfo import Trainers
|
||||||
from modelscope.models.cv.referring_video_object_segmentation import \
|
|
||||||
ReferringVideoObjectSegmentation
|
|
||||||
from modelscope.msdatasets import MsDataset
|
from modelscope.msdatasets import MsDataset
|
||||||
from modelscope.trainers import build_trainer
|
from modelscope.trainers import build_trainer
|
||||||
from modelscope.utils.config import Config, ConfigDict
|
from modelscope.utils.config import Config, ConfigDict
|
||||||
from modelscope.utils.constant import ModelFile
|
from modelscope.utils.constant import ModelFile
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -64,7 +61,9 @@ class TestImageInstanceSegmentationTrainer(unittest.TestCase):
|
|||||||
shutil.rmtree('./work_dir')
|
shutil.rmtree('./work_dir')
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_trainer(self):
|
def test_trainer(self):
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
model=self.model_id,
|
model=self.model_id,
|
||||||
@@ -81,7 +80,8 @@ class TestImageInstanceSegmentationTrainer(unittest.TestCase):
|
|||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 2, 'skip test in current test level')
|
||||||
def test_trainer_with_model_and_args(self):
|
def test_trainer_with_model_and_args(self):
|
||||||
|
from modelscope.models.cv.referring_video_object_segmentation import \
|
||||||
|
ReferringVideoObjectSegmentation
|
||||||
cache_path = snapshot_download(self.model_id)
|
cache_path = snapshot_download(self.model_id)
|
||||||
model = ReferringVideoObjectSegmentation.from_pretrained(cache_path)
|
model = ReferringVideoObjectSegmentation.from_pretrained(cache_path)
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ from modelscope.utils.test_utils import test_level
|
|||||||
|
|
||||||
class TableQuestionAnsweringTest(unittest.TestCase):
|
class TableQuestionAnsweringTest(unittest.TestCase):
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
def test_trainer_with_model_name(self):
|
def test_trainer_with_model_name(self):
|
||||||
# load data
|
# load data
|
||||||
input_dataset = MsDataset.load(
|
input_dataset = MsDataset.load(
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import unittest
|
|||||||
from modelscope.hub.snapshot_download import snapshot_download
|
from modelscope.hub.snapshot_download import snapshot_download
|
||||||
from modelscope.metainfo import Trainers
|
from modelscope.metainfo import Trainers
|
||||||
from modelscope.trainers import build_trainer
|
from modelscope.trainers import build_trainer
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -29,7 +30,9 @@ class TestTinynasDamoyoloTrainerSingleGPU(unittest.TestCase):
|
|||||||
super().tearDown()
|
super().tearDown()
|
||||||
shutil.rmtree('./workdirs', ignore_errors=True)
|
shutil.rmtree('./workdirs', ignore_errors=True)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_trainer_from_scratch_singleGPU(self):
|
def test_trainer_from_scratch_singleGPU(self):
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
cfg_file=os.path.join(self.cache_path, 'configuration.json'),
|
cfg_file=os.path.join(self.cache_path, 'configuration.json'),
|
||||||
@@ -57,7 +60,9 @@ class TestTinynasDamoyoloTrainerSingleGPU(unittest.TestCase):
|
|||||||
checkpoint_path=os.path.join('./workdirs/damoyolo_s',
|
checkpoint_path=os.path.join('./workdirs/damoyolo_s',
|
||||||
'epoch_3_ckpt.pth'))
|
'epoch_3_ckpt.pth'))
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_trainer_from_scratch_singleGPU_model_id(self):
|
def test_trainer_from_scratch_singleGPU_model_id(self):
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
model=self.model_id,
|
model=self.model_id,
|
||||||
@@ -110,7 +115,9 @@ class TestTinynasDamoyoloTrainerSingleGPU(unittest.TestCase):
|
|||||||
name=Trainers.tinynas_damoyolo, default_args=kwargs)
|
name=Trainers.tinynas_damoyolo, default_args=kwargs)
|
||||||
trainer.train()
|
trainer.train()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_trainer_finetune_singleGPU(self):
|
def test_trainer_finetune_singleGPU(self):
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
cfg_file=os.path.join(self.cache_path, 'configuration.json'),
|
cfg_file=os.path.join(self.cache_path, 'configuration.json'),
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ from modelscope.trainers.builder import TRAINERS
|
|||||||
from modelscope.trainers.trainer import EpochBasedTrainer
|
from modelscope.trainers.trainer import EpochBasedTrainer
|
||||||
from modelscope.utils.constant import LogKeys, ModeKeys, ModelFile, Tasks
|
from modelscope.utils.constant import LogKeys, ModeKeys, ModelFile, Tasks
|
||||||
from modelscope.utils.hub import read_config
|
from modelscope.utils.hub import read_config
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import create_dummy_test_dataset, test_level
|
from modelscope.utils.test_utils import create_dummy_test_dataset, test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -84,7 +85,9 @@ class TrainerTest(unittest.TestCase):
|
|||||||
super().tearDown()
|
super().tearDown()
|
||||||
shutil.rmtree(self.tmp_dir)
|
shutil.rmtree(self.tmp_dir)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_train_0(self):
|
def test_train_0(self):
|
||||||
json_cfg = {
|
json_cfg = {
|
||||||
'task': Tasks.image_classification,
|
'task': Tasks.image_classification,
|
||||||
@@ -167,7 +170,9 @@ class TrainerTest(unittest.TestCase):
|
|||||||
self.assertIn('tensorboard_output', results_files)
|
self.assertIn('tensorboard_output', results_files)
|
||||||
self.assertTrue(len(glob.glob(f'{self.tmp_dir}/*/*events*')) > 0)
|
self.assertTrue(len(glob.glob(f'{self.tmp_dir}/*/*events*')) > 0)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_train_visualization(self):
|
def test_train_visualization(self):
|
||||||
json_cfg = {
|
json_cfg = {
|
||||||
'task': Tasks.image_classification,
|
'task': Tasks.image_classification,
|
||||||
@@ -247,7 +252,9 @@ class TrainerTest(unittest.TestCase):
|
|||||||
self.assertIn(f'{LogKeys.EPOCH}_3.pth', results_files)
|
self.assertIn(f'{LogKeys.EPOCH}_3.pth', results_files)
|
||||||
self.assertTrue(len(glob.glob(f'{self.tmp_dir}/*/*events*')) > 0)
|
self.assertTrue(len(glob.glob(f'{self.tmp_dir}/*/*events*')) > 0)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_train_1(self):
|
def test_train_1(self):
|
||||||
json_cfg = {
|
json_cfg = {
|
||||||
'task': Tasks.image_classification,
|
'task': Tasks.image_classification,
|
||||||
@@ -312,7 +319,9 @@ class TrainerTest(unittest.TestCase):
|
|||||||
self.assertIn(f'{LogKeys.EPOCH}_3.pth', results_files)
|
self.assertIn(f'{LogKeys.EPOCH}_3.pth', results_files)
|
||||||
self.assertTrue(len(glob.glob(f'{self.tmp_dir}/*/*events*')) > 0)
|
self.assertTrue(len(glob.glob(f'{self.tmp_dir}/*/*events*')) > 0)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_train_with_default_config(self):
|
def test_train_with_default_config(self):
|
||||||
json_cfg = {
|
json_cfg = {
|
||||||
'task': Tasks.image_classification,
|
'task': Tasks.image_classification,
|
||||||
@@ -431,7 +440,9 @@ class TrainerTest(unittest.TestCase):
|
|||||||
for i in [2, 5, 8]:
|
for i in [2, 5, 8]:
|
||||||
self.assertIn(MetricKeys.ACCURACY, lines[i])
|
self.assertIn(MetricKeys.ACCURACY, lines[i])
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_train_with_iters_per_epoch(self):
|
def test_train_with_iters_per_epoch(self):
|
||||||
json_cfg = {
|
json_cfg = {
|
||||||
'task': Tasks.image_classification,
|
'task': Tasks.image_classification,
|
||||||
@@ -550,7 +561,9 @@ class TrainerTest(unittest.TestCase):
|
|||||||
for i in [2, 5, 8]:
|
for i in [2, 5, 8]:
|
||||||
self.assertIn(MetricKeys.ACCURACY, lines[i])
|
self.assertIn(MetricKeys.ACCURACY, lines[i])
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_train_with_old_and_new_cfg(self):
|
def test_train_with_old_and_new_cfg(self):
|
||||||
old_cfg = {
|
old_cfg = {
|
||||||
'task': Tasks.image_classification,
|
'task': Tasks.image_classification,
|
||||||
@@ -693,7 +706,9 @@ class TrainerTest(unittest.TestCase):
|
|||||||
|
|
||||||
class DummyTrainerTest(unittest.TestCase):
|
class DummyTrainerTest(unittest.TestCase):
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_dummy(self):
|
def test_dummy(self):
|
||||||
default_args = dict(cfg_file='configs/examples/train.json')
|
default_args = dict(cfg_file='configs/examples/train.json')
|
||||||
trainer = build_trainer('dummy', default_args)
|
trainer = build_trainer('dummy', default_args)
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ from modelscope.trainers import EpochBasedTrainer, build_trainer
|
|||||||
from modelscope.utils.config import Config
|
from modelscope.utils.config import Config
|
||||||
from modelscope.utils.constant import ModelFile, Tasks
|
from modelscope.utils.constant import ModelFile, Tasks
|
||||||
from modelscope.utils.hub import read_config
|
from modelscope.utils.hub import read_config
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
|
|
||||||
@@ -42,7 +43,9 @@ class TestTrainerWithNlp(unittest.TestCase):
|
|||||||
shutil.rmtree(self.tmp_dir)
|
shutil.rmtree(self.tmp_dir)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_trainer(self):
|
def test_trainer(self):
|
||||||
model_id = 'damo/nlp_structbert_sentence-similarity_chinese-tiny'
|
model_id = 'damo/nlp_structbert_sentence-similarity_chinese-tiny'
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
@@ -79,7 +82,9 @@ class TestTrainerWithNlp(unittest.TestCase):
|
|||||||
output_dir = os.path.join(self.tmp_dir, ModelFile.TRAIN_OUTPUT_DIR)
|
output_dir = os.path.join(self.tmp_dir, ModelFile.TRAIN_OUTPUT_DIR)
|
||||||
pipeline_sentence_similarity(output_dir)
|
pipeline_sentence_similarity(output_dir)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_trainer_callback(self):
|
def test_trainer_callback(self):
|
||||||
model_id = 'damo/nlp_structbert_sentence-similarity_chinese-tiny'
|
model_id = 'damo/nlp_structbert_sentence-similarity_chinese-tiny'
|
||||||
|
|
||||||
@@ -101,9 +106,8 @@ class TestTrainerWithNlp(unittest.TestCase):
|
|||||||
|
|
||||||
self.assertEqual(trainer.iter, 3)
|
self.assertEqual(trainer.iter, 3)
|
||||||
|
|
||||||
@unittest.skipIf(
|
@unittest.skipUnless(
|
||||||
version.parse(torch.__version__) < version.parse('2.0.0.dev'),
|
exists('torch<2.4'), 'Skip test because torch version is too high.')
|
||||||
'skip test when torch version < 2.0')
|
|
||||||
def test_trainer_compile(self):
|
def test_trainer_compile(self):
|
||||||
model_id = 'damo/nlp_structbert_sentence-similarity_chinese-tiny'
|
model_id = 'damo/nlp_structbert_sentence-similarity_chinese-tiny'
|
||||||
|
|
||||||
@@ -406,7 +410,9 @@ class TestTrainerWithNlp(unittest.TestCase):
|
|||||||
trainer, 'trainer_continue_train', level='strict'):
|
trainer, 'trainer_continue_train', level='strict'):
|
||||||
trainer.train(os.path.join(self.tmp_dir, 'iter_3'))
|
trainer.train(os.path.join(self.tmp_dir, 'iter_3'))
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_trainer_with_new_style_configuration(self):
|
def test_trainer_with_new_style_configuration(self):
|
||||||
tmp_dir = tempfile.TemporaryDirectory().name
|
tmp_dir = tempfile.TemporaryDirectory().name
|
||||||
if not os.path.exists(tmp_dir):
|
if not os.path.exists(tmp_dir):
|
||||||
@@ -481,7 +487,9 @@ class TestTrainerWithNlp(unittest.TestCase):
|
|||||||
cache_path + '/pytorch_model.bin', saving_fn=saving_fn))
|
cache_path + '/pytorch_model.bin', saving_fn=saving_fn))
|
||||||
self.assertTrue(os.path.isfile(f'{tmp_dir}/predicts.txt'))
|
self.assertTrue(os.path.isfile(f'{tmp_dir}/predicts.txt'))
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_trainer_with_custom_sampler(self):
|
def test_trainer_with_custom_sampler(self):
|
||||||
tmp_dir = tempfile.TemporaryDirectory().name
|
tmp_dir = tempfile.TemporaryDirectory().name
|
||||||
if not os.path.exists(tmp_dir):
|
if not os.path.exists(tmp_dir):
|
||||||
@@ -509,7 +517,9 @@ class TestTrainerWithNlp(unittest.TestCase):
|
|||||||
type(trainer.train_dataloader.sampler) == CustomSampler)
|
type(trainer.train_dataloader.sampler) == CustomSampler)
|
||||||
self.assertTrue(type(trainer.eval_dataloader.sampler) == CustomSampler)
|
self.assertTrue(type(trainer.eval_dataloader.sampler) == CustomSampler)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_trainer_with_prediction(self):
|
def test_trainer_with_prediction(self):
|
||||||
tmp_dir = tempfile.TemporaryDirectory().name
|
tmp_dir = tempfile.TemporaryDirectory().name
|
||||||
if not os.path.exists(tmp_dir):
|
if not os.path.exists(tmp_dir):
|
||||||
@@ -551,7 +561,9 @@ class TestTrainerWithNlp(unittest.TestCase):
|
|||||||
checkpoint_path=cache_path + '/pytorch_model.bin')
|
checkpoint_path=cache_path + '/pytorch_model.bin')
|
||||||
self.assertTrue(os.path.isfile(f'{tmp_dir}/predicts.txt'))
|
self.assertTrue(os.path.isfile(f'{tmp_dir}/predicts.txt'))
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_trainer_with_prediction_msdataset(self):
|
def test_trainer_with_prediction_msdataset(self):
|
||||||
tmp_dir = tempfile.TemporaryDirectory().name
|
tmp_dir = tempfile.TemporaryDirectory().name
|
||||||
if not os.path.exists(tmp_dir):
|
if not os.path.exists(tmp_dir):
|
||||||
@@ -608,7 +620,9 @@ class TestTrainerWithNlp(unittest.TestCase):
|
|||||||
for i in range(2):
|
for i in range(2):
|
||||||
self.assertIn(f'epoch_{i + 1}.pth', results_files)
|
self.assertIn(f'epoch_{i + 1}.pth', results_files)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_trainer_with_hook_register(self):
|
def test_trainer_with_hook_register(self):
|
||||||
model_id = 'damo/nlp_structbert_sentence-similarity_chinese-tiny'
|
model_id = 'damo/nlp_structbert_sentence-similarity_chinese-tiny'
|
||||||
|
|
||||||
|
|||||||
@@ -1,26 +1,31 @@
|
|||||||
# Copyright (c) Alibaba, Inc. and its affiliates.
|
# Copyright (c) Alibaba, Inc. and its affiliates.
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from modelscope.trainers.nlp import CsanmtTranslationTrainer
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.test_utils import test_level
|
|
||||||
|
|
||||||
|
|
||||||
class TranslationTest(unittest.TestCase):
|
class TranslationTest(unittest.TestCase):
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('tensorflow'), 'Skip test because tensorflow is not installed.')
|
||||||
def test_run_with_model_name_for_en2zh(self):
|
def test_run_with_model_name_for_en2zh(self):
|
||||||
|
from modelscope.trainers.nlp import CsanmtTranslationTrainer
|
||||||
model_id = 'damo/nlp_csanmt_translation_en2zh'
|
model_id = 'damo/nlp_csanmt_translation_en2zh'
|
||||||
trainer = CsanmtTranslationTrainer(model=model_id)
|
trainer = CsanmtTranslationTrainer(model=model_id)
|
||||||
trainer.train()
|
trainer.train()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('tensorflow'), 'Skip test because tensorflow is not installed.')
|
||||||
def test_run_with_model_name_for_en2fr(self):
|
def test_run_with_model_name_for_en2fr(self):
|
||||||
|
from modelscope.trainers.nlp import CsanmtTranslationTrainer
|
||||||
model_id = 'damo/nlp_csanmt_translation_en2fr'
|
model_id = 'damo/nlp_csanmt_translation_en2fr'
|
||||||
trainer = CsanmtTranslationTrainer(model=model_id)
|
trainer = CsanmtTranslationTrainer(model=model_id)
|
||||||
trainer.train()
|
trainer.train()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('tensorflow'), 'Skip test because tensorflow is not installed.')
|
||||||
def test_run_with_model_name_for_en2es(self):
|
def test_run_with_model_name_for_en2es(self):
|
||||||
|
from modelscope.trainers.nlp import CsanmtTranslationTrainer
|
||||||
model_id = 'damo/nlp_csanmt_translation_en2es'
|
model_id = 'damo/nlp_csanmt_translation_en2es'
|
||||||
trainer = CsanmtTranslationTrainer(model=model_id)
|
trainer = CsanmtTranslationTrainer(model=model_id)
|
||||||
trainer.train()
|
trainer.train()
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ from modelscope.msdatasets.dataset_cls.custom_datasets import \
|
|||||||
from modelscope.trainers import build_trainer
|
from modelscope.trainers import build_trainer
|
||||||
from modelscope.utils.config import Config
|
from modelscope.utils.config import Config
|
||||||
from modelscope.utils.constant import ModelFile
|
from modelscope.utils.constant import ModelFile
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
from modelscope.utils.logger import get_logger
|
from modelscope.utils.logger import get_logger
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
|
|
||||||
@@ -41,7 +42,9 @@ class VideoSummarizationTrainerTest(unittest.TestCase):
|
|||||||
shutil.rmtree(self.tmp_dir, ignore_errors=True)
|
shutil.rmtree(self.tmp_dir, ignore_errors=True)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skipUnless(
|
||||||
|
exists('transformers<5.0'),
|
||||||
|
'Skip test because transformers version is too high.')
|
||||||
def test_trainer(self):
|
def test_trainer(self):
|
||||||
kwargs = dict(
|
kwargs = dict(
|
||||||
model=self.model_id,
|
model=self.model_id,
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from modelscope.utils.import_utils import exists
|
||||||
|
|
||||||
|
|
||||||
class CompatibilityTest(unittest.TestCase):
|
class CompatibilityTest(unittest.TestCase):
|
||||||
|
|
||||||
@@ -11,6 +13,8 @@ class CompatibilityTest(unittest.TestCase):
|
|||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
|
@unittest.skipUnless(
|
||||||
|
exists('xtcocotools'), 'Skip because xtcocotools is not installed.')
|
||||||
def test_xtcocotools(self):
|
def test_xtcocotools(self):
|
||||||
from xtcocotools.coco import COCO
|
from xtcocotools.coco import COCO
|
||||||
|
|
||||||
|
|||||||
@@ -12,9 +12,6 @@ from modelscope.utils.constant import Frameworks
|
|||||||
from modelscope.utils.device import (create_device, device_placement,
|
from modelscope.utils.device import (create_device, device_placement,
|
||||||
verify_device)
|
verify_device)
|
||||||
|
|
||||||
# import tensorflow must be imported after torch is imported when using tf1.15
|
|
||||||
import tensorflow as tf # isort:skip
|
|
||||||
|
|
||||||
|
|
||||||
class DeviceTest(unittest.TestCase):
|
class DeviceTest(unittest.TestCase):
|
||||||
|
|
||||||
@@ -89,6 +86,8 @@ class DeviceTest(unittest.TestCase):
|
|||||||
|
|
||||||
@unittest.skip('skip this test to avoid debug logging.')
|
@unittest.skip('skip this test to avoid debug logging.')
|
||||||
def test_device_placement_tf_gpu(self):
|
def test_device_placement_tf_gpu(self):
|
||||||
|
# import tensorflow must be imported after torch is imported when using tf1.15
|
||||||
|
import tensorflow as tf # isort:skip
|
||||||
tf.debugging.set_log_device_placement(True)
|
tf.debugging.set_log_device_placement(True)
|
||||||
with device_placement(Frameworks.tf, 'gpu:0'):
|
with device_placement(Frameworks.tf, 'gpu:0'):
|
||||||
a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
|
a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class HFUtilTest(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
logger.info('SetUp')
|
logger.info('SetUp')
|
||||||
self.api = HubApi()
|
self.api = HubApi()
|
||||||
self.api.login(TEST_ACCESS_TOKEN1)
|
response, _ = self.api.login(TEST_ACCESS_TOKEN1)
|
||||||
self.user = TEST_MODEL_ORG
|
self.user = TEST_MODEL_ORG
|
||||||
print(self.user)
|
print(self.user)
|
||||||
self.create_model_name = '%s/%s_%s' % (self.user, 'test_model_upload',
|
self.create_model_name = '%s/%s_%s' % (self.user, 'test_model_upload',
|
||||||
@@ -80,6 +80,7 @@ class HFUtilTest(unittest.TestCase):
|
|||||||
'baichuan-inc/baichuan-7B', trust_remote_code=True)
|
'baichuan-inc/baichuan-7B', trust_remote_code=True)
|
||||||
self.assertTrue(model is not None)
|
self.assertTrue(model is not None)
|
||||||
|
|
||||||
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
def test_auto_config(self):
|
def test_auto_config(self):
|
||||||
from modelscope import AutoConfig, GenerationConfig
|
from modelscope import AutoConfig, GenerationConfig
|
||||||
config = AutoConfig.from_pretrained(
|
config = AutoConfig.from_pretrained(
|
||||||
@@ -108,33 +109,19 @@ class HFUtilTest(unittest.TestCase):
|
|||||||
def test_transformer_patch(self):
|
def test_transformer_patch(self):
|
||||||
with patch_context():
|
with patch_context():
|
||||||
from transformers import AutoTokenizer, AutoModelForCausalLM
|
from transformers import AutoTokenizer, AutoModelForCausalLM
|
||||||
tokenizer = AutoTokenizer.from_pretrained(
|
tokenizer = AutoTokenizer.from_pretrained('Qwen/Qwen2.5-0.5B')
|
||||||
'iic/nlp_structbert_sentiment-classification_chinese-tiny')
|
|
||||||
self.assertIsNotNone(tokenizer)
|
self.assertIsNotNone(tokenizer)
|
||||||
model = AutoModelForCausalLM.from_pretrained(
|
model = AutoModelForCausalLM.from_pretrained('Qwen/Qwen2.5-0.5B')
|
||||||
'iic/nlp_structbert_sentiment-classification_chinese-tiny')
|
|
||||||
self.assertIsNotNone(model)
|
self.assertIsNotNone(model)
|
||||||
|
|
||||||
def test_patch_model(self):
|
def test_patch_model(self):
|
||||||
from modelscope.utils.hf_util.patcher import patch_context
|
from modelscope.utils.hf_util.patcher import patch_context
|
||||||
with patch_context():
|
with patch_context():
|
||||||
from transformers import AutoModel
|
from transformers import AutoModel
|
||||||
model = AutoModel.from_pretrained(
|
model = AutoModel.from_pretrained('Qwen/Qwen2.5-0.5B')
|
||||||
'iic/nlp_structbert_sentiment-classification_chinese-tiny')
|
|
||||||
self.assertTrue(model is not None)
|
self.assertTrue(model is not None)
|
||||||
try:
|
try:
|
||||||
model = AutoModel.from_pretrained(
|
model = AutoModel.from_pretrained('Qwen/Qwen2.5-0.5B')
|
||||||
'iic/nlp_structbert_sentiment-classification_chinese-tiny')
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
else:
|
|
||||||
self.assertTrue(False)
|
|
||||||
|
|
||||||
def test_patch_config_bert(self):
|
|
||||||
from transformers import BertConfig
|
|
||||||
try:
|
|
||||||
BertConfig.from_pretrained(
|
|
||||||
'iic/nlp_structbert_sentiment-classification_chinese-tiny')
|
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
@@ -143,22 +130,18 @@ class HFUtilTest(unittest.TestCase):
|
|||||||
def test_patch_config(self):
|
def test_patch_config(self):
|
||||||
with patch_context():
|
with patch_context():
|
||||||
from transformers import AutoConfig
|
from transformers import AutoConfig
|
||||||
config = AutoConfig.from_pretrained(
|
config = AutoConfig.from_pretrained('Qwen/Qwen2.5-0.5B')
|
||||||
'iic/nlp_structbert_sentiment-classification_chinese-tiny')
|
self.assertTrue(config is not None)
|
||||||
self.assertTrue(getattr(config, 'base_model_prefix') == 'encoder')
|
|
||||||
try:
|
try:
|
||||||
config = AutoConfig.from_pretrained(
|
AutoConfig.from_pretrained('Qwen/Qwen2.5-0.5B')
|
||||||
'iic/nlp_structbert_sentiment-classification_chinese-tiny')
|
self.assertTrue(False)
|
||||||
self.assertTrue(
|
|
||||||
getattr(config, 'base_model_prefix', None) != 'encoder')
|
|
||||||
except: # noqa
|
except: # noqa
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# Test patch again
|
# Test patch again
|
||||||
with patch_context():
|
with patch_context():
|
||||||
from transformers import AutoConfig
|
from transformers import AutoConfig
|
||||||
config = AutoConfig.from_pretrained(
|
config = AutoConfig.from_pretrained('Qwen/Qwen2.5-0.5B')
|
||||||
'iic/nlp_structbert_sentiment-classification_chinese-tiny')
|
|
||||||
self.assertTrue(config is not None)
|
self.assertTrue(config is not None)
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
@unittest.skipUnless(test_level() >= 1, 'skip test in current test level')
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ class MegatronTest(DistributedTestCase):
|
|||||||
shutil.rmtree(self.tmp_dir)
|
shutil.rmtree(self.tmp_dir)
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
|
||||||
@unittest.skipUnless(test_level() >= 0, 'skip test in current test level')
|
@unittest.skip
|
||||||
def test_init_megatron_util(self):
|
def test_init_megatron_util(self):
|
||||||
dummy_megatron_cfg = {
|
dummy_megatron_cfg = {
|
||||||
'tensor_model_parallel_size': 1,
|
'tensor_model_parallel_size': 1,
|
||||||
@@ -37,8 +37,7 @@ class MegatronTest(DistributedTestCase):
|
|||||||
init_megatron_util(dummy_megatron_cfg)
|
init_megatron_util(dummy_megatron_cfg)
|
||||||
self.assertTrue(is_megatron_initialized())
|
self.assertTrue(is_megatron_initialized())
|
||||||
|
|
||||||
@unittest.skipIf(not torch.cuda.is_available()
|
@unittest.skip
|
||||||
or torch.cuda.device_count() <= 1, 'distributed unittest')
|
|
||||||
def test_convert_megatron_checkpoint(self):
|
def test_convert_megatron_checkpoint(self):
|
||||||
cache_path = snapshot_download('damo/nlp_gpt3_text-generation_1.3B')
|
cache_path = snapshot_download('damo/nlp_gpt3_text-generation_1.3B')
|
||||||
splited_dir = os.path.join(self.tmp_dir, 'splited')
|
splited_dir = os.path.join(self.tmp_dir, 'splited')
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import subprocess
|
|||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from modelscope.models.cv.anydoor.ldm.util import exists
|
||||||
from modelscope.pipelines import pipeline
|
from modelscope.pipelines import pipeline
|
||||||
from modelscope.utils.constant import Tasks
|
from modelscope.utils.constant import Tasks
|
||||||
from modelscope.utils.test_utils import test_level
|
from modelscope.utils.test_utils import test_level
|
||||||
@@ -24,6 +25,9 @@ class SentenceEmbeddingPipelineTest(unittest.TestCase):
|
|||||||
'is responsible for the movement of planets around the sun.',
|
'is responsible for the movement of planets around the sun.',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@unittest.skipUnless(
|
||||||
|
exists('sentence_transformers'),
|
||||||
|
'Skip because sentence_transformers is not installed.')
|
||||||
def test_ori_pipeline(self):
|
def test_ori_pipeline(self):
|
||||||
ppl = pipeline(
|
ppl = pipeline(
|
||||||
Tasks.sentence_embedding,
|
Tasks.sentence_embedding,
|
||||||
|
|||||||
Reference in New Issue
Block a user