test_serving_infer_cpp.sh 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #!/bin/bash
  2. source test_tipc/utils_func.sh
  3. FILENAME=$1
  4. MODE="serving_infer"
  5. # parser model_name
  6. dataline=$(cat ${FILENAME})
  7. IFS=$'\n'
  8. lines=(${dataline})
  9. model_name=$(func_parser_value "${lines[1]}")
  10. echo "ppdet serving_cpp_infer: ${model_name}"
  11. python=$(func_parser_value "${lines[2]}")
  12. filename_key=$(func_parser_key "${lines[3]}")
  13. filename_value=$(func_parser_value "${lines[3]}")
  14. # parser export params
  15. save_export_key=$(func_parser_key "${lines[5]}")
  16. save_export_value=$(func_parser_value "${lines[5]}")
  17. export_weight_key=$(func_parser_key "${lines[6]}")
  18. export_weight_value=$(func_parser_value "${lines[6]}")
  19. norm_export=$(func_parser_value "${lines[7]}")
  20. pact_export=$(func_parser_value "${lines[8]}")
  21. fpgm_export=$(func_parser_value "${lines[9]}")
  22. distill_export=$(func_parser_value "${lines[10]}")
  23. export_key1=$(func_parser_key "${lines[11]}")
  24. export_value1=$(func_parser_value "${lines[11]}")
  25. export_key2=$(func_parser_key "${lines[12]}")
  26. export_value2=$(func_parser_value "${lines[12]}")
  27. kl_quant_export=$(func_parser_value "${lines[13]}")
  28. # parser serving params
  29. infer_mode_list=$(func_parser_value "${lines[15]}")
  30. infer_is_quant_list=$(func_parser_value "${lines[16]}")
  31. model_key=$(func_parser_key "${lines[17]}")
  32. op_key=$(func_parser_key "${lines[18]}")
  33. op_value=$(func_parser_value "${lines[18]}")
  34. port_key=$(func_parser_key "${lines[19]}")
  35. port_value=$(func_parser_value "${lines[19]}")
  36. gpu_ids_key=$(func_parser_key "${lines[20]}")
  37. gpu_ids_value=$(func_parser_value "${lines[20]}")
  38. web_service_key1=$(func_parser_key "${lines[21]}")
  39. web_service_value1=$(func_parser_value "${lines[21]}")
  40. http_client_py=$(func_parser_value "${lines[22]}")
  41. serving_client_key=$(func_parser_key "${lines[23]}")
  42. infer_image_key=$(func_parser_key "${lines[24]}")
  43. infer_image_value=$(func_parser_value "${lines[24]}")
  44. http_client_key1=$(func_parser_key "${lines[25]}")
  45. http_client_value1=$(func_parser_value "${lines[25]}")
  46. LOG_PATH="./test_tipc/output/${model_name}/${MODE}"
  47. mkdir -p ${LOG_PATH}
  48. status_log="${LOG_PATH}/results_serving_cpp.log"
  49. function func_serving_inference(){
  50. IFS='|'
  51. _python=$1
  52. _log_path=$2
  53. _set_server_model_dir=$3
  54. _set_client_model_dir=$4
  55. _set_image_file=$5
  56. set_op=$(func_set_params "${op_key}" "${op_value}")
  57. set_port=$(func_set_params "${port_key}" "${port_value}")
  58. set_web_service_params1=$(func_set_params "${web_service_key1}" "${web_service_value1}")
  59. set_http_client_params1=$(func_set_params "${http_client_key1}" "${http_client_value1}")
  60. # inference
  61. for gpu_ids in ${gpu_ids_value[*]}; do
  62. if [ ${gpu_ids} = "null" ];then
  63. server_log_path="${_log_path}/cpp_server_cpu.log"
  64. client_log_path="${_log_path}/cpp_client_cpu.log"
  65. else
  66. server_log_path="${_log_path}/cpp_server_gpu.log"
  67. client_log_path="${_log_path}/cpp_client_gpu.log"
  68. fi
  69. set_gpu_ids=$(func_set_params "${gpu_ids_key}" "${gpu_ids}")
  70. # run web service
  71. web_service_cmd="${_python} -m paddle_serving_server.serve ${_set_server_model_dir} ${set_op} ${set_port} ${set_gpu_ids} ${set_web_service_params1} > ${server_log_path} 2>&1 &"
  72. eval $web_service_cmd
  73. last_status=${PIPESTATUS[0]}
  74. cat ${server_log_path}
  75. status_check $last_status "${web_service_cmd}" "${status_log}" "${model_name}" "${server_log_path}"
  76. sleep 5s
  77. # run http client
  78. http_client_cmd="${_python} ${http_client_py} ${_set_client_model_dir} ${_set_image_file} ${set_http_client_params1} > ${client_log_path} 2>&1"
  79. eval $http_client_cmd
  80. last_status=${PIPESTATUS[0]}
  81. cat ${client_log_path}
  82. status_check $last_status "${http_client_cmd}" "${status_log}" "${model_name}" "${client_log_path}"
  83. ps ux | grep -i ${port_value} | awk '{print $2}' | xargs kill -s 9
  84. sleep 2s
  85. done
  86. }
  87. # run serving infer
  88. Count=0
  89. IFS="|"
  90. infer_quant_flag=(${infer_is_quant_list})
  91. for infer_mode in ${infer_mode_list[*]}; do
  92. if [ ${infer_mode} != "null" ]; then
  93. # run export
  94. case ${infer_mode} in
  95. norm) run_export=${norm_export} ;;
  96. quant) run_export=${pact_export} ;;
  97. fpgm) run_export=${fpgm_export} ;;
  98. distill) run_export=${distill_export} ;;
  99. kl_quant) run_export=${kl_quant_export} ;;
  100. *) echo "Undefined infer_mode!"; exit 1;
  101. esac
  102. set_export_weight=$(func_set_params "${export_weight_key}" "${export_weight_value}")
  103. set_save_export_dir=$(func_set_params "${save_export_key}" "${save_export_value}")
  104. set_filename=$(func_set_params "${filename_key}" "${model_name}")
  105. export_log_path="${LOG_PATH}/export.log"
  106. export_cmd="${python} ${run_export} ${set_export_weight} ${set_filename} ${set_save_export_dir} "
  107. echo $export_cmd
  108. eval "${export_cmd} > ${export_log_path} 2>&1"
  109. status_export=$?
  110. cat ${export_log_path}
  111. status_check $status_export "${export_cmd}" "${status_log}" "${model_name}" "${export_log_path}"
  112. fi
  113. #run inference
  114. set_server_model_dir=$(func_set_params "${model_key}" "${save_export_value}/${model_name}/serving_server")
  115. set_client_model_dir=$(func_set_params "${serving_client_key}" "${save_export_value}/${model_name}/serving_client")
  116. set_infer_image_file=$(func_set_params "${infer_image_key}" "${infer_image_value}")
  117. is_quant=${infer_quant_flag[Count]}
  118. func_serving_inference "${python}" "${LOG_PATH}" "${set_server_model_dir}" "${set_client_model_dir}" ${set_infer_image_file}
  119. Count=$(($Count + 1))
  120. done
  121. eval "unset CUDA_VISIBLE_DEVICES"