Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
241e53da
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看板
提交
241e53da
编写于
4月 16, 2021
作者:
H
HexToString
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
merge from origin
上级
0a8e26d4
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
92 addition
and
5 deletion
+92
-5
core/predictor/common/utils.h
core/predictor/common/utils.h
+35
-1
python/paddle_serving_app/local_predict.py
python/paddle_serving_app/local_predict.py
+25
-4
python/paddle_serving_server/server.py
python/paddle_serving_server/server.py
+26
-0
python/pipeline/pipeline_server.py
python/pipeline/pipeline_server.py
+6
-0
未找到文件。
core/predictor/common/utils.h
浏览文件 @
241e53da
...
...
@@ -13,8 +13,10 @@
// limitations under the License.
#pragma once
#include <string>
#include <algorithm>
#include <cctype>
#include <fstream>
#include <string>
#include "core/predictor/common/inner_common.h"
#include "core/predictor/common/macros.h"
...
...
@@ -26,6 +28,38 @@ namespace predictor {
namespace
butil
=
base
;
#endif
enum
class
Precision
{
kUnk
=
-
1
,
// unknown type
kFloat32
=
0
,
// fp32
kInt8
,
// int8
kHalf
,
// fp16
kBfloat16
,
// bf16
};
static
std
::
string
PrecisionTypeString
(
const
Precision
data_type
)
{
switch
(
data_type
)
{
case
Precision
::
kFloat32
:
return
"kFloat32"
;
case
Precision
::
kInt8
:
return
"kInt8"
;
case
Precision
::
kHalf
:
return
"kHalf"
;
case
Precision
::
kBfloat16
:
return
"kBloat16"
;
default:
return
"unUnk"
;
}
}
static
std
::
string
ToLower
(
const
std
::
string
&
data
)
{
std
::
string
result
=
data
;
std
::
transform
(
result
.
begin
(),
result
.
end
(),
result
.
begin
(),
[](
unsigned
char
c
)
{
return
tolower
(
c
);
});
return
result
;
}
class
TimerFlow
{
public:
static
const
int
MAX_SIZE
=
1024
;
...
...
python/paddle_serving_app/local_predict.py
浏览文件 @
241e53da
...
...
@@ -27,6 +27,12 @@ logging.basicConfig(format="%(asctime)s - %(levelname)s - %(message)s")
logger
=
logging
.
getLogger
(
"LocalPredictor"
)
logger
.
setLevel
(
logging
.
INFO
)
precision_map
=
{
'int8'
:
paddle_infer
.
PrecisionType
.
Int8
,
'fp32'
:
paddle_infer
.
PrecisionType
.
Float32
,
'fp16'
:
paddle_infer
.
PrecisionType
.
Half
,
}
class
LocalPredictor
(
object
):
"""
...
...
@@ -56,6 +62,8 @@ class LocalPredictor(object):
use_trt
=
False
,
use_lite
=
False
,
use_xpu
=
False
,
precision
=
"fp32"
,
use_calib
=
False
,
use_feed_fetch_ops
=
False
):
"""
Load model configs and create the paddle predictor by Paddle Inference API.
...
...
@@ -71,6 +79,8 @@ class LocalPredictor(object):
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
precision: precision mode, "fp32" default
use_calib: use TensorRT calibration, False default
use_feed_fetch_ops: use feed/fetch ops, False default.
"""
client_config
=
"{}/serving_server_conf.prototxt"
.
format
(
model_path
)
...
...
@@ -88,9 +98,11 @@ class LocalPredictor(object):
logger
.
info
(
"LocalPredictor load_model_config params: model_path:{}, use_gpu:{},
\
gpu_id:{}, use_profile:{}, thread_num:{}, mem_optim:{}, ir_optim:{},
\
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_lite
,
use_xpu
,
use_feed_fetch_ops
))
use_trt:{}, use_lite:{}, use_xpu: {}, precision: {}, use_calib: {},
\
use_feed_fetch_ops:{}"
.
format
(
model_path
,
use_gpu
,
gpu_id
,
use_profile
,
thread_num
,
mem_optim
,
ir_optim
,
use_trt
,
use_lite
,
use_xpu
,
precision
,
use_calib
,
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
]
...
...
@@ -106,6 +118,9 @@ class LocalPredictor(object):
self
.
fetch_names_to_idx_
[
var
.
alias_name
]
=
i
self
.
fetch_names_to_type_
[
var
.
alias_name
]
=
var
.
fetch_type
precision_type
=
paddle_infer
.
PrecisionType
.
Float32
if
precision
.
lower
()
in
precision_map
:
precision_type
=
precision_map
[
precision
.
lower
()]
if
use_profile
:
config
.
enable_profile
()
if
mem_optim
:
...
...
@@ -121,6 +136,7 @@ class LocalPredictor(object):
config
.
enable_use_gpu
(
100
,
gpu_id
)
if
use_trt
:
config
.
enable_tensorrt_engine
(
precision_mode
=
precision_type
,
workspace_size
=
1
<<
20
,
max_batch_size
=
32
,
min_subgraph_size
=
3
,
...
...
@@ -129,7 +145,7 @@ class LocalPredictor(object):
if
use_lite
:
config
.
enable_lite_engine
(
precision_mode
=
p
addle_infer
.
PrecisionType
.
Float32
,
precision_mode
=
p
recision_type
,
zero_copy
=
True
,
passes_filter
=
[],
ops_filter
=
[])
...
...
@@ -138,6 +154,11 @@ class LocalPredictor(object):
# 2MB l3 cache
config
.
enable_xpu
(
8
*
1024
*
1024
)
if
not
use_gpu
and
not
use_lite
:
if
precision_type
==
paddle_infer
.
PrecisionType
.
Int8
:
config
.
enable_quantizer
()
if
precision
.
lower
()
==
"bf16"
:
config
.
enable_mkldnn_bfloat16
()
self
.
predictor
=
paddle_infer
.
create_predictor
(
config
)
def
predict
(
self
,
feed
=
None
,
fetch
=
None
,
batch
=
False
,
log_id
=
0
):
...
...
python/paddle_serving_server/server.py
浏览文件 @
241e53da
...
...
@@ -71,6 +71,8 @@ class Server(object):
self
.
max_concurrency
=
0
self
.
num_threads
=
2
self
.
port
=
8080
self
.
precision
=
"fp32"
self
.
use_calib
=
False
self
.
reload_interval_s
=
10
self
.
max_body_size
=
64
*
1024
*
1024
self
.
module_path
=
os
.
path
.
dirname
(
paddle_serving_server
.
__file__
)
...
...
@@ -113,6 +115,12 @@ class Server(object):
def
set_port
(
self
,
port
):
self
.
port
=
port
def
set_precision
(
self
,
precision
=
"fp32"
):
self
.
precision
=
precision
def
set_use_calib
(
self
,
use_calib
=
False
):
self
.
use_calib
=
use_calib
def
set_reload_interval
(
self
,
interval
):
self
.
reload_interval_s
=
interval
...
...
@@ -186,6 +194,10 @@ class Server(object):
engine
.
use_trt
=
self
.
use_trt
engine
.
use_lite
=
self
.
use_lite
engine
.
use_xpu
=
self
.
use_xpu
engine
.
use_gpu
=
False
if
self
.
device
==
"gpu"
:
engine
.
use_gpu
=
True
if
os
.
path
.
exists
(
'{}/__params__'
.
format
(
model_config_path
)):
engine
.
combined_model
=
True
else
:
...
...
@@ -472,6 +484,8 @@ class Server(object):
"-max_concurrency {} "
\
"-num_threads {} "
\
"-port {} "
\
"-precision {} "
\
"-use_calib {} "
\
"-reload_interval_s {} "
\
"-resource_path {} "
\
"-resource_file {} "
\
...
...
@@ -485,6 +499,8 @@ class Server(object):
self
.
max_concurrency
,
self
.
num_threads
,
self
.
port
,
self
.
precision
,
self
.
use_calib
,
self
.
reload_interval_s
,
self
.
workdir
,
self
.
resource_fn
,
...
...
@@ -500,6 +516,8 @@ class Server(object):
"-max_concurrency {} "
\
"-num_threads {} "
\
"-port {} "
\
"-precision {} "
\
"-use_calib {} "
\
"-reload_interval_s {} "
\
"-resource_path {} "
\
"-resource_file {} "
\
...
...
@@ -514,6 +532,8 @@ class Server(object):
self
.
max_concurrency
,
self
.
num_threads
,
self
.
port
,
self
.
precision
,
self
.
use_calib
,
self
.
reload_interval_s
,
self
.
workdir
,
self
.
resource_fn
,
...
...
@@ -562,6 +582,12 @@ class MultiLangServer(object):
def
set_port
(
self
,
port
):
self
.
gport_
=
port
def
set_precision
(
self
,
precision
=
"fp32"
):
self
.
precision
=
precision
def
set_use_calib
(
self
,
use_calib
=
False
):
self
.
use_calib
=
use_calib
def
set_reload_interval
(
self
,
interval
):
self
.
bserver_
.
set_reload_interval
(
interval
)
...
...
python/pipeline/pipeline_server.py
浏览文件 @
241e53da
...
...
@@ -238,6 +238,8 @@ class PipelineServer(object):
"devices"
:
""
,
"mem_optim"
:
True
,
"ir_optim"
:
False
,
"precision"
:
"fp32"
,
"use_calib"
:
False
,
},
}
for
op
in
self
.
_used_op
:
...
...
@@ -394,6 +396,8 @@ class ServerYamlConfChecker(object):
"devices"
:
""
,
"mem_optim"
:
True
,
"ir_optim"
:
False
,
"precision"
:
"fp32"
,
"use_calib"
:
False
,
}
conf_type
=
{
"model_config"
:
str
,
...
...
@@ -403,6 +407,8 @@ class ServerYamlConfChecker(object):
"devices"
:
str
,
"mem_optim"
:
bool
,
"ir_optim"
:
bool
,
"precision"
:
str
,
"use_calib"
:
bool
,
}
conf_qualification
=
{
"thread_num"
:
(
">="
,
1
),
}
ServerYamlConfChecker
.
check_conf
(
conf
,
default_conf
,
conf_type
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录