2022-08-22 16:01:42 +08:00
|
|
|
#!/bin/bash
|
|
|
|
|
# default values.
|
2023-06-08 10:01:58 +08:00
|
|
|
BASE_PY38_CPU_IMAGE=reg.docker.alibaba-inc.com/modelscope/modelscope:ubuntu20.04-py38-torch1.11.0-tf1.15.5-base-1.6.1
|
|
|
|
|
BASE_PY38_GPU_IMAGE=reg.docker.alibaba-inc.com/modelscope/modelscope:ubuntu20.04-cuda11.3.0-py38-torch1.11.0-tf1.15.5-base-1.6.1
|
|
|
|
|
BASE_PY37_CPU_IMAGE=reg.docker.alibaba-inc.com/modelscope/modelscope:ubuntu20.04-py37-torch1.11.0-tf1.15.5-base-1.6.1
|
|
|
|
|
BASE_PY37_GPU_IMAGE=reg.docker.alibaba-inc.com/modelscope/modelscope:ubuntu20.04-cuda11.3.0-py37-torch1.11.0-tf1.15.5-base-1.6.1
|
2022-08-22 16:01:42 +08:00
|
|
|
MODELSCOPE_REPO_ADDRESS=reg.docker.alibaba-inc.com/modelscope/modelscope
|
|
|
|
|
python_version=3.7.13
|
|
|
|
|
torch_version=1.11.0
|
|
|
|
|
cudatoolkit_version=11.3
|
|
|
|
|
tensorflow_version=1.15.5
|
|
|
|
|
modelscope_version=None
|
|
|
|
|
is_ci_test=False
|
|
|
|
|
is_dsw=False
|
|
|
|
|
is_cpu=False
|
|
|
|
|
run_ci_test=False
|
|
|
|
|
function usage(){
|
|
|
|
|
echo "usage: build.sh "
|
|
|
|
|
echo " --python=python_version set python version, default: $python_version"
|
|
|
|
|
echo " --torch=torch_version set pytorch version, fefault: $torch_version"
|
|
|
|
|
echo " --cudatoolkit=cudatoolkit_version set cudatoolkit version used for pytorch, default: $cudatoolkit_version"
|
|
|
|
|
echo " --tensorflow=tensorflow_version set tensorflow version, default: $tensorflow_version"
|
|
|
|
|
echo " --modelscope=modelscope_version set modelscope version, default: $modelscope_version"
|
|
|
|
|
echo " --test option for run test before push image, only push on ci test pass"
|
|
|
|
|
echo " --cpu option for build cpu version"
|
|
|
|
|
echo " --dsw option for build dsw version"
|
|
|
|
|
echo " --ci option for build ci version"
|
|
|
|
|
echo " --push option for push image to remote repo"
|
|
|
|
|
}
|
|
|
|
|
for i in "$@"; do
|
|
|
|
|
case $i in
|
|
|
|
|
--python=*)
|
|
|
|
|
python_version="${i#*=}"
|
|
|
|
|
shift
|
|
|
|
|
;;
|
|
|
|
|
--torch=*)
|
|
|
|
|
torch_version="${i#*=}"
|
|
|
|
|
shift # pytorch version
|
|
|
|
|
;;
|
|
|
|
|
--tensorflow=*)
|
|
|
|
|
tensorflow_version="${i#*=}"
|
|
|
|
|
shift # tensorflow version
|
|
|
|
|
;;
|
|
|
|
|
--cudatoolkit=*)
|
|
|
|
|
cudatoolkit_version="${i#*=}"
|
|
|
|
|
shift # cudatoolkit for pytorch
|
|
|
|
|
;;
|
|
|
|
|
--modelscope=*)
|
|
|
|
|
modelscope_version="${i#*=}"
|
2023-03-02 11:06:56 +08:00
|
|
|
shift # modelscope version
|
2022-08-22 16:01:42 +08:00
|
|
|
;;
|
|
|
|
|
--test)
|
|
|
|
|
run_ci_test=True
|
|
|
|
|
shift # will run ci test
|
|
|
|
|
;;
|
|
|
|
|
--cpu)
|
|
|
|
|
is_cpu=True
|
|
|
|
|
shift # is cpu image
|
|
|
|
|
;;
|
|
|
|
|
--ci)
|
|
|
|
|
is_ci_test=True
|
|
|
|
|
shift # is ci, will not install modelscope
|
|
|
|
|
;;
|
|
|
|
|
--dsw)
|
|
|
|
|
is_dsw=True
|
|
|
|
|
shift # is dsw, will set dsw cache location
|
|
|
|
|
;;
|
|
|
|
|
--push)
|
|
|
|
|
is_push=True
|
2023-03-02 11:06:56 +08:00
|
|
|
shift # option for push image to remote repo
|
2022-08-22 16:01:42 +08:00
|
|
|
;;
|
|
|
|
|
--help)
|
|
|
|
|
usage
|
|
|
|
|
exit 0
|
|
|
|
|
;;
|
|
|
|
|
-*|--*)
|
|
|
|
|
echo "Unknown option $i"
|
|
|
|
|
usage
|
|
|
|
|
exit 1
|
|
|
|
|
;;
|
|
|
|
|
*)
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
if [ "$modelscope_version" == "None" ]; then
|
|
|
|
|
echo "ModelScope version must specify!"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
if [ "$is_cpu" == "True" ]; then
|
|
|
|
|
base_tag=ubuntu20.04
|
|
|
|
|
export USE_GPU=False
|
|
|
|
|
else
|
|
|
|
|
base_tag=ubuntu20.04-cuda11.3.0
|
|
|
|
|
export USE_GPU=True
|
|
|
|
|
fi
|
|
|
|
|
if [[ $python_version == 3.7* ]]; then
|
2023-06-08 10:01:58 +08:00
|
|
|
if [ "$is_cpu" == "True" ]; then
|
|
|
|
|
echo "Building python3.7 cpu image"
|
|
|
|
|
export BASE_IMAGE=$BASE_PY37_CPU_IMAGE
|
|
|
|
|
else
|
|
|
|
|
echo "Building python3.7 gpu image"
|
|
|
|
|
export BASE_IMAGE=$BASE_PY37_GPU_IMAGE
|
|
|
|
|
fi
|
2022-08-22 16:01:42 +08:00
|
|
|
base_tag=$base_tag-py37
|
2023-02-07 02:28:20 +00:00
|
|
|
elif [[ $python_version == 3.8* ]]; then
|
2023-06-08 10:01:58 +08:00
|
|
|
if [ "$is_cpu" == "True" ]; then
|
|
|
|
|
echo "Building python3.8 cpu image"
|
|
|
|
|
export BASE_IMAGE=$BASE_PY38_CPU_IMAGE
|
|
|
|
|
else
|
|
|
|
|
echo "Building python3.8 gpu image"
|
|
|
|
|
export BASE_IMAGE=$BASE_PY38_GPU_IMAGE
|
|
|
|
|
fi
|
2022-08-22 16:01:42 +08:00
|
|
|
base_tag=$base_tag-py38
|
|
|
|
|
else
|
|
|
|
|
echo "Unsupport python version: $python_version"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
target_image_tag=$base_tag-torch$torch_version-tf$tensorflow_version
|
|
|
|
|
if [ "$is_ci_test" == "True" ]; then
|
|
|
|
|
target_image_tag=$target_image_tag-$modelscope_version-ci
|
|
|
|
|
else
|
|
|
|
|
target_image_tag=$target_image_tag-$modelscope_version-test
|
|
|
|
|
fi
|
|
|
|
|
export IMAGE_TO_BUILD=$MODELSCOPE_REPO_ADDRESS:$target_image_tag
|
|
|
|
|
export PYTHON_VERSION=$python_version
|
|
|
|
|
export TORCH_VERSION=$torch_version
|
|
|
|
|
export CUDATOOLKIT_VERSION=$cudatoolkit_version
|
|
|
|
|
export TENSORFLOW_VERSION=$tensorflow_version
|
|
|
|
|
echo -e "Building image with:\npython$python_version\npytorch$torch_version\ntensorflow:$tensorflow_version\ncudatoolkit:$cudatoolkit_version\ncpu:$is_cpu\nis_ci:$is_ci_test\nis_dsw:$is_dsw\n"
|
|
|
|
|
docker_file_content=`cat docker/Dockerfile.ubuntu`
|
|
|
|
|
if [ "$is_ci_test" != "True" ]; then
|
|
|
|
|
echo "Building ModelScope lib, will install ModelScope lib to image"
|
2023-06-12 11:03:28 +08:00
|
|
|
docker_file_content="${docker_file_content} \nRUN pip install --no-cache-dir modelscope==$modelscope_version -f https://modelscope.oss-cn-beijing.aliyuncs.com/releases/repo.html"
|
2022-08-22 16:01:42 +08:00
|
|
|
fi
|
|
|
|
|
echo "$is_dsw"
|
|
|
|
|
if [ "$is_dsw" == "False" ]; then
|
|
|
|
|
echo "Not DSW image"
|
|
|
|
|
else
|
2023-03-02 11:06:56 +08:00
|
|
|
echo "Building dsw image will need set ModelScope lib cache location."
|
2022-08-22 16:01:42 +08:00
|
|
|
docker_file_content="${docker_file_content} \nENV MODELSCOPE_CACHE=/mnt/workspace/.cache/modelscope"
|
2023-06-12 11:03:28 +08:00
|
|
|
# pre compile extension
|
|
|
|
|
docker_file_content="${docker_file_content} \nRUN python -c 'from modelscope.utils.pre_compile import pre_compile_all;pre_compile_all()'"
|
2022-08-22 16:01:42 +08:00
|
|
|
fi
|
2023-02-07 02:28:20 +00:00
|
|
|
if [ "$is_ci_test" == "True" ]; then
|
|
|
|
|
echo "Building CI image, uninstall modelscope"
|
|
|
|
|
docker_file_content="${docker_file_content} \nRUN pip uninstall modelscope -y"
|
|
|
|
|
fi
|
2022-08-22 16:01:42 +08:00
|
|
|
printf "$docker_file_content" > Dockerfile
|
2023-02-07 02:28:20 +00:00
|
|
|
|
|
|
|
|
while true
|
|
|
|
|
do
|
|
|
|
|
docker build -t $IMAGE_TO_BUILD \
|
2022-08-22 16:01:42 +08:00
|
|
|
--build-arg USE_GPU \
|
|
|
|
|
--build-arg BASE_IMAGE \
|
|
|
|
|
--build-arg PYTHON_VERSION \
|
|
|
|
|
--build-arg TORCH_VERSION \
|
|
|
|
|
--build-arg CUDATOOLKIT_VERSION \
|
|
|
|
|
--build-arg TENSORFLOW_VERSION \
|
|
|
|
|
-f Dockerfile .
|
2023-02-07 02:28:20 +00:00
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
|
echo "Image build done"
|
|
|
|
|
break
|
|
|
|
|
else
|
|
|
|
|
echo "Running docker build command error, we will retry"
|
|
|
|
|
fi
|
|
|
|
|
done
|
2022-08-22 16:01:42 +08:00
|
|
|
|
|
|
|
|
if [ "$run_ci_test" == "True" ]; then
|
|
|
|
|
echo "Running ci case."
|
|
|
|
|
export MODELSCOPE_CACHE=/home/mulin.lyh/model_scope_cache
|
|
|
|
|
export MODELSCOPE_HOME_CACHE=/home/mulin.lyh/ci_case_home # for credential
|
|
|
|
|
export IMAGE_NAME=$MODELSCOPE_REPO_ADDRESS
|
|
|
|
|
export IMAGE_VERSION=$target_image_tag
|
|
|
|
|
export MODELSCOPE_DOMAIN=www.modelscope.cn
|
|
|
|
|
export HUB_DATASET_ENDPOINT=http://www.modelscope.cn
|
|
|
|
|
export CI_TEST=True
|
|
|
|
|
export TEST_LEVEL=1
|
|
|
|
|
if [ "$is_ci_test" != "True" ]; then
|
|
|
|
|
echo "Testing for dsw image or MaaS-lib image"
|
|
|
|
|
export CI_COMMAND="python tests/run.py"
|
|
|
|
|
fi
|
|
|
|
|
bash .dev_scripts/dockerci.sh
|
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
|
echo "Running unittest failed, please check the log!"
|
|
|
|
|
exit -1
|
|
|
|
|
fi
|
|
|
|
|
fi
|
|
|
|
|
if [ "$is_push" == "True" ]; then
|
|
|
|
|
echo "Pushing image: $IMAGE_TO_BUILD"
|
|
|
|
|
docker push $IMAGE_TO_BUILD
|
|
|
|
|
fi
|