Browse Source

[to #43387011]feat: ci test to new host and running in docker

ci 测试迁移新的机器,并且在容器中运行,减小互相干扰的可能
        Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/9427096

    * add docker ci script
master
mulin.lyh 3 years ago
parent
commit
69047b99ae
10 changed files with 98 additions and 8 deletions
  1. +17
    -0
      .dev_scripts/ci_container_test.sh
  2. +26
    -0
      .dev_scripts/dockerci.sh
  3. +3
    -3
      .pre-commit-config.yaml
  4. +37
    -0
      .pre-commit-config_local.yaml
  5. +1
    -1
      modelscope/hub/errors.py
  6. +8
    -1
      modelscope/hub/snapshot_download.py
  7. +1
    -1
      requirements/multi-modal.txt
  8. +3
    -0
      requirements/nlp.txt
  9. +0
    -2
      tests/hub/test_hub_operation.py
  10. +2
    -0
      tests/hub/test_hub_repository.py

+ 17
- 0
.dev_scripts/ci_container_test.sh View File

@@ -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

+ 26
- 0
.dev_scripts/dockerci.sh View File

@@ -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

+ 3
- 3
.pre-commit-config.yaml View File

@@ -4,17 +4,17 @@ repos:
hooks:
- id: flake8
exclude: thirdparty/|examples/
- repo: https://github.com/timothycrosley/isort
- repo: https://github.com/PyCQA/isort.git
rev: 4.3.21
hooks:
- id: isort
exclude: examples
- repo: https://github.com/pre-commit/mirrors-yapf
- repo: https://github.com/pre-commit/mirrors-yapf.git
rev: v0.30.0
hooks:
- id: yapf
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
hooks:
- id: trailing-whitespace


+ 37
- 0
.pre-commit-config_local.yaml View File

@@ -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"]

+ 1
- 1
modelscope/hub/errors.py View File

@@ -35,7 +35,7 @@ def handle_http_response(response, logger, cookies, model_id):
except HTTPError:
if cookies is None: # code in [403] and
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.')
raise



+ 8
- 1
modelscope/hub/snapshot_download.py View File

@@ -85,12 +85,19 @@ def snapshot_download(model_id: str,
raise NotExistError('The specified branch or tag : %s not exist!'
% revision)

snapshot_header = headers if 'CI_TEST' in os.environ else {
**headers,
**{
'Snapshot': 'True'
}
}
model_files = _api.get_model_files(
model_id=model_id,
revision=revision,
recursive=True,
use_cookies=False if cookies is None else cookies,
headers={'Snapshot': 'True'})
headers=snapshot_header,
)

for model_file in model_files:
if model_file['Type'] == 'tree':


+ 1
- 1
requirements/multi-modal.txt View File

@@ -1,6 +1,6 @@
fairseq
ftfy>=6.0.3
ofa>=0.0.2-3.6
ofa>=0.0.2
pycocoevalcap>=1.2
pycocotools>=2.0.4
rouge_score


+ 3
- 0
requirements/nlp.txt View File

@@ -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
spacy>=2.3.5

+ 0
- 2
tests/hub/test_hub_operation.py View File

@@ -79,8 +79,6 @@ class HubOperationTest(unittest.TestCase):
model_file_download(
model_id=self.model_id,
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):
rmtree(ModelScopeConfig.path_credential)


+ 2
- 0
tests/hub/test_hub_repository.py View File

@@ -27,6 +27,7 @@ DEFAULT_GIT_PATH = 'git'
class HubRepositoryTest(unittest.TestCase):

def setUp(self):
self.old_cwd = os.getcwd()
self.api = HubApi()
# note this is temporary before official account management is ready
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)

def tearDown(self):
os.chdir(self.old_cwd)
self.api.delete_model(model_id=self.model_id)

def test_clone_repo(self):


Loading…
Cancel
Save