Skip to content

Commit f7cab20

Browse files
committed
Creat the ci_model_unit.sh
1 parent cf23ca0 commit f7cab20

File tree

1 file changed

+131
-0
lines changed

1 file changed

+131
-0
lines changed

scripts/unit_test/ci_model_unit.sh

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -e
18+
export paddle=$1
19+
export FLAGS_enable_CE=${2-false}
20+
export nlp_dir=/workspace/PaddleFormers
21+
export log_path=/workspace/PaddleFormers/model_unittest_logs
22+
export model_unittest_path=/workspace/PaddleFormers/scripts/regression
23+
cd $nlp_dir
24+
25+
if [ ! -d "model_unittest_logs" ];then
26+
mkdir model_unittest_logs
27+
fi
28+
29+
install_requirements() {
30+
python -m pip config --user set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
31+
python -m pip config --user set global.trusted-host pypi.tuna.tsinghua.edu.cn
32+
python -m pip install -r requirements.txt
33+
python -m pip install -r requirements-dev.txt
34+
python -m pip install -r tests/requirements.txt
35+
python -m pip uninstall paddlepaddle paddlepaddle_gpu -y
36+
python -m pip install --no-cache-dir ${paddle} --no-dependencies
37+
python -c "import paddle;print('paddle');print(paddle.__version__);print(paddle.version.show())" >> ${log_path}/commit_info.txt
38+
39+
python setup.py bdist_wheel > /dev/null
40+
python -m pip install dist/p****.whl
41+
python -c "from paddleformers import __version__; print('paddleformers version:', __version__)" >> ${log_path}/commit_info.txt
42+
python -c "import paddleformers; print('paddleformers commit:',paddleformers.version.commit)" >> ${log_path}/commit_info.txt
43+
python -m pip list >> ${log_path}/commit_info.txt
44+
}
45+
46+
set_env() {
47+
export NVIDIA_TF32_OVERRIDE=0
48+
export FLAGS_cudnn_deterministic=1
49+
export HF_ENDPOINT=https://hf-mirror.com
50+
export FLAGS_use_cuda_managed_memory=true
51+
52+
# for CE
53+
if [[ ${FLAGS_enable_CE} == "true" ]];then
54+
export CE_TEST_ENV=1
55+
export RUN_SLOW_TEST=1
56+
export PYTHONPATH=${nlp_dir}:${nlp_dir}/llm:${PYTHONPATH}
57+
fi
58+
}
59+
60+
print_info() {
61+
if [ $1 -ne 0 ]; then
62+
cat ${log_path}/model_unittest.log | grep -v "Fail to fscanf: Success" \
63+
| grep -v "SKIPPED" | grep -v "warning" > ${log_path}/model_unittest_FAIL.log
64+
tail -n 1 ${log_path}/model_unittest.log >> ${log_path}/model_unittest_FAIL.log
65+
echo -e "\033[31m ${log_path}/model_unittest_FAIL \033[0m"
66+
cat ${log_path}/model_unittest_FAIL.log
67+
if [ -n "${AGILE_JOB_BUILD_ID}" ]; then
68+
cp ${log_path}/model_unittest_FAIL.log ${PPNLP_HOME}/upload/model_unittest_FAIL.log.${AGILE_PIPELINE_BUILD_ID}.${AGILE_JOB_BUILD_ID}
69+
cd ${PPNLP_HOME} && python upload.py ${PPNLP_HOME}/upload 'paddlenlp/PaddleNLP_CI/PaddleNLP-CI-Model-Unittest-GPU'
70+
rm -rf upload/* && cd -
71+
fi
72+
if [ $1 -eq 124 ]; then
73+
echo "\033[32m [failed-timeout] Test case execution was terminated after exceeding the ${running_time} min limit."
74+
fi
75+
else
76+
tail -n 1 ${log_path}/model_unittest.log
77+
echo -e "\033[32m ${log_path}/model_unittest_SUCCESS \033[0m"
78+
fi
79+
}
80+
81+
get_diff_TO_case(){
82+
export FLAGS_enable_CI=false
83+
if [ -z "${AGILE_COMPILE_BRANCH}" ]; then
84+
# Scheduled Regression Test
85+
FLAGS_enable_CI=true
86+
else
87+
for file_name in `git diff --numstat ${AGILE_COMPILE_BRANCH} -- |awk '{print $NF}'`;do
88+
ext="${file_name##*.}"
89+
echo "file_name: ${file_name}, ext: ${file_name##*.}"
90+
91+
if [ ! -f ${file_name} ];then # Delete Files for a Pull Request
92+
continue
93+
elif [[ "$ext" == "md" || "$ext" == "rst" || "$file_name" == docs/* ]]; then
94+
continue
95+
else
96+
FLAGS_enable_CI=true
97+
fi
98+
done
99+
fi
100+
}
101+
102+
get_diff_TO_case
103+
set_env
104+
if [[ ${FLAGS_enable_CI} == "true" ]] || [[ ${FLAGS_enable_CE} == "true" ]];then
105+
install_requirements
106+
cd ${nlp_dir}
107+
echo ' Testing all model unittest cases '
108+
unset http_proxy && unset https_proxy
109+
set +e
110+
DOWNLOAD_SOURCE=aistudio WAIT_UNTIL_DONE=True \
111+
PYTHONPATH=$(pwd) \
112+
COVERAGE_SOURCE=paddleformers \
113+
python -m pytest -s -v ${model_unittest_path} > ${log_path}/model_unittest.log 2>&1
114+
exit_code=$?
115+
print_info $exit_code model_unittest
116+
117+
if [ -n "${AGILE_JOB_BUILD_ID}" ]; then
118+
cd ${nlp_dir}
119+
echo -e "\033[35m ---- Generate Allure Report \033[0m"
120+
unset http_proxy && unset https_proxy
121+
cp ${nlp_dir}/scripts/unit_test/gen_allure_report.py ./
122+
python gen_allure_report.py > /dev/null
123+
echo -e "\033[35m ---- Report: https://xly.bce.baidu.com/ipipe/ipipe-report/report/${AGILE_JOB_BUILD_ID}/report/ \033[0m"
124+
else
125+
echo "AGILE_JOB_BUILD_ID is empty, skip generate allure report"
126+
fi
127+
else
128+
echo -e "\033[32m Changed Not CI case, Skips \033[0m"
129+
exit_code=0
130+
fi
131+
exit $exit_code

0 commit comments

Comments
 (0)