Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
5104ccd7
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看板
提交
5104ccd7
编写于
10月 29, 2019
作者:
X
xulongteng
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'refs/remotes/origin/bert' into bert
上级
2efc8755
e46028ec
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
14 addition
and
36 deletion
+14
-36
demo-client/src/bert_service.cpp
demo-client/src/bert_service.cpp
+2
-2
demo-serving/conf/model_toolkit.prototxt
demo-serving/conf/model_toolkit.prototxt
+1
-0
demo-serving/op/bert_service_op.cpp
demo-serving/op/bert_service_op.cpp
+6
-29
demo-serving/op/bert_service_op.h
demo-serving/op/bert_service_op.h
+1
-1
demo-serving/proto/bert_service.proto
demo-serving/proto/bert_service.proto
+2
-2
sdk-cpp/proto/bert_service.proto
sdk-cpp/proto/bert_service.proto
+2
-2
未找到文件。
demo-client/src/bert_service.cpp
浏览文件 @
5104ccd7
...
@@ -30,7 +30,7 @@ using baidu::paddle_serving::predictor::bert_service::Request;
...
@@ -30,7 +30,7 @@ using baidu::paddle_serving::predictor::bert_service::Request;
using
baidu
::
paddle_serving
::
predictor
::
bert_service
::
Response
;
using
baidu
::
paddle_serving
::
predictor
::
bert_service
::
Response
;
using
baidu
::
paddle_serving
::
predictor
::
bert_service
::
BertResInstance
;
using
baidu
::
paddle_serving
::
predictor
::
bert_service
::
BertResInstance
;
using
baidu
::
paddle_serving
::
predictor
::
bert_service
::
BertReqInstance
;
using
baidu
::
paddle_serving
::
predictor
::
bert_service
::
BertReqInstance
;
using
baidu
::
paddle_serving
::
predictor
::
bert_service
::
Embedding
_v
alues
;
using
baidu
::
paddle_serving
::
predictor
::
bert_service
::
Embedding
V
alues
;
extern
int
batch_size
=
1
;
extern
int
batch_size
=
1
;
extern
int
max_seq_len
=
128
;
extern
int
max_seq_len
=
128
;
...
@@ -108,7 +108,7 @@ void print_res(const Request& req,
...
@@ -108,7 +108,7 @@ void print_res(const Request& req,
std
::
ostringstream
oss
;
std
::
ostringstream
oss
;
oss
<<
"["
;
oss
<<
"["
;
for
(
uint32_t
bi
=
0
;
bi
<
res_ins
.
instances_size
();
bi
++
)
{
for
(
uint32_t
bi
=
0
;
bi
<
res_ins
.
instances_size
();
bi
++
)
{
const
Embedding
_v
alues
&
emb_ins
=
res_ins
.
instances
(
bi
);
const
Embedding
V
alues
&
emb_ins
=
res_ins
.
instances
(
bi
);
oss
<<
"["
;
oss
<<
"["
;
for
(
uint32_t
ei
=
0
;
ei
<
emb_ins
.
values_size
();
ei
++
)
{
for
(
uint32_t
ei
=
0
;
ei
<
emb_ins
.
values_size
();
ei
++
)
{
oss
<<
emb_ins
.
values
(
ei
)
<<
" "
;
oss
<<
emb_ins
.
values
(
ei
)
<<
" "
;
...
...
demo-serving/conf/model_toolkit.prototxt
浏览文件 @
5104ccd7
...
@@ -45,4 +45,5 @@ engines {
...
@@ -45,4 +45,5 @@ engines {
runtime_thread_num: 0
runtime_thread_num: 0
batch_infer_size: 0
batch_infer_size: 0
enable_batch_align: 0
enable_batch_align: 0
enable_memory_optimization: true
}
}
demo-serving/op/bert_service_op.cpp
浏览文件 @
5104ccd7
...
@@ -26,12 +26,7 @@ using baidu::paddle_serving::predictor::bert_service::BertResInstance;
...
@@ -26,12 +26,7 @@ using baidu::paddle_serving::predictor::bert_service::BertResInstance;
using
baidu
::
paddle_serving
::
predictor
::
bert_service
::
Response
;
using
baidu
::
paddle_serving
::
predictor
::
bert_service
::
Response
;
using
baidu
::
paddle_serving
::
predictor
::
bert_service
::
BertReqInstance
;
using
baidu
::
paddle_serving
::
predictor
::
bert_service
::
BertReqInstance
;
using
baidu
::
paddle_serving
::
predictor
::
bert_service
::
Request
;
using
baidu
::
paddle_serving
::
predictor
::
bert_service
::
Request
;
using
baidu
::
paddle_serving
::
predictor
::
bert_service
::
Embedding_values
;
using
baidu
::
paddle_serving
::
predictor
::
bert_service
::
EmbeddingValues
;
extern
int64_t
MAX_SEQ_LEN
=
128
;
const
bool
POOLING
=
true
;
const
int
LAYER_NUM
=
12
;
extern
int
EMB_SIZE
=
768
;
int
BertServiceOp
::
inference
()
{
int
BertServiceOp
::
inference
()
{
timeval
op_start
;
timeval
op_start
;
...
@@ -48,8 +43,8 @@ int BertServiceOp::inference() {
...
@@ -48,8 +43,8 @@ int BertServiceOp::inference() {
return
0
;
return
0
;
}
}
MAX_SEQ_LEN
=
req
->
instances
(
0
).
max_seq_len
();
const
int64_t
MAX_SEQ_LEN
=
req
->
instances
(
0
).
max_seq_len
();
EMB_SIZE
=
req
->
instances
(
0
).
emb_size
();
const
int64_t
EMB_SIZE
=
req
->
instances
(
0
).
emb_size
();
paddle
::
PaddleTensor
src_ids
;
paddle
::
PaddleTensor
src_ids
;
paddle
::
PaddleTensor
pos_ids
;
paddle
::
PaddleTensor
pos_ids
;
...
@@ -99,7 +94,6 @@ int BertServiceOp::inference() {
...
@@ -99,7 +94,6 @@ int BertServiceOp::inference() {
memcpy
(
src_data
,
memcpy
(
src_data
,
req_instance
.
token_ids
().
data
(),
req_instance
.
token_ids
().
data
(),
sizeof
(
int64_t
)
*
MAX_SEQ_LEN
);
sizeof
(
int64_t
)
*
MAX_SEQ_LEN
);
#if 1
memcpy
(
pos_data
,
memcpy
(
pos_data
,
req_instance
.
position_ids
().
data
(),
req_instance
.
position_ids
().
data
(),
sizeof
(
int64_t
)
*
MAX_SEQ_LEN
);
sizeof
(
int64_t
)
*
MAX_SEQ_LEN
);
...
@@ -109,7 +103,6 @@ int BertServiceOp::inference() {
...
@@ -109,7 +103,6 @@ int BertServiceOp::inference() {
memcpy
(
input_masks_data
,
memcpy
(
input_masks_data
,
req_instance
.
input_masks
().
data
(),
req_instance
.
input_masks
().
data
(),
sizeof
(
float
)
*
MAX_SEQ_LEN
);
sizeof
(
float
)
*
MAX_SEQ_LEN
);
#endif
index
+=
MAX_SEQ_LEN
;
index
+=
MAX_SEQ_LEN
;
}
}
...
@@ -151,30 +144,14 @@ int BertServiceOp::inference() {
...
@@ -151,30 +144,14 @@ int BertServiceOp::inference() {
uint64_t
infer_time
=
uint64_t
infer_time
=
(
infer_end
.
tv_sec
*
1000
+
infer_end
.
tv_usec
/
1000
-
(
infer_end
.
tv_sec
*
1000
+
infer_end
.
tv_usec
/
1000
-
(
infer_start
.
tv_sec
*
1000
+
infer_start
.
tv_usec
/
1000
));
(
infer_start
.
tv_sec
*
1000
+
infer_start
.
tv_usec
/
1000
));
#if 0
LOG(INFO) << "batch_size : " << out->at(0).shape[0]
<< " seq_len : " << out->at(0).shape[1]
<< " emb_size : " << out->at(0).shape[2];
float *out_data = reinterpret_cast<float *>(out->at(0).data.data());
for (uint32_t bi = 0; bi < batch_size; bi++) {
BertResInstance *res_instance = res->add_instances();
for (uint32_t si = 0; si < MAX_SEQ_LEN; si++) {
Embedding_values *emb_instance = res_instance->add_instances();
for (uint32_t ei = 0; ei < EMB_SIZE; ei++) {
uint32_t index = bi * MAX_SEQ_LEN * EMB_SIZE + si * EMB_SIZE + ei;
emb_instance->add_values(out_data[index]);
}
}
}
#else
LOG
(
INFO
)
<<
"batch_size : "
<<
out
->
at
(
0
).
shape
[
0
]
LOG
(
INFO
)
<<
"batch_size : "
<<
out
->
at
(
0
).
shape
[
0
]
<<
" emb_size : "
<<
out
->
at
(
0
).
shape
[
1
];
<<
" emb_size : "
<<
out
->
at
(
0
).
shape
[
1
];
float
*
out_data
=
reinterpret_cast
<
float
*>
(
out
->
at
(
0
).
data
.
data
());
float
*
out_data
=
reinterpret_cast
<
float
*>
(
out
->
at
(
0
).
data
.
data
());
for
(
uint32_t
bi
=
0
;
bi
<
batch_size
;
bi
++
)
{
for
(
uint32_t
bi
=
0
;
bi
<
batch_size
;
bi
++
)
{
BertResInstance
*
res_instance
=
res
->
add_instances
();
BertResInstance
*
res_instance
=
res
->
add_instances
();
for
(
uint32_t
si
=
0
;
si
<
1
;
si
++
)
{
for
(
uint32_t
si
=
0
;
si
<
1
;
si
++
)
{
Embedding
_v
alues
*
emb_instance
=
res_instance
->
add_instances
();
Embedding
V
alues
*
emb_instance
=
res_instance
->
add_instances
();
for
(
uint32_t
ei
=
0
;
ei
<
EMB_SIZE
;
ei
++
)
{
for
(
uint32_t
ei
=
0
;
ei
<
EMB_SIZE
;
ei
++
)
{
uint32_t
index
=
bi
*
EMB_SIZE
+
ei
;
uint32_t
index
=
bi
*
EMB_SIZE
+
ei
;
emb_instance
->
add_values
(
out_data
[
index
]);
emb_instance
->
add_values
(
out_data
[
index
]);
...
@@ -189,7 +166,7 @@ int BertServiceOp::inference() {
...
@@ -189,7 +166,7 @@ int BertServiceOp::inference() {
res
->
set_op_time
(
op_time
);
res
->
set_op_time
(
op_time
);
res
->
set_infer_time
(
infer_time
);
res
->
set_infer_time
(
infer_time
);
#endif
for
(
size_t
i
=
0
;
i
<
in
->
size
();
++
i
)
{
for
(
size_t
i
=
0
;
i
<
in
->
size
();
++
i
)
{
(
*
in
)[
i
].
shape
.
clear
();
(
*
in
)[
i
].
shape
.
clear
();
}
}
...
...
demo-serving/op/bert_service_op.h
浏览文件 @
5104ccd7
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
#include "paddle/fluid/inference/api/paddle_inference_api.h"
#include "paddle/fluid/inference/api/paddle_inference_api.h"
#endif
#endif
#else
#else
#include "
./paddle_inference_api.h"
#include "
paddle_inference_api.h" // NOLINT
#endif
#endif
#include "demo-serving/bert_service.pb.h"
#include "demo-serving/bert_service.pb.h"
...
...
demo-serving/proto/bert_service.proto
浏览文件 @
5104ccd7
...
@@ -31,9 +31,9 @@ message BertReqInstance {
...
@@ -31,9 +31,9 @@ message BertReqInstance {
message
Request
{
repeated
BertReqInstance
instances
=
1
;
};
message
Request
{
repeated
BertReqInstance
instances
=
1
;
};
message
Embedding
_v
alues
{
repeated
float
values
=
1
;
};
message
Embedding
V
alues
{
repeated
float
values
=
1
;
};
message
BertResInstance
{
repeated
Embedding
_v
alues
instances
=
1
;
};
message
BertResInstance
{
repeated
Embedding
V
alues
instances
=
1
;
};
message
Response
{
message
Response
{
repeated
BertResInstance
instances
=
1
;
repeated
BertResInstance
instances
=
1
;
...
...
sdk-cpp/proto/bert_service.proto
浏览文件 @
5104ccd7
...
@@ -31,9 +31,9 @@ message BertReqInstance {
...
@@ -31,9 +31,9 @@ message BertReqInstance {
message
Request
{
repeated
BertReqInstance
instances
=
1
;
};
message
Request
{
repeated
BertReqInstance
instances
=
1
;
};
message
Embedding
_v
alues
{
repeated
float
values
=
1
;
};
message
Embedding
V
alues
{
repeated
float
values
=
1
;
};
message
BertResInstance
{
repeated
Embedding
_v
alues
instances
=
1
;
};
message
BertResInstance
{
repeated
Embedding
V
alues
instances
=
1
;
};
message
Response
{
message
Response
{
repeated
BertResInstance
instances
=
1
;
repeated
BertResInstance
instances
=
1
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录