Skip to content

Commit 51c01cf

Browse files
authored
Merge pull request #1756 from Aurelius84/dy2stat_benchmark
[TIPC-Benchmark]Support @to_static traing for Benchmark
2 parents e7cb66b + 6eaed4f commit 51c01cf

6 files changed

+33
-15
lines changed

test_tipc/benchmark_train.sh

+21-6
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,22 @@ FILENAME=$new_filename
6565
# MODE must be one of ['benchmark_train']
6666
MODE=$2
6767
PARAMS=$3
68-
# bash test_tipc/benchmark_train.sh test_tipc/configs/det_mv3_db_v2_0/train_benchmark.txt benchmark_train dynamic_bs8_null_DP_N1C1
68+
REST_ARGS=$4
69+
# bash test_tipc/benchmark_train.sh test_tipc/configs/det_mv3_db_v2_0/train_benchmark.txt benchmark_train
70+
# bash test_tipc/benchmark_train.sh test_tipc/configs/det_mv3_db_v2_0/train_benchmark.txt benchmark_train to_static
71+
# 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
72+
73+
to_static="d2sF"
74+
# parse "to_static" options and modify trainer into "to_static_trainer"
75+
if [ $REST_ARGS = "to_static" ] || [ $PARAMS = "to_static" ] ;then
76+
to_static="d2sT"
77+
sed -i 's/trainer:norm_train/trainer:to_static_train/g' $FILENAME
78+
# clear PARAM contents
79+
if [ $PARAMS = "to_static" ] ;then
80+
PARAMS=""
81+
fi
82+
fi
83+
6984
IFS=$'\n'
7085
# parser params from train_benchmark.txt
7186
sed -i 's/ -o DataLoader.Train.sampler.shuffle=False//g' $FILENAME
@@ -168,7 +183,7 @@ for batch_size in ${batch_size_list[*]}; do
168183
if [ ${#gpu_id} -le 1 ];then
169184
log_path="$SAVE_LOG/profiling_log"
170185
mkdir -p $log_path
171-
log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_profiling"
186+
log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}_profiling"
172187
func_sed_params "$FILENAME" "${line_gpuid}" "0" # sed used gpu_id
173188
# set profile_option params
174189
tmp=`sed -i "${line_profile}s/.*/${profile_option}/" "${FILENAME}"`
@@ -184,8 +199,8 @@ for batch_size in ${batch_size_list[*]}; do
184199
speed_log_path="$SAVE_LOG/index"
185200
mkdir -p $log_path
186201
mkdir -p $speed_log_path
187-
log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_log"
188-
speed_log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_speed"
202+
log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}_log"
203+
speed_log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}_speed"
189204
func_sed_params "$FILENAME" "${line_profile}" "null" # sed profile_id as null
190205
cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} benchmark_train > ${log_path}/${log_name} 2>&1 "
191206
echo $cmd
@@ -219,8 +234,8 @@ for batch_size in ${batch_size_list[*]}; do
219234
speed_log_path="$SAVE_LOG/index"
220235
mkdir -p $log_path
221236
mkdir -p $speed_log_path
222-
log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_log"
223-
speed_log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_speed"
237+
log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}_log"
238+
speed_log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_mode}_${device_num}_${to_static}_speed"
224239
func_sed_params "$FILENAME" "${line_gpuid}" "$gpu_id" # sed used gpu_id
225240
func_sed_params "$FILENAME" "${line_profile}" "null" # sed --profile_option as null
226241
cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} benchmark_train > ${log_path}/${log_name} 2>&1 "

test_tipc/config/MobileNetV1/MobileNetV1_train_infer_python.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ norm_train:tools/train.py -c ppcls/configs/ImageNet/MobileNetV1/MobileNetV1.yaml
1717
pact_train:null
1818
fpgm_train:null
1919
distill_train:null
20-
null:null
20+
to_static_train:-o Global.to_static=True
2121
null:null
2222
##
2323
===========================eval_params===========================

test_tipc/config/MobileNetV2/MobileNetV2_train_infer_python.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ norm_train:tools/train.py -c ppcls/configs/ImageNet/MobileNetV2/MobileNetV2.yaml
1717
pact_train:null
1818
fpgm_train:null
1919
distill_train:null
20-
null:null
20+
to_static_train:-o Global.to_static=True
2121
null:null
2222
##
2323
===========================eval_params===========================

test_tipc/config/ResNet/ResNet152_train_infer_python.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ norm_train:tools/train.py -c ppcls/configs/ImageNet/ResNet/ResNet152.yaml -o Glo
1717
pact_train:null
1818
fpgm_train:null
1919
distill_train:null
20-
null:null
20+
to_static_train:-o Global.to_static=True
2121
null:null
2222
##
2323
===========================eval_params===========================

test_tipc/config/ResNet/ResNet50_train_infer_python.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ norm_train:tools/train.py -c ppcls/configs/ImageNet/ResNet/ResNet50.yaml -o Glob
1717
pact_train:null
1818
fpgm_train:null
1919
distill_train:null
20-
null:null
20+
to_static_train:-o Global.to_static=True
2121
null:null
2222
##
2323
===========================eval_params===========================

test_tipc/test_train_inference_python.sh

+8-5
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ fpgm_key=$(func_parser_key "${lines[17]}")
4040
fpgm_trainer=$(func_parser_value "${lines[17]}")
4141
distill_key=$(func_parser_key "${lines[18]}")
4242
distill_trainer=$(func_parser_value "${lines[18]}")
43-
trainer_key1=$(func_parser_key "${lines[19]}")
44-
trainer_value1=$(func_parser_value "${lines[19]}")
43+
to_static_key=$(func_parser_key "${lines[19]}")
44+
to_static_trainer=$(func_parser_value "${lines[19]}")
4545
trainer_key2=$(func_parser_key "${lines[20]}")
4646
trainer_value2=$(func_parser_value "${lines[20]}")
4747

@@ -246,9 +246,12 @@ else
246246
elif [ ${trainer} = "${distill_key}" ]; then
247247
run_train=${distill_trainer}
248248
run_export=${distill_export}
249-
elif [ ${trainer} = ${trainer_key1} ]; then
250-
run_train=${trainer_value1}
251-
run_export=${export_value1}
249+
# In case of @to_static, we re-used norm_traier,
250+
# but append "-o Global.to_static=True" for config
251+
# to trigger "apply_to_static" logic in 'engine.py'
252+
elif [ ${trainer} = "${to_static_key}" ]; then
253+
run_train="${norm_trainer} ${to_static_trainer}"
254+
run_export=${norm_export}
252255
elif [[ ${trainer} = ${trainer_key2} ]]; then
253256
run_train=${trainer_value2}
254257
run_export=${export_value2}

0 commit comments

Comments
 (0)