serving_build.sh 7.6 KB
Newer Older
G
guru4elephant 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
#!/usr/bin/env bash

function init() {
    source /root/.bashrc
    set -v
    export PYTHONROOT=/usr
    cd Serving
}

function check_cmd() {
    eval $@
    if [ $? -ne 0 ]; then
        exit 1
    fi
}

function build_client() {
18
    local TYPE=$1
G
guru4elephant 已提交
19
    local DIRNAME=build-client-$TYPE
20 21
    mkdir $DIRNAME # pwd: /Serving
    cd $DIRNAME # pwd: /Serving/build-client-$TYPE
G
guru4elephant 已提交
22 23 24 25 26 27 28
    case $TYPE in
        CPU|GPU)
            cmake -DPYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/ \
                  -DPYTHON_LIBRARIES=$PYTHONROOT/lib64/libpython2.7.so \
                  -DPYTHON_EXECUTABLE=$PYTHONROOT/bin/python \
                  -DCLIENT_ONLY=ON ..
            check_cmd "make -j2 >/dev/null"
Y
Your Name 已提交
29
            pip install -U python/dist/paddle_serving_client* >/dev/null
G
guru4elephant 已提交
30 31 32 33 34 35 36
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "build client $TYPE part finished as expected."
Y
Your Name 已提交
37
    cd .. # pwd: /Serving
G
guru4elephant 已提交
38 39 40 41
    rm -rf $DIRNAME
}

function build_server() {
42
    local TYPE=$1
G
guru4elephant 已提交
43
    local DIRNAME=build-server-$TYPE
44 45
    mkdir $DIRNAME # pwd: /Serving
    cd $DIRNAME # pwd: /Serving/build-server-$TYPE
G
guru4elephant 已提交
46 47 48 49 50 51
    case $TYPE in
        CPU)
            cmake -DPYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/ \
                  -DPYTHON_LIBRARIES=$PYTHONROOT/lib64/libpython2.7.so \
                  -DPYTHON_EXECUTABLE=$PYTHONROOT/bin/python \
                  -DCLIENT_ONLY=OFF ..
W
wangjiawei04 已提交
52
            check_cmd "make -j2 >/dev/null && make install -j2 >/dev/null"
Y
Your Name 已提交
53
            pip install -U python/dist/paddle_serving_server* >/dev/null
G
guru4elephant 已提交
54 55 56 57 58 59 60
            ;;
        GPU)
            cmake -DPYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/ \
                  -DPYTHON_LIBRARIES=$PYTHONROOT/lib64/libpython2.7.so \
                  -DPYTHON_EXECUTABLE=$PYTHONROOT/bin/python \
                  -DCLIENT_ONLY=OFF \
                  -DWITH_GPU=ON ..
W
wangjiawei04 已提交
61
            check_cmd "make -j2 >/dev/null && make install -j2 >/dev/null"
Y
Your Name 已提交
62
            pip install -U python/dist/paddle_serving_server* >/dev/null
G
guru4elephant 已提交
63 64 65 66 67 68 69
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "build server $TYPE part finished as expected."
Y
Your Name 已提交
70
    cd .. # pwd: /Serving
Y
Your Name 已提交
71
    # rm -rf $DIRNAME    for export SERVING_BIN
G
guru4elephant 已提交
72 73
}

74
function kill_server_process() {
Y
Your Name 已提交
75
    ps -ef | grep "serving" | grep -v serving_build | grep -v grep | awk '{print $2}' | xargs kill
76 77
}

G
guru4elephant 已提交
78
function python_test_fit_a_line() {
Y
Your Name 已提交
79 80
    # pwd: /Serving/python/examples
    cd fit_a_line # pwd: /Serving/python/examples/fit_a_line
G
guru4elephant 已提交
81 82
    sh get_data.sh
    local TYPE=$1
W
wangjiawei04 已提交
83
    echo $TYPE
G
guru4elephant 已提交
84 85 86
    case $TYPE in
        CPU)
            # test rpc
87 88
            check_cmd "python -m paddle_serving_server.serve --model uci_housing_model --port 9393 --thread 4 > /dev/null &"
            sleep 5 # wait for the server to start
G
guru4elephant 已提交
89
            check_cmd "python test_client.py uci_housing_client/serving_client_conf.prototxt > /dev/null"
90
            kill_server_process
G
guru4elephant 已提交
91
            # test web
92 93 94 95 96
            check_cmd "python -m paddle_serving_server.serve --model uci_housing_model --name uci --port 9393 --thread 4 --name uci > /dev/null &"
            sleep 5 # wait for the server to start
            check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"x\": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332], \"fetch\":[\"price\"]}' http://127.0.0.1:9393/uci/prediction"
            # check http code
            http_code=`curl -H "Content-Type:application/json" -X POST -d '{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332], "fetch":["price"]}' -s -w "%{http_code}" -o /dev/null http://127.0.0.1:9393/uci/prediction`
Y
Your Name 已提交
97 98 99 100
            if [ ${http_code} -ne 200 ]; then
                echo "HTTP status code -ne 200"
                exit 1
            fi
101
            kill_server_process
G
guru4elephant 已提交
102 103
            ;;
        GPU)
104 105 106 107 108 109 110 111 112 113 114 115
            # test rpc
            check_cmd "python -m paddle_serving_server_gpu.serve --model uci_housing_model --port 9393 --thread 4 --gpu_ids 0 > /dev/null &"
            sleep 5 # wait for the server to start
            check_cmd "python test_client.py uci_housing_client/serving_client_conf.prototxt > /dev/null"
            kill_server_process

            # test web
            check_cmd "python -m paddle_serving_server_gpu.serve --model uci_housing_model --port 9393 --thread 2 --gpu_ids 0 --name uci > /dev/null &"
            sleep 5 # wait for the server to start
            check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"x\": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332], \"fetch\":[\"price\"]}' http://127.0.0.1:9393/uci/prediction"
            # check http code
            http_code=`curl -H "Content-Type:application/json" -X POST -d '{"x": [0.0137, -0.1136, 0.2553, -0.0692, 0.0582, -0.0727, -0.1583, -0.0584, 0.6283, 0.4919, 0.1856, 0.0795, -0.0332], "fetch":["price"]}' -s -w "%{http_code}" -o /dev/null http://127.0.0.1:9393/uci/prediction`
Y
Your Name 已提交
116 117 118 119
            if [ ${http_code} -ne 200 ]; then
                echo "HTTP status code -ne 200"
                exit 1
            fi
120
            kill_server_process
G
guru4elephant 已提交
121 122 123 124 125 126 127 128
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "test fit_a_line $TYPE part finished as expected."
    rm -rf image kvdb log uci_housing* work*
Y
Your Name 已提交
129
    cd .. # pwd: /Serving/python/examples
G
guru4elephant 已提交
130 131
}

W
wangjiawei04 已提交
132
function python_run_criteo_ctr_with_cube() {
Y
merge  
Your Name 已提交
133
    # pwd: /Serving/python/examples
W
wangjiawei04 已提交
134
    local TYPE=$1
135
    yum install -y bc >/dev/null
Y
merge  
Your Name 已提交
136
    cd criteo_ctr_with_cube # pwd: /Serving/python/examples/criteo_ctr_with_cube
W
wangjiawei04 已提交
137 138 139 140 141 142 143
    check_cmd "wget https://paddle-serving.bj.bcebos.com/unittest/ctr_cube_unittest.tar.gz"
    check_cmd "tar xf ctr_cube_unittest.tar.gz"
    check_cmd "mv models/ctr_client_conf ./"
    check_cmd "mv models/ctr_serving_model_kv ./"
    check_cmd "mv models/data ./cube/"
    check_cmd "mv models/ut_data ./"
    cp ../../../build-server-$TYPE/output/bin/cube* ./cube/ 
W
wangjiawei04 已提交
144 145 146
    mkdir -p $PYTHONROOT/lib/python2.7/site-packages/paddle_serving_server/serving-cpu-avx-openblas-0.1.3/
    yes | cp ../../../build-server-$TYPE/output/demo/serving/bin/serving $PYTHONROOT/lib/python2.7/site-packages/paddle_serving_server/serving-cpu-avx-openblas-0.1.3/

W
wangjiawei04 已提交
147 148 149 150 151 152 153 154 155 156 157
    sh cube_prepare.sh &
    check_cmd "mkdir work_dir1 && cp cube/conf/cube.conf ./work_dir1/"    
    python test_server.py ctr_serving_model_kv &
    check_cmd "python test_client.py ctr_client_conf/serving_client_conf.prototxt ./ut_data >score"
    AUC=$(tail -n 2  score | awk 'NR==1')
    VAR2="0.70"
    RES=$( echo "$AUC>$VAR2" | bc )
    if [[ $RES -eq 0 ]]; then
        echo "error with criteo_ctr_with_cube inference auc test, auc should > 0.70"
        exit 1
    fi
158
    echo "criteo_ctr_with_cube inference auc test success"
W
wangjiawei04 已提交
159 160
    ps -ef | grep "paddle_serving_server" | grep -v grep | awk '{print $2}' | xargs kill
    ps -ef | grep "cube" | grep -v grep | awk '{print $2}' | xargs kill
Y
merge  
Your Name 已提交
161
    cd .. # pwd: /Serving/python/examples
W
wangjiawei04 已提交
162 163
}

G
guru4elephant 已提交
164
function python_run_test() {
165
    # Using the compiled binary
Y
Your Name 已提交
166
    local TYPE=$1 # pwd: /Serving
Y
Your Name 已提交
167
    export SERVING_BIN=$PWD/build-server-${TYPE}/core/general-server/serving
Y
Your Name 已提交
168 169
    cd python/examples # pwd: /Serving/python/examples
    python_test_fit_a_line $TYPE # pwd: /Serving/python/examples
Y
merge  
Your Name 已提交
170
    python_run_criteo_ctr_with_cube $TYPE # pwd: /Serving/python/examples
G
guru4elephant 已提交
171
    echo "test python $TYPE part finished as expected."
Y
Your Name 已提交
172
    cd ../.. # pwd: /Serving
G
guru4elephant 已提交
173 174 175
}

function main() {
Y
Your Name 已提交
176 177 178 179 180
    local TYPE=$1 # pwd: /
    init # pwd: /Serving
    build_client $TYPE # pwd: /Serving
    build_server $TYPE # pwd: /Serving
    python_run_test $TYPE # pwd: /Serving
G
guru4elephant 已提交
181 182 183 184
    echo "serving $TYPE part finished as expected."
}

main $@