#!/bin/bash
Network="wav2vec2.0"
batch_size=8
learning_rate=''
device_id=0
export RANK_SIZE=8
data_path=""
echo "all para $*"
for para in $*
do
if [[ $para == --device_id* ]];then
device_id=`echo ${para#*=}`
elif [[ $para == --data_path* ]];then
data_path=`echo ${para#*=}`
elif [[ $para == --hf32 ]];then
hf32=`echo ${para#*=}`
export ALLOW_HF32=True
elif [[ $para == --fp32 ]];then
fp32=`echo ${para#*=}`
export ALLOW_FP32=True
fi
done
echo "data_path para $data_path"
if [[ $data_path == "" ]];then
echo "[Error] para \"data_path\" must be confing"
exit 1
fi
ln -snf $data_path ./data
if [ $ASCEND_DEVICE_ID ];then
echo "device id is ${ASCEND_DEVICE_ID}"
ln -s source dest
elif [ ${device_id} ]; then
export ASCEND_DEVICE_ID=${device_id}
echo "device id is ${ASCEND_DEVICE_ID}"
else
echo "[Error] device id must be confing"
exit 1
fi
cur_path=`pwd`
cur_path_last_dirname=${cur_path##*/}
if [ x"${cur_path_last_dirname}" == x"test" ]; then
test_path_dir=${cur_path}
cd ..
cur_path=`pwd`
else
test_path_dir=${cur_path}/test
fi
ASCEND_DEVICE_ID=${device_id}
if [ -d ${test_path_dir}/output/$ASCEND_DEVICE_ID ];then
rm -rf ${test_path_dir}/output/$ASCEND_DEVICE_ID
mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID
else
mkdir -p ${test_path_dir}/output/$ASCEND_DEVICE_ID
fi
start_time=$(date +%s)
check_etp_flag=`env | grep etp_running_flag`
etp_flag=`echo ${check_etp_flag#*=}`
if [ x"${etp_flag}" != x"true" ];then
source ${test_path_dir}/env_npu.sh
fi
get_lscpu_value() {
awk -F: "(\$1 == \"${1}\"){gsub(/ /, \"\", \$2); print \$2; found=1} END{exit found!=1}"
}
lscpu_out=$(lscpu)
n_sockets=4
n_cores_per_socket=$(get_lscpu_value 'Core(s) per socket' <<< "${lscpu_out}")
echo "num_sockets = ${n_sockets} cores_per_socket=${n_cores_per_socket}"
EXIT_STATUS=0
check_status()
{
if ((${PIPESTATUS[0]} != 0)); then
EXIT_STATUS=1
fi
}
export PYTHONPATH=../:$PYTHONPATH
echo ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
echo "$data_path"
fairseq-hydra-train \
task.data=./data/manifest \
dataset.batch_size=$batch_size \
hydra.run.dir=$PWD \
distributed_training.distributed_world_size=1 \
optimization.max_update=160000 \
--config-dir ./examples/wav2vec/config/finetuning --config-name base_100h \
> ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log 2>&1 &
wait
end_time=$(date +%s)
e2e_time=$(( $end_time - $start_time ))
echo "------------------ Final result ------------------"
FPS=`cat ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log |grep -a 'train_wps'|awk -F "train_wps" '{print $NF}' |awk -F "," '{print substr($1,5,length($1)-5)}' | awk 'BEGIN {max=0} {if ($1 > max) max=$1} END {print max}'`
echo "Final Performance images/sec : $FPS"
best_wer=`cat ${test_path_dir}/output/${ASCEND_DEVICE_ID}/train_${ASCEND_DEVICE_ID}.log|grep -a 'valid_best_wer'|awk -F "valid_best_wer" '{print $NF}' |awk -F "," '{print substr($1,5,length($1)-6)}' | awk 'BEGIN {min=65536} {if ($1 < min) min=$1} END {print min}'`
echo "Final Train best wer : ${best_wer}"
echo "E2E Training Duration sec : $e2e_time"
BatchSize=${batch_size}
DeviceType=`uname -m`
CaseName=${Network}_bs${BatchSize}_${RANK_SIZE}'p'_'acc'
ActualFPS=${FPS}
TrainingTime=`awk 'BEGIN{printf "%.2f\n", '${batch_size}'*1000/'${FPS}'}'`
grep Train: ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_$ASCEND_DEVICE_ID.log|grep -v Test|awk -F "Loss" '{print $NF}' | awk -F " " '{print $2}' >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt
ActualLoss=`awk 'END {print}' ${test_path_dir}/output/$ASCEND_DEVICE_ID/train_${CaseName}_loss.txt`
echo "Network = ${Network}" > ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log
echo "RankSize = ${RANK_SIZE}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log
echo "BatchSize = ${BatchSize}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log
echo "DeviceType = ${DeviceType}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log
echo "CaseName = ${CaseName}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log
echo "ActualFPS = ${ActualFPS}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log
echo "TrainingTime = ${TrainingTime}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log
echo "TrainAccuracy = ${train_accuracy}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log
echo "ActualLoss = ${ActualLoss}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log
echo "E2ETrainingTime = ${e2e_time}" >> ${test_path_dir}/output/$ASCEND_DEVICE_ID/${CaseName}.log