Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
afcd0199
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看板
提交
afcd0199
编写于
10月 15, 2019
作者:
X
xulongteng
浏览文件
操作
浏览文件
下载
差异文件
Merge remote-tracking branch 'refs/remotes/origin/bert' into bert
上级
f84565cb
2baa063d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
37 addition
and
9 deletion
+37
-9
demo-client/src/bert_service.cpp
demo-client/src/bert_service.cpp
+4
-2
demo-serving/op/bert_service_op.cpp
demo-serving/op/bert_service_op.cpp
+33
-7
未找到文件。
demo-client/src/bert_service.cpp
浏览文件 @
afcd0199
...
...
@@ -36,9 +36,11 @@ extern int max_seq_len = 128;
extern
int
layer_num
=
12
;
extern
int
emb_size
=
768
;
extern
int
thread_num
=
1
;
extern
int
max_turn
=
1000
;
std
::
atomic
<
int
>
g_concurrency
(
0
);
std
::
vector
<
std
::
vector
<
int
>>
response_time
;
std
::
vector
<
std
::
vector
<
int
>>
infer_time
;
char
*
data_filename
=
"./data/bert/demo_wiki_train"
;
#if 1
...
...
@@ -64,7 +66,7 @@ int create_req(Request* req,
std
::
vector
<
std
::
string
>
seg_list
=
split
(
feature_list
[
1
],
" "
);
std
::
vector
<
std
::
string
>
pos_list
=
split
(
feature_list
[
2
],
" "
);
for
(
int
fi
=
0
;
fi
<
max_seq_len
;
fi
++
)
{
if
(
fi
<
token_list
.
size
()
)
{
if
(
std
::
stoi
(
token_list
[
fi
])
!=
0
)
{
ins
->
add_token_ids
(
std
::
stoi
(
token_list
[
fi
]));
ins
->
add_sentence_type_ids
(
std
::
stoi
(
seg_list
[
fi
]));
ins
->
add_position_ids
(
std
::
stoi
(
pos_list
[
fi
]));
...
...
@@ -157,7 +159,7 @@ void thread_worker(PredictorApi* api,
api
->
thrd_initialize
();
std
::
string
line
;
int
turns
=
0
;
while
(
turns
<
1000
)
{
while
(
turns
<
max_turn
)
{
timeval
start
;
gettimeofday
(
&
start
,
NULL
);
api
->
thrd_clear
();
...
...
demo-serving/op/bert_service_op.cpp
浏览文件 @
afcd0199
...
...
@@ -34,6 +34,9 @@ const int LAYER_NUM = 12;
const
int
EMB_SIZE
=
768
;
int
BertServiceOp
::
inference
()
{
timeval
op_start
;
gettimeofday
(
&
op_start
,
NULL
);
const
Request
*
req
=
dynamic_cast
<
const
Request
*>
(
get_request_message
());
TensorVector
*
in
=
butil
::
get_object
<
TensorVector
>
();
...
...
@@ -120,18 +123,33 @@ int BertServiceOp::inference() {
return
-
1
;
}
/*
float* example = (float*)(*in)[3].data.data();
for(uint32_t i = 0; i < MAX_SEQ_LEN; i++){
LOG(INFO) << *(example + i);
*/
#if 0 // print request
std::ostringstream oss;
for (int j = 0; j < 3; j++) {
int64_t* example = reinterpret_cast<int64_t*>(*in)[j].data.data();
for (uint32_t i = 0; i < MAX_SEQ_LEN; i++) {
oss << *(example + i) << " ";
}
oss << ";";
}
float* example = reinterpret_cast<float*>(*in)[3].data.data();
for (int i = 0; i < MAX_SEQ_LEN; i++) {
oss << *(example + i) << " ";
}
LOG(INFO) << "msg: " << oss.str();
#endif
timeval
infer_start
;
gettimeofday
(
&
infer_start
,
NULL
);
if
(
predictor
::
InferManager
::
instance
().
infer
(
BERT_MODEL_NAME
,
in
,
out
,
batch_size
))
{
LOG
(
ERROR
)
<<
"Failed do infer in fluid model: "
<<
BERT_MODEL_NAME
;
return
-
1
;
}
timeval
infer_end
;
gettimeofday
(
&
infer_end
,
NULL
);
uint64_t
infer_time
=
(
infer_end
.
tv_sec
*
1000
+
infer_end
.
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]
...
...
@@ -163,6 +181,13 @@ int BertServiceOp::inference() {
}
}
timeval
op_end
;
gettimeofday
(
&
op_end
,
NULL
);
uint64_t
op_time
=
(
op_end
.
tv_sec
*
1000
+
op_end
.
tv_usec
/
1000
-
(
op_start
.
tv_sec
*
1000
+
op_start
.
tv_usec
/
1000
));
res
->
set_op_time
(
op_time
);
res
->
set_infer_time
(
infer_time
);
#endif
for
(
size_t
i
=
0
;
i
<
in
->
size
();
++
i
)
{
(
*
in
)[
i
].
shape
.
clear
();
...
...
@@ -175,6 +200,7 @@ int BertServiceOp::inference() {
}
out
->
clear
();
butil
::
return_object
<
TensorVector
>
(
out
);
return
0
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录