Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
0be0c9c0
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看板
提交
0be0c9c0
编写于
3月 05, 2020
作者:
M
MRXLT
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix bert demo
上级
2e75c394
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
29 addition
and
21 deletion
+29
-21
core/general-client/src/general_model.cpp
core/general-client/src/general_model.cpp
+12
-11
python/examples/bert/bert_client.py
python/examples/bert/bert_client.py
+16
-8
python/examples/bert/bert_server.py
python/examples/bert/bert_server.py
+0
-2
python/examples/bert/get_data.sh
python/examples/bert/get_data.sh
+1
-0
未找到文件。
core/general-client/src/general_model.cpp
浏览文件 @
0be0c9c0
...
...
@@ -132,13 +132,12 @@ int PredictorClient::create_predictor() {
_api
.
thrd_initialize
();
}
int
PredictorClient
::
predict
(
const
std
::
vector
<
std
::
vector
<
float
>>&
float_feed
,
const
std
::
vector
<
std
::
string
>&
float_feed_name
,
const
std
::
vector
<
std
::
vector
<
int64_t
>>&
int_feed
,
const
std
::
vector
<
std
::
string
>&
int_feed_name
,
const
std
::
vector
<
std
::
string
>&
fetch_name
,
PredictorRes
&
predict_res
)
{
// NOLINT
int
PredictorClient
::
predict
(
const
std
::
vector
<
std
::
vector
<
float
>>
&
float_feed
,
const
std
::
vector
<
std
::
string
>
&
float_feed_name
,
const
std
::
vector
<
std
::
vector
<
int64_t
>>
&
int_feed
,
const
std
::
vector
<
std
::
string
>
&
int_feed_name
,
const
std
::
vector
<
std
::
string
>
&
fetch_name
,
PredictorRes
&
predict_res
)
{
// NOLINT
predict_res
.
_int64_map
.
clear
();
predict_res
.
_float_map
.
clear
();
Timer
timeline
;
...
...
@@ -218,6 +217,7 @@ int PredictorClient::predict(
VLOG
(
2
)
<<
"fetch name: "
<<
name
;
if
(
_fetch_name_to_type
[
name
]
==
0
)
{
int
len
=
res
.
insts
(
0
).
tensor_array
(
idx
).
int64_data_size
();
VLOG
(
2
)
<<
"fetch tensor : "
<<
name
<<
" type: int64 len : "
<<
len
;
predict_res
.
_int64_map
[
name
].
resize
(
1
);
predict_res
.
_int64_map
[
name
][
0
].
resize
(
len
);
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
...
...
@@ -226,6 +226,7 @@ int PredictorClient::predict(
}
}
else
if
(
_fetch_name_to_type
[
name
]
==
1
)
{
int
len
=
res
.
insts
(
0
).
tensor_array
(
idx
).
float_data_size
();
VLOG
(
2
)
<<
"fetch tensor : "
<<
name
<<
" type: float32 len : "
<<
len
;
predict_res
.
_float_map
[
name
].
resize
(
1
);
predict_res
.
_float_map
[
name
][
0
].
resize
(
len
);
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
...
...
@@ -244,7 +245,7 @@ int PredictorClient::predict(
<<
"prepro_1:"
<<
preprocess_end
<<
" "
<<
"client_infer_0:"
<<
client_infer_start
<<
" "
<<
"client_infer_1:"
<<
client_infer_end
<<
" "
;
if
(
FLAGS_profile_server
)
{
int
op_num
=
res
.
profile_time_size
()
/
2
;
for
(
int
i
=
0
;
i
<
op_num
;
++
i
)
{
...
...
@@ -252,10 +253,10 @@ int PredictorClient::predict(
oss
<<
"op"
<<
i
<<
"_1:"
<<
res
.
profile_time
(
i
*
2
+
1
)
<<
" "
;
}
}
oss
<<
"postpro_0:"
<<
postprocess_start
<<
" "
;
oss
<<
"postpro_1:"
<<
postprocess_end
;
fprintf
(
stderr
,
"%s
\n
"
,
oss
.
str
().
c_str
());
}
return
0
;
...
...
@@ -342,7 +343,7 @@ std::vector<std::vector<std::vector<float>>> PredictorClient::batch_predict(
}
VLOG
(
2
)
<<
"batch ["
<<
bi
<<
"] "
<<
"i
tn
feed value prepared"
;
<<
"i
nt
feed value prepared"
;
}
int64_t
preprocess_end
=
timeline
.
TimeStampUS
();
...
...
python/examples/bert/bert_client.py
浏览文件 @
0be0c9c0
...
...
@@ -120,7 +120,6 @@ class BertService():
def
test
():
bc
=
BertService
(
model_name
=
'bert_chinese_L-12_H-768_A-12'
,
max_seq_len
=
20
,
...
...
@@ -130,16 +129,25 @@ def test():
config_file
=
'./serving_client_conf/serving_client_conf.prototxt'
fetch
=
[
"pooled_output"
]
bc
.
load_client
(
config_file
,
server_addr
)
batch_size
=
4
batch_size
=
1
batch
=
[]
for
line
in
sys
.
stdin
:
if
len
(
batch
)
<
batch_size
:
batch
.
append
([
line
.
strip
()])
if
batch_size
==
1
:
result
=
bc
.
run_general
([[
line
.
strip
()]],
fetch
)
print
(
result
)
else
:
result
=
bc
.
run_batch_general
(
batch
,
fetch
)
batch
=
[]
for
r
in
result
:
print
(
r
)
if
len
(
batch
)
<
batch_size
:
batch
.
append
([
line
.
strip
()])
else
:
result
=
bc
.
run_batch_general
(
batch
,
fetch
)
batch
=
[]
for
r
in
result
:
print
(
r
)
if
len
(
batch
)
>
0
:
result
=
bc
.
run_batch_general
(
batch
,
fetch
)
batch
=
[]
for
r
in
result
:
print
(
r
)
if
__name__
==
'__main__'
:
...
...
python/examples/bert/bert_server.py
浏览文件 @
0be0c9c0
...
...
@@ -31,8 +31,6 @@ op_seq_maker.add_op(general_response_op)
server
=
Server
()
server
.
set_op_sequence
(
op_seq_maker
.
get_op_sequence
())
server
.
set_num_threads
(
4
)
server
.
set_local_bin
(
"~/github/Serving/build_server/core/general-server/serving"
)
server
.
load_model_config
(
sys
.
argv
[
1
])
port
=
int
(
sys
.
argv
[
2
])
...
...
python/examples/bert/get_data.sh
0 → 100644
浏览文件 @
0be0c9c0
wget https://paddle-serving.bj.bcebos.com/bert_example/data-c.txt
--no-check-certificate
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录