Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
64d71041
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看板
提交
64d71041
编写于
8月 01, 2019
作者:
W
wangguibao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
CTR prediction serving
上级
4f871066
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
147 addition
and
18 deletion
+147
-18
configure/proto/server_configure.proto
configure/proto/server_configure.proto
+14
-0
configure/tests/test_configure.cpp
configure/tests/test_configure.cpp
+2
-0
demo-serving/CMakeLists.txt
demo-serving/CMakeLists.txt
+2
-1
demo-serving/op/ctr_prediction_op.cpp
demo-serving/op/ctr_prediction_op.cpp
+31
-16
predictor/framework/kv_manager.h
predictor/framework/kv_manager.h
+91
-0
predictor/framework/resource.cpp
predictor/framework/resource.cpp
+7
-1
未找到文件。
configure/proto/server_configure.proto
浏览文件 @
64d71041
...
@@ -26,6 +26,20 @@ message EngineDesc {
...
@@ -26,6 +26,20 @@ message EngineDesc {
required
int32
enable_batch_align
=
8
;
required
int32
enable_batch_align
=
8
;
optional
string
version_file
=
9
;
optional
string
version_file
=
9
;
optional
string
version_type
=
10
;
optional
string
version_type
=
10
;
/*
* Sparse Parameter Service type. Valid types are:
* "None": not use sparse parameter service
* "Local": Use local kv service (rocksdb library & API)
* "Remote": Use remote kv service (cube)
*/
enum
SparseParamServiceType
{
NONE
=
0
;
LOCAL
=
1
;
REMOTE
=
2
;
}
optional
SparseParamServiceType
sparse_param_service_type
=
11
;
optional
string
sparse_param_service_table_name
=
12
;
};
};
// model_toolkit conf
// model_toolkit conf
...
...
configure/tests/test_configure.cpp
浏览文件 @
64d71041
...
@@ -66,6 +66,8 @@ int test_write_conf() {
...
@@ -66,6 +66,8 @@ int test_write_conf() {
engine
->
set_runtime_thread_num
(
0
);
engine
->
set_runtime_thread_num
(
0
);
engine
->
set_batch_infer_size
(
0
);
engine
->
set_batch_infer_size
(
0
);
engine
->
set_enable_batch_align
(
0
);
engine
->
set_enable_batch_align
(
0
);
engine
->
set_sparse_param_service_type
(
EngineDesc
::
LOCAL
);
engine
->
set_sparse_param_service_table_name
(
"local_kv"
);
int
ret
=
baidu
::
paddle_serving
::
configure
::
write_proto_conf
(
int
ret
=
baidu
::
paddle_serving
::
configure
::
write_proto_conf
(
&
model_toolkit_conf
,
output_dir
,
model_toolkit_conf_file
);
&
model_toolkit_conf
,
output_dir
,
model_toolkit_conf_file
);
...
...
demo-serving/CMakeLists.txt
浏览文件 @
64d71041
...
@@ -18,7 +18,7 @@ include(op/CMakeLists.txt)
...
@@ -18,7 +18,7 @@ include(op/CMakeLists.txt)
include
(
proto/CMakeLists.txt
)
include
(
proto/CMakeLists.txt
)
add_executable
(
serving
${
serving_srcs
}
)
add_executable
(
serving
${
serving_srcs
}
)
add_dependencies
(
serving pdcodegen fluid_cpu_engine pdserving paddle_fluid
add_dependencies
(
serving pdcodegen fluid_cpu_engine pdserving paddle_fluid
opencv_imgcodecs
)
opencv_imgcodecs
cube-api
)
if
(
WITH_GPU
)
if
(
WITH_GPU
)
add_dependencies
(
serving fluid_gpu_engine
)
add_dependencies
(
serving fluid_gpu_engine
)
endif
()
endif
()
...
@@ -40,6 +40,7 @@ target_link_libraries(serving opencv_imgcodecs
...
@@ -40,6 +40,7 @@ target_link_libraries(serving opencv_imgcodecs
${
opencv_depend_libs
}
)
${
opencv_depend_libs
}
)
target_link_libraries
(
serving pdserving
)
target_link_libraries
(
serving pdserving
)
target_link_libraries
(
serving cube-api
)
target_link_libraries
(
serving kvdb rocksdb
)
target_link_libraries
(
serving kvdb rocksdb
)
...
...
demo-serving/op/ctr_prediction_op.cpp
浏览文件 @
64d71041
...
@@ -15,7 +15,9 @@
...
@@ -15,7 +15,9 @@
#include "demo-serving/op/ctr_prediction_op.h"
#include "demo-serving/op/ctr_prediction_op.h"
#include <algorithm>
#include <algorithm>
#include <string>
#include <string>
#include "cube/cube-api/include/cube_api.h"
#include "predictor/framework/infer.h"
#include "predictor/framework/infer.h"
#include "predictor/framework/kv_manager.h"
#include "predictor/framework/memory.h"
#include "predictor/framework/memory.h"
namespace
baidu
{
namespace
baidu
{
...
@@ -41,13 +43,6 @@ const int CTR_PREDICTION_DENSE_SLOT_ID = 26;
...
@@ -41,13 +43,6 @@ const int CTR_PREDICTION_DENSE_SLOT_ID = 26;
const
int
CTR_PREDICTION_DENSE_DIM
=
13
;
const
int
CTR_PREDICTION_DENSE_DIM
=
13
;
const
int
CTR_PREDICTION_EMBEDDING_SIZE
=
10
;
const
int
CTR_PREDICTION_EMBEDDING_SIZE
=
10
;
#if 1
struct
CubeValue
{
int
error
;
std
::
string
buff
;
};
#endif
void
fill_response_with_message
(
Response
*
response
,
void
fill_response_with_message
(
Response
*
response
,
int
err_code
,
int
err_code
,
std
::
string
err_msg
)
{
std
::
string
err_msg
)
{
...
@@ -61,6 +56,13 @@ void fill_response_with_message(Response *response,
...
@@ -61,6 +56,13 @@ void fill_response_with_message(Response *response,
return
;
return
;
}
}
std
::
string
str_tolower
(
std
::
string
s
)
{
std
::
transform
(
s
.
begin
(),
s
.
end
(),
s
.
begin
(),
[](
unsigned
char
c
)
{
return
std
::
tolower
(
c
);
});
return
s
;
}
int
CTRPredictionOp
::
inference
()
{
int
CTRPredictionOp
::
inference
()
{
const
Request
*
req
=
dynamic_cast
<
const
Request
*>
(
get_request_message
());
const
Request
*
req
=
dynamic_cast
<
const
Request
*>
(
get_request_message
());
...
@@ -83,8 +85,8 @@ int CTRPredictionOp::inference() {
...
@@ -83,8 +85,8 @@ int CTRPredictionOp::inference() {
}
}
// Query cube API for sparse embeddings
// Query cube API for sparse embeddings
std
::
vector
<
int64_t
>
keys
;
std
::
vector
<
u
int64_t
>
keys
;
std
::
vector
<
CubeValue
>
values
;
std
::
vector
<
rec
::
mcube
::
CubeValue
>
values
;
for
(
uint32_t
si
=
0
;
si
<
sample_size
;
++
si
)
{
for
(
uint32_t
si
=
0
;
si
<
sample_size
;
++
si
)
{
const
CTRReqInstance
&
req_instance
=
req
->
instances
(
si
);
const
CTRReqInstance
&
req_instance
=
req
->
instances
(
si
);
...
@@ -100,13 +102,26 @@ int CTRPredictionOp::inference() {
...
@@ -100,13 +102,26 @@ int CTRPredictionOp::inference() {
}
}
}
}
#if 0
#if 1
mCube::CubeAPI* cube = CubeAPI::instance();
rec
::
mcube
::
CubeAPI
*
cube
=
rec
::
mcube
::
CubeAPI
::
instance
();
int ret = cube->seek(keys, values);
predictor
::
KVManager
&
kv_manager
=
predictor
::
KVManager
::
instance
();
if (ret != 0) {
const
predictor
::
KVInfo
*
kvinfo
=
fill_response_with_message(res, -1, "Query cube for embeddings error");
kv_manager
.
get_kv_info
(
CTR_PREDICTION_MODEL_NAME
);
LOG(ERROR) << "Query cube for embeddings error";
std
::
string
table_name
;
return -1;
if
(
kvinfo
->
sparse_param_service_type
!=
configure
::
EngineDesc
::
NONE
)
{
std
::
string
table_name
=
kvinfo
->
sparse_param_service_table_name
;
}
if
(
kvinfo
->
sparse_param_service_type
==
configure
::
EngineDesc
::
LOCAL
)
{
// Query local KV service
}
else
if
(
kvinfo
->
sparse_param_service_type
==
configure
::
EngineDesc
::
REMOTE
)
{
int
ret
=
cube
->
seek
(
table_name
,
keys
,
&
values
);
if
(
ret
!=
0
)
{
fill_response_with_message
(
res
,
-
1
,
"Query cube for embeddings error"
);
LOG
(
ERROR
)
<<
"Query cube for embeddings error"
;
return
-
1
;
}
}
}
#else
#else
float
buff
[
CTR_PREDICTION_EMBEDDING_SIZE
]
=
{
float
buff
[
CTR_PREDICTION_EMBEDDING_SIZE
]
=
{
...
...
predictor/framework/kv_manager.h
0 → 100644
浏览文件 @
64d71041
// Copyright (c) 2019 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include <map>
#include <string>
#include "predictor/common/inner_common.h"
namespace
baidu
{
namespace
paddle_serving
{
namespace
predictor
{
using
configure
::
ModelToolkitConf
;
struct
KVInfo
{
std
::
string
model_name
;
uint32_t
sparse_param_service_type
;
std
::
string
sparse_param_service_table_name
;
};
class
KVManager
{
public:
static
KVManager
&
instance
()
{
static
KVManager
ins
;
return
ins
;
}
int
proc_initialize
(
const
char
*
path
,
const
char
*
file
)
{
ModelToolkitConf
model_toolkit_conf
;
if
(
configure
::
read_proto_conf
(
path
,
file
,
&
model_toolkit_conf
)
!=
0
)
{
LOG
(
ERROR
)
<<
"failed load infer config, path: "
<<
path
<<
"/"
<<
file
;
return
-
1
;
}
size_t
engine_num
=
model_toolkit_conf
.
engines_size
();
for
(
size_t
ei
=
0
;
ei
<
engine_num
;
++
ei
)
{
const
configure
::
EngineDesc
&
conf
=
model_toolkit_conf
.
engines
(
ei
);
std
::
string
engine_name
=
conf
.
name
();
KVInfo
*
kvinfo
=
new
(
std
::
nothrow
)
KVInfo
();
kvinfo
->
model_name
=
engine_name
;
if
(
conf
.
has_sparse_param_service_type
())
{
kvinfo
->
sparse_param_service_type
=
conf
.
sparse_param_service_type
();
}
else
{
kvinfo
->
sparse_param_service_type
=
configure
::
EngineDesc
::
NONE
;
}
if
(
conf
.
has_sparse_param_service_table_name
())
{
kvinfo
->
sparse_param_service_table_name
=
conf
.
sparse_param_service_table_name
();
}
else
{
kvinfo
->
sparse_param_service_table_name
=
""
;
}
auto
r
=
_map
.
insert
(
std
::
make_pair
(
engine_name
,
kvinfo
));
if
(
!
r
.
second
)
{
LOG
(
ERROR
)
<<
"Failed insert item: "
<<
engine_name
;
return
-
1
;
}
LOG
(
WARNING
)
<<
"Succ proc initialize kvmanager for engine: "
<<
engine_name
;
}
return
0
;
}
const
KVInfo
*
get_kv_info
(
std
::
string
model_name
)
{
auto
it
=
_map
.
find
(
model_name
);
if
(
it
==
_map
.
end
())
{
LOG
(
WARNING
)
<<
"Cannot find kvinfo for model "
<<
model_name
;
return
NULL
;
}
return
it
->
second
;
}
private:
std
::
map
<
std
::
string
,
KVInfo
*>
_map
;
};
}
// namespace predictor
}
// namespace paddle_serving
}
// namespace baidu
predictor/framework/resource.cpp
浏览文件 @
64d71041
...
@@ -16,7 +16,7 @@
...
@@ -16,7 +16,7 @@
#include <string>
#include <string>
#include "predictor/common/inner_common.h"
#include "predictor/common/inner_common.h"
#include "predictor/framework/infer.h"
#include "predictor/framework/infer.h"
#include "predictor/framework/kv_manager.h"
namespace
baidu
{
namespace
baidu
{
namespace
paddle_serving
{
namespace
paddle_serving
{
namespace
predictor
{
namespace
predictor
{
...
@@ -76,6 +76,12 @@ int Resource::initialize(const std::string& path, const std::string& file) {
...
@@ -76,6 +76,12 @@ int Resource::initialize(const std::string& path, const std::string& file) {
<<
model_toolkit_path
<<
"/"
<<
model_toolkit_file
;
<<
model_toolkit_path
<<
"/"
<<
model_toolkit_file
;
return
-
1
;
return
-
1
;
}
}
if
(
KVManager
::
instance
().
proc_initialize
(
model_toolkit_path
.
c_str
(),
model_toolkit_file
.
c_str
())
!=
0
)
{
LOG
(
ERROR
)
<<
"Failed proc initialize kvmanager, config: "
<<
model_toolkit_path
<<
"/"
<<
model_toolkit_file
;
}
}
}
if
(
THREAD_KEY_CREATE
(
&
_tls_bspec_key
,
dynamic_resource_deleter
)
!=
0
)
{
if
(
THREAD_KEY_CREATE
(
&
_tls_bspec_key
,
dynamic_resource_deleter
)
!=
0
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录