Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
fb06526c
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看板
提交
fb06526c
编写于
6月 18, 2020
作者:
B
barrierye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update gpu part
上级
0888751c
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
78 addition
and
39 deletion
+78
-39
python/paddle_serving_server/__init__.py
python/paddle_serving_server/__init__.py
+8
-3
python/paddle_serving_server_gpu/__init__.py
python/paddle_serving_server_gpu/__init__.py
+70
-36
未找到文件。
python/paddle_serving_server/__init__.py
浏览文件 @
fb06526c
...
...
@@ -577,8 +577,13 @@ class MultiLangServer(object):
self
.
bserver_
.
set_num_threads
(
threads
)
def
set_max_body_size
(
self
,
body_size
):
self
.
body_size_
=
body_size
self
.
bserver_
.
set_max_body_size
(
body_size
)
if
body_size
>=
self
.
body_size_
:
self
.
body_size_
=
body_size
else
:
print
(
"max_body_size is less than default value, will use default value in service."
)
def
set_port
(
self
,
port
):
self
.
gport_
=
port
...
...
@@ -610,8 +615,8 @@ class MultiLangServer(object):
def
load_model_config
(
self
,
model_config_paths
):
self
.
bserver_
.
load_model_config
(
model_config_paths
)
if
isinstance
(
model_config_paths
,
dict
):
print
(
"You have specified multiple model paths, please ensure "
"that the input and output of multiple models are the same."
)
#
print("You have specified multiple model paths, please ensure "
#
"that the input and output of multiple models are the same.")
self
.
model_config_path_
=
list
(
model_config_paths
.
items
())[
0
][
1
]
self
.
is_multi_model_
=
True
else
:
...
...
python/paddle_serving_server_gpu/__init__.py
浏览文件 @
fb06526c
...
...
@@ -491,10 +491,17 @@ class Server(object):
class
MultiLangServerService
(
multi_lang_general_model_service_pb2_grpc
.
MultiLangGeneralModelService
):
def
__init__
(
self
,
model_config_path
,
endpoints
):
def
__init__
(
self
,
model_config_path
,
is_multi_model
,
endpoints
,
timeout_ms
=
None
):
self
.
is_multi_model_
=
is_multi_model
from
paddle_serving_client
import
Client
self
.
_parse_model_config
(
model_config_path
)
self
.
bclient_
=
Client
()
if
timeout_ms
is
not
None
:
self
.
bclient_
.
set_rpc_timeout_ms
(
timeout_ms
)
self
.
bclient_
.
load_client_config
(
"{}/serving_server_conf.prototxt"
.
format
(
model_config_path
))
self
.
bclient_
.
connect
(
endpoints
)
...
...
@@ -559,29 +566,35 @@ class MultiLangServerService(
feed_batch
.
append
(
feed_dict
)
return
feed_batch
,
fetch_names
,
is_python
def
_pack_resp_package
(
self
,
result
,
fetch_names
,
is_python
,
tag
):
def
_pack_resp_package
(
self
,
results
,
fetch_names
,
is_python
,
tag
):
if
not
self
.
is_multi_model_
:
results
=
{
'general_infer_0'
:
results
}
resp
=
multi_lang_general_model_service_pb2
.
Response
()
# Only one model is supported temporarily
model_output
=
multi_lang_general_model_service_pb2
.
ModelOutput
()
inst
=
multi_lang_general_model_service_pb2
.
FetchInst
()
for
idx
,
name
in
enumerate
(
fetch_names
):
tensor
=
multi_lang_general_model_service_pb2
.
Tensor
()
v_type
=
self
.
fetch_types_
[
name
]
if
is_python
:
tensor
.
data
=
result
[
name
].
tobytes
()
else
:
if
v_type
==
0
:
# int64
tensor
.
int64_data
.
extend
(
result
[
name
].
reshape
(
-
1
).
tolist
())
elif
v_type
==
1
:
# float32
tensor
.
float_data
.
extend
(
result
[
name
].
reshape
(
-
1
).
tolist
())
for
model_name
,
model_result
in
results
.
items
():
model_output
=
multi_lang_general_model_service_pb2
.
ModelOutput
()
inst
=
multi_lang_general_model_service_pb2
.
FetchInst
()
for
idx
,
name
in
enumerate
(
fetch_names
):
tensor
=
multi_lang_general_model_service_pb2
.
Tensor
()
v_type
=
self
.
fetch_types_
[
name
]
if
is_python
:
tensor
.
data
=
model_result
[
name
].
tobytes
()
else
:
raise
Exception
(
"error type."
)
tensor
.
shape
.
extend
(
list
(
result
[
name
].
shape
))
if
name
in
self
.
lod_tensor_set_
:
tensor
.
lod
.
extend
(
result
[
"{}.lod"
.
format
(
name
)].
tolist
())
inst
.
tensor_array
.
append
(
tensor
)
model_output
.
insts
.
append
(
inst
)
resp
.
outputs
.
append
(
model_output
)
if
v_type
==
0
:
# int64
tensor
.
int64_data
.
extend
(
model_result
[
name
].
reshape
(
-
1
)
.
tolist
())
elif
v_type
==
1
:
# float32
tensor
.
float_data
.
extend
(
model_result
[
name
].
reshape
(
-
1
)
.
tolist
())
else
:
raise
Exception
(
"error type."
)
tensor
.
shape
.
extend
(
list
(
model_result
[
name
].
shape
))
if
name
in
self
.
lod_tensor_set_
:
tensor
.
lod
.
extend
(
model_result
[
"{}.lod"
.
format
(
name
)]
.
tolist
())
inst
.
tensor_array
.
append
(
tensor
)
model_output
.
insts
.
append
(
inst
)
model_output
.
engine_name
=
model_name
resp
.
outputs
.
append
(
model_output
)
resp
.
tag
=
tag
return
resp
...
...
@@ -593,19 +606,33 @@ class MultiLangServerService(
class
MultiLangServer
(
object
):
def
__init__
(
self
,
worker_num
=
2
):
def
__init__
(
self
):
self
.
bserver_
=
Server
()
self
.
worker_num_
=
worker_num
self
.
worker_num_
=
4
self
.
body_size_
=
64
*
1024
*
1024
self
.
concurrency_
=
100000
self
.
bclient_timeout_ms_
=
2000
self
.
is_multi_model_
=
False
# for model ensemble
def
set_bclient_timeout_ms
(
self
,
timeout
):
self
.
bclient_timeout_ms_
=
timeout
def
set_max_concurrency
(
self
,
concurrency
):
self
.
concurrency_
=
concurrency
self
.
bserver_
.
set_max_concurrency
(
concurrency
)
def
set_num_threads
(
self
,
threads
):
self
.
worker_num_
=
threads
self
.
bserver_
.
set_num_threads
(
threads
)
def
set_max_body_size
(
self
,
body_size
):
# TODO: grpc body
self
.
bserver_
.
set_max_body_size
(
body_size
)
if
body_size
>=
self
.
body_size_
:
self
.
body_size_
=
body_size
else
:
print
(
"max_body_size is less than default value, will use default value in service."
)
def
set_port
(
self
,
port
):
self
.
gport_
=
port
...
...
@@ -628,15 +655,15 @@ class MultiLangServer(object):
def
set_gpuid
(
self
,
gpuid
=
0
):
self
.
bserver_
.
set_gpuid
(
gpuid
)
def
use_mkl
(
self
,
flag
):
self
.
bserver_
.
use_mkl
(
flag
)
def
load_model_config
(
self
,
model_config_path
):
if
not
isinstance
(
model_config_path
,
str
):
raise
Exception
(
"MultiLangServer only supports multi-model temporarily"
)
self
.
bserver_
.
load_model_config
(
model_config_path
)
self
.
model_config_path_
=
model_config_path
self
.
bserver_
.
load_model_config
(
model_config_paths
)
if
isinstance
(
model_config_paths
,
dict
):
# print("You have specified multiple model paths, please ensure "
# "that the input and output of multiple models are the same.")
self
.
model_config_path_
=
list
(
model_config_paths
.
items
())[
0
][
1
]
self
.
is_multi_model_
=
True
else
:
self
.
model_config_path_
=
model_config_paths
def
prepare_server
(
self
,
workdir
=
None
,
port
=
9292
,
device
=
"cpu"
):
if
not
self
.
_port_is_available
(
port
):
...
...
@@ -665,11 +692,18 @@ class MultiLangServer(object):
p_bserver
=
Process
(
target
=
self
.
_launch_brpc_service
,
args
=
(
self
.
bserver_
,
))
p_bserver
.
start
()
options
=
[(
'grpc.max_send_message_length'
,
self
.
body_size_
),
(
'grpc.max_receive_message_length'
,
self
.
body_size_
)]
server
=
grpc
.
server
(
futures
.
ThreadPoolExecutor
(
max_workers
=
self
.
worker_num_
))
futures
.
ThreadPoolExecutor
(
max_workers
=
self
.
worker_num_
),
options
=
options
,
maximum_concurrent_rpcs
=
self
.
concurrency_
)
multi_lang_general_model_service_pb2_grpc
.
add_MultiLangGeneralModelServiceServicer_to_server
(
MultiLangServerService
(
self
.
model_config_path_
,
[
"0.0.0.0:{}"
.
format
(
self
.
port_list_
[
0
])]),
MultiLangServerService
(
self
.
model_config_path_
,
self
.
is_multi_model_
,
[
"0.0.0.0:{}"
.
format
(
self
.
port_list_
[
0
])],
timeout_ms
=
self
.
bclient_timeout_ms_
),
server
)
server
.
add_insecure_port
(
'[::]:{}'
.
format
(
self
.
gport_
))
server
.
start
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录