Skip to content

Commit 89e5f22

Browse files
committed
Add checking validation script for ci testing.
1 parent 8273d73 commit 89e5f22

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed

tools/ci/check_validate.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/bash
2+
3+
set +ex
4+
5+
function LOG {
6+
echo [$0:${BASH_LINENO[0]}] $* >&2
7+
}
8+
9+
LOG "[INFO] Start validate samples changed by pull request ..."
10+
11+
export GRAPH_NET_EXTRACT_WORKSPACE=$(cd $(dirname $0)/../.. && pwd)
12+
export PYTHONPATH=${GRAPH_NET_EXTRACT_WORKSPACE}:$PYTHONPATH
13+
14+
[ -z "$CUDA_VISIBLE_DEVICES" ] && CUDA_VISIBLE_DEVICES="0"
15+
16+
function prepare_env() {
17+
num_changed_files=$(git diff --name-only develop | grep -E "samples/(.*\.py|.*\.json)" | wc -l)
18+
if [ ${num_changed_files} -eq 0 ]; then
19+
LOG "[INFO] This pull request doesn't change any files of op benchmark, skip the CI."
20+
exit 0
21+
fi
22+
23+
LOG "[INFO] Device Id: ${CUDA_VISIBLE_DEVICES}"
24+
# Update pip
25+
LOG "[INFO] Update pip ..."
26+
env http_proxy="" https_proxy="" pip install -U pip > /dev/null
27+
[ $? -ne 0 ] && LOG "[FATAL] Update pip failed!" && exit -1
28+
# install torch
29+
}
30+
31+
function check_validation() {
32+
LOG "[INFO] Start run validate for changed samples ..."
33+
MODIFIED_MODEL_PATHS=()
34+
for file in $(git diff --name-only develop | grep -E "samples/(.*\.py|.*\.json)")
35+
do
36+
LOG "[INFO] Found ${file} modified."
37+
model_path=$(dirname ${file})
38+
MODIFIED_MODEL_PATHS[${#MODIFIED_MODEL_PATHS[@]}]=$model_path
39+
done
40+
MODIFIED_MODEL_PATHS=($(echo ${MODIFIED_MODEL_PATHS[@]} | tr ' ' '\n' | sort | uniq))
41+
LOG "[INFO] Validation of these models will run: ${MODIFIED_MODEL_PATHS[@]}"
42+
fail_name=()
43+
for model_path in ${MODIFIED_MODEL_PATHS[@]}
44+
do
45+
python -m graph_net.torch.validate --model-path ${GRAPH_NET_EXTRACT_WORKSPACE}/${model_path} >&2
46+
[ $? -ne 0 ] && fail_name[${#fail_name[@]}]="${model_path}(Run on ${device_type})"
47+
done
48+
if [ ${#fail_name[@]} -ne 0 ]
49+
then
50+
LOG "[FATAL] Failed tests: ${fail_name[@]}"
51+
echo ${fail_name[@]}
52+
exit -1
53+
fi
54+
}
55+
56+
function summary_problems() {
57+
local check_validation_code=$1
58+
local check_validation_info=$2
59+
if [ $check_validation_code -ne 0 ]
60+
then
61+
LOG "[FATAL] ============================================"
62+
LOG "[FATAL] Summary problems:"
63+
LOG "[FATAL] === API test error - Please fix the failed API tests accroding to fatal log:"
64+
LOG "[FATAL] $check_validation_info"
65+
exit $check_validation_code
66+
fi
67+
}
68+
69+
function main() {
70+
prepare_env
71+
check_validation_info=$(check_validation)
72+
check_validation_code=$?
73+
summary_problems $check_validation_code "$check_validation_info"
74+
LOG "[INFO] check_validation run success and no error!"
75+
}
76+
77+
main

0 commit comments

Comments
 (0)