test_train_inference_python_npu.sh 2.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#!/bin/bash
source test_tipc/utils_func.sh
function readlinkf() {
    perl -MCwd -e 'print Cwd::abs_path shift' "$1";
}
function func_parser_config() {
    strs=$1
    IFS=" "
    array=(${strs})
    tmp=${array[2]}
    echo ${tmp}
}
function func_parser_dir() {
    strs=$1
    IFS="/"
    array=(${strs})
    len=${#array[*]}
    dir=""
    count=1
    for arr in ${array[*]}; do 
        if [ ${len} = "${count}" ]; then
            continue;
        else
            dir="${dir}/${arr}"
            count=$((${count} + 1))
        fi
    done
    echo "${dir}"
}
BASEDIR=$(dirname "$0")
REPO_ROOT_PATH=$(readlinkf ${BASEDIR}/../)
FILENAME=$1
 # change gpu to npu in tipc txt configs
 sed -i "s/use_gpu:True/use_npu:True/g" $FILENAME
 sed -i "s/--device:gpu|cpu/--device:npu|cpu/g" $FILENAME
D
duanyanhui 已提交
36 37
 sed -i "s/--device:gpu/--device:npu/g" $FILENAME
 sed -i "s/--device:cpu|gpu/--device:cpu|npu/g" $FILENAME
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
 sed -i "s/trainer:pact_train/trainer:norm_train/g" $FILENAME
 sed -i "s/trainer:fpgm_train/trainer:norm_train/g" $FILENAME
 sed -i "s/--slim_config _template_pact/ /g" $FILENAME
 sed -i "s/--slim_config _template_fpgm/ /g" $FILENAME
 sed -i "s/--slim_config _template_kl_quant/ /g" $FILENAME
 sed -i 's/\"gpu\"/\"npu\"/g' test_tipc/test_train_inference_python.sh

 # parser params
dataline=`cat $FILENAME`
IFS=$'\n'
lines=(${dataline})
# replace training config file
grep -n '.yml' $FILENAME  | cut -d ":" -f 1 \
| while read line_num ; do 
    train_cmd=$(func_parser_value "${lines[line_num-1]}")
    trainer_config=$(func_parser_config ${train_cmd})
    sed -i 's/use_gpu/use_npu/g' "$REPO_ROOT_PATH/$trainer_config"
D
duanyanhui 已提交
55
    sed -i 's/aligned: True/aligned: False/g' "$REPO_ROOT_PATH/$trainer_config"
56 57 58 59 60 61 62 63 64
    # fine use_gpu in those included yaml
    sub_datalinee=`cat $REPO_ROOT_PATH/$trainer_config`
    IFS=$'\n'
    sub_lines=(${sub_datalinee})
    grep -n '.yml' "$REPO_ROOT_PATH/$trainer_config" | cut -d ":" -f 1 \
    | while read sub_line_num; do
        sub_config=${sub_lines[sub_line_num-1]} 
        dst=${#sub_config}-5
        sub_path=$(func_parser_dir "${trainer_config}")
D
duanyanhui 已提交
65 66
        sub_config_name=$(echo "$sub_config" | awk -F"'" '{ print $2 }')
        sub_config_path="${REPO_ROOT_PATH}${sub_path}/${sub_config_name}"
67
        sed -i 's/use_gpu/use_npu/g' "$sub_config_path"
D
duanyanhui 已提交
68
        sed -i 's/aligned: True/aligned: False/g' "$sub_config_path"
69 70 71 72 73 74
    done
done
# pass parameters to test_train_inference_python.sh
cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} $2"
echo $cmd
eval $cmd