Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
6ea67de5
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看板
提交
6ea67de5
编写于
3月 09, 2020
作者:
D
Dong Daxiang
提交者:
GitHub
3月 09, 2020
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #256 from MRXLT/general-server-batch
fix batch predict
上级
7c9687c1
5f06c445
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
55 addition
and
36 deletion
+55
-36
core/general-client/include/general_model.h
core/general-client/include/general_model.h
+4
-9
core/general-client/src/general_model.cpp
core/general-client/src/general_model.cpp
+34
-21
core/general-client/src/pybind_general_model.cpp
core/general-client/src/pybind_general_model.cpp
+6
-2
python/paddle_serving_client/__init__.py
python/paddle_serving_client/__init__.py
+11
-4
未找到文件。
core/general-client/include/general_model.h
浏览文件 @
6ea67de5
...
@@ -84,19 +84,14 @@ class PredictorClient {
...
@@ -84,19 +84,14 @@ class PredictorClient {
PredictorRes
&
predict_res
,
// NOLINT
PredictorRes
&
predict_res
,
// NOLINT
const
int
&
pid
);
const
int
&
pid
);
std
::
vector
<
std
::
vector
<
float
>>
predict
(
int
batch_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
);
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>>>
batch_predict
(
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>>>&
float_feed_batch
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>>>&
float_feed_batch
,
const
std
::
vector
<
std
::
string
>&
float_feed_name
,
const
std
::
vector
<
std
::
string
>&
float_feed_name
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int64_t
>>>&
int_feed_batch
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int64_t
>>>&
int_feed_batch
,
const
std
::
vector
<
std
::
string
>&
int_feed_name
,
const
std
::
vector
<
std
::
string
>&
int_feed_name
,
const
std
::
vector
<
std
::
string
>&
fetch_name
);
const
std
::
vector
<
std
::
string
>&
fetch_name
,
PredictorRes
&
predict_res_batch
,
// NOLINT
const
int
&
pid
);
private:
private:
PredictorApi
_api
;
PredictorApi
_api
;
...
...
core/general-client/src/general_model.cpp
浏览文件 @
6ea67de5
...
@@ -264,26 +264,22 @@ int PredictorClient::predict(const std::vector<std::vector<float>> &float_feed,
...
@@ -264,26 +264,22 @@ int PredictorClient::predict(const std::vector<std::vector<float>> &float_feed,
return
0
;
return
0
;
}
}
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>>>
PredictorClient
::
batch_predict
(
int
PredictorClient
::
batch_predict
(
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>>>
&
float_feed_batch
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>>>
&
float_feed_batch
,
const
std
::
vector
<
std
::
string
>
&
float_feed_name
,
const
std
::
vector
<
std
::
string
>
&
float_feed_name
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int64_t
>>>
&
int_feed_batch
,
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int64_t
>>>
&
int_feed_batch
,
const
std
::
vector
<
std
::
string
>
&
int_feed_name
,
const
std
::
vector
<
std
::
string
>
&
int_feed_name
,
const
std
::
vector
<
std
::
string
>
&
fetch_name
)
{
const
std
::
vector
<
std
::
string
>
&
fetch_name
,
PredictorRes
&
predict_res_batch
,
const
int
&
pid
)
{
int
batch_size
=
std
::
max
(
float_feed_batch
.
size
(),
int_feed_batch
.
size
());
int
batch_size
=
std
::
max
(
float_feed_batch
.
size
(),
int_feed_batch
.
size
());
std
::
vector
<
std
::
vector
<
std
::
vector
<
float
>>>
fetch_result_batch
;
if
(
fetch_name
.
size
()
==
0
)
{
return
fetch_result_batch
;
}
predict_res_batch
.
_int64_map
.
clear
();
predict_res_batch
.
_float_map
.
clear
();
Timer
timeline
;
Timer
timeline
;
int64_t
preprocess_start
=
timeline
.
TimeStampUS
();
int64_t
preprocess_start
=
timeline
.
TimeStampUS
();
fetch_result_batch
.
resize
(
batch_size
);
int
fetch_name_num
=
fetch_name
.
size
();
int
fetch_name_num
=
fetch_name
.
size
();
for
(
int
bi
=
0
;
bi
<
batch_size
;
bi
++
)
{
fetch_result_batch
[
bi
].
resize
(
fetch_name_num
);
}
_api
.
thrd_clear
();
_api
.
thrd_clear
();
_predictor
=
_api
.
fetch_predictor
(
"general_model"
);
_predictor
=
_api
.
fetch_predictor
(
"general_model"
);
...
@@ -371,20 +367,36 @@ std::vector<std::vector<std::vector<float>>> PredictorClient::batch_predict(
...
@@ -371,20 +367,36 @@ std::vector<std::vector<std::vector<float>>> PredictorClient::batch_predict(
}
else
{
}
else
{
client_infer_end
=
timeline
.
TimeStampUS
();
client_infer_end
=
timeline
.
TimeStampUS
();
postprocess_start
=
client_infer_end
;
postprocess_start
=
client_infer_end
;
for
(
auto
&
name
:
fetch_name
)
{
predict_res_batch
.
_int64_map
[
name
].
resize
(
batch_size
);
predict_res_batch
.
_float_map
[
name
].
resize
(
batch_size
);
}
for
(
int
bi
=
0
;
bi
<
batch_size
;
bi
++
)
{
for
(
int
bi
=
0
;
bi
<
batch_size
;
bi
++
)
{
for
(
auto
&
name
:
fetch_name
)
{
for
(
auto
&
name
:
fetch_name
)
{
int
idx
=
_fetch_name_to_idx
[
name
];
int
idx
=
_fetch_name_to_idx
[
name
];
int
len
=
res
.
insts
(
bi
).
tensor_array
(
idx
).
data_size
();
int
len
=
res
.
insts
(
bi
).
tensor_array
(
idx
).
data_size
();
VLOG
(
2
)
<<
"fetch name: "
<<
name
;
if
(
_fetch_name_to_type
[
name
]
==
0
)
{
VLOG
(
2
)
<<
"tensor data size: "
<<
len
;
int
len
=
res
.
insts
(
bi
).
tensor_array
(
idx
).
int64_data_size
();
fetch_result_batch
[
bi
][
idx
].
resize
(
len
);
VLOG
(
2
)
<<
"fetch tensor : "
<<
name
<<
" type: int64 len : "
<<
len
;
VLOG
(
2
)
predict_res_batch
.
_int64_map
[
name
][
bi
].
resize
(
len
);
<<
"fetch name "
<<
name
<<
" index "
<<
idx
<<
" first data "
VLOG
(
2
)
<<
"fetch name "
<<
name
<<
" index "
<<
idx
<<
" first data "
<<
*
(
const
float
*
)
res
.
insts
(
bi
).
tensor_array
(
idx
).
data
(
0
).
c_str
();
<<
res
.
insts
(
bi
).
tensor_array
(
idx
).
int64_data
(
0
);
/*
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
TBA
predict_res_batch
.
_int64_map
[
name
][
bi
][
i
]
=
*/
res
.
insts
(
bi
).
tensor_array
(
idx
).
int64_data
(
i
);
}
}
else
if
(
_fetch_name_to_type
[
name
]
==
1
)
{
int
len
=
res
.
insts
(
bi
).
tensor_array
(
idx
).
float_data_size
();
VLOG
(
2
)
<<
"fetch tensor : "
<<
name
<<
" type: float32 len : "
<<
len
;
predict_res_batch
.
_float_map
[
name
][
bi
].
resize
(
len
);
VLOG
(
2
)
<<
"fetch name "
<<
name
<<
" index "
<<
idx
<<
" first data "
<<
res
.
insts
(
bi
).
tensor_array
(
idx
).
float_data
(
0
);
for
(
int
i
=
0
;
i
<
len
;
++
i
)
{
predict_res_batch
.
_float_map
[
name
][
bi
][
i
]
=
res
.
insts
(
bi
).
tensor_array
(
idx
).
float_data
(
i
);
}
}
}
}
}
}
postprocess_end
=
timeline
.
TimeStampUS
();
postprocess_end
=
timeline
.
TimeStampUS
();
...
@@ -393,6 +405,7 @@ std::vector<std::vector<std::vector<float>>> PredictorClient::batch_predict(
...
@@ -393,6 +405,7 @@ std::vector<std::vector<std::vector<float>>> PredictorClient::batch_predict(
if
(
FLAGS_profile_client
)
{
if
(
FLAGS_profile_client
)
{
std
::
ostringstream
oss
;
std
::
ostringstream
oss
;
oss
<<
"PROFILE
\t
"
oss
<<
"PROFILE
\t
"
<<
"pid:"
<<
pid
<<
"
\t
"
<<
"prepro_0:"
<<
preprocess_start
<<
" "
<<
"prepro_0:"
<<
preprocess_start
<<
" "
<<
"prepro_1:"
<<
preprocess_end
<<
" "
<<
"prepro_1:"
<<
preprocess_end
<<
" "
<<
"client_infer_0:"
<<
client_infer_start
<<
" "
<<
"client_infer_0:"
<<
client_infer_start
<<
" "
...
@@ -411,7 +424,7 @@ std::vector<std::vector<std::vector<float>>> PredictorClient::batch_predict(
...
@@ -411,7 +424,7 @@ std::vector<std::vector<std::vector<float>>> PredictorClient::batch_predict(
fprintf
(
stderr
,
"%s
\n
"
,
oss
.
str
().
c_str
());
fprintf
(
stderr
,
"%s
\n
"
,
oss
.
str
().
c_str
());
}
}
return
fetch_result_batch
;
return
0
;
}
}
}
// namespace general_model
}
// namespace general_model
...
...
core/general-client/src/pybind_general_model.cpp
浏览文件 @
6ea67de5
...
@@ -90,12 +90,16 @@ PYBIND11_MODULE(serving_client, m) {
...
@@ -90,12 +90,16 @@ PYBIND11_MODULE(serving_client, m) {
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int64_t
>>>
const
std
::
vector
<
std
::
vector
<
std
::
vector
<
int64_t
>>>
&
int_feed_batch
,
&
int_feed_batch
,
const
std
::
vector
<
std
::
string
>
&
int_feed_name
,
const
std
::
vector
<
std
::
string
>
&
int_feed_name
,
const
std
::
vector
<
std
::
string
>
&
fetch_name
)
{
const
std
::
vector
<
std
::
string
>
&
fetch_name
,
PredictorRes
&
predict_res_batch
,
const
int
&
pid
)
{
return
self
.
batch_predict
(
float_feed_batch
,
return
self
.
batch_predict
(
float_feed_batch
,
float_feed_name
,
float_feed_name
,
int_feed_batch
,
int_feed_batch
,
int_feed_name
,
int_feed_name
,
fetch_name
);
fetch_name
,
predict_res_batch
,
pid
);
});
});
}
}
...
...
python/paddle_serving_client/__init__.py
浏览文件 @
6ea67de5
...
@@ -199,6 +199,7 @@ class Client(object):
...
@@ -199,6 +199,7 @@ class Client(object):
float_feed_names
=
[]
float_feed_names
=
[]
fetch_names
=
[]
fetch_names
=
[]
counter
=
0
counter
=
0
batch_size
=
len
(
feed_batch
)
for
feed
in
feed_batch
:
for
feed
in
feed_batch
:
int_slot
=
[]
int_slot
=
[]
float_slot
=
[]
float_slot
=
[]
...
@@ -221,15 +222,21 @@ class Client(object):
...
@@ -221,15 +222,21 @@ class Client(object):
if
key
in
self
.
fetch_names_
:
if
key
in
self
.
fetch_names_
:
fetch_names
.
append
(
key
)
fetch_names
.
append
(
key
)
result_batch
=
self
.
client_handle_
.
batch_predict
(
result_batch
=
self
.
result_handle_
res
=
self
.
client_handle_
.
batch_predict
(
float_slot_batch
,
float_feed_names
,
int_slot_batch
,
int_feed_names
,
float_slot_batch
,
float_feed_names
,
int_slot_batch
,
int_feed_names
,
fetch_names
)
fetch_names
,
result_batch
,
self
.
pid
)
result_map_batch
=
[]
result_map_batch
=
[]
for
result
in
result_batch
:
for
index
in
range
(
batch_size
)
:
result_map
=
{}
result_map
=
{}
for
i
,
name
in
enumerate
(
fetch_names
):
for
i
,
name
in
enumerate
(
fetch_names
):
result_map
[
name
]
=
result
[
i
]
if
self
.
fetch_names_to_type_
[
name
]
==
int_type
:
result_map
[
name
]
=
result_batch
.
get_int64_by_name
(
name
)[
index
]
elif
self
.
fetch_names_to_type_
[
name
]
==
float_type
:
result_map
[
name
]
=
result_batch
.
get_float_by_name
(
name
)[
index
]
result_map_batch
.
append
(
result_map
)
result_map_batch
.
append
(
result_map
)
return
result_map_batch
return
result_map_batch
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录