提交 e039650e 编写于 作者: L LDOUBLEV

add benchmark_train.sh v2

上级 6cb47e76
#!/bin/bash #!/bin/bash
source test_tipc/common_func.sh source test_tipc/common_func.sh
# set env
python=python3.7
export model_branch=`git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3`
export model_commit=$(git log|head -n1|awk '{print $2}')
export str_tmp=$(echo `pip list|grep paddlepaddle-gpu|awk -F ' ' '{print $2}'`)
export frame_version=${str_tmp%%.post*}
export frame_commit=$(echo `${python} -c "import paddle;print(paddle.version.commit)"`)
# run benchmark sh # run benchmark sh
# Usage: # Usage:
# bash run_benchmark_train.sh config.txt params # bash run_benchmark_train.sh config.txt params
...@@ -55,30 +63,15 @@ function get_repo_name(){ ...@@ -55,30 +63,15 @@ function get_repo_name(){
} }
FILENAME=$1 FILENAME=$1
cp FILENAME as new FILENAME
new_filename="./test_tipc/benchmark_train.txt"
cmd=`yes|cp $FILENAME $new_filename`
FILENAME=$new_filename
# MODE be one of ['benchmark_train'] # MODE be one of ['benchmark_train']
MODE=$2 MODE=$2
params=$3 PARAMS=$3
# bash test_tipc/benchmark_train.sh test_tipc/configs/det_mv3_db_v2.0/train_benchmark.txt benchmark_train dynamic_bs8_null_SingleP_DP_N1C1 # bash test_tipc/benchmark_train.sh test_tipc/configs/det_mv3_db_v2.0/train_benchmark.txt benchmark_train dynamic_bs8_null_SingleP_DP_N1C1
IFS="\n" IFS=$'\n'
# parser params from input: modeltype_bs${bs_item}_${fp_item}_${run_process_type}_${run_mode}_${device_num}
IFS="_"
params_list=(${params})
model_type=${params_list[0]}
batch_size=${params_list[1]}
batch_size=`echo ${batch_size} | tr -cd "[0-9]" `
precision=${params_list[2]}
run_process_type=${params_list[3]}
run_mode=${params_list[4]}
device_num=${params_list[5]}
device_num_copy=$device_num
IFS=";"
# sed batchsize and precision
func_sed_params "$FILENAME" "6" "$precision"
func_sed_params "$FILENAME" "9" "$batch_size"
# parser params from train_benchmark.txt # parser params from train_benchmark.txt
dataline=`cat $FILENAME` dataline=`cat $FILENAME`
# parser params # parser params
...@@ -87,24 +80,22 @@ lines=(${dataline}) ...@@ -87,24 +80,22 @@ lines=(${dataline})
model_name=$(func_parser_value "${lines[1]}") model_name=$(func_parser_value "${lines[1]}")
# 获取benchmark_params所在的行数 # 获取benchmark_params所在的行数
line_num=`grep -n "benchmark_params" $FILENAME | cut -d ":" -f 1` line_num=`grep -n "train_benchmark_params" $FILENAME | cut -d ":" -f 1`
# for train log parser # for train log parser
batch_size=$(func_parser_value "${lines[line_num]}")
line_num=`expr $line_num + 1` line_num=`expr $line_num + 1`
fp_items=$(func_parser_value "${lines[line_num]}")
line_num=`expr $line_num + 1`
epoch=$(func_parser_value "${lines[line_num]}")
line_num=`expr $line_num + 1`
profile_option_key=$(func_parser_key "${lines[line_num]}") profile_option_key=$(func_parser_key "${lines[line_num]}")
profile_option_params=$(func_parser_value "${lines[line_num]}") profile_option_params=$(func_parser_value "${lines[line_num]}")
profile_option="${profile_option_key}:${profile_option_params}" profile_option="${profile_option_key}:${profile_option_params}"
line_num=`expr $line_num + 1` line_num=`expr $line_num + 1`
flags_value=$(func_parser_value "${lines[line_num]}") flags_value=$(func_parser_value "${lines[line_num]}")
# set flags
gpu_id=$(set_gpu_id $device_num)
repo_name=$(get_repo_name )
SAVE_LOG=${BENCHMARK_LOG_DIR:-$(pwd)} # */benchmark_log
status_log="${SAVE_LOG}/benchmark_log/results.log"
# set export
IFS=";" IFS=";"
flags_list=(${flags_value}) flags_list=(${flags_value})
for _flag in ${flags_list[*]}; do for _flag in ${flags_list[*]}; do
...@@ -112,35 +103,71 @@ for _flag in ${flags_list[*]}; do ...@@ -112,35 +103,71 @@ for _flag in ${flags_list[*]}; do
eval $cmd eval $cmd
done done
if [ ${precision} = "null" ];then # set log_name
precision="fp32" repo_name=$(get_repo_name )
fi SAVE_LOG=${BENCHMARK_LOG_DIR:-$(pwd)} # */benchmark_log
mkdir -p "${SAVE_LOG}/benchmark_log/"
# set env status_log="${SAVE_LOG}/benchmark_log/results.log"
python=python
export model_branch=`git symbolic-ref HEAD 2>/dev/null | cut -d"/" -f 3`
export model_commit=$(git log|head -n1|awk '{print $2}')
export str_tmp=$(echo `pip list|grep paddlepaddle-gpu|awk -F ' ' '{print $2}'`)
export frame_version=${str_tmp%%.post*}
export frame_commit=$(echo `${python} -c "import paddle;print(paddle.version.commit)"`)
# set eval and export as null # set eval and export as null
# line eval_py: 24 # line eval_py: 24
# line export_py: 30 # line export_py: 30
func_sed_params "$FILENAME" "24" "null" func_sed_params "$FILENAME" "24" "null"
func_sed_params "$FILENAME" "30" "null" func_sed_params "$FILENAME" "30" "null"
func_sed_params "$FILENAME" "3" "python" func_sed_params "$FILENAME" "3" "$python"
# if params
if [ ! -n "$PARAMS" ] ;then
# PARAMS input is not a word.
IFS="|"
batch_size_list=(${batch_size})
fp_items_list=(${fp_items})
device_num_list=(N1C4)
run_mode="DP"
echo "batchsize list: $batch_size_list ${batch_size_list[1]}"
echo "fp_item_lists: $fp_items_list ${fp_items_list[1]}"
else
# parser params from input: modeltype_bs${bs_item}_${fp_item}_${run_process_type}_${run_mode}_${device_num}
IFS="_"
params_list=(${PARAMS})
model_type=${params_list[0]}
batch_size=${params_list[1]}
batch_size=`echo ${batch_size} | tr -cd "[0-9]" `
precision=${params_list[2]}
run_process_type=${params_list[3]}
run_mode=${params_list[4]}
device_num=${params_list[5]}
IFS=";"
if [ ${precision} = "null" ];then
precision="fp32"
fi
fp_items_list=($precision)
batch_size_list=($batch_size)
device_num_list=($device_num)
fi
if [ ${#gpu_id} -le 1 ];then IFS="|"
for batch_size in ${batch_size_list[*]}; do
for precision in ${fp_items_list[*]}; do
for device_num in ${device_num_list[*]}; do
echo "for $batch_size $precision $device_num $epoch"
# sed batchsize and precision
func_sed_params "$FILENAME" "6" "$precision"
func_sed_params "$FILENAME" "9" "$MODE=$batch_size"
func_sed_params "$FILENAME" "7" "$MODE=$epoch"
gpu_id=$(set_gpu_id $device_num)
if [ ${#gpu_id} -le 1 ];then
run_process_type="SingleP"
log_path="$SAVE_LOG/profiling_log" log_path="$SAVE_LOG/profiling_log"
mkdir -p $log_path mkdir -p $log_path
log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_process_type}_${run_mode}_${device_num}_profiling" log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_process_type}_${run_mode}_${device_num}_profiling"
func_sed_params "$FILENAME" "4" "0" # sed used gpu_id func_sed_params "$FILENAME" "4" "0" # sed used gpu_id
# set profile_option params # set profile_option params
IFS=";" echo "profile_option: ${profile_option}"
cmd="sed -i '13s/.*/${profile_option}/' '${FILENAME}'" tmp=`sed -i "13s/.*/${profile_option}/" "${FILENAME}"`
eval $cmd
# run test_train_inference_python.sh # run test_train_inference_python.sh
cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} benchmark_train > ${log_path}/${log_name} 2>&1 " cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} benchmark_train > ${log_path}/${log_name} 2>&1 "
...@@ -173,18 +200,19 @@ if [ ${#gpu_id} -le 1 ];then ...@@ -173,18 +200,19 @@ if [ ${#gpu_id} -le 1 ];then
--run_mode ${run_mode} \ --run_mode ${run_mode} \
--run_process_type ${run_process_type} \ --run_process_type ${run_process_type} \
--fp_item ${precision} \ --fp_item ${precision} \
--keyword samples/s: \ --keyword ips: \
--skip_steps 2 \ --skip_steps 2 \
--device_num ${device_num} \ --device_num ${device_num} \
--speed_unit images/s \ --speed_unit samples/s \
--convergence_key loss: " --convergence_key loss: "
echo $cmd echo $cmd
eval $cmd eval $cmd
last_status=${PIPESTATUS[0]} last_status=${PIPESTATUS[0]}
status_check $last_status "${cmd}" "${status_log}" status_check $last_status "${cmd}" "${status_log}"
else
else IFS=";"
unset_env=`unset CUDA_VISIBLE_DEVICES` unset_env=`unset CUDA_VISIBLE_DEVICES`
run_process_type="MultiP"
log_path="$SAVE_LOG/train_log" log_path="$SAVE_LOG/train_log"
speed_log_path="$SAVE_LOG/index" speed_log_path="$SAVE_LOG/index"
mkdir -p $log_path mkdir -p $log_path
...@@ -210,7 +238,7 @@ else ...@@ -210,7 +238,7 @@ else
--run_mode ${run_mode} \ --run_mode ${run_mode} \
--run_process_type ${run_process_type} \ --run_process_type ${run_process_type} \
--fp_item ${precision} \ --fp_item ${precision} \
--keyword samples/s: \ --keyword ips: \
--skip_steps 2 \ --skip_steps 2 \
--device_num ${device_num} \ --device_num ${device_num} \
--speed_unit images/s \ --speed_unit images/s \
...@@ -219,5 +247,7 @@ else ...@@ -219,5 +247,7 @@ else
eval $cmd eval $cmd
last_status=${PIPESTATUS[0]} last_status=${PIPESTATUS[0]}
status_check $last_status "${cmd}" "${status_log}" status_check $last_status "${cmd}" "${status_log}"
fi fi
done
done
done
\ No newline at end of file
...@@ -4,9 +4,9 @@ python:python3.7 ...@@ -4,9 +4,9 @@ python:python3.7
gpu_list:0|0,1 gpu_list:0|0,1
Global.use_gpu:True|True Global.use_gpu:True|True
Global.auto_cast:null Global.auto_cast:null
Global.epoch_num:lite_train_lite_infer=1|whole_train_whole_infer=300|benchmark_train=2 Global.epoch_num:lite_train_lite_infer=1|whole_train_whole_infer=300
Global.save_model_dir:./output/ Global.save_model_dir:./output/
Train.loader.batch_size_per_card:lite_train_lite_infer=2|whole_train_whole_infer=4|benchmark_train=16 Train.loader.batch_size_per_card:lite_train_lite_infer=2|whole_train_whole_infer=4
Global.pretrained_model:null Global.pretrained_model:null
train_model_name:latest train_model_name:latest
train_infer_img_dir:./train_data/icdar2015/text_localization/ch4_test_images/ train_infer_img_dir:./train_data/icdar2015/text_localization/ch4_test_images/
...@@ -49,6 +49,9 @@ inference:tools/infer/predict_det.py ...@@ -49,6 +49,9 @@ inference:tools/infer/predict_det.py
null:null null:null
--benchmark:True --benchmark:True
null:null null:null
===========================benchmark_params========================== ===========================train_benchmark_params==========================
batch_size:8|16
fp_items:fp32|fp16
epoch:2
--profiler_options:batch_range=[10,20];state=GPU;tracer_option=Default;profile_path=model.profile --profiler_options:batch_range=[10,20];state=GPU;tracer_option=Default;profile_path=model.profile
flags:FLAGS_eager_delete_tensor_gb=0.0;FLAGS_fraction_of_gpu_memory_to_use=0.98;FLAGS_conv_workspace_size_limit=4096 flags:FLAGS_eager_delete_tensor_gb=0.0;FLAGS_fraction_of_gpu_memory_to_use=0.98;FLAGS_conv_workspace_size_limit=4096
\ No newline at end of file
...@@ -283,7 +283,7 @@ def train(config, ...@@ -283,7 +283,7 @@ def train(config,
eta_sec_format = str(datetime.timedelta(seconds=int(eta_sec))) eta_sec_format = str(datetime.timedelta(seconds=int(eta_sec)))
strs = 'epoch: [{}/{}], global_step: {}, {}, avg_reader_cost: ' \ strs = 'epoch: [{}/{}], global_step: {}, {}, avg_reader_cost: ' \
'{:.5f} s, avg_batch_cost: {:.5f} s, avg_samples: {}, ' \ '{:.5f} s, avg_batch_cost: {:.5f} s, avg_samples: {}, ' \
'samples/s: {:.5f}, eta: {}'.format( 'ips: {:.5f} , eta: {}'.format(
epoch, epoch_num, global_step, logs, epoch, epoch_num, global_step, logs,
train_reader_cost / print_batch_step, train_reader_cost / print_batch_step,
train_batch_cost / print_batch_step, train_batch_cost / print_batch_step,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册