From 33a639dd3b1d602da2f9208937b8b1efb7358a92 Mon Sep 17 00:00:00 2001 From: Aurelius84 Date: Mon, 14 Mar 2022 08:18:19 +0000 Subject: [PATCH 1/3] [TIPC-Benchmark]Support @to_static traing for Benchmark --- test_tipc/benchmark_train.sh | 15 ++++++++++++++- .../MobileNetV1_train_infer_python.txt | 2 +- .../MobileNetV2_train_infer_python.txt | 2 +- .../ResNet/ResNet152_train_infer_python.txt | 2 +- .../config/ResNet/ResNet50_train_infer_python.txt | 2 +- test_tipc/test_train_inference_python.sh | 13 ++++++++----- 6 files changed, 26 insertions(+), 10 deletions(-) diff --git a/test_tipc/benchmark_train.sh b/test_tipc/benchmark_train.sh index 39d4c6d1a..48b2291cd 100644 --- a/test_tipc/benchmark_train.sh +++ b/test_tipc/benchmark_train.sh @@ -65,7 +65,20 @@ FILENAME=$new_filename # MODE must be one of ['benchmark_train'] MODE=$2 PARAMS=$3 -# bash test_tipc/benchmark_train.sh test_tipc/configs/det_mv3_db_v2_0/train_benchmark.txt benchmark_train dynamic_bs8_null_DP_N1C1 +REST_ARGS=$4 +# bash test_tipc/benchmark_train.sh test_tipc/configs/det_mv3_db_v2_0/train_benchmark.txt benchmark_train +# bash test_tipc/benchmark_train.sh test_tipc/configs/det_mv3_db_v2_0/train_benchmark.txt benchmark_train to_static +# bash test_tipc/benchmark_train.sh test_tipc/configs/det_mv3_db_v2_0/train_benchmark.txt benchmark_train dynamic_bs8_null_DP_N1C1 to_static + +# parse "to_static" options and modify trainer into "to_static_trainer" +if [ $REST_ARGS = "to_static" ] || [ $PARAMS = "to_static" ] ;then + sed -i 's/trainer:norm_train/trainer:to_static_train/g' $FILENAME + # clear PARAM contents + if [ $PARAMS = "to_static" ] ;then + PARAMS="" + fi +fi + IFS=$'\n' # parser params from train_benchmark.txt sed -i 's/ -o DataLoader.Train.sampler.shuffle=False//g' $FILENAME diff --git a/test_tipc/config/MobileNetV1/MobileNetV1_train_infer_python.txt b/test_tipc/config/MobileNetV1/MobileNetV1_train_infer_python.txt index 400b15f82..ac12953dd 100644 --- a/test_tipc/config/MobileNetV1/MobileNetV1_train_infer_python.txt +++ b/test_tipc/config/MobileNetV1/MobileNetV1_train_infer_python.txt @@ -17,7 +17,7 @@ norm_train:tools/train.py -c ppcls/configs/ImageNet/MobileNetV1/MobileNetV1.yaml pact_train:null fpgm_train:null distill_train:null -null:null +to_static_train:-o Global.to_static=True null:null ## ===========================eval_params=========================== diff --git a/test_tipc/config/MobileNetV2/MobileNetV2_train_infer_python.txt b/test_tipc/config/MobileNetV2/MobileNetV2_train_infer_python.txt index 796480cc2..eef9b5752 100644 --- a/test_tipc/config/MobileNetV2/MobileNetV2_train_infer_python.txt +++ b/test_tipc/config/MobileNetV2/MobileNetV2_train_infer_python.txt @@ -17,7 +17,7 @@ norm_train:tools/train.py -c ppcls/configs/ImageNet/MobileNetV2/MobileNetV2.yaml pact_train:null fpgm_train:null distill_train:null -null:null +to_static_train:-o Global.to_static=True null:null ## ===========================eval_params=========================== diff --git a/test_tipc/config/ResNet/ResNet152_train_infer_python.txt b/test_tipc/config/ResNet/ResNet152_train_infer_python.txt index ccbba95d1..e45266a9a 100644 --- a/test_tipc/config/ResNet/ResNet152_train_infer_python.txt +++ b/test_tipc/config/ResNet/ResNet152_train_infer_python.txt @@ -17,7 +17,7 @@ norm_train:tools/train.py -c ppcls/configs/ImageNet/ResNet/ResNet152.yaml -o Glo pact_train:null fpgm_train:null distill_train:null -null:null +to_static_train:-o Global.to_static=True null:null ## ===========================eval_params=========================== diff --git a/test_tipc/config/ResNet/ResNet50_train_infer_python.txt b/test_tipc/config/ResNet/ResNet50_train_infer_python.txt index df1f3ca6a..6a668ccd3 100644 --- a/test_tipc/config/ResNet/ResNet50_train_infer_python.txt +++ b/test_tipc/config/ResNet/ResNet50_train_infer_python.txt @@ -17,7 +17,7 @@ norm_train:tools/train.py -c ppcls/configs/ImageNet/ResNet/ResNet50.yaml -o Glob pact_train:null fpgm_train:null distill_train:null -null:null +to_static_train:-o Global.to_static=True null:null ## ===========================eval_params=========================== diff --git a/test_tipc/test_train_inference_python.sh b/test_tipc/test_train_inference_python.sh index 134b7c418..a567ef3c6 100644 --- a/test_tipc/test_train_inference_python.sh +++ b/test_tipc/test_train_inference_python.sh @@ -40,8 +40,8 @@ fpgm_key=$(func_parser_key "${lines[17]}") fpgm_trainer=$(func_parser_value "${lines[17]}") distill_key=$(func_parser_key "${lines[18]}") distill_trainer=$(func_parser_value "${lines[18]}") -trainer_key1=$(func_parser_key "${lines[19]}") -trainer_value1=$(func_parser_value "${lines[19]}") +to_static_key=$(func_parser_key "${lines[19]}") +to_static_trainer=$(func_parser_value "${lines[19]}") trainer_key2=$(func_parser_key "${lines[20]}") trainer_value2=$(func_parser_value "${lines[20]}") @@ -246,9 +246,12 @@ else elif [ ${trainer} = "${distill_key}" ]; then run_train=${distill_trainer} run_export=${distill_export} - elif [ ${trainer} = ${trainer_key1} ]; then - run_train=${trainer_value1} - run_export=${export_value1} + # In case of @to_static, we re-used norm_traier, + # but append "-o Global.to_static=True" for config + # to trigger "apply_to_static" logic in 'engine.py' + elif [ ${trainer} = "${to_static_key}" ]; then + run_train="${norm_trainer} ${to_static_trainer}" + run_export=${norm_export} elif [[ ${trainer} = ${trainer_key2} ]]; then run_train=${trainer_value2} run_export=${export_value2} From 5d233f4c5ef3729be6c53f5b5ceaa151555bd663 Mon Sep 17 00:00:00 2001 From: Aurelius84 Date: Mon, 14 Mar 2022 12:41:45 +0000 Subject: [PATCH 2/3] add info in log_name --- test_tipc/benchmark_train.sh | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test_tipc/benchmark_train.sh b/test_tipc/benchmark_train.sh index 48b2291cd..51876b857 100644 --- a/test_tipc/benchmark_train.sh +++ b/test_tipc/benchmark_train.sh @@ -70,8 +70,10 @@ REST_ARGS=$4 # bash test_tipc/benchmark_train.sh test_tipc/configs/det_mv3_db_v2_0/train_benchmark.txt benchmark_train to_static # bash test_tipc/benchmark_train.sh test_tipc/configs/det_mv3_db_v2_0/train_benchmark.txt benchmark_train dynamic_bs8_null_DP_N1C1 to_static +to_static="d2sF" # parse "to_static" options and modify trainer into "to_static_trainer" if [ $REST_ARGS = "to_static" ] || [ $PARAMS = "to_static" ] ;then + to_static="d2sT" sed -i 's/trainer:norm_train/trainer:to_static_train/g' $FILENAME # clear PARAM contents if [ $PARAMS = "to_static" ] ;then @@ -181,7 +183,7 @@ for batch_size in ${batch_size_list[*]}; do if [ ${#gpu_id} -le 1 ];then log_path="$SAVE_LOG/profiling_log" mkdir -p $log_path - log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_profiling" + log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}profiling" func_sed_params "$FILENAME" "${line_gpuid}" "0" # sed used gpu_id # set profile_option params tmp=`sed -i "${line_profile}s/.*/${profile_option}/" "${FILENAME}"` @@ -197,8 +199,8 @@ for batch_size in ${batch_size_list[*]}; do speed_log_path="$SAVE_LOG/index" mkdir -p $log_path mkdir -p $speed_log_path - log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_log" - speed_log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_speed" + log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}_log" + speed_log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}_speed" func_sed_params "$FILENAME" "${line_profile}" "null" # sed profile_id as null cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} benchmark_train > ${log_path}/${log_name} 2>&1 " echo $cmd @@ -232,8 +234,8 @@ for batch_size in ${batch_size_list[*]}; do speed_log_path="$SAVE_LOG/index" mkdir -p $log_path mkdir -p $speed_log_path - log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_log" - speed_log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_speed" + log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}_log" + speed_log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}_speed" func_sed_params "$FILENAME" "${line_gpuid}" "$gpu_id" # sed used gpu_id func_sed_params "$FILENAME" "${line_profile}" "null" # sed --profile_option as null cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} benchmark_train > ${log_path}/${log_name} 2>&1 " From 6eaed4f098d46b611a76113ff443fe1f361eb37f Mon Sep 17 00:00:00 2001 From: Aurelius84 Date: Tue, 15 Mar 2022 06:19:49 +0000 Subject: [PATCH 3/3] fix dash --- test_tipc/benchmark_train.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test_tipc/benchmark_train.sh b/test_tipc/benchmark_train.sh index 51876b857..b6e9c1f72 100644 --- a/test_tipc/benchmark_train.sh +++ b/test_tipc/benchmark_train.sh @@ -183,7 +183,7 @@ for batch_size in ${batch_size_list[*]}; do if [ ${#gpu_id} -le 1 ];then log_path="$SAVE_LOG/profiling_log" mkdir -p $log_path - log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}profiling" + log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}_profiling" func_sed_params "$FILENAME" "${line_gpuid}" "0" # sed used gpu_id # set profile_option params tmp=`sed -i "${line_profile}s/.*/${profile_option}/" "${FILENAME}"`