run_benchmark.sh 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #!/usr/bin/env bash
  2. set -xe
  3. # Usage:CUDA_VISIBLE_DEVICES=0 bash benchmark/run_benchmark.sh ${run_mode} ${batch_size} ${fp_item} ${max_epoch} ${model_name}
  4. python="python3.7"
  5. # Parameter description
  6. function _set_params(){
  7. run_mode=${1:-"sp"} # sp|mp
  8. batch_size=${2:-"2"}
  9. fp_item=${3:-"fp32"} # fp32|fp16
  10. max_epoch=${4:-"1"}
  11. model_item=${5:-"model_item"}
  12. run_log_path=${TRAIN_LOG_DIR:-$(pwd)}
  13. # 添加日志解析需要的参数
  14. base_batch_size=${batch_size}
  15. mission_name="目标检测"
  16. direction_id="0"
  17. ips_unit="images/s"
  18. skip_steps=10 # 解析日志,有些模型前几个step耗时长,需要跳过 (必填)
  19. keyword="ips:" # 解析日志,筛选出数据所在行的关键字 (必填)
  20. index="1"
  21. model_name=${model_item}_bs${batch_size}_${fp_item}
  22. device=${CUDA_VISIBLE_DEVICES//,/ }
  23. arr=(${device})
  24. num_gpu_devices=${#arr[*]}
  25. log_file=${run_log_path}/${model_item}_${run_mode}_bs${batch_size}_${fp_item}_${num_gpu_devices}
  26. }
  27. function _train(){
  28. echo "Train on ${num_gpu_devices} GPUs"
  29. echo "current CUDA_VISIBLE_DEVICES=$CUDA_VISIBLE_DEVICES, gpus=$num_gpu_devices, batch_size=$batch_size"
  30. # set runtime params
  31. set_optimizer_lr_sp=" "
  32. set_optimizer_lr_mp=" "
  33. # parse model_item
  34. case ${model_item} in
  35. faster_rcnn) model_yml="benchmark/configs/faster_rcnn_r50_fpn_1x_coco.yml"
  36. set_optimizer_lr_sp="LearningRate.base_lr=0.001" ;;
  37. fcos) model_yml="configs/fcos/fcos_r50_fpn_1x_coco.yml"
  38. set_optimizer_lr_sp="LearningRate.base_lr=0.001" ;;
  39. deformable_detr) model_yml="configs/deformable_detr/deformable_detr_r50_1x_coco.yml" ;;
  40. gfl) model_yml="configs/gfl/gfl_r50_fpn_1x_coco.yml"
  41. set_optimizer_lr_sp="LearningRate.base_lr=0.001" ;;
  42. hrnet) model_yml="configs/keypoint/hrnet/hrnet_w32_256x192.yml" ;;
  43. higherhrnet) model_yml="configs/keypoint/higherhrnet/higherhrnet_hrnet_w32_512.yml" ;;
  44. solov2) model_yml="configs/solov2/solov2_r50_fpn_1x_coco.yml" ;;
  45. jde) model_yml="configs/mot/jde/jde_darknet53_30e_1088x608.yml" ;;
  46. fairmot) model_yml="configs/mot/fairmot/fairmot_dla34_30e_1088x608.yml" ;;
  47. *) echo "Undefined model_item"; exit 1;
  48. esac
  49. set_batch_size="TrainReader.batch_size=${batch_size}"
  50. set_max_epoch="epoch=${max_epoch}"
  51. set_log_iter="log_iter=1"
  52. if [ ${fp_item} = "fp16" ]; then
  53. set_fp_item="--fp16"
  54. else
  55. set_fp_item=" "
  56. fi
  57. case ${run_mode} in
  58. sp) train_cmd="${python} -u tools/train.py -c ${model_yml} ${set_fp_item} \
  59. -o ${set_batch_size} ${set_max_epoch} ${set_log_iter} ${set_optimizer_lr_sp}" ;;
  60. mp) rm -rf mylog
  61. train_cmd="${python} -m paddle.distributed.launch --log_dir=./mylog \
  62. --gpus=${CUDA_VISIBLE_DEVICES} tools/train.py -c ${model_yml} ${set_fp_item} \
  63. -o ${set_batch_size} ${set_max_epoch} ${set_log_iter} ${set_optimizer_lr_mp}"
  64. log_parse_file="mylog/workerlog.0" ;;
  65. *) echo "choose run_mode(sp or mp)"; exit 1;
  66. esac
  67. timeout 15m ${train_cmd} > ${log_file} 2>&1
  68. if [ $? -ne 0 ];then
  69. echo -e "${train_cmd}, FAIL"
  70. export job_fail_flag=1
  71. else
  72. echo -e "${train_cmd}, SUCCESS"
  73. export job_fail_flag=0
  74. fi
  75. kill -9 `ps -ef|grep 'python'|awk '{print $2}'`
  76. if [ $run_mode = "mp" -a -d mylog ]; then
  77. rm ${log_file}
  78. cp mylog/workerlog.0 ${log_file}
  79. fi
  80. }
  81. source ${BENCHMARK_ROOT}/scripts/run_model.sh # 在该脚本中会对符合benchmark规范的log使用analysis.py 脚本进行性能数据解析;该脚本在连调时可从benchmark repo中下载https://github.com/PaddlePaddle/benchmark/blob/master/scripts/run_model.sh;如果不联调只想要产出训练log可以注掉本行,提交时需打开
  82. _set_params $@
  83. # _train # 如果只想产出训练log,不解析,可取消注释
  84. _run # 该函数在run_model.sh中,执行时会调用_train; 如果不联调只想要产出训练log可以注掉本行,提交时需打开