未验证 提交 4ba2f8b8 编写于 作者: D Dong Daxiang 提交者: GitHub

Merge pull request #405 from MRXLT/0.2.0-cherry-v2

[cherry-pick to 0.2.0] cherry pick PR 399 400 401 402 403
...@@ -228,14 +228,6 @@ curl -H "Content-Type:application/json" -X POST -d '{"url": "https://paddle-serv ...@@ -228,14 +228,6 @@ curl -H "Content-Type:application/json" -X POST -d '{"url": "https://paddle-serv
| Description | Get click probability from a feature vector of item | | Description | Get click probability from a feature vector of item |
| Key | Value |
| :----------------- | :----------------------------------------------------------- |
| Model Name | DNN-CTR(with cube) |
| URL | https://paddle-serving.bj.bcebos.com/unittest/ctr_cube_unittest.tar.gz |
| Client/Server Code | https://github.com/PaddlePaddle/Serving/tree/develop/python/examples/criteo_ctr_with_cube |
| Description | Get click probability from a feature vector of item |
<h2 align="center">Document</h2> <h2 align="center">Document</h2>
### New to Paddle Serving ### New to Paddle Serving
......
...@@ -268,14 +268,6 @@ curl -H "Content-Type:application/json" -X POST -d '{"url": "https://paddle-serv ...@@ -268,14 +268,6 @@ curl -H "Content-Type:application/json" -X POST -d '{"url": "https://paddle-serv
| Key | Value |
| :----------------- | :----------------------------------------------------------- |
| 模型名 | DNN-CTR(with cube) |
| 下载链接 | https://paddle-serving.bj.bcebos.com/unittest/ctr_cube_unittest.tar.gz |
| 客户端/服务端代码 | https://github.com/PaddlePaddle/Serving/tree/develop/python/examples/criteo_ctr_with_cube |
| 介绍 | 从项目的特征向量中获得点击概率 |
<h2 align="center">文档</h2> <h2 align="center">文档</h2>
### 新手教程 ### 新手教程
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <string> #include <string>
#include <utility>
#include <vector> #include <vector>
#include "core/predictor/common/inner_common.h" #include "core/predictor/common/inner_common.h"
#include "core/predictor/framework/bsf.h" #include "core/predictor/framework/bsf.h"
...@@ -588,12 +589,14 @@ class VersionedInferEngine : public InferEngine { ...@@ -588,12 +589,14 @@ class VersionedInferEngine : public InferEngine {
LOG(ERROR) << "Failed generate engine with type:" << engine_type; LOG(ERROR) << "Failed generate engine with type:" << engine_type;
return -1; return -1;
} }
VLOG(2) << "FLGS_logtostderr " << FLAGS_logtostderr;
int tmp = FLAGS_logtostderr;
if (engine->proc_initialize(conf, version) != 0) { if (engine->proc_initialize(conf, version) != 0) {
LOG(ERROR) << "Failed initialize engine, type:" << engine_type; LOG(ERROR) << "Failed initialize engine, type:" << engine_type;
return -1; return -1;
} }
VLOG(2) << "FLGS_logtostderr " << FLAGS_logtostderr;
FLAGS_logtostderr = tmp;
auto r = _versions.insert(std::make_pair(engine->version(), engine)); auto r = _versions.insert(std::make_pair(engine->version(), engine));
if (!r.second) { if (!r.second) {
LOG(ERROR) << "Failed insert item: " << engine->version() LOG(ERROR) << "Failed insert item: " << engine->version()
...@@ -760,7 +763,6 @@ class InferManager { ...@@ -760,7 +763,6 @@ class InferManager {
LOG(ERROR) << "failed load infer config, path: " << path << "/" << file; LOG(ERROR) << "failed load infer config, path: " << path << "/" << file;
return -1; return -1;
} }
size_t engine_num = model_toolkit_conf.engines_size(); size_t engine_num = model_toolkit_conf.engines_size();
for (size_t ei = 0; ei < engine_num; ++ei) { for (size_t ei = 0; ei < engine_num; ++ei) {
std::string engine_name = model_toolkit_conf.engines(ei).name(); std::string engine_name = model_toolkit_conf.engines(ei).name();
...@@ -769,12 +771,10 @@ class InferManager { ...@@ -769,12 +771,10 @@ class InferManager {
LOG(ERROR) << "Failed generate versioned engine: " << engine_name; LOG(ERROR) << "Failed generate versioned engine: " << engine_name;
return -1; return -1;
} }
if (engine->proc_initialize(model_toolkit_conf.engines(ei)) != 0) { if (engine->proc_initialize(model_toolkit_conf.engines(ei)) != 0) {
LOG(ERROR) << "Failed initialize version engine, name:" << engine_name; LOG(ERROR) << "Failed initialize version engine, name:" << engine_name;
return -1; return -1;
} }
auto r = _map.insert(std::make_pair(engine_name, engine)); auto r = _map.insert(std::make_pair(engine_name, engine));
if (!r.second) { if (!r.second) {
LOG(ERROR) << "Failed insert item: " << engine_name; LOG(ERROR) << "Failed insert item: " << engine_name;
...@@ -782,7 +782,6 @@ class InferManager { ...@@ -782,7 +782,6 @@ class InferManager {
} }
LOG(WARNING) << "Succ proc initialize engine: " << engine_name; LOG(WARNING) << "Succ proc initialize engine: " << engine_name;
} }
return 0; return 0;
} }
......
...@@ -21,37 +21,10 @@ wget https://paddle-serving.bj.bcebos.com/data/text_classification/imdb_serving_ ...@@ -21,37 +21,10 @@ wget https://paddle-serving.bj.bcebos.com/data/text_classification/imdb_serving_
tar -xzf imdb_serving_example.tar.gz tar -xzf imdb_serving_example.tar.gz
``` ```
### Server Side Code
```python
# test_server_go.py
import os
import sys
from paddle_serving_server import OpMaker
from paddle_serving_server import OpSeqMaker
from paddle_serving_server import Server
op_maker = OpMaker()
read_op = op_maker.create('general_text_reader')
general_infer_op = op_maker.create('general_infer')
general_response_op = op_maker.create('general_text_response')
op_seq_maker = OpSeqMaker()
op_seq_maker.add_op(read_op)
op_seq_maker.add_op(general_infer_op)
op_seq_maker.add_op(general_response_op)
server = Server()
server.set_op_sequence(op_seq_maker.get_op_sequence())
server.load_model_config(sys.argv[1])
server.prepare_server(workdir="work_dir1", port=9292, device="cpu")
server.run_server()
```
### Start Server ### Start Server
``` shell ``` shell
python test_server_go.py ./serving_server_model/ 9292 python -m paddle_serving_server.serve --model ./serving_server_model/ --port 9292
``` ```
### Client code example ### Client code example
......
...@@ -20,106 +20,79 @@ wget https://paddle-serving.bj.bcebos.com/data/text_classification/imdb_serving_ ...@@ -20,106 +20,79 @@ wget https://paddle-serving.bj.bcebos.com/data/text_classification/imdb_serving_
tar -xzf imdb_serving_example.tar.gz tar -xzf imdb_serving_example.tar.gz
``` ```
### 服务器端代码
```python
# test_server_go.py
import os
import sys
from paddle_serving_server import OpMaker
from paddle_serving_server import OpSeqMaker
from paddle_serving_server import Server
op_maker = OpMaker ()
read_op = op_maker.create ('general_text_reader')
general_infer_op = op_maker.create ('general_infer')
general_response_op = op_maker.create ('general_text_response')
op_seq_maker = OpSeqMaker ()
op_seq_maker.add_op (read_op)
op_seq_maker.add_op (general_infer_op)
op_seq_maker.add_op (general_response_op)
server = Server ()
server.set_op_sequence (op_seq_maker.get_op_sequence ())
server.load_model_config (sys.argv [1])
server.prepare_server (workdir = "work_dir1", port = 9292, device = "cpu")
server.run_server ()
```
### 启动服务器 ### 启动服务器
```shell ```shell
python test_server_go.py ./serving_server_model/ 9292 python -m paddle_serving_server.serve --model ./serving_server_model/ --port 9292
``` ```
### 客户端代码示例 ### 客户端代码示例
```go ``` go
// imdb_client.go // imdb_client.go
package main package main
import ( import (
       "io" "io"
       "fmt" "fmt"
       "strings" "strings"
       "bufio" "bufio"
       "strconv" "strconv"
       "os" "os"
       serving_client "github.com/PaddlePaddle/Serving/go/serving_client" serving_client "github.com/PaddlePaddle/Serving/go/serving_client"
) )
func main () { func main() {
     var config_file_path string var config_file_path string
     config_file_path = os.Args [1] config_file_path = os.Args[1]
     handle: = serving_client.LoadModelConfig (config_file_path) handle := serving_client.LoadModelConfig(config_file_path)
     handle = serving_client.Connect ("127.0.0.1", "9292", handle) handle = serving_client.Connect("127.0.0.1", "9292", handle)
     test_file_path: = os.Args [2] test_file_path := os.Args[2]
     fi, err: = os.Open (test_file_path) fi, err := os.Open(test_file_path)
     if err! = nil { if err != nil {
     fmt.Print (err) fmt.Print(err)
     } }
     defer fi.Close () defer fi.Close()
     br: = bufio.NewReader (fi) br := bufio.NewReader(fi)
     fetch: = [] string {"cost", "acc", "prediction"} fetch := []string{"cost", "acc", "prediction"}
     var result map [string] [] float32 var result map[string][]float32
     for { for {
     line, err: = br.ReadString ('\ n') line, err := br.ReadString('\n')
if err == io.EOF { if err == io.EOF {
break break
} }
line = strings.Trim (line, "\ n") line = strings.Trim(line, "\n")
var words = [] int64 {} var words = []int64{}
s: = strings.Split (line, "") s := strings.Split(line, " ")
value, err: = strconv.Atoi (s [0]) value, err := strconv.Atoi(s[0])
var feed_int_map map [string] [] int64 var feed_int_map map[string][]int64
       
for _, v: = range s [1: value + 1] { for _, v := range s[1:value + 1] {
int_v, _: = strconv.Atoi (v) int_v, _ := strconv.Atoi(v)
words = append (words, int64 (int_v)) words = append(words, int64(int_v))
} }
label, err: = strconv.Atoi (s [len (s) -1]) label, err := strconv.Atoi(s[len(s)-1])
if err! = nil { if err != nil {
panic (err) panic(err)
} }
feed_int_map = map [string] [] int64 {} feed_int_map = map[string][]int64{}
feed_int_map ["words"] = words feed_int_map["words"] = words
feed_int_map ["label"] = [] int64 {int64 (label)} feed_int_map["label"] = []int64{int64(label)}
Ranch
result = serving_client.Predict (handle, feed_int_map, fetch) result = serving_client.Predict(handle, feed_int_map, fetch)
fmt.Println (result ["prediction"] [1], "\ t", int64 (label)) fmt.Println(result["prediction"][1], "\t", int64(label))
    } }
} }
``` ```
......
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = source
BUILDDIR = build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
:github_url: https://github.com/PaddlePaddle/Serving
.. mdinclude:: md/logo.md
Paddle Serving
==============
.. toctree::
:maxdepth: 1
:caption: Readme
:hidden:
.. _instruction: instruction.html
此差异已折叠。
sphinx==2.1.0
mistune
sphinx_rtd_theme
paddlepaddle>=1.6
...@@ -28,7 +28,7 @@ func main() { ...@@ -28,7 +28,7 @@ func main() {
var config_file_path string var config_file_path string
config_file_path = os.Args[1] config_file_path = os.Args[1]
handle := serving_client.LoadModelConfig(config_file_path) handle := serving_client.LoadModelConfig(config_file_path)
handle = serving_client.Connect("127.0.0.1", "9393", handle) handle = serving_client.Connect("127.0.0.1", "9292", handle)
test_file_path := os.Args[2] test_file_path := os.Args[2]
fi, err := os.Open(test_file_path) fi, err := os.Open(test_file_path)
......
...@@ -61,4 +61,7 @@ def single_func(idx, resource): ...@@ -61,4 +61,7 @@ def single_func(idx, resource):
multi_thread_runner = MultiThreadRunner() multi_thread_runner = MultiThreadRunner()
result = multi_thread_runner.run(single_func, args.thread, {}) result = multi_thread_runner.run(single_func, args.thread, {})
print(result) avg_cost = 0
for cost in result[0]:
avg_cost += cost
print("total cost of each thread".format(avg_cost / args.thread))
...@@ -93,7 +93,7 @@ class Client(object): ...@@ -93,7 +93,7 @@ class Client(object):
lib_path = os.path.dirname(paddle_serving_client.__file__) lib_path = os.path.dirname(paddle_serving_client.__file__)
client_path = os.path.join(lib_path, 'serving_client.so') client_path = os.path.join(lib_path, 'serving_client.so')
lib_path = os.path.join(lib_path, 'lib') lib_path = os.path.join(lib_path, 'lib')
os.popen('patchelf --set-rpath {} {}'.format(lib_path, client_path)) os.system('patchelf --set-rpath {} {}'.format(lib_path, client_path))
def load_client_config(self, path): def load_client_config(self, path):
from .serving_client import PredictorClient from .serving_client import PredictorClient
......
...@@ -12,6 +12,6 @@ ...@@ -12,6 +12,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
""" Paddle Serving Client version string """ """ Paddle Serving Client version string """
serving_client_version = "0.1.3" serving_client_version = "0.2.0"
serving_server_version = "0.1.3" serving_server_version = "0.2.0"
module_proto_version = "0.1.3" module_proto_version = "0.2.0"
...@@ -211,6 +211,7 @@ class Server(object): ...@@ -211,6 +211,7 @@ class Server(object):
tar_name = floder_name + ".tar.gz" tar_name = floder_name + ".tar.gz"
bin_url = "https://paddle-serving.bj.bcebos.com/bin/" + tar_name bin_url = "https://paddle-serving.bj.bcebos.com/bin/" + tar_name
self.server_path = os.path.join(self.module_path, floder_name) self.server_path = os.path.join(self.module_path, floder_name)
if not os.path.exists(self.server_path): if not os.path.exists(self.server_path):
print('Frist time run, downloading PaddleServing components ...') print('Frist time run, downloading PaddleServing components ...')
r = os.system('wget ' + bin_url + ' --no-check-certificate') r = os.system('wget ' + bin_url + ' --no-check-certificate')
......
...@@ -12,6 +12,6 @@ ...@@ -12,6 +12,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
""" Paddle Serving Client version string """ """ Paddle Serving Client version string """
serving_client_version = "0.1.3" serving_client_version = "0.2.0"
serving_server_version = "0.1.3" serving_server_version = "0.2.0"
module_proto_version = "0.1.3" module_proto_version = "0.2.0"
...@@ -20,6 +20,7 @@ import google.protobuf.text_format ...@@ -20,6 +20,7 @@ import google.protobuf.text_format
import tarfile import tarfile
import socket import socket
import paddle_serving_server_gpu as paddle_serving_server import paddle_serving_server_gpu as paddle_serving_server
import time
from .version import serving_server_version from .version import serving_server_version
from contextlib import closing from contextlib import closing
import argparse import argparse
...@@ -115,6 +116,7 @@ class Server(object): ...@@ -115,6 +116,7 @@ class Server(object):
self.reload_interval_s = 10 self.reload_interval_s = 10
self.module_path = os.path.dirname(paddle_serving_server.__file__) self.module_path = os.path.dirname(paddle_serving_server.__file__)
self.cur_path = os.getcwd() self.cur_path = os.getcwd()
self.check_cuda
self.use_local_bin = False self.use_local_bin = False
self.gpuid = 0 self.gpuid = 0
...@@ -141,6 +143,13 @@ class Server(object): ...@@ -141,6 +143,13 @@ class Server(object):
self.use_local_bin = True self.use_local_bin = True
self.bin_path = os.environ["SERVING_BIN"] self.bin_path = os.environ["SERVING_BIN"]
def check_cuda(self):
r = os.system("whereis cuda")
if r != 0:
raise SystemExit(
"CUDA not found, please check your environment or use cpu version by \"pip install paddle_serving_server\""
)
def set_gpuid(self, gpuid=0): def set_gpuid(self, gpuid=0):
self.gpuid = gpuid self.gpuid = gpuid
...@@ -215,11 +224,21 @@ class Server(object): ...@@ -215,11 +224,21 @@ class Server(object):
os.chdir(self.module_path) os.chdir(self.module_path)
need_download = False need_download = False
device_version = "serving-gpu-" device_version = "serving-gpu-"
floder_name = device_version + serving_server_version folder_name = device_version + serving_server_version
tar_name = floder_name + ".tar.gz" tar_name = folder_name + ".tar.gz"
bin_url = "https://paddle-serving.bj.bcebos.com/bin/" + tar_name bin_url = "https://paddle-serving.bj.bcebos.com/bin/" + tar_name
self.server_path = os.path.join(self.module_path, floder_name) self.server_path = os.path.join(self.module_path, folder_name)
download_flag = "{}/{}.is_download".format(self.module_path,
folder_name)
if os.path.exists(download_flag):
os.chdir(self.cur_path)
self.bin_path = self.server_path + "/serving"
return
if not os.path.exists(self.server_path): if not os.path.exists(self.server_path):
os.system("touch {}/{}.is_download".format(self.module_path,
folder_name))
print('Frist time run, downloading PaddleServing components ...') print('Frist time run, downloading PaddleServing components ...')
r = os.system('wget ' + bin_url + ' --no-check-certificate') r = os.system('wget ' + bin_url + ' --no-check-certificate')
if r != 0: if r != 0:
...@@ -318,4 +337,8 @@ class Server(object): ...@@ -318,4 +337,8 @@ class Server(object):
self.gpuid,) self.gpuid,)
print("Going to Run Comand") print("Going to Run Comand")
print(command) print(command)
# wait for other process to download server bin
while not os.path.exists(self.server_path):
time.sleep(1)
os.system(command) os.system(command)
...@@ -12,6 +12,6 @@ ...@@ -12,6 +12,6 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
""" Paddle Serving Client version string """ """ Paddle Serving Client version string """
serving_client_version = "0.1.3" serving_client_version = "0.2.0"
serving_server_version = "0.1.3" serving_server_version = "0.2.0"
module_proto_version = "0.1.3" module_proto_version = "0.2.0"
...@@ -66,6 +66,12 @@ class WebService(object): ...@@ -66,6 +66,12 @@ class WebService(object):
return server return server
def _launch_rpc_service(self, service_idx): def _launch_rpc_service(self, service_idx):
if service_idx == 0:
self.rpc_service_list[service_idx].check_local_bin()
if not self.rpc_service_list[service_idx].use_local_bin:
self.rpc_service_list[service_idx].download_bin()
else:
time.sleep(3)
self.rpc_service_list[service_idx].run_server() self.rpc_service_list[service_idx].run_server()
def prepare_server(self, workdir="", port=9393, device="gpu", gpuid=0): def prepare_server(self, workdir="", port=9393, device="gpu", gpuid=0):
...@@ -160,15 +166,6 @@ class WebService(object): ...@@ -160,15 +166,6 @@ class WebService(object):
if not isinstance(result, dict) and result == -1: if not isinstance(result, dict) and result == -1:
result = {"result": "Request Value Error"} result = {"result": "Request Value Error"}
return result return result
'''
feed, fetch = self.preprocess(request.json, request.json["fetch"])
if "fetch" in feed:
del feed["fetch"]
fetch_map = client.predict(feed=feed, fetch=fetch)
fetch_map = self.postprocess(
feed=request.json, fetch=fetch, fetch_map=fetch_map)
return fetch_map
'''
app_instance.run(host="0.0.0.0", app_instance.run(host="0.0.0.0",
port=self.port, port=self.port,
......
...@@ -176,6 +176,7 @@ function python_run_criteo_ctr_with_cube() { ...@@ -176,6 +176,7 @@ function python_run_criteo_ctr_with_cube() {
local TYPE=$1 local TYPE=$1
yum install -y bc >/dev/null yum install -y bc >/dev/null
cd criteo_ctr_with_cube # pwd: /Serving/python/examples/criteo_ctr_with_cube cd criteo_ctr_with_cube # pwd: /Serving/python/examples/criteo_ctr_with_cube
export SERVING_BIN=${SERVING_WORKDIR}/build-server-${TYPE}/core/general-server/serving
case $TYPE in case $TYPE in
CPU) CPU)
check_cmd "wget https://paddle-serving.bj.bcebos.com/unittest/ctr_cube_unittest.tar.gz" check_cmd "wget https://paddle-serving.bj.bcebos.com/unittest/ctr_cube_unittest.tar.gz"
...@@ -191,6 +192,7 @@ function python_run_criteo_ctr_with_cube() { ...@@ -191,6 +192,7 @@ function python_run_criteo_ctr_with_cube() {
sh cube_prepare.sh & sh cube_prepare.sh &
check_cmd "mkdir work_dir1 && cp cube/conf/cube.conf ./work_dir1/" check_cmd "mkdir work_dir1 && cp cube/conf/cube.conf ./work_dir1/"
python test_server.py ctr_serving_model_kv & python test_server.py ctr_serving_model_kv &
sleep 5
check_cmd "python test_client.py ctr_client_conf/serving_client_conf.prototxt ./ut_data >score" check_cmd "python test_client.py ctr_client_conf/serving_client_conf.prototxt ./ut_data >score"
tail -n 2 score tail -n 2 score
AUC=$(tail -n 2 score | awk 'NR==1') AUC=$(tail -n 2 score | awk 'NR==1')
...@@ -217,6 +219,7 @@ function python_run_criteo_ctr_with_cube() { ...@@ -217,6 +219,7 @@ function python_run_criteo_ctr_with_cube() {
sh cube_prepare.sh & sh cube_prepare.sh &
check_cmd "mkdir work_dir1 && cp cube/conf/cube.conf ./work_dir1/" check_cmd "mkdir work_dir1 && cp cube/conf/cube.conf ./work_dir1/"
python test_server_gpu.py ctr_serving_model_kv & python test_server_gpu.py ctr_serving_model_kv &
sleep 5
check_cmd "python test_client.py ctr_client_conf/serving_client_conf.prototxt ./ut_data >score" check_cmd "python test_client.py ctr_client_conf/serving_client_conf.prototxt ./ut_data >score"
tail -n 2 score | awk 'NR==1' tail -n 2 score | awk 'NR==1'
AUC=$(tail -n 2 score | awk 'NR==1') AUC=$(tail -n 2 score | awk 'NR==1')
...@@ -235,6 +238,7 @@ function python_run_criteo_ctr_with_cube() { ...@@ -235,6 +238,7 @@ function python_run_criteo_ctr_with_cube() {
exit 1 exit 1
;; ;;
esac esac
unset SERVING_BIN
echo "test criteo_ctr_with_cube $TYPE part finished as expected." echo "test criteo_ctr_with_cube $TYPE part finished as expected."
cd .. # pwd: /Serving/python/examples cd .. # pwd: /Serving/python/examples
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册