test_train_inference_python_xpu.sh 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #!/bin/bash
  2. source test_tipc/utils_func.sh
  3. function readlinkf() {
  4. perl -MCwd -e 'print Cwd::abs_path shift' "$1";
  5. }
  6. function func_parser_config() {
  7. strs=$1
  8. IFS=" "
  9. array=(${strs})
  10. tmp=${array[2]}
  11. echo ${tmp}
  12. }
  13. function func_parser_dir() {
  14. strs=$1
  15. IFS="/"
  16. array=(${strs})
  17. len=${#array[*]}
  18. dir=""
  19. count=1
  20. for arr in ${array[*]}; do
  21. if [ ${len} = "${count}" ]; then
  22. continue;
  23. else
  24. dir="${dir}/${arr}"
  25. count=$((${count} + 1))
  26. fi
  27. done
  28. echo "${dir}"
  29. }
  30. BASEDIR=$(dirname "$0")
  31. REPO_ROOT_PATH=$(readlinkf ${BASEDIR}/../)
  32. FILENAME=$1
  33. # change gpu to xpu in tipc txt configs
  34. sed -i "s/use_gpu:True/use_xpu:True/g" $FILENAME
  35. sed -i "s/--device:gpu|cpu/--device:xpu|cpu/g" $FILENAME
  36. sed -i "s/trainer:pact_train/trainer:norm_train/g" $FILENAME
  37. sed -i "s/trainer:fpgm_train/trainer:norm_train/g" $FILENAME
  38. sed -i "s/--slim_config _template_pact/ /g" $FILENAME
  39. sed -i "s/--slim_config _template_fpgm/ /g" $FILENAME
  40. sed -i "s/--slim_config _template_kl_quant/ /g" $FILENAME
  41. sed -i 's/\"gpu\"/\"xpu\"/g' test_tipc/test_train_inference_python.sh
  42. # parser params
  43. dataline=`cat $FILENAME`
  44. IFS=$'\n'
  45. lines=(${dataline})
  46. # replace training config file
  47. grep -n '.yml' $FILENAME | cut -d ":" -f 1 \
  48. | while read line_num ; do
  49. train_cmd=$(func_parser_value "${lines[line_num-1]}")
  50. trainer_config=$(func_parser_config ${train_cmd})
  51. echo ${trainer_config}
  52. sed -i 's/use_gpu/use_xpu/g' "$REPO_ROOT_PATH/$trainer_config"
  53. # fine use_gpu in those included yaml
  54. sub_datalinee=`cat $REPO_ROOT_PATH/$trainer_config`
  55. IFS=$'\n'
  56. sub_lines=(${sub_datalinee})
  57. grep -n '.yml' "$REPO_ROOT_PATH/$trainer_config" | cut -d ":" -f 1 \
  58. | while read sub_line_num; do
  59. sub_config=${sub_lines[sub_line_num-1]}
  60. dst=${#sub_config}-5
  61. sub_path=$(func_parser_dir "${trainer_config}")
  62. sub_config_path="${REPO_ROOT_PATH}${sub_path}/${sub_config:3:${dst}}"
  63. echo ${sub_config_path}
  64. sed -i 's/use_gpu/use_xpu/g' "$sub_config_path"
  65. done
  66. done
  67. # pass parameters to test_train_inference_python.sh
  68. cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} $2"
  69. echo $cmd
  70. eval $cmd