common_func.sh 1.7 KB
Newer Older
S
stephon 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/bin/bash

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

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

C
cuicheng01 已提交
19 20 21 22 23 24 25 26
function func_parser_value_lite(){
    strs=$1
    IFS=$2
    array=(${strs})
    tmp=${array[1]}
    echo ${tmp}
}

G
gaotingquan 已提交
27 28 29 30 31 32 33 34 35 36 37
function func_set_amp_params(){
    key=$1
    value=$2

    if [[ ${value} = "fp16" ]];then
        echo "-o AMP.scale_loss=128 -o AMP.use_dynamic_loss_scaling=True -o AMP.level=O2"
    else
        echo " "
    fi
}

S
stephon 已提交
38 39 40 41 42 43 44 45 46 47 48 49 50 51
function func_set_params(){
    key=$1
    value=$2
    if [ ${key}x = "null"x ];then
        echo " "
    elif [[ ${value} = "null" ]] || [[ ${value} = " " ]] || [ ${#value} -le 0 ];then
        echo " "
    else 
        echo "${key}=${value}"
    fi
}

function func_parser_params(){
    strs=$1
H
HydrogenSulfate 已提交
52
    MODE=$2
S
stephon 已提交
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
    IFS=":"
    array=(${strs})
    key=${array[0]}
    tmp=${array[1]}
    IFS="|"
    res=""
    for _params in ${tmp[*]}; do
        IFS="="
        array=(${_params})
        mode=${array[0]}
        value=${array[1]}
        if [[ ${mode} = ${MODE} ]]; then
            IFS="|"
            #echo $(func_set_params "${mode}" "${value}")
            echo $value
            break
        fi
        IFS="|"
    done
    echo ${res}
}

function status_check(){
    last_status=$1   # the exit code
    run_command=$2
    run_log=$3
H
HydrogenSulfate 已提交
79
    model_name=$4
G
gaotingquan 已提交
80
    log_path=$5
S
stephon 已提交
81
    if [ $last_status -eq 0 ]; then
G
gaotingquan 已提交
82
        echo -e "\033[33m Run successfully with command - ${model_name} - ${run_command} - ${log_path} ! \033[0m" | tee -a ${run_log}
S
stephon 已提交
83
    else
G
gaotingquan 已提交
84
        echo -e "\033[33m Run failed with command - ${model_name} - ${run_command} - ${log_path} ! \033[0m" | tee -a ${run_log}
S
stephon 已提交
85 86
    fi
}