serving_build.sh 35.7 KB
Newer Older
G
guru4elephant 已提交
1 2
#!/usr/bin/env bash

3 4 5 6 7 8 9 10 11 12 13 14
function unsetproxy() {
    HTTP_PROXY_TEMP=$http_proxy
    HTTPS_PROXY_TEMP=$https_proxy
    unset http_proxy
    unset https_proxy
}

function setproxy() {
    export http_proxy=$HTTP_PROXY_TEMP
    export https_proxy=$HTTPS_PROXY_TEMP
}

G
guru4elephant 已提交
15 16 17 18 19
function init() {
    source /root/.bashrc
    set -v
    export PYTHONROOT=/usr
    cd Serving
B
barrierye 已提交
20
    export SERVING_WORKDIR=$PWD
D
dongdaxiang 已提交
21
    $PYTHONROOT/bin/python -m pip install -r python/requirements.txt
G
guru4elephant 已提交
22 23 24 25 26 27 28 29 30
}

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

31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
function rerun() {
    if [ $# -ne 2 ]; then
        echo "usage: rerun command rerun-times"
        exit 1
    fi
    local command=$1
    local times=$2
    for((i=1;i<=${times};i++))
    do
        if [ ${i} != 1 ]; then
            echo "${i}-th run command: ${command}..."
        fi
        eval $command
        if [ $? -eq 0 ]; then
            return 0
        fi
        echo "${i}-th run(command: ${command}) failed."
    done
    exit 1
}

B
barrierye 已提交
52 53 54 55 56
function build_app() {
    local TYPE=$1
    local DIRNAME=build-app-$TYPE
    mkdir $DIRNAME # pwd: /Serving
    cd $DIRNAME # pwd: /Serving/build-app-$TYPE
B
barrierye 已提交
57
    pip install numpy sentencepiece
B
barrierye 已提交
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
    case $TYPE in
        CPU|GPU)
            cmake -DPYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/ \
                  -DPYTHON_LIBRARIES=$PYTHONROOT/lib/libpython2.7.so \
                  -DPYTHON_EXECUTABLE=$PYTHONROOT/bin/python \
                  -DAPP=ON ..
            rerun "make -j2 >/dev/null" 3 # due to some network reasons, compilation may fail
            pip install -U python/dist/paddle_serving_app* >/dev/null
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "build app $TYPE part finished as expected."
    cd .. # pwd: /Serving
}

G
guru4elephant 已提交
76
function build_client() {
77
    local TYPE=$1
G
guru4elephant 已提交
78
    local DIRNAME=build-client-$TYPE
79 80
    mkdir $DIRNAME # pwd: /Serving
    cd $DIRNAME # pwd: /Serving/build-client-$TYPE
G
guru4elephant 已提交
81 82 83 84 85
    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 \
86
                  -DCLIENT=ON ..
87
            rerun "make -j2 >/dev/null" 3 # due to some network reasons, compilation may fail
Y
Your Name 已提交
88
            pip install -U python/dist/paddle_serving_client* >/dev/null
G
guru4elephant 已提交
89 90 91 92 93 94 95
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "build client $TYPE part finished as expected."
Y
Your Name 已提交
96
    cd .. # pwd: /Serving
97
    # rm -rf $DIRNAME
G
guru4elephant 已提交
98 99 100
}

function build_server() {
101
    local TYPE=$1
G
guru4elephant 已提交
102
    local DIRNAME=build-server-$TYPE
103 104
    mkdir $DIRNAME # pwd: /Serving
    cd $DIRNAME # pwd: /Serving/build-server-$TYPE
G
guru4elephant 已提交
105 106 107 108 109
    case $TYPE in
        CPU)
            cmake -DPYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/ \
                  -DPYTHON_LIBRARIES=$PYTHONROOT/lib64/libpython2.7.so \
                  -DPYTHON_EXECUTABLE=$PYTHONROOT/bin/python \
G
guru4elephant 已提交
110
                  -DSERVER=ON ..
111 112
            rerun "make -j2 >/dev/null" 3 # due to some network reasons, compilation may fail
            check_cmd "make install -j2 >/dev/null"
Y
Your Name 已提交
113
            pip install -U python/dist/paddle_serving_server* >/dev/null
G
guru4elephant 已提交
114 115 116 117 118
            ;;
        GPU)
            cmake -DPYTHON_INCLUDE_DIR=$PYTHONROOT/include/python2.7/ \
                  -DPYTHON_LIBRARIES=$PYTHONROOT/lib64/libpython2.7.so \
                  -DPYTHON_EXECUTABLE=$PYTHONROOT/bin/python \
119
                  -DSERVER=ON \
G
guru4elephant 已提交
120
                  -DWITH_GPU=ON ..
121 122
            rerun "make -j2 >/dev/null" 3 # due to some network reasons, compilation may fail
            check_cmd "make install -j2 >/dev/null"
Y
Your Name 已提交
123
            pip install -U python/dist/paddle_serving_server* >/dev/null
G
guru4elephant 已提交
124 125 126 127 128 129 130
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "build server $TYPE part finished as expected."
Y
Your Name 已提交
131
    cd .. # pwd: /Serving
Y
Your Name 已提交
132
    # rm -rf $DIRNAME    for export SERVING_BIN
G
guru4elephant 已提交
133 134
}

135
function kill_server_process() {
Y
Your Name 已提交
136
    ps -ef | grep "serving" | grep -v serving_build | grep -v grep | awk '{print $2}' | xargs kill
137 138
}

G
guru4elephant 已提交
139
function python_test_fit_a_line() {
Y
Your Name 已提交
140 141
    # pwd: /Serving/python/examples
    cd fit_a_line # pwd: /Serving/python/examples/fit_a_line
G
guru4elephant 已提交
142 143
    sh get_data.sh
    local TYPE=$1
B
barrierye 已提交
144
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
G
guru4elephant 已提交
145 146 147
    case $TYPE in
        CPU)
            # test rpc
148 149
            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 已提交
150
            check_cmd "python test_client.py uci_housing_client/serving_client_conf.prototxt > /dev/null"
151
            kill_server_process
B
barrierye 已提交
152

G
guru4elephant 已提交
153
            # test web
154
            unsetproxy # maybe the proxy is used on iPipe, which makes web-test failed.
155 156
            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
M
MRXLT 已提交
157
            check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"feed\":[{\"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"
158
            # check http code
M
fix ci  
MRXLT 已提交
159
            http_code=`curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"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 已提交
160 161 162 163
            if [ ${http_code} -ne 200 ]; then
                echo "HTTP status code -ne 200"
                exit 1
            fi
B
barrierye 已提交
164 165 166 167 168 169 170 171 172 173
            # test web batch
            check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"feed\":[{\"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]}, {\"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 '{"feed":[{"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]}, {"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`
            if [ ${http_code} -ne 200 ]; then
                echo "HTTP status code -ne 200"
                exit 1
            fi
            setproxy # recover proxy state
            kill_server_process
G
guru4elephant 已提交
174 175
            ;;
        GPU)
B
fix bug  
barrierye 已提交
176
            export CUDA_VISIBLE_DEVICES=0
177 178 179 180 181
            # 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
M
MRXLT 已提交
182

183
            # test web
184
            unsetproxy # maybe the proxy is used on iPipe, which makes web-test failed.
185 186
            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
M
MRXLT 已提交
187
            check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"feed\":[{\"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"
188
            # check http code
M
fix ci  
MRXLT 已提交
189
            http_code=`curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"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 已提交
190 191 192 193
            if [ ${http_code} -ne 200 ]; then
                echo "HTTP status code -ne 200"
                exit 1
            fi
B
barrierye 已提交
194 195 196 197 198 199 200 201 202 203
            # test web batch
            check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"feed\":[{\"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]}, {\"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 '{"feed":[{"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]}, {"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`
            if [ ${http_code} -ne 200 ]; then
                echo "HTTP status code -ne 200"
                exit 1
            fi
            setproxy # recover proxy state
            kill_server_process
G
guru4elephant 已提交
204 205 206 207 208 209 210 211
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "test fit_a_line $TYPE part finished as expected."
    rm -rf image kvdb log uci_housing* work*
B
barrierye 已提交
212
    unset SERVING_BIN
Y
Your Name 已提交
213
    cd .. # pwd: /Serving/python/examples
G
guru4elephant 已提交
214 215
}

W
wangjiawei04 已提交
216
function python_run_criteo_ctr_with_cube() {
Y
merge  
Your Name 已提交
217
    # pwd: /Serving/python/examples
W
wangjiawei04 已提交
218
    local TYPE=$1
219
    yum install -y bc >/dev/null
Y
merge  
Your Name 已提交
220
    cd criteo_ctr_with_cube # pwd: /Serving/python/examples/criteo_ctr_with_cube
M
MRXLT 已提交
221
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
B
barrierye 已提交
222 223 224 225 226 227 228 229
    case $TYPE in
        CPU)
            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 ./"
M
MRXLT 已提交
230
            cp ../../../build-server-$TYPE/output/bin/cube* ./cube/
B
barrierye 已提交
231 232 233
            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/
            sh cube_prepare.sh &
M
MRXLT 已提交
234
            check_cmd "mkdir work_dir1 && cp cube/conf/cube.conf ./work_dir1/"
B
barrierye 已提交
235
            python test_server.py ctr_serving_model_kv &
M
MRXLT 已提交
236
            sleep 5
B
barrierye 已提交
237
            check_cmd "python test_client.py ctr_client_conf/serving_client_conf.prototxt ./ut_data >score"
W
wangjiawei04 已提交
238
            tail -n 2 score | awk 'NR==1'
B
barrierye 已提交
239
            AUC=$(tail -n 2  score | awk 'NR==1')
240
            VAR2="0.67" #TODO: temporarily relax the threshold to 0.67
B
barrierye 已提交
241 242
            RES=$( echo "$AUC>$VAR2" | bc )
            if [[ $RES -eq 0 ]]; then
J
Jiawei Wang 已提交
243
                echo "error with criteo_ctr_with_cube inference auc test, auc should > 0.67"
B
barrierye 已提交
244 245 246
                exit 1
            fi
            echo "criteo_ctr_with_cube inference auc test success"
B
barrierye 已提交
247
            kill_server_process
B
barrierye 已提交
248 249 250
            ps -ef | grep "cube" | grep -v grep | awk '{print $2}' | xargs kill
            ;;
        GPU)
W
wangjiawei04 已提交
251 252 253 254 255 256 257
            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/
258
            mkdir -p $PYTHONROOT/lib/python2.7/site-packages/paddle_serving_server_gpu/serving-gpu-0.1.3/
W
wangjiawei04 已提交
259 260 261 262
            yes | cp ../../../build-server-$TYPE/output/demo/serving/bin/serving $PYTHONROOT/lib/python2.7/site-packages/paddle_serving_server_gpu/serving-gpu-0.1.3/
            sh cube_prepare.sh &
            check_cmd "mkdir work_dir1 && cp cube/conf/cube.conf ./work_dir1/"
            python test_server_gpu.py ctr_serving_model_kv &
M
MRXLT 已提交
263
            sleep 5
W
wangjiawei04 已提交
264 265 266
            check_cmd "python test_client.py ctr_client_conf/serving_client_conf.prototxt ./ut_data >score"
            tail -n 2 score | awk 'NR==1'
            AUC=$(tail -n 2  score | awk 'NR==1')
J
Jiawei Wang 已提交
267
            VAR2="0.67" #TODO: temporarily relax the threshold to 0.67
W
wangjiawei04 已提交
268 269
            RES=$( echo "$AUC>$VAR2" | bc )
            if [[ $RES -eq 0 ]]; then
J
Jiawei Wang 已提交
270
                echo "error with criteo_ctr_with_cube inference auc test, auc should > 0.67"
W
wangjiawei04 已提交
271 272 273
                exit 1
            fi
            echo "criteo_ctr_with_cube inference auc test success"
B
barrierye 已提交
274
            kill_server_process
W
wangjiawei04 已提交
275
            ps -ef | grep "cube" | grep -v grep | awk '{print $2}' | xargs kill
B
barrierye 已提交
276 277 278 279 280 281
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
M
MRXLT 已提交
282
    unset SERVING_BIN
B
barrierye 已提交
283
    echo "test criteo_ctr_with_cube $TYPE part finished as expected."
Y
merge  
Your Name 已提交
284
    cd .. # pwd: /Serving/python/examples
W
wangjiawei04 已提交
285 286
}

W
wangjiawei04 已提交
287 288 289
function python_test_bert() {
    # pwd: /Serving/python/examples
    local TYPE=$1
B
barrierye 已提交
290
    yum install -y libXext libSM libXrender >/dev/null
J
Jiawei Wang 已提交
291
    pip install ujson
292
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
W
wangjiawei04 已提交
293 294 295 296
    cd bert # pwd: /Serving/python/examples/bert
    case $TYPE in
        CPU)
            pip install paddlehub
297 298 299 300
            # Because download from paddlehub may timeout,
            # download the model from bos(max_seq_len=128).
            wget https://paddle-serving.bj.bcebos.com/paddle_hub_models/text/SemanticModel/bert_chinese_L-12_H-768_A-12.tar.gz
            tar -xzf bert_chinese_L-12_H-768_A-12.tar.gz
W
wangjiawei04 已提交
301
            sh get_data.sh
302
            check_cmd "python -m paddle_serving_server.serve --model bert_chinese_L-12_H-768_A-12_model --port 9292 &"
303
            sleep 5
W
wangjiawei04 已提交
304
            pip install paddle_serving_app
305
            check_cmd "head -n 10 data-c.txt | python bert_client.py --model bert_chinese_L-12_H-768_A-12_client/serving_client_conf.prototxt"
J
Jiawei Wang 已提交
306
            kill_server_process
M
MRXLT 已提交
307
            echo "bert RPC inference pass"
W
wangjiawei04 已提交
308 309
            ;;
        GPU)
B
fix bug  
barrierye 已提交
310
            export CUDA_VISIBLE_DEVICES=0
W
wangjiawei04 已提交
311
            pip install paddlehub
312 313 314 315
            # Because download from paddlehub may timeout,
            # download the model from bos(max_seq_len=128).
            wget https://paddle-serving.bj.bcebos.com/paddle_hub_models/text/SemanticModel/bert_chinese_L-12_H-768_A-12.tar.gz
            tar -xzf bert_chinese_L-12_H-768_A-12.tar.gz
W
wangjiawei04 已提交
316
            sh get_data.sh
317
            check_cmd "python -m paddle_serving_server_gpu.serve --model bert_chinese_L-12_H-768_A-12_model --port 9292 --gpu_ids 0 &"
318
            sleep 5
W
wangjiawei04 已提交
319
            pip install paddle_serving_app
320
            check_cmd "head -n 10 data-c.txt | python bert_client.py --model bert_chinese_L-12_H-768_A-12_client/serving_client_conf.prototxt"
J
Jiawei Wang 已提交
321
            kill_server_process
W
wangjiawei04 已提交
322 323 324
            echo "bert RPC inference pass"
            ;;
        *)
B
barrierye 已提交
325 326 327
            echo "error type"
            exit 1
            ;;
W
wangjiawei04 已提交
328 329
    esac
    echo "test bert $TYPE finished as expected."
330
    unset SERVING_BIN
W
wangjiawei04 已提交
331 332 333
    cd ..
}

M
MRXLT 已提交
334
function python_test_multi_fetch() {
M
MRXLT 已提交
335 336 337 338 339 340 341 342 343
    # pwd: /Serving/python/examples
    local TYPT=$1
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
    cd bert # pwd: /Serving/python/examples/bert
    case $TYPE in
        CPU)
            #download model (max_seq_len=32)
            wget https://paddle-serving.bj.bcebos.com/bert_example/bert_multi_fetch.tar.gz
            tar -xzvf bert_multi_fetch.tar.gz
M
fix ci  
MRXLT 已提交
344
            check_cmd "python -m paddle_serving_server.serve --model bert_seq32_model --port 9292 &"
M
MRXLT 已提交
345
            sleep 5
M
MRXLT 已提交
346
            check_cmd "head -n 8 data-c.txt | python test_multi_fetch_client.py"
M
MRXLT 已提交
347 348 349 350 351 352 353
            kill_server_process
            echo "bert mutli fetch RPC inference pass"
            ;;
        GPU)
            #download model (max_seq_len=32)
            wget https://paddle-serving.bj.bcebos.com/bert_example/bert_multi_fetch.tar.gz
            tar -xzvf bert_multi_fetch.tar.gz
M
fix ci  
MRXLT 已提交
354
            check_cmd "python -m paddle_serving_server_gpu.serve --model bert_seq32_model --port 9292 --gpu_ids 0 &"
M
MRXLT 已提交
355
            sleep 5
M
MRXLT 已提交
356
            check_cmd "head -n 8 data-c.txt | python test_multi_fetch_client.py"
M
MRXLT 已提交
357 358 359 360 361 362 363 364 365 366 367 368 369 370
            kill_server_process
            echo "bert mutli fetch RPC inference pass"
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "test multi fetch $TYPE finished as expected."
    unset SERVING_BIN
    cd ..
}

function python_test_multi_process(){
M
MRXLT 已提交
371 372 373
    # pwd: /Serving/python/examples
    local TYPT=$1
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
M
fix ci  
MRXLT 已提交
374
    cd fit_a_line # pwd: /Serving/python/examples/fit_a_line
M
fix bug  
MRXLT 已提交
375
    sh get_data.sh
M
MRXLT 已提交
376 377
    case $TYPE in
        CPU)
B
barrierye 已提交
378 379
            check_cmd "python -m paddle_serving_server.serve --model uci_housing_model --port 9292 --workdir test9292 &"
            check_cmd "python -m paddle_serving_server.serve --model uci_housing_model --port 9293 --workdir test9293 &"
M
MRXLT 已提交
380 381 382 383 384 385
            sleep 5
            check_cmd "python test_multi_process_client.py"
            kill_server_process
            echo "bert mutli rpc RPC inference pass"
            ;;
        GPU)
B
barrierye 已提交
386
            rm -rf ./image #TODO: The following code tried to create this folder, but no corresponding code was found
B
barrierye 已提交
387 388
            check_cmd "python -m paddle_serving_server_gpu.serve --model uci_housing_model --port 9292 --workdir test9292 --gpu_ids 0 &"
            check_cmd "python -m paddle_serving_server_gpu.serve --model uci_housing_model --port 9293 --workdir test9293 --gpu_ids 0 &"
M
MRXLT 已提交
389 390 391 392 393 394 395 396 397 398 399 400 401
            sleep 5
            check_cmd "python test_multi_process_client.py"
            kill_server_process
            echo "bert mutli process RPC inference pass"
            ;;
        *)
            echo "error type"
            exit 1
            ;;
    esac
    echo "test multi process $TYPE finished as expected."
    unset SERVING_BIN
    cd ..
M
MRXLT 已提交
402 403
}

W
wangjiawei04 已提交
404 405 406
function python_test_imdb() {
    # pwd: /Serving/python/examples
    local TYPE=$1
407 408
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
    cd imdb # pwd: /Serving/python/examples/imdb
W
wangjiawei04 已提交
409 410 411
    case $TYPE in
        CPU)
            sh get_data.sh
J
Jiawei Wang 已提交
412
            check_cmd "python -m paddle_serving_server.serve --model imdb_cnn_model/ --port 9292 &"
B
barrierye 已提交
413
            sleep 5
W
wangjiawei04 已提交
414
            check_cmd "head test_data/part-0 | python test_client.py imdb_cnn_client_conf/serving_client_conf.prototxt imdb.vocab"
B
barrierye 已提交
415
            # test batch predict
M
MRXLT 已提交
416
            check_cmd "python benchmark.py --thread 4 --batch_size 8 --model imdb_bow_client_conf/serving_client_conf.prototxt --request rpc --endpoint 127.0.0.1:9292"
W
wangjiawei04 已提交
417
            echo "imdb CPU RPC inference pass"
B
barrierye 已提交
418
            kill_server_process
J
Jiawei Wang 已提交
419 420
            rm -rf work_dir1
            sleep 5
W
wangjiawei04 已提交
421

B
barrierye 已提交
422 423
            unsetproxy # maybe the proxy is used on iPipe, which makes web-test failed.
            check_cmd "python text_classify_service.py imdb_cnn_model/ workdir/ 9292 imdb.vocab &"
424
            sleep 5
M
MRXLT 已提交
425
            check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"feed\":[{\"words\": \"i am very sad | 0\"}], \"fetch\":[\"prediction\"]}' http://127.0.0.1:9292/imdb/prediction"
B
barrierye 已提交
426
            http_code=`curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"words": "i am very sad | 0"}], "fetch":["prediction"]}' -s -w "%{http_code}" -o /dev/null http://127.0.0.1:9292/imdb/prediction`
B
barrierye 已提交
427 428 429 430
            if [ ${http_code} -ne 200 ]; then
                echo "HTTP status code -ne 200"
                exit 1
            fi
B
barrierye 已提交
431
            # test batch predict
M
MRXLT 已提交
432
            check_cmd "python benchmark.py --thread 4 --batch_size 8 --model imdb_bow_client_conf/serving_client_conf.prototxt --request http --endpoint 127.0.0.1:9292"
B
barrierye 已提交
433 434 435
            setproxy # recover proxy state
            kill_server_process
            ps -ef | grep "text_classify_service.py" | grep -v grep | awk '{print $2}' | xargs kill
B
barrierye 已提交
436
            echo "imdb CPU HTTP inference pass"
W
wangjiawei04 已提交
437 438 439 440 441
            ;;
        GPU)
            echo "imdb ignore GPU test"
            ;;
        *)
B
barrierye 已提交
442 443 444
            echo "error type"
            exit 1
            ;;
W
wangjiawei04 已提交
445 446
    esac
    echo "test imdb $TYPE finished as expected."
447 448 449 450 451 452 453 454 455 456 457 458 459 460
    unset SERVING_BIN
    cd ..
}

function python_test_lac() {
    # pwd: /Serving/python/examples
    local TYPE=$1
    export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
    cd lac # pwd: /Serving/python/examples/lac
    case $TYPE in
        CPU)
            sh get_data.sh
            check_cmd "python -m paddle_serving_server.serve --model jieba_server_model/ --port 9292 &"
            sleep 5
B
barrierye 已提交
461
            check_cmd "echo \"我爱北京天安门\" | python lac_client.py jieba_client_conf/serving_client_conf.prototxt lac_dict/"
462
            echo "lac CPU RPC inference pass"
B
barrierye 已提交
463
            kill_server_process
464

B
barrierye 已提交
465
            unsetproxy # maybe the proxy is used on iPipe, which makes web-test failed.
466 467
            check_cmd "python lac_web_service.py jieba_server_model/ lac_workdir 9292 &"
            sleep 5
B
barrierye 已提交
468 469
            check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"feed\":[{\"words\": \"我爱北京天安门\"}], \"fetch\":[\"word_seg\"]}' http://127.0.0.1:9292/lac/prediction"
            # check http code
B
barrierye 已提交
470
            http_code=`curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"words": "我爱北京天安门"}], "fetch":["word_seg"]}' -s -w "%{http_code}" -o /dev/null http://127.0.0.1:9292/lac/prediction`
B
barrierye 已提交
471 472 473 474 475 476 477
            if [ ${http_code} -ne 200 ]; then
                echo "HTTP status code -ne 200"
                exit 1
            fi
            # http batch
            check_cmd "curl -H \"Content-Type:application/json\" -X POST -d '{\"feed\":[{\"words\": \"我爱北京天安门\"}, {\"words\": \"我爱北京天安门\"}], \"fetch\":[\"word_seg\"]}' http://127.0.0.1:9292/lac/prediction"
            # check http code
B
barrierye 已提交
478
            http_code=`curl -H "Content-Type:application/json" -X POST -d '{"feed":[{"words": "我爱北京天安门"}, {"words": "我爱北京天安门"}], "fetch":["word_seg"]}' -s -w "%{http_code}" -o /dev/null http://127.0.0.1:9292/lac/prediction`
B
barrierye 已提交
479 480 481 482
            if [ ${http_code} -ne 200 ]; then
                echo "HTTP status code -ne 200"
                exit 1
            fi
B
barrierye 已提交
483
            setproxy # recover proxy state
B
barrierye 已提交
484
            kill_server_process
485 486 487 488 489 490 491
            ps -ef | grep "lac_web_service" | grep -v grep | awk '{print $2}' | xargs kill
            echo "lac CPU HTTP inference pass"
            ;;
        GPU)
            echo "lac ignore GPU test"
            ;;
        *)
B
barrierye 已提交
492 493 494
            echo "error type"
            exit 1
            ;;
495 496 497
    esac
    echo "test lac $TYPE finished as expected."
    unset SERVING_BIN
W
wangjiawei04 已提交
498 499 500
    cd ..
}

G
guru4elephant 已提交
501
function python_run_test() {
502
    # Using the compiled binary
Y
Your Name 已提交
503 504 505
    local TYPE=$1 # pwd: /Serving
    cd python/examples # pwd: /Serving/python/examples
    python_test_fit_a_line $TYPE # pwd: /Serving/python/examples
Y
merge  
Your Name 已提交
506
    python_run_criteo_ctr_with_cube $TYPE # pwd: /Serving/python/examples
W
wangjiawei04 已提交
507
    python_test_bert $TYPE # pwd: /Serving/python/examples
M
MRXLT 已提交
508
    python_test_imdb $TYPE # pwd: /Serving/python/examples
M
MRXLT 已提交
509 510 511
    python_test_lac $TYPE # pwd: /Serving/python/examples
    python_test_multi_process $TYPE # pwd: /Serving/python/examples
    python_test_multi_fetch $TYPE # pwd: /Serving/python/examples
G
guru4elephant 已提交
512
    echo "test python $TYPE part finished as expected."
Y
Your Name 已提交
513
    cd ../.. # pwd: /Serving
G
guru4elephant 已提交
514 515
}

B
barrierye 已提交
516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634
function monitor_test() {
    local TYPE=$1 # pwd: /Serving
    mkdir _monitor_test && cd _monitor_test # pwd: /Serving/_monitor_test
    case $TYPE in
        CPU):
            pip install pyftpdlib
            mkdir remote_path
            mkdir local_path
            cd remote_path # pwd: /Serving/_monitor_test/remote_path
            check_cmd "python -m pyftpdlib -p 8000 &>/dev/null &"
            cd .. # pwd: /Serving/_monitor_test

            # type: ftp
            # remote_path: /
            # remote_model_name: uci_housing.tar.gz
            # local_tmp_path: ___tmp
            # local_path: local_path
            cd remote_path # pwd: /Serving/_monitor_test/remote_path
            wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
            touch donefile
            cd ..  # pwd: /Serving/_monitor_test
            mkdir -p local_path/uci_housing_model
            python -m paddle_serving_server.monitor \
                    --type='ftp' --ftp_host='127.0.0.1' --ftp_port='8000' \
                    --remote_path='/' --remote_model_name='uci_housing.tar.gz' \
                    --remote_donefile_name='donefile' --local_path='local_path' \
                    --local_model_name='uci_housing_model' --local_timestamp_file='fluid_time_file' \
                    --local_tmp_path='___tmp' --unpacked_filename='uci_housing_model' \
                    --interval='1' >/dev/null &
            sleep 10
            if [ ! -f "local_path/uci_housing_model/fluid_time_file" ]; then
                echo "local_path/uci_housing_model/fluid_time_file not exist."
                exit 1
            fi
            ps -ef | grep "monitor" | grep -v grep | awk '{print $2}' | xargs kill
            rm -rf remote_path/*
            rm -rf local_path/*

            # type: ftp
            # remote_path: /tmp_dir
            # remote_model_name: uci_housing_model
            # local_tmp_path: ___tmp
            # local_path: local_path
            mkdir -p remote_path/tmp_dir && cd remote_path/tmp_dir # pwd: /Serving/_monitor_test/remote_path/tmp_dir
            wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
            tar -xzf uci_housing.tar.gz
            touch donefile
            cd ../.. # pwd: /Serving/_monitor_test
            mkdir -p local_path/uci_housing_model
            python -m paddle_serving_server.monitor \
                    --type='ftp' --ftp_host='127.0.0.1' --ftp_port='8000' \
                    --remote_path='/tmp_dir' --remote_model_name='uci_housing_model' \
                    --remote_donefile_name='donefile' --local_path='local_path' \
                    --local_model_name='uci_housing_model' --local_timestamp_file='fluid_time_file' \
                    --local_tmp_path='___tmp' --interval='1' >/dev/null &
            sleep 10
            if [ ! -f "local_path/uci_housing_model/fluid_time_file" ]; then
                echo "local_path/uci_housing_model/fluid_time_file not exist."
                exit 1
            fi
            ps -ef | grep "monitor" | grep -v grep | awk '{print $2}' | xargs kill
            rm -rf remote_path/*
            rm -rf local_path/*

            # type: general
            # remote_path: /
            # remote_model_name: uci_housing.tar.gz
            # local_tmp_path: ___tmp
            # local_path: local_path
            cd remote_path # pwd: /Serving/_monitor_test/remote_path
            wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
            touch donefile
            cd ..  # pwd: /Serving/_monitor_test
            mkdir -p local_path/uci_housing_model
            python -m paddle_serving_server.monitor \
                    --type='general' --general_host='ftp://127.0.0.1:8000' \
                    --remote_path='/' --remote_model_name='uci_housing.tar.gz' \
                    --remote_donefile_name='donefile' --local_path='local_path' \
                    --local_model_name='uci_housing_model' --local_timestamp_file='fluid_time_file' \
                    --local_tmp_path='___tmp' --unpacked_filename='uci_housing_model' \
                    --interval='1' >/dev/null &
            sleep 10
            if [ ! -f "local_path/uci_housing_model/fluid_time_file" ]; then
                echo "local_path/uci_housing_model/fluid_time_file not exist."
                exit 1
            fi
            ps -ef | grep "monitor" | grep -v grep | awk '{print $2}' | xargs kill
            rm -rf remote_path/*
            rm -rf local_path/*

            # type: general
            # remote_path: /tmp_dir
            # remote_model_name: uci_housing_model
            # local_tmp_path: ___tmp
            # local_path: local_path
            mkdir -p remote_path/tmp_dir && cd remote_path/tmp_dir # pwd: /Serving/_monitor_test/remote_path/tmp_dir
            wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
            tar -xzf uci_housing.tar.gz
            touch donefile
            cd ../.. # pwd: /Serving/_monitor_test
            mkdir -p local_path/uci_housing_model
            python -m paddle_serving_server.monitor \
                    --type='general' --general_host='ftp://127.0.0.1:8000' \
                    --remote_path='/tmp_dir' --remote_model_name='uci_housing_model' \
                    --remote_donefile_name='donefile' --local_path='local_path' \
                    --local_model_name='uci_housing_model' --local_timestamp_file='fluid_time_file' \
                    --local_tmp_path='___tmp' --interval='1' >/dev/null &
            sleep 10
            if [ ! -f "local_path/uci_housing_model/fluid_time_file" ]; then
                echo "local_path/uci_housing_model/fluid_time_file not exist."
                exit 1
            fi
            ps -ef | grep "monitor" | grep -v grep | awk '{print $2}' | xargs kill
            rm -rf remote_path/*
            rm -rf local_path/*

            ps -ef | grep "pyftpdlib" | grep -v grep | awk '{print $2}' | xargs kill
            ;;
        GPU):
B
barrierye 已提交
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746
            pip install pyftpdlib
            mkdir remote_path
            mkdir local_path
            cd remote_path # pwd: /Serving/_monitor_test/remote_path
            check_cmd "python -m pyftpdlib -p 8000 &>/dev/null &"
            cd .. # pwd: /Serving/_monitor_test

            # type: ftp
            # remote_path: /
            # remote_model_name: uci_housing.tar.gz
            # local_tmp_path: ___tmp
            # local_path: local_path
            cd remote_path # pwd: /Serving/_monitor_test/remote_path
            wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
            touch donefile
            cd ..  # pwd: /Serving/_monitor_test
            mkdir -p local_path/uci_housing_model
            python -m paddle_serving_server_gpu.monitor \
                    --type='ftp' --ftp_host='127.0.0.1' --ftp_port='8000' \
                    --remote_path='/' --remote_model_name='uci_housing.tar.gz' \
                    --remote_donefile_name='donefile' --local_path='local_path' \
                    --local_model_name='uci_housing_model' --local_timestamp_file='fluid_time_file' \
                    --local_tmp_path='___tmp' --unpacked_filename='uci_housing_model' \
                    --interval='1' >/dev/null &
            sleep 10
            if [ ! -f "local_path/uci_housing_model/fluid_time_file" ]; then
                echo "local_path/uci_housing_model/fluid_time_file not exist."
                exit 1
            fi
            ps -ef | grep "monitor" | grep -v grep | awk '{print $2}' | xargs kill
            rm -rf remote_path/*
            rm -rf local_path/*

            # type: ftp
            # remote_path: /tmp_dir
            # remote_model_name: uci_housing_model
            # local_tmp_path: ___tmp
            # local_path: local_path
            mkdir -p remote_path/tmp_dir && cd remote_path/tmp_dir # pwd: /Serving/_monitor_test/remote_path/tmp_dir
            wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
            tar -xzf uci_housing.tar.gz
            touch donefile
            cd ../.. # pwd: /Serving/_monitor_test
            mkdir -p local_path/uci_housing_model
            python -m paddle_serving_server_gpu.monitor \
                    --type='ftp' --ftp_host='127.0.0.1' --ftp_port='8000' \
                    --remote_path='/tmp_dir' --remote_model_name='uci_housing_model' \
                    --remote_donefile_name='donefile' --local_path='local_path' \
                    --local_model_name='uci_housing_model' --local_timestamp_file='fluid_time_file' \
                    --local_tmp_path='___tmp' --interval='1' >/dev/null &
            sleep 10
            if [ ! -f "local_path/uci_housing_model/fluid_time_file" ]; then
                echo "local_path/uci_housing_model/fluid_time_file not exist."
                exit 1
            fi
            ps -ef | grep "monitor" | grep -v grep | awk '{print $2}' | xargs kill
            rm -rf remote_path/*
            rm -rf local_path/*

            # type: general
            # remote_path: /
            # remote_model_name: uci_housing.tar.gz
            # local_tmp_path: ___tmp
            # local_path: local_path
            cd remote_path # pwd: /Serving/_monitor_test/remote_path
            wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
            touch donefile
            cd ..  # pwd: /Serving/_monitor_test
            mkdir -p local_path/uci_housing_model
            python -m paddle_serving_server_gpu.monitor \
                    --type='general' --general_host='ftp://127.0.0.1:8000' \
                    --remote_path='/' --remote_model_name='uci_housing.tar.gz' \
                    --remote_donefile_name='donefile' --local_path='local_path' \
                    --local_model_name='uci_housing_model' --local_timestamp_file='fluid_time_file' \
                    --local_tmp_path='___tmp' --unpacked_filename='uci_housing_model' \
                    --interval='1' >/dev/null &
            sleep 10
            if [ ! -f "local_path/uci_housing_model/fluid_time_file" ]; then
                echo "local_path/uci_housing_model/fluid_time_file not exist."
                exit 1
            fi
            ps -ef | grep "monitor" | grep -v grep | awk '{print $2}' | xargs kill
            rm -rf remote_path/*
            rm -rf local_path/*

            # type: general
            # remote_path: /tmp_dir
            # remote_model_name: uci_housing_model
            # local_tmp_path: ___tmp
            # local_path: local_path
            mkdir -p remote_path/tmp_dir && cd remote_path/tmp_dir # pwd: /Serving/_monitor_test/remote_path/tmp_dir
            wget --no-check-certificate https://paddle-serving.bj.bcebos.com/uci_housing.tar.gz
            tar -xzf uci_housing.tar.gz
            touch donefile
            cd ../.. # pwd: /Serving/_monitor_test
            mkdir -p local_path/uci_housing_model
            python -m paddle_serving_server_gpu.monitor \
                    --type='general' --general_host='ftp://127.0.0.1:8000' \
                    --remote_path='/tmp_dir' --remote_model_name='uci_housing_model' \
                    --remote_donefile_name='donefile' --local_path='local_path' \
                    --local_model_name='uci_housing_model' --local_timestamp_file='fluid_time_file' \
                    --local_tmp_path='___tmp' --interval='1' >/dev/null &
            sleep 10
            if [ ! -f "local_path/uci_housing_model/fluid_time_file" ]; then
                echo "local_path/uci_housing_model/fluid_time_file not exist."
                exit 1
            fi
            ps -ef | grep "monitor" | grep -v grep | awk '{print $2}' | xargs kill
            rm -rf remote_path/*
            rm -rf local_path/*

            ps -ef | grep "pyftpdlib" | grep -v grep | awk '{print $2}' | xargs kill
B
barrierye 已提交
747 748
            ;;
        *)
B
barrierye 已提交
749 750 751
            echo "error type"
            exit 1
            ;;
B
barrierye 已提交
752 753 754 755 756 757
    esac
    cd .. # pwd: /Serving
    rm -rf _monitor_test
    echo "test monitor $TYPE finished as expected."
}

G
guru4elephant 已提交
758
function main() {
Y
Your Name 已提交
759 760 761 762
    local TYPE=$1 # pwd: /
    init # pwd: /Serving
    build_client $TYPE # pwd: /Serving
    build_server $TYPE # pwd: /Serving
B
barrierye 已提交
763
    build_app $TYPE # pwd: /Serving
Y
Your Name 已提交
764
    python_run_test $TYPE # pwd: /Serving
B
barrierye 已提交
765
    monitor_test $TYPE # pwd: /Serving
G
guru4elephant 已提交
766 767 768 769
    echo "serving $TYPE part finished as expected."
}

main $@