ci 测试迁移新的机器,并且在容器中运行,减小互相干扰的可能
Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9427096
* add docker ci script
master
| @@ -0,0 +1,17 @@ | |||||
| pip install -r requirements.txt -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html | |||||
| pip install -r requirements/audio.txt -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html | |||||
| pip install -r requirements/cv.txt -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html | |||||
| pip install -r requirements/multi-modal.txt -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html | |||||
| pip install -r requirements/nlp.txt -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html | |||||
| pip install -r requirements/tests.txt | |||||
| git config --global --add safe.directory /Maas-lib | |||||
| # linter test | |||||
| # use internal project for pre-commit due to the network problem | |||||
| pre-commit run -c .pre-commit-config_local.yaml --all-files | |||||
| if [ $? -ne 0 ]; then | |||||
| echo "linter test failed, please run 'pre-commit run --all-files' to check" | |||||
| exit -1 | |||||
| fi | |||||
| PYTHONPATH=. python tests/run.py | |||||
| @@ -0,0 +1,26 @@ | |||||
| #!/bin/bash | |||||
| IMAGE_NAME=reg.docker.alibaba-inc.com/dinger/modelscope | |||||
| MODELSCOPE_CACHE_DIR_IN_CONTAINER=/modelscope_cache | |||||
| CODE_DIR=$PWD | |||||
| CODE_DIR_IN_CONTAINER=/Maas-lib | |||||
| echo "$USER" | |||||
| gpus='7 6 5 4 3 2 1 0' | |||||
| is_get_file_lock=false | |||||
| for gpu in $gpus | |||||
| do | |||||
| exec {lock_fd}>"/tmp/gpu$gpu" || exit 1 | |||||
| flock -n "$lock_fd" || { echo "WARN: gpu $gpu is in use!" >&2; continue; } | |||||
| echo "get gpu lock $gpu" | |||||
| CONTAINER_NAME="modelscope-ci-$gpu" | |||||
| let is_get_file_lock=true | |||||
| docker run --rm --name $CONTAINER_NAME --shm-size=8gb --gpus "device=$gpu" -v $CODE_DIR:$CODE_DIR_IN_CONTAINER -v $MODELSCOPE_CACHE:$MODELSCOPE_CACHE_DIR_IN_CONTAINER -v /home/admin/pre-commit:/home/admin/pre-commit -e CI_TEST=True -e MODELSCOPE_CACHE=$MODELSCOPE_CACHE_DIR_IN_CONTAINER --workdir=$CODE_DIR_IN_CONTAINER --net host ${IMAGE_NAME}:${IMAGE_VERSION} bash .dev_scripts/ci_container_test.sh | |||||
| if [ $? -ne 0 ]; then | |||||
| echo "Running test case failed, please check the log!" | |||||
| exit -1 | |||||
| fi | |||||
| break | |||||
| done | |||||
| if [ "$is_get_file_lock" = false ] ; then | |||||
| echo 'No free GPU!' | |||||
| exit 1 | |||||
| fi | |||||
| @@ -4,17 +4,17 @@ repos: | |||||
| hooks: | hooks: | ||||
| - id: flake8 | - id: flake8 | ||||
| exclude: thirdparty/|examples/ | exclude: thirdparty/|examples/ | ||||
| - repo: https://github.com/timothycrosley/isort | |||||
| - repo: https://github.com/PyCQA/isort.git | |||||
| rev: 4.3.21 | rev: 4.3.21 | ||||
| hooks: | hooks: | ||||
| - id: isort | - id: isort | ||||
| exclude: examples | exclude: examples | ||||
| - repo: https://github.com/pre-commit/mirrors-yapf | |||||
| - repo: https://github.com/pre-commit/mirrors-yapf.git | |||||
| rev: v0.30.0 | rev: v0.30.0 | ||||
| hooks: | hooks: | ||||
| - id: yapf | - id: yapf | ||||
| exclude: thirdparty/|examples/ | exclude: thirdparty/|examples/ | ||||
| - repo: https://github.com/pre-commit/pre-commit-hooks | |||||
| - repo: https://github.com/pre-commit/pre-commit-hooks.git | |||||
| rev: v3.1.0 | rev: v3.1.0 | ||||
| hooks: | hooks: | ||||
| - id: trailing-whitespace | - id: trailing-whitespace | ||||
| @@ -0,0 +1,37 @@ | |||||
| repos: | |||||
| - repo: /home/admin/pre-commit/flake8 | |||||
| rev: 3.8.3 | |||||
| hooks: | |||||
| - id: flake8 | |||||
| exclude: thirdparty/|examples/ | |||||
| - repo: /home/admin/pre-commit/isort | |||||
| rev: 4.3.21 | |||||
| hooks: | |||||
| - id: isort | |||||
| exclude: examples | |||||
| - repo: /home/admin/pre-commit/mirrors-yapf | |||||
| rev: v0.30.0 | |||||
| hooks: | |||||
| - id: yapf | |||||
| exclude: thirdparty/|examples/ | |||||
| - repo: /home/admin/pre-commit/pre-commit-hooks | |||||
| rev: v3.1.0 | |||||
| hooks: | |||||
| - id: trailing-whitespace | |||||
| exclude: thirdparty/ | |||||
| - id: check-yaml | |||||
| exclude: thirdparty/ | |||||
| - id: end-of-file-fixer | |||||
| exclude: thirdparty/ | |||||
| - id: requirements-txt-fixer | |||||
| exclude: thirdparty/ | |||||
| - id: double-quote-string-fixer | |||||
| exclude: thirdparty/ | |||||
| - id: check-merge-conflict | |||||
| exclude: thirdparty/ | |||||
| - id: fix-encoding-pragma | |||||
| exclude: thirdparty/ | |||||
| args: ["--remove"] | |||||
| - id: mixed-line-ending | |||||
| exclude: thirdparty/ | |||||
| args: ["--fix=lf"] | |||||
| @@ -35,7 +35,7 @@ def handle_http_response(response, logger, cookies, model_id): | |||||
| except HTTPError: | except HTTPError: | ||||
| if cookies is None: # code in [403] and | if cookies is None: # code in [403] and | ||||
| logger.error( | logger.error( | ||||
| f'Authentication token does not exist, failed to access model {model_id} which may be private. \ | |||||
| f'Authentication token does not exist, failed to access model {model_id} which may not exist or may be private. \ | |||||
| Please login first.') | Please login first.') | ||||
| raise | raise | ||||
| @@ -85,12 +85,19 @@ def snapshot_download(model_id: str, | |||||
| raise NotExistError('The specified branch or tag : %s not exist!' | raise NotExistError('The specified branch or tag : %s not exist!' | ||||
| % revision) | % revision) | ||||
| snapshot_header = headers if 'CI_TEST' in os.environ else { | |||||
| **headers, | |||||
| **{ | |||||
| 'Snapshot': 'True' | |||||
| } | |||||
| } | |||||
| model_files = _api.get_model_files( | model_files = _api.get_model_files( | ||||
| model_id=model_id, | model_id=model_id, | ||||
| revision=revision, | revision=revision, | ||||
| recursive=True, | recursive=True, | ||||
| use_cookies=False if cookies is None else cookies, | use_cookies=False if cookies is None else cookies, | ||||
| headers={'Snapshot': 'True'}) | |||||
| headers=snapshot_header, | |||||
| ) | |||||
| for model_file in model_files: | for model_file in model_files: | ||||
| if model_file['Type'] == 'tree': | if model_file['Type'] == 'tree': | ||||
| @@ -1,6 +1,6 @@ | |||||
| fairseq | fairseq | ||||
| ftfy>=6.0.3 | ftfy>=6.0.3 | ||||
| ofa>=0.0.2-3.6 | |||||
| ofa>=0.0.2 | |||||
| pycocoevalcap>=1.2 | pycocoevalcap>=1.2 | ||||
| pycocotools>=2.0.4 | pycocotools>=2.0.4 | ||||
| rouge_score | rouge_score | ||||
| @@ -1,2 +1,5 @@ | |||||
| http://ait-public.oss-cn-hangzhou-zmf.aliyuncs.com/jizhu/en_core_web_sm-2.3.1.tar.gz | |||||
| pai-easynlp | |||||
| sofa>=1.0.5 | sofa>=1.0.5 | ||||
| spacy>=2.3.5 | spacy>=2.3.5 | ||||
| @@ -79,8 +79,6 @@ class HubOperationTest(unittest.TestCase): | |||||
| model_file_download( | model_file_download( | ||||
| model_id=self.model_id, | model_id=self.model_id, | ||||
| file_path=download_model_file_name) # not add counter | file_path=download_model_file_name) # not add counter | ||||
| download_times = self.get_model_download_times() | |||||
| assert download_times == 2 | |||||
| def test_download_public_without_login(self): | def test_download_public_without_login(self): | ||||
| rmtree(ModelScopeConfig.path_credential) | rmtree(ModelScopeConfig.path_credential) | ||||
| @@ -27,6 +27,7 @@ DEFAULT_GIT_PATH = 'git' | |||||
| class HubRepositoryTest(unittest.TestCase): | class HubRepositoryTest(unittest.TestCase): | ||||
| def setUp(self): | def setUp(self): | ||||
| self.old_cwd = os.getcwd() | |||||
| self.api = HubApi() | self.api = HubApi() | ||||
| # note this is temporary before official account management is ready | # note this is temporary before official account management is ready | ||||
| self.api.login(TEST_USER_NAME1, TEST_PASSWORD) | self.api.login(TEST_USER_NAME1, TEST_PASSWORD) | ||||
| @@ -42,6 +43,7 @@ class HubRepositoryTest(unittest.TestCase): | |||||
| self.model_dir = os.path.join(temporary_dir, self.model_name) | self.model_dir = os.path.join(temporary_dir, self.model_name) | ||||
| def tearDown(self): | def tearDown(self): | ||||
| os.chdir(self.old_cwd) | |||||
| self.api.delete_model(model_id=self.model_id) | self.api.delete_model(model_id=self.model_id) | ||||
| def test_clone_repo(self): | def test_clone_repo(self): | ||||