test_train_dy2static_python.sh 1.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10
#!/bin/bash
source test_tipc/common_func.sh

# always use the lite_train_lite_infer mode to speed. Modify the config file.
MODE=lite_train_lite_infer
BASEDIR=$(dirname "$0")

FILENAME=$1
sed -i 's/gpu_list.*$/gpu_list:0/g' $FILENAME
sed -i '23,$d' $FILENAME
11
#sed -i 's/-o Global.device:.*$/-o Global.device:cpu/g' $FILENAME
12 13 14 15 16 17 18 19 20 21 22
sed -i '16s/$/ -o Global.print_batch_step=1/' ${FILENAME}


# get the log path.
IFS=$'\n'
dataline=$(cat ${FILENAME})
lines=(${dataline})
model_name=$(func_parser_value "${lines[1]}")
LOG_PATH="./test_tipc/output/${model_name}/${MODE}"
rm -rf $LOG_PATH
mkdir -p ${LOG_PATH}
23
status_log="${LOG_PATH}/results_python.log"
24

25 26 27
# make cudnn algorithm deterministic, such as conv.
export FLAGS_cudnn_deterministic=True

28
# start dygraph train
29 30
dygraph_output=$LOG_PATH/python_train_infer_dygraph_output.txt
dygraph_loss=$LOG_PATH/dygraph_loss.txt
31 32 33 34 35 36
sed -i '15ctrainer:norm_train' ${FILENAME}
cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} $MODE >$dygraph_output 2>&1"
echo $cmd
eval $cmd

# start dy2static train
37 38
dy2static_output=$LOG_PATH/python_train_infer_dy2static_output.txt
dy2static_loss=$LOG_PATH/dy2static_loss.txt
39 40 41 42 43 44
sed -i '15ctrainer:to_static_train' ${FILENAME}
cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} $MODE >$dy2static_output 2>&1"
echo $cmd
eval $cmd

# analysis and compare the losses. 
X
xiongkun 已提交
45
dyout=`cat $dy2static_output | python3 test_tipc/extract_loss.py -v 'Iter:' -e 'loss: {%f},'`
46 47 48 49 50 51 52
stout=`cat $dygraph_output   | python3 test_tipc/extract_loss.py -v 'Iter:' -e 'loss: {%f},'  `
echo $dyout > $dygraph_loss
echo $stout > $dy2static_loss
diff_log=$LOG_PATH/diff_log.txt
diff_cmd="diff -w $dygraph_loss $dy2static_loss | tee $diff_log"
eval $diff_cmd
last_status=$?
53
if [ "$dyout" = "" ]; then
54
    status_check 2 $diff_cmd $status_log $model_name $diff_log
55
fi
56 57
if [ "$stout" = "" ]; then
    status_check 2 $diff_cmd $status_log $model_name $diff_log
58
fi
59
status_check $last_status $diff_cmd $status_log $model_name $diff_log