Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
1344d989
S
Serving
项目概览
PaddlePaddle
/
Serving
接近 2 年 前同步成功
通知
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看板
“1ea9acc7823587266a26293a3b74deafc6637427”上不存在“arch/m68k/platform/68000/m68EZ328.c”
提交
1344d989
编写于
8月 30, 2021
作者:
S
ShiningZhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add comment for client
上级
54814efe
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
58 addition
and
55 deletion
+58
-55
core/general-client/example/simple_client.cpp
core/general-client/example/simple_client.cpp
+6
-7
core/general-client/include/brpc_client.h
core/general-client/include/brpc_client.h
+2
-2
core/general-client/include/client.h
core/general-client/include/client.h
+38
-38
core/general-client/src/brpc_client.cpp
core/general-client/src/brpc_client.cpp
+8
-5
core/general-client/src/client.cpp
core/general-client/src/client.cpp
+4
-3
未找到文件。
core/general-client/example/simple_client.cpp
浏览文件 @
1344d989
// Copyright (c) 20
19
PaddlePaddle Authors. All Rights Reserved.
// Copyright (c) 20
21
PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
...
...
@@ -17,17 +17,16 @@
#include "core/general-client/include/brpc_client.h"
using
namespace
std
;
// NOLINT
using
baidu
::
paddle_serving
::
client
::
ServingClient
;
using
baidu
::
paddle_serving
::
client
::
ServingBrpcClient
;
using
baidu
::
paddle_serving
::
client
::
PredictorInputs
;
using
baidu
::
paddle_serving
::
client
::
PredictorOutputs
;
DEFINE_string
(
server_port
,
"127.0.0.1:9292"
,
""
);
DEFINE_string
(
client_conf
,
"serving_client_conf.prototxt"
,
""
);
DEFINE_string
(
test_type
,
"brpc"
,
""
);
DEFINE_string
(
sample_type
,
"fit_a_line"
,
""
);
DEFINE_string
(
server_port
,
"127.0.0.1:9292"
,
"ip:port"
);
DEFINE_string
(
client_conf
,
"serving_client_conf.prototxt"
,
"Path of client conf"
);
DEFINE_string
(
test_type
,
"brpc"
,
"brpc"
);
// fit_a_line, bert
DEFINE_string
(
sample_type
,
"fit_a_line"
,
"List: fit_a_line, bert"
);
namespace
{
int
prepare_fit_a_line
(
PredictorInputs
&
input
,
std
::
vector
<
std
::
string
>&
fetch_name
)
{
...
...
core/general-client/include/brpc_client.h
浏览文件 @
1344d989
// Copyright (c) 20
19
PaddlePaddle Authors. All Rights Reserved.
// Copyright (c) 20
21
PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
...
...
@@ -33,7 +33,7 @@ class ServingBrpcClient : public ServingClient {
int
predict
(
const
PredictorInputs
&
inputs
,
PredictorOutputs
&
outputs
,
std
::
vector
<
std
::
string
>&
fetch_name
,
const
std
::
vector
<
std
::
string
>&
fetch_name
,
const
uint64_t
log_id
);
private:
...
...
core/general-client/include/client.h
浏览文件 @
1344d989
// Copyright (c) 20
19
PaddlePaddle Authors. All Rights Reserved.
// Copyright (c) 20
21
PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
...
...
@@ -47,7 +47,7 @@ class ServingClient {
virtual
int
predict
(
const
PredictorInputs
&
inputs
,
PredictorOutputs
&
outputs
,
std
::
vector
<
std
::
string
>&
fetch_name
,
const
std
::
vector
<
std
::
string
>&
fetch_name
,
const
uint64_t
log_id
)
=
0
;
protected:
...
...
@@ -66,75 +66,75 @@ class PredictorData {
PredictorData
()
{};
virtual
~
PredictorData
()
{};
v
irtual
v
oid
add_float_data
(
const
std
::
vector
<
float
>&
data
,
const
std
::
string
&
name
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
lod
);
void
add_float_data
(
const
std
::
vector
<
float
>&
data
,
const
std
::
string
&
name
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
lod
);
v
irtual
v
oid
add_int64_data
(
const
std
::
vector
<
int64_t
>&
data
,
const
std
::
string
&
name
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
lod
);
void
add_int64_data
(
const
std
::
vector
<
int64_t
>&
data
,
const
std
::
string
&
name
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
lod
);
v
irtual
v
oid
add_int32_data
(
const
std
::
vector
<
int32_t
>&
data
,
const
std
::
string
&
name
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
lod
);
void
add_int32_data
(
const
std
::
vector
<
int32_t
>&
data
,
const
std
::
string
&
name
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
lod
);
v
irtual
v
oid
add_string_data
(
const
std
::
string
&
data
,
const
std
::
string
&
name
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
lod
);
void
add_string_data
(
const
std
::
string
&
data
,
const
std
::
string
&
name
,
const
std
::
vector
<
int
>&
shape
,
const
std
::
vector
<
int
>&
lod
);
virtual
const
std
::
map
<
std
::
string
,
std
::
vector
<
float
>>&
float_data_map
()
const
{
const
std
::
map
<
std
::
string
,
std
::
vector
<
float
>>&
float_data_map
()
const
{
return
_float_data_map
;
};
virtual
std
::
map
<
std
::
string
,
std
::
vector
<
float
>>*
mutable_float_data_map
()
{
std
::
map
<
std
::
string
,
std
::
vector
<
float
>>*
mutable_float_data_map
()
{
return
&
_float_data_map
;
};
virtual
const
std
::
map
<
std
::
string
,
std
::
vector
<
int64_t
>>&
int64_data_map
()
const
{
const
std
::
map
<
std
::
string
,
std
::
vector
<
int64_t
>>&
int64_data_map
()
const
{
return
_int64_data_map
;
};
virtual
std
::
map
<
std
::
string
,
std
::
vector
<
int64_t
>>*
mutable_int64_data_map
()
{
std
::
map
<
std
::
string
,
std
::
vector
<
int64_t
>>*
mutable_int64_data_map
()
{
return
&
_int64_data_map
;
};
virtual
const
std
::
map
<
std
::
string
,
std
::
vector
<
int32_t
>>&
int_data_map
()
const
{
const
std
::
map
<
std
::
string
,
std
::
vector
<
int32_t
>>&
int_data_map
()
const
{
return
_int32_data_map
;
};
virtual
std
::
map
<
std
::
string
,
std
::
vector
<
int32_t
>>*
mutable_int_data_map
()
{
std
::
map
<
std
::
string
,
std
::
vector
<
int32_t
>>*
mutable_int_data_map
()
{
return
&
_int32_data_map
;
};
virtual
const
std
::
map
<
std
::
string
,
std
::
string
>&
string_data_map
()
const
{
const
std
::
map
<
std
::
string
,
std
::
string
>&
string_data_map
()
const
{
return
_string_data_map
;
};
virtual
std
::
map
<
std
::
string
,
std
::
string
>*
mutable_string_data_map
()
{
std
::
map
<
std
::
string
,
std
::
string
>*
mutable_string_data_map
()
{
return
&
_string_data_map
;
};
virtual
const
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>&
shape_map
()
const
{
const
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>&
shape_map
()
const
{
return
_shape_map
;
};
virtual
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>*
mutable_shape_map
()
{
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>*
mutable_shape_map
()
{
return
&
_shape_map
;
};
virtual
const
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>&
lod_map
()
const
{
const
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>&
lod_map
()
const
{
return
_lod_map
;
};
virtual
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>*
mutable_lod_map
()
{
std
::
map
<
std
::
string
,
std
::
vector
<
int
>>*
mutable_lod_map
()
{
return
&
_lod_map
;
};
virtual
std
::
string
print
();
std
::
string
print
();
private:
template
<
typename
T1
,
typename
T2
>
...
...
@@ -196,7 +196,7 @@ class PredictorInputs : public PredictorData {
PredictorInputs
()
{};
virtual
~
PredictorInputs
()
{};
static
int
gen_p
roto
(
const
PredictorInputs
&
inputs
,
static
int
GenP
roto
(
const
PredictorInputs
&
inputs
,
const
std
::
map
<
std
::
string
,
int
>&
feed_name_to_idx
,
const
std
::
vector
<
std
::
string
>&
feed_name
,
predictor
::
general_model
::
Request
&
req
);
...
...
@@ -212,23 +212,23 @@ class PredictorOutputs {
PredictorOutputs
()
{};
virtual
~
PredictorOutputs
()
{};
virtual
std
::
vector
<
std
::
shared_ptr
<
PredictorOutputs
::
PredictorOutput
>>&
datas
()
{
const
std
::
vector
<
std
::
shared_ptr
<
PredictorOutputs
::
PredictorOutput
>>&
datas
()
{
return
_datas
;
};
virtual
std
::
vector
<
std
::
shared_ptr
<
PredictorOutputs
::
PredictorOutput
>>*
mutable_datas
()
{
std
::
vector
<
std
::
shared_ptr
<
PredictorOutputs
::
PredictorOutput
>>*
mutable_datas
()
{
return
&
_datas
;
};
v
irtual
v
oid
add_data
(
const
std
::
shared_ptr
<
PredictorOutputs
::
PredictorOutput
>&
data
)
{
void
add_data
(
const
std
::
shared_ptr
<
PredictorOutputs
::
PredictorOutput
>&
data
)
{
_datas
.
push_back
(
data
);
};
virtual
std
::
string
print
();
std
::
string
print
();
v
irtual
v
oid
clear
();
void
clear
();
static
int
parse_p
roto
(
const
predictor
::
general_model
::
Response
&
res
,
static
int
ParseP
roto
(
const
predictor
::
general_model
::
Response
&
res
,
const
std
::
vector
<
std
::
string
>&
fetch_name
,
std
::
map
<
std
::
string
,
int
>&
fetch_name_to_type
,
PredictorOutputs
&
outputs
);
...
...
core/general-client/src/brpc_client.cpp
浏览文件 @
1344d989
// Copyright (c) 20
19
PaddlePaddle Authors. All Rights Reserved.
// Copyright (c) 20
21
PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
...
...
@@ -47,6 +47,7 @@ int ServingBrpcClient::connect(const std::string server_port) {
}
std
::
string
ServingBrpcClient
::
gen_desc
(
const
std
::
string
server_port
)
{
// default config for brpc
SDKConf
sdk_conf
;
Predictor
*
predictor
=
sdk_conf
.
add_predictors
();
...
...
@@ -83,13 +84,14 @@ std::string ServingBrpcClient::gen_desc(const std::string server_port) {
int
ServingBrpcClient
::
predict
(
const
PredictorInputs
&
inputs
,
PredictorOutputs
&
outputs
,
std
::
vector
<
std
::
string
>&
fetch_name
,
const
std
::
vector
<
std
::
string
>&
fetch_name
,
const
uint64_t
log_id
)
{
Timer
timeline
;
int64_t
preprocess_start
=
timeline
.
TimeStampUS
();
// thread initialize for StubTLS
_api
.
thrd_initialize
();
std
::
string
variant_tag
;
// predictor is bound to request with brpc::Controller
_predictor
=
_api
.
fetch_predictor
(
"general_model"
,
&
variant_tag
);
if
(
_predictor
==
NULL
)
{
LOG
(
ERROR
)
<<
"Failed fetch predictor so predict error!"
;
...
...
@@ -105,7 +107,7 @@ int ServingBrpcClient::predict(const PredictorInputs& inputs,
req
.
add_fetch_var_names
(
name
);
}
if
(
PredictorInputs
::
gen_p
roto
(
inputs
,
_feed_name_to_idx
,
_feed_name
,
req
)
!=
0
)
{
if
(
PredictorInputs
::
GenP
roto
(
inputs
,
_feed_name_to_idx
,
_feed_name
,
req
)
!=
0
)
{
LOG
(
ERROR
)
<<
"Failed to preprocess req!"
;
return
-
1
;
}
...
...
@@ -132,7 +134,7 @@ int ServingBrpcClient::predict(const PredictorInputs& inputs,
client_infer_end
=
timeline
.
TimeStampUS
();
postprocess_start
=
client_infer_end
;
if
(
PredictorOutputs
::
parse_p
roto
(
res
,
fetch_name
,
_fetch_name_to_type
,
outputs
)
!=
0
)
{
if
(
PredictorOutputs
::
ParseP
roto
(
res
,
fetch_name
,
_fetch_name_to_type
,
outputs
)
!=
0
)
{
LOG
(
ERROR
)
<<
"Failed to post_process res!"
;
return
-
1
;
}
...
...
@@ -160,6 +162,7 @@ int ServingBrpcClient::predict(const PredictorInputs& inputs,
fprintf
(
stderr
,
"%s
\n
"
,
oss
.
str
().
c_str
());
}
// release predictor
_api
.
thrd_clear
();
return
0
;
...
...
core/general-client/src/client.cpp
浏览文件 @
1344d989
// Copyright (c) 20
19
PaddlePaddle Authors. All Rights Reserved.
// Copyright (c) 20
21
PaddlePaddle Authors. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
...
...
@@ -32,6 +32,7 @@ int ServingClient::init(const std::vector<std::string>& client_conf,
return
-
1
;
}
// pure virtual func, subclass implementation
if
(
connect
(
server_port
)
!=
0
)
{
LOG
(
ERROR
)
<<
"Failed to connect"
;
return
-
1
;
...
...
@@ -148,7 +149,7 @@ std::string PredictorData::print() {
return
res
;
}
int
PredictorInputs
::
gen_p
roto
(
const
PredictorInputs
&
inputs
,
int
PredictorInputs
::
GenP
roto
(
const
PredictorInputs
&
inputs
,
const
std
::
map
<
std
::
string
,
int
>&
feed_name_to_idx
,
const
std
::
vector
<
std
::
string
>&
feed_name
,
Request
&
req
)
{
...
...
@@ -317,7 +318,7 @@ void PredictorOutputs::clear() {
_datas
.
clear
();
}
int
PredictorOutputs
::
parse_p
roto
(
const
Response
&
res
,
int
PredictorOutputs
::
ParseP
roto
(
const
Response
&
res
,
const
std
::
vector
<
std
::
string
>&
fetch_name
,
std
::
map
<
std
::
string
,
int
>&
fetch_name_to_type
,
PredictorOutputs
&
outputs
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录