Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
580e8478
S
Serving
项目概览
PaddlePaddle
/
Serving
1 年多 前同步成功
通知
186
Star
833
Fork
253
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
105
列表
看板
标记
里程碑
合并请求
10
Wiki
2
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Serving
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
105
Issue
105
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
2
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
580e8478
编写于
6月 09, 2020
作者:
B
barrierye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
use future in channel && remove type def
上级
93e3d126
变更
9
展开全部
隐藏空白更改
内联
并排
Showing
9 changed file
with
269 addition
and
189 deletion
+269
-189
core/configure/CMakeLists.txt
core/configure/CMakeLists.txt
+9
-3
core/configure/proto/general_python_service.proto
core/configure/proto/general_python_service.proto
+6
-1
core/configure/proto/pyserving_channel.proto
core/configure/proto/pyserving_channel.proto
+5
-3
python/examples/fit_a_line/test_py_client.py
python/examples/fit_a_line/test_py_client.py
+1
-2
python/examples/fit_a_line/test_py_server.py
python/examples/fit_a_line/test_py_server.py
+15
-28
python/paddle_serving_client/general_python_service.proto
python/paddle_serving_client/general_python_service.proto
+0
-29
python/paddle_serving_client/pyclient.py
python/paddle_serving_client/pyclient.py
+12
-9
python/paddle_serving_server/pyserver.py
python/paddle_serving_server/pyserver.py
+203
-106
python/paddle_serving_server/serve.py
python/paddle_serving_server/serve.py
+18
-8
未找到文件。
core/configure/CMakeLists.txt
浏览文件 @
580e8478
...
...
@@ -39,6 +39,9 @@ py_grpc_proto_compile(multi_lang_general_model_service_py_proto SRCS proto/multi
add_custom_target
(
multi_lang_general_model_service_py_proto_init ALL COMMAND
${
CMAKE_COMMAND
}
-E touch __init__.py
)
add_dependencies
(
multi_lang_general_model_service_py_proto multi_lang_general_model_service_py_proto_init
)
py_grpc_proto_compile
(
general_python_service_py_proto SRCS proto/general_python_service.proto
)
add_custom_target
(
general_python_service_py_proto_init ALL COMMAND
${
CMAKE_COMMAND
}
-E touch __init__.py
)
add_dependencies
(
general_python_service_py_proto general_python_service_py_proto_init
)
if
(
CLIENT
)
py_proto_compile
(
sdk_configure_py_proto SRCS proto/sdk_configure.proto
)
add_custom_target
(
sdk_configure_py_proto_init ALL COMMAND
${
CMAKE_COMMAND
}
-E touch __init__.py
)
...
...
@@ -60,6 +63,12 @@ add_custom_command(TARGET multi_lang_general_model_service_py_proto POST_BUILD
COMMAND cp *.py
${
PADDLE_SERVING_BINARY_DIR
}
/python/paddle_serving_client/proto
COMMENT
"Copy generated multi_lang_general_model_service proto file into directory paddle_serving_client/proto."
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
)
add_custom_command
(
TARGET general_python_service_py_proto POST_BUILD
COMMAND
${
CMAKE_COMMAND
}
-E make_directory
${
PADDLE_SERVING_BINARY_DIR
}
/python/paddle_serving_client/proto
COMMAND cp *.py
${
PADDLE_SERVING_BINARY_DIR
}
/python/paddle_serving_client/proto
COMMENT
"Copy generated general_python_service proto file into directory paddle_serving_client/proto."
WORKING_DIRECTORY
${
CMAKE_CURRENT_BINARY_DIR
}
)
endif
()
if
(
APP
)
...
...
@@ -79,9 +88,6 @@ py_proto_compile(pyserving_channel_py_proto SRCS proto/pyserving_channel.proto)
add_custom_target
(
pyserving_channel_py_proto_init ALL COMMAND
${
CMAKE_COMMAND
}
-E touch __init__.py
)
add_dependencies
(
pyserving_channel_py_proto pyserving_channel_py_proto_init
)
py_grpc_proto_compile
(
general_python_service_py_proto SRCS proto/general_python_service.proto
)
add_custom_target
(
general_python_service_py_proto_init ALL COMMAND
${
CMAKE_COMMAND
}
-E touch __init__.py
)
add_dependencies
(
general_python_service_py_proto general_python_service_py_proto_init
)
if
(
NOT WITH_GPU
)
add_custom_command
(
TARGET server_config_py_proto POST_BUILD
COMMAND
${
CMAKE_COMMAND
}
-E make_directory
${
PADDLE_SERVING_BINARY_DIR
}
/python/paddle_serving_server/proto
...
...
python/paddle_serving_server
/general_python_service.proto
→
core/configure/proto
/general_python_service.proto
浏览文件 @
580e8478
...
...
@@ -13,6 +13,7 @@
// limitations under the License.
syntax
=
"proto2"
;
package
baidu
.
paddle_serving.pyserving
;
service
GeneralPythonService
{
rpc
inference
(
Request
)
returns
(
Response
)
{}
...
...
@@ -21,11 +22,15 @@ service GeneralPythonService {
message
Request
{
repeated
bytes
feed_insts
=
1
;
repeated
string
feed_var_names
=
2
;
repeated
bytes
shape
=
3
;
repeated
string
type
=
4
;
}
message
Response
{
repeated
bytes
fetch_insts
=
1
;
repeated
string
fetch_var_names
=
2
;
required
int32
is_error
=
3
;
required
int32
ecode
=
3
;
optional
string
error_info
=
4
;
repeated
bytes
shape
=
5
;
repeated
string
type
=
6
;
}
python/paddle_serving_server/python_service
_channel.proto
→
core/configure/proto/pyserving
_channel.proto
浏览文件 @
580e8478
...
...
@@ -13,17 +13,19 @@
// limitations under the License.
syntax
=
"proto2"
;
package
baidu
.
paddle_serving.pyserving
;
message
ChannelData
{
repeated
Inst
insts
=
1
;
required
int32
id
=
2
;
optional
string
type
=
3
[
default
=
"CD"
];
// CD(channel data), CF(channel futures)
required
int32
is_error
=
4
;
required
int32
type
=
3
[
default
=
0
];
required
int32
ecode
=
4
;
optional
string
error_info
=
5
;
}
message
Inst
{
required
bytes
data
=
1
;
required
string
name
=
2
;
required
bytes
shape
=
3
;
required
string
type
=
4
;
}
python/examples/fit_a_line/test_py_client.py
浏览文件 @
580e8478
...
...
@@ -30,8 +30,7 @@ lp = LineProfiler()
lp_wrapper
=
lp
(
client
.
predict
)
for
i
in
range
(
1
):
fetch_map
=
lp_wrapper
(
feed
=
{
"x"
:
x
},
fetch_with_type
=
{
"combine_op_output"
:
"float"
})
fetch_map
=
lp_wrapper
(
feed
=
{
"x"
:
x
},
fetch
=
[
"combine_op_output"
])
# fetch_map = client.predict(
# feed={"x": x}, fetch_with_type={"combine_op_output": "float"})
print
(
fetch_map
)
...
...
python/examples/fit_a_line/test_py_server.py
浏览文件 @
580e8478
...
...
@@ -16,29 +16,26 @@
from
paddle_serving_server.pyserver
import
Op
from
paddle_serving_server.pyserver
import
Channel
from
paddle_serving_server.pyserver
import
PyServer
from
paddle_serving_server
import
python_service_channel_pb2
import
numpy
as
np
import
logging
logging
.
basicConfig
(
format
=
'%(asctime)s %(levelname)-8s [%(filename)s:%(lineno)d] %(message)s'
,
datefmt
=
'%Y-%m-%d %H:%M'
,
#level=logging.DEBUG)
level
=
logging
.
INFO
)
# channel data: {name(str): data(
bytes
)}
# channel data: {name(str): data(
narray
)}
class
CombineOp
(
Op
):
def
preprocess
(
self
,
input_data
):
cnt
=
0
for
op_name
,
data
in
input_data
.
items
():
for
op_name
,
channel
data
in
input_data
.
items
():
logging
.
debug
(
"CombineOp preprocess: {}"
.
format
(
op_name
))
cnt
+=
np
.
frombuffer
(
data
.
insts
[
0
].
data
,
dtype
=
'float'
)
data
=
python_service_channel_pb2
.
ChannelData
()
inst
=
python_service_channel_pb2
.
Inst
()
inst
.
data
=
np
.
ndarray
.
tobytes
(
cnt
)
inst
.
name
=
"combine_op_output"
data
.
insts
.
append
(
inst
)
data
=
channeldata
.
parse
()
cnt
+=
data
[
"prediction"
]
data
=
{
"combine_op_output"
:
cnt
}
return
data
def
postprocess
(
self
,
output_data
):
...
...
@@ -47,12 +44,8 @@ class CombineOp(Op):
class
UciOp
(
Op
):
def
postprocess
(
self
,
output_data
):
data
=
python_service_channel_pb2
.
ChannelData
()
inst
=
python_service_channel_pb2
.
Inst
()
pred
=
np
.
array
(
output_data
[
"price"
][
0
][
0
],
dtype
=
'float'
)
inst
.
data
=
np
.
ndarray
.
tobytes
(
pred
)
inst
.
name
=
"prediction"
data
.
insts
.
append
(
inst
)
pred
=
np
.
array
(
output_data
[
"price"
][
0
][
0
],
dtype
=
'float32'
)
data
=
{
"prediction"
:
pred
}
return
data
...
...
@@ -60,12 +53,10 @@ read_channel = Channel(name="read_channel")
combine_channel
=
Channel
(
name
=
"combine_channel"
)
out_channel
=
Channel
(
name
=
"out_channel"
)
cnn
_op
=
UciOp
(
name
=
"
cnn
"
,
uci1
_op
=
UciOp
(
name
=
"
uci1
"
,
input
=
read_channel
,
in_dtype
=
'float'
,
outputs
=
[
combine_channel
],
out_dtype
=
'float'
,
server_model
=
"./uci_housing_model"
,
server_port
=
"9393"
,
device
=
"cpu"
,
...
...
@@ -73,15 +64,13 @@ cnn_op = UciOp(
server_name
=
"127.0.0.1:9393"
,
fetch_names
=
[
"price"
],
concurrency
=
1
,
timeout
=
0.
0
1
,
timeout
=
0.1
,
retry
=
2
)
bow
_op
=
UciOp
(
name
=
"
bow
"
,
uci2
_op
=
UciOp
(
name
=
"
uci2
"
,
input
=
read_channel
,
in_dtype
=
'float'
,
outputs
=
[
combine_channel
],
out_dtype
=
'float'
,
server_model
=
"./uci_housing_model"
,
server_port
=
"9292"
,
device
=
"cpu"
,
...
...
@@ -95,9 +84,7 @@ bow_op = UciOp(
combine_op
=
CombineOp
(
name
=
"combine"
,
input
=
combine_channel
,
in_dtype
=
'float'
,
outputs
=
[
out_channel
],
out_dtype
=
'float'
,
concurrency
=
1
,
timeout
=-
1
,
retry
=
1
)
...
...
@@ -109,8 +96,8 @@ pyserver = PyServer(profile=False, retry=1)
pyserver
.
add_channel
(
read_channel
)
pyserver
.
add_channel
(
combine_channel
)
pyserver
.
add_channel
(
out_channel
)
pyserver
.
add_op
(
cnn
_op
)
pyserver
.
add_op
(
bow
_op
)
pyserver
.
add_op
(
uci1
_op
)
pyserver
.
add_op
(
uci2
_op
)
pyserver
.
add_op
(
combine_op
)
pyserver
.
prepare_server
(
port
=
8080
,
worker_num
=
2
)
pyserver
.
run_server
()
python/paddle_serving_client/general_python_service.proto
已删除
100644 → 0
浏览文件 @
93e3d126
// Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
syntax
=
"proto2"
;
service
GeneralPythonService
{
rpc
inference
(
Request
)
returns
(
Response
)
{}
}
message
Request
{
repeated
bytes
feed_insts
=
1
;
repeated
string
feed_var_names
=
2
;
}
message
Response
{
repeated
bytes
fetch_insts
=
1
;
repeated
string
fetch_var_names
=
2
;
}
python/paddle_serving_client/pyclient.py
浏览文件 @
580e8478
...
...
@@ -13,8 +13,8 @@
# limitations under the License.
# pylint: disable=doc-string-missing
import
grpc
import
general_python_service_pb2
import
general_python_service_pb2_grpc
from
.proto
import
general_python_service_pb2
from
.proto
import
general_python_service_pb2_grpc
import
numpy
as
np
...
...
@@ -33,24 +33,27 @@ class PyClient(object):
if
not
isinstance
(
data
,
np
.
ndarray
):
raise
TypeError
(
"only numpy array type is supported temporarily."
)
data2bytes
=
np
.
ndarray
.
tobytes
(
data
)
req
.
feed_var_names
.
append
(
name
)
req
.
feed_insts
.
append
(
data2bytes
)
req
.
feed_insts
.
append
(
data
.
tobytes
())
req
.
shape
.
append
(
np
.
array
(
data
.
shape
,
dtype
=
"int32"
).
tobytes
())
req
.
type
.
append
(
str
(
data
.
dtype
))
return
req
def
predict
(
self
,
feed
,
fetch
_with_type
):
def
predict
(
self
,
feed
,
fetch
):
if
not
isinstance
(
feed
,
dict
):
raise
TypeError
(
"feed must be dict type with format: {name: value}."
)
if
not
isinstance
(
fetch
_with_type
,
dic
t
):
if
not
isinstance
(
fetch
,
lis
t
):
raise
TypeError
(
"fetch_with_type must be
dict type with format: {name : type}
."
)
"fetch_with_type must be
list type with format: [name]
."
)
req
=
self
.
_pack_data_for_infer
(
feed
)
resp
=
self
.
_stub
.
inference
(
req
)
fetch_map
=
{}
for
idx
,
name
in
enumerate
(
resp
.
fetch_var_names
):
if
name
not
in
fetch
_with_type
:
if
name
not
in
fetch
:
continue
fetch_map
[
name
]
=
np
.
frombuffer
(
resp
.
fetch_insts
[
idx
],
dtype
=
fetch_with_type
[
name
])
resp
.
fetch_insts
[
idx
],
dtype
=
resp
.
type
[
idx
])
fetch_map
[
name
].
shape
=
np
.
frombuffer
(
resp
.
shape
[
idx
],
dtype
=
"int32"
)
return
fetch_map
python/paddle_serving_server/pyserver.py
浏览文件 @
580e8478
此差异已折叠。
点击以展开。
python/paddle_serving_server/serve.py
浏览文件 @
580e8478
...
...
@@ -49,6 +49,10 @@ def parse_args(): # pylint: disable=doc-string-missing
type
=
int
,
default
=
512
*
1024
*
1024
,
help
=
"Limit sizes of messages"
)
parser
.
add_argument
(
"--use_multilang"
,
action
=
'store_true'
,
help
=
"Use Multi-language-service"
)
return
parser
.
parse_args
()
...
...
@@ -63,6 +67,7 @@ def start_standard_model(): # pylint: disable=doc-string-missing
ir_optim
=
args
.
ir_optim
max_body_size
=
args
.
max_body_size
use_mkl
=
args
.
use_mkl
use_multilang
=
args
.
use_multilang
if
model
==
""
:
print
(
"You must specify your serving model"
)
...
...
@@ -79,14 +84,19 @@ def start_standard_model(): # pylint: disable=doc-string-missing
op_seq_maker
.
add_op
(
general_infer_op
)
op_seq_maker
.
add_op
(
general_response_op
)
server
=
serving
.
Server
()
server
.
set_op_sequence
(
op_seq_maker
.
get_op_sequence
())
server
.
set_num_threads
(
thread_num
)
server
.
set_memory_optimize
(
mem_optim
)
server
.
set_ir_optimize
(
ir_optim
)
server
.
use_mkl
(
use_mkl
)
server
.
set_max_body_size
(
max_body_size
)
server
.
set_port
(
port
)
server
=
None
if
use_multilang
:
server
=
serving
.
MultiLangServer
()
server
.
set_op_sequence
(
op_seq_maker
.
get_op_sequence
())
else
:
server
=
serving
.
Server
()
server
.
set_op_sequence
(
op_seq_maker
.
get_op_sequence
())
server
.
set_num_threads
(
thread_num
)
server
.
set_memory_optimize
(
mem_optim
)
server
.
set_ir_optimize
(
ir_optim
)
server
.
use_mkl
(
use_mkl
)
server
.
set_max_body_size
(
max_body_size
)
server
.
set_port
(
port
)
server
.
load_model_config
(
model
)
server
.
prepare_server
(
workdir
=
workdir
,
port
=
port
,
device
=
device
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录