benchmark_train.sh 5.98 KB
Newer Older
1
2
3
4
5
#!/bin/bash
source test_tipc/common_func.sh

# run benchmark sh 
# Usage:
LDOUBLEV's avatar
LDOUBLEV committed
6
# bash run_benchmark_train.sh config.txt params
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38

function func_parser_params(){
    strs=$1
    IFS="="
    array=(${strs})
    tmp=${array[1]}
    echo ${tmp}
}

function func_sed_params(){
    filename=$1
    line=$2
    param_value=$3
    params=`sed -n "${line}p" $filename`
    IFS=":"
    array=(${params})
    key=${array[0]}
    value=${array[1]}
    if [[ $value =~ 'benchmark_train' ]];then
        IFS='='
        _val=(${value})
        param_value="${_val[0]}=${param_value}"
    fi
    new_params="${key}:${param_value}"
    IFS=";"
    cmd="sed -i '${line}s/.*/${new_params}/' '${filename}'"
    eval $cmd
}

function set_gpu_id(){
    string=$1
    _str=${string:1:6}
LDOUBLEV's avatar
LDOUBLEV committed
39
    IFS="C"
40
    arr=(${_str})
LDOUBLEV's avatar
LDOUBLEV committed
41
    M=${arr[0]}
42
    P=${arr[1]}
LDOUBLEV's avatar
LDOUBLEV committed
43
44
    gn=`expr $P - 1`
    gpu_num=`expr $gn / $M`
45
46
47
48
    seq=`seq -s "," 0 $gpu_num`
    echo $seq
}

LDOUBLEV's avatar
LDOUBLEV committed
49
50
51
52
53
54
55
function get_repo_name(){
    IFS=";"
    cur_dir=$(pwd)
    IFS="/"
    arr=(${cur_dir})
    echo ${arr[-1]}
}
56

LDOUBLEV's avatar
LDOUBLEV committed
57
58
59
60
61
FILENAME=$1
# MODE 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_SingleP_DP_N1C1
LDOUBLEV's avatar
LDOUBLEV committed
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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=";"

LDOUBLEV's avatar
LDOUBLEV committed
77

LDOUBLEV's avatar
LDOUBLEV committed
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# sed batchsize and precision
func_sed_params "$FILENAME" "6" "$precision"
func_sed_params "$FILENAME" "9" "$batch_size"

# parser params from train_benchmark.txt
dataline=`cat $FILENAME`
# parser params
IFS=$'\n'
lines=(${dataline})
model_name=$(func_parser_value "${lines[1]}")

# 获取benchmark_params所在的行数
line_num=`grep -n "benchmark_params" $FILENAME  | cut -d ":" -f 1`
# for train log parser
line_num=`expr $line_num + 3`
LDOUBLEV's avatar
LDOUBLEV committed
93
speed_unit_value=$(func_parser_value "${lines[line_num]}")
LDOUBLEV's avatar
LDOUBLEV committed
94
95
96
97
98
99

line_num=`expr $line_num + 1`
skip_steps_value=$(func_parser_value "${lines[line_num]}")

line_num=`expr $line_num + 1`
keyword_value=$(func_parser_value "${lines[line_num]}")
LDOUBLEV's avatar
LDOUBLEV committed
100
echo $keyword_value
LDOUBLEV's avatar
LDOUBLEV committed
101
102
103
104
105
106
107
108
109
110
111

line_num=`expr $line_num + 1`
convergence_key_value=$(func_parser_value "${lines[line_num]}")

line_num=`expr $line_num + 1`
flags_value=$(func_parser_value "${lines[line_num]}")

gpu_id=$(set_gpu_id $device_num)
repo_name=$(get_repo_name )

SAVE_LOG="benchmark_log"
LDOUBLEV's avatar
LDOUBLEV committed
112
status_log="benchmark_log/results.log"
LDOUBLEV's avatar
LDOUBLEV committed
113

LDOUBLEV's avatar
LDOUBLEV committed
114
115
116
117
118
119
120
121
# set export 
IFS=";"
flags_list=(${flags_value})
for _flag in ${flags_list[*]}; do
    cmd="export ${_flag}"
    eval $cmd
done

LDOUBLEV's avatar
LDOUBLEV committed
122
123
124
125
if [ ${precision} = "null" ];then
    precision="fp32"
fi

LDOUBLEV's avatar
LDOUBLEV committed
126
127
128
129
130
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_process_type}_${run_mode}_${device_num}_profiling"
    func_sed_params "$FILENAME" "4" "0"  # sed used gpu_id 
LDOUBLEV's avatar
LDOUBLEV committed
131
    cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} benchmark_train > ${log_path}/${log_name} 2>&1 "
LDOUBLEV's avatar
LDOUBLEV committed
132
    echo $cmd
LDOUBLEV's avatar
LDOUBLEV committed
133
    eval $cmd
LDOUBLEV's avatar
LDOUBLEV committed
134
    eval "cat ${log_path}/${log_name}"
LDOUBLEV's avatar
LDOUBLEV committed
135

LDOUBLEV's avatar
LDOUBLEV committed
136
137
    # without profile
    log_path="$SAVE_LOG/train_log"
LDOUBLEV's avatar
LDOUBLEV committed
138
    speed_log_path="$SAVE_LOG/index"
LDOUBLEV's avatar
LDOUBLEV committed
139
    mkdir -p $log_path
LDOUBLEV's avatar
LDOUBLEV committed
140
    mkdir -p $speed_log_path
LDOUBLEV's avatar
LDOUBLEV committed
141
    log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_process_type}_${run_mode}_${device_num}_log"
LDOUBLEV's avatar
LDOUBLEV committed
142
    speed_log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_process_type}_${run_mode}_${device_num}_speed"
LDOUBLEV's avatar
LDOUBLEV committed
143
    func_sed_params "$FILENAME" "13" "null"  # sed used gpu_id 
LDOUBLEV's avatar
LDOUBLEV committed
144
    cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} benchmark_train > ${log_path}/${log_name} 2>&1 "
LDOUBLEV's avatar
LDOUBLEV committed
145
    echo $cmd
LDOUBLEV's avatar
LDOUBLEV committed
146
    eval $cmd
LDOUBLEV's avatar
LDOUBLEV committed
147
    eval "cat ${log_path}/${log_name}"
LDOUBLEV's avatar
LDOUBLEV committed
148
149
150
151

    # parser log
    _model_name="${model_name}_bs${batch_size}_${precision}_${run_process_type}_${run_mode}"
    cmd="python3.7 analysis.py --filename ${log_path}/${log_name} \
LDOUBLEV's avatar
LDOUBLEV committed
152
            --speed_log_file '${speed_log_path}/${speed_log_name}' \
LDOUBLEV's avatar
LDOUBLEV committed
153
154
155
156
157
158
159
160
161
162
163
164
165
166
            --model_name ${_model_name} \
            --base_batch_size ${batch_size} \
            --run_mode ${run_mode} \
            --run_process_type ${run_process_type} \
            --fp_item ${precision} \
            --keyword ${keyword_value}: \
            --skip_steps ${skip_steps_value} \
            --device_num ${device_num} \
            --speed_unit ${speed_unit_value} \
            --convergence_key ${convergence_key_value}: "
    echo $cmd
    eval $cmd
    

LDOUBLEV's avatar
LDOUBLEV committed
167
168
else
    log_path="$SAVE_LOG/train_log"
LDOUBLEV's avatar
LDOUBLEV committed
169
    speed_log_path="$SAVE_LOG/index"
LDOUBLEV's avatar
LDOUBLEV committed
170
    mkdir -p $log_path
LDOUBLEV's avatar
LDOUBLEV committed
171
    mkdir -p $speed_log_path
LDOUBLEV's avatar
LDOUBLEV committed
172
    log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_process_type}_${run_mode}_${device_num}_log"
LDOUBLEV's avatar
LDOUBLEV committed
173
    speed_log_name="${repo_name}_${model_name}_bs${batch_size}_${precision}_${run_process_type}_${run_mode}_${device_num}_speed"
LDOUBLEV's avatar
LDOUBLEV committed
174
    func_sed_params "$FILENAME" "4" "$gpu_id"  # sed used gpu_id 
LDOUBLEV's avatar
LDOUBLEV committed
175
    func_sed_params "$FILENAME" "13" "null"  # sed --profile_option as null
LDOUBLEV's avatar
LDOUBLEV committed
176
    cmd="bash test_tipc/test_train_inference_python.sh ${FILENAME} benchmark_train > ${log_path}/${log_name} 2>&1 "
LDOUBLEV's avatar
LDOUBLEV committed
177
    echo $cmd
LDOUBLEV's avatar
LDOUBLEV committed
178
    eval $cmd
LDOUBLEV's avatar
LDOUBLEV committed
179
    eval "cat ${log_path}/${log_name}"
LDOUBLEV's avatar
LDOUBLEV committed
180
181
182
183
    # parser log
    _model_name="${model_name}_bs${batch_size}_${precision}_${run_process_type}_${run_mode}"
    
    cmd="python3.7 analysis.py --filename ${log_path}/${log_name} \
LDOUBLEV's avatar
LDOUBLEV committed
184
            --speed_log_file '${speed_log_path}/${speed_log_name}' \
LDOUBLEV's avatar
LDOUBLEV committed
185
186
187
188
189
190
191
192
193
194
195
196
            --model_name ${_model_name} \
            --base_batch_size ${batch_size} \
            --run_mode ${run_mode} \
            --run_process_type ${run_process_type} \
            --fp_item ${precision} \
            --keyword ${keyword_value}: \
            --skip_steps ${skip_steps_value} \
            --device_num ${device_num} \
            --speed_unit ${speed_unit_value} \
            --convergence_key ${convergence_key_value}: "
    echo $cmd
    eval $cmd
197

LDOUBLEV's avatar
LDOUBLEV committed
198
fi
199