Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
3c525182
S
Serving
项目概览
PaddlePaddle
/
Serving
接近 2 年 前同步成功
通知
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看板
提交
3c525182
编写于
1月 06, 2021
作者:
Z
zhangjun
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add local predict support
上级
3378a130
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
40 addition
and
8 deletion
+40
-8
python/paddle_serving_app/local_predict.py
python/paddle_serving_app/local_predict.py
+17
-2
python/pipeline/local_service_handler.py
python/pipeline/local_service_handler.py
+23
-6
未找到文件。
python/paddle_serving_app/local_predict.py
浏览文件 @
3c525182
...
...
@@ -57,6 +57,8 @@ class LocalPredictor(object):
mem_optim
=
True
,
ir_optim
=
False
,
use_trt
=
False
,
use_lite
=
False
,
use_xpu
=
False
,
use_feed_fetch_ops
=
False
):
"""
Load model config and set the engine config for the paddle predictor
...
...
@@ -70,6 +72,8 @@ class LocalPredictor(object):
mem_optim: memory optimization, True default.
ir_optim: open calculation chart optimization, False default.
use_trt: use nvidia TensorRT optimization, False default
use_lite: use Paddle-Lite Engint, False default
use_xpu: run predict on Baidu Kunlun, False default
use_feed_fetch_ops: use feed/fetch ops, False default.
"""
client_config
=
"{}/serving_server_conf.prototxt"
.
format
(
model_path
)
...
...
@@ -80,9 +84,9 @@ class LocalPredictor(object):
config
=
AnalysisConfig
(
model_path
)
logger
.
info
(
"load_model_config params: model_path:{}, use_gpu:{},
\
gpu_id:{}, use_profile:{}, thread_num:{}, mem_optim:{}, ir_optim:{},
\
use_trt:{}, use_feed_fetch_ops:{}"
.
format
(
use_trt:{}, use_
lite:{}, use_xpu: {}, use_
feed_fetch_ops:{}"
.
format
(
model_path
,
use_gpu
,
gpu_id
,
use_profile
,
thread_num
,
mem_optim
,
ir_optim
,
use_trt
,
use_feed_fetch_ops
))
ir_optim
,
use_trt
,
use_
lite
,
use_xpu
,
use_
feed_fetch_ops
))
self
.
feed_names_
=
[
var
.
alias_name
for
var
in
model_conf
.
feed_var
]
self
.
fetch_names_
=
[
var
.
alias_name
for
var
in
model_conf
.
fetch_var
]
...
...
@@ -119,6 +123,17 @@ class LocalPredictor(object):
use_static
=
False
,
use_calib_mode
=
False
)
if
use_lite
:
config
.
enable_lite_engine
(
precision_mode
=
PrecisionType
.
Float32
,
zero_copy
=
True
,
passes_filter
=
[],
ops_filter
=
[]
)
if
use_xpu
:
config
.
enable_xpu
(
100
*
1024
*
1024
)
self
.
predictor
=
create_paddle_predictor
(
config
)
def
predict
(
self
,
feed
=
None
,
fetch
=
None
,
batch
=
False
,
log_id
=
0
):
...
...
python/pipeline/local_service_handler.py
浏览文件 @
3c525182
...
...
@@ -44,6 +44,8 @@ class LocalServiceHandler(object):
ir_optim
=
False
,
available_port_generator
=
None
,
use_trt
=
False
,
use_lite
=
False
,
use_xpu
=
False
,
use_profile
=
False
):
"""
Initialization of localservicehandler
...
...
@@ -60,6 +62,8 @@ class LocalServiceHandler(object):
ir_optim: use calculation chart optimization, False default.
available_port_generator: generate available ports
use_trt: use nvidia tensorRt engine, False default.
use_lite: use Paddle-Lite engine, False default.
use_xpu: run predict on Baidu Kunlun, False default.
use_profile: use profiling, False default.
Returns:
...
...
@@ -74,10 +78,16 @@ class LocalServiceHandler(object):
if
devices
==
""
:
# cpu
devices
=
[
-
1
]
self
.
_device_type
=
"cpu"
self
.
_port_list
.
append
(
available_port_generator
.
next
())
_LOGGER
.
info
(
"Model({}) will be launch in cpu device. Port({})"
.
format
(
model_config
,
self
.
_port_list
))
if
use_lite
:
self
.
_device_type
=
"arm"
self
.
_port_list
.
append
(
available_port_generator
.
next
())
_LOGGER
.
info
(
"Model({}) will be launch in arm device. Port({})"
.
format
(
model_config
,
self
.
_port_list
))
else
:
self
.
_device_type
=
"cpu"
self
.
_port_list
.
append
(
available_port_generator
.
next
())
_LOGGER
.
info
(
"Model({}) will be launch in cpu device. Port({})"
.
format
(
model_config
,
self
.
_port_list
))
else
:
# gpu
self
.
_device_type
=
"gpu"
...
...
@@ -96,6 +106,8 @@ class LocalServiceHandler(object):
self
.
_rpc_service_list
=
[]
self
.
_server_pros
=
[]
self
.
_use_trt
=
use_trt
self
.
_use_lite
=
use_lite
self
.
_use_xpu
=
use_xpu
self
.
_use_profile
=
use_profile
self
.
fetch_names_
=
fetch_names
...
...
@@ -138,8 +150,11 @@ class LocalServiceHandler(object):
if
self
.
_local_predictor_client
is
None
:
self
.
_local_predictor_client
=
LocalPredictor
()
use_gpu
=
False
use_lite
=
False
if
self
.
_device_type
==
"gpu"
:
use_gpu
=
True
elif
self
.
_device_type
==
"arm"
:
use_lite
=
True
self
.
_local_predictor_client
.
load_model_config
(
model_path
=
self
.
_model_config
,
use_gpu
=
use_gpu
,
...
...
@@ -148,7 +163,9 @@ class LocalServiceHandler(object):
thread_num
=
self
.
_thread_num
,
mem_optim
=
self
.
_mem_optim
,
ir_optim
=
self
.
_ir_optim
,
use_trt
=
self
.
_use_trt
)
use_trt
=
self
.
_use_trt
,
use_lite
=
use_lite
,
use_xpu
=
self
.
_use_xpu
)
return
self
.
_local_predictor_client
def
get_client_config
(
self
):
...
...
@@ -185,7 +202,7 @@ class LocalServiceHandler(object):
server
=
Server
()
else
:
#gpu
#gpu
or arm
from
paddle_serving_server_gpu
import
OpMaker
,
OpSeqMaker
,
Server
op_maker
=
OpMaker
()
read_op
=
op_maker
.
create
(
'general_reader'
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录