Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Serving
提交
2872e68a
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看板
提交
2872e68a
编写于
12月 13, 2019
作者:
W
wangguibao
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix elastic-ctr Serving OP
上级
4db121d7
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
97 addition
and
50 deletion
+97
-50
cmake/paddlepaddle.cmake
cmake/paddlepaddle.cmake
+1
-1
demo-serving/CMakeLists.txt
demo-serving/CMakeLists.txt
+1
-1
elastic-ctr/client/demo/elastic_ctr.py
elastic-ctr/client/demo/elastic_ctr.py
+5
-9
elastic-ctr/serving/CMakeLists.txt
elastic-ctr/serving/CMakeLists.txt
+1
-1
elastic-ctr/serving/op/elastic_ctr_prediction_op.cpp
elastic-ctr/serving/op/elastic_ctr_prediction_op.cpp
+87
-38
elastic-ctr/serving/op/elastic_ctr_prediction_op.h
elastic-ctr/serving/op/elastic_ctr_prediction_op.h
+2
-0
未找到文件。
cmake/paddlepaddle.cmake
浏览文件 @
2872e68a
...
...
@@ -62,7 +62,7 @@ ExternalProject_Add(
${
CMAKE_COMMAND
}
-E copy_directory
${
PADDLE_DOWNLOAD_DIR
}
/paddle/include
${
PADDLE_INSTALL_DIR
}
/include &&
${
CMAKE_COMMAND
}
-E copy_directory
${
PADDLE_DOWNLOAD_DIR
}
/paddle/lib
${
PADDLE_INSTALL_DIR
}
/lib &&
${
CMAKE_COMMAND
}
-E copy_directory
${
PADDLE_DOWNLOAD_DIR
}
/third_party
${
PADDLE_INSTALL_DIR
}
/third_party &&
${
CMAKE_COMMAND
}
-E copy
${
PADDLE_INSTALL_DIR
}
/third_party/install/mkldnn/lib/libmkldnn.so.
0
${
PADDLE_INSTALL_DIR
}
/third_party/install/mkldnn/lib/libmkldnn.so
${
CMAKE_COMMAND
}
-E copy
${
PADDLE_INSTALL_DIR
}
/third_party/install/mkldnn/lib/libmkldnn.so.
1
${
PADDLE_INSTALL_DIR
}
/third_party/install/mkldnn/lib/libmkldnn.so
)
INCLUDE_DIRECTORIES
(
${
PADDLE_INCLUDE_DIR
}
)
...
...
demo-serving/CMakeLists.txt
浏览文件 @
2872e68a
...
...
@@ -90,7 +90,7 @@ if (${WITH_MKL})
install
(
FILES
${
CMAKE_BINARY_DIR
}
/third_party/install/Paddle/third_party/install/mklml/lib/libmklml_intel.so
${
CMAKE_BINARY_DIR
}
/third_party/install/Paddle/third_party/install/mklml/lib/libiomp5.so
${
CMAKE_BINARY_DIR
}
/third_party/install/Paddle/third_party/install/mkldnn/lib/libmkldnn.so.
0
${
CMAKE_BINARY_DIR
}
/third_party/install/Paddle/third_party/install/mkldnn/lib/libmkldnn.so.
1
DESTINATION
${
PADDLE_SERVING_INSTALL_DIR
}
/demo/serving/bin
)
endif
()
elastic-ctr/client/demo/elastic_ctr.py
浏览文件 @
2872e68a
...
...
@@ -105,13 +105,11 @@ def data_reader(data_file, samples, labels):
for
i
in
range
(
0
,
len
(
features
)):
if
slots
[
i
]
in
sample
:
sample
[
slots
[
i
]]
=
[
sample
[
slots
[
i
]]
+
str2long
(
features
[
i
])
%
CTR_EMBEDDING_TABLE_SIZE
]
sample
[
slots
[
i
]].
append
(
int
(
features
[
i
])
%
CTR_EMBEDDING_TABLE_SIZE
)
else
:
sample
[
slots
[
i
]]
=
[
str2long
(
features
[
i
])
%
CTR_EMBEDDING_TABLE_SIZE
int
(
features
[
i
])
%
CTR_EMBEDDING_TABLE_SIZE
]
for
x
in
SLOTS
:
...
...
@@ -142,11 +140,11 @@ if __name__ == "__main__":
sys
.
exit
(
-
1
)
ret
=
data_reader
(
sys
.
argv
[
4
],
samples
,
labels
)
print
(
len
(
samples
))
correct
=
0
wrong_label_1_count
=
0
result_list
=
[]
for
i
in
range
(
0
,
len
(
samples
)
-
BATCH_SIZE
,
BATCH_SIZE
):
#for i in range(0, len(samples) - BATCH_SIZE, BATCH_SIZE):
for
i
in
range
(
0
,
len
(
samples
),
BATCH_SIZE
):
api
.
clear
()
batch
=
samples
[
i
:
i
+
BATCH_SIZE
]
instances
=
[]
...
...
@@ -181,7 +179,5 @@ if __name__ == "__main__":
# (i + idx, pred, labels[i + idx], x["prob0"], x["prob1"]))
pass
idx
=
idx
+
1
#print("Acc=%f" % (float(correct) / len(samples)))
print
(
"auc = "
,
auc
(
labels
,
result_list
)
)
elastic-ctr/serving/CMakeLists.txt
浏览文件 @
2872e68a
...
...
@@ -53,7 +53,7 @@ if (${WITH_MKL})
install
(
FILES
${
CMAKE_BINARY_DIR
}
/third_party/install/Paddle/third_party/install/mklml/lib/libmklml_intel.so
${
CMAKE_BINARY_DIR
}
/third_party/install/Paddle/third_party/install/mklml/lib/libiomp5.so
${
CMAKE_BINARY_DIR
}
/third_party/install/Paddle/third_party/install/mkldnn/lib/libmkldnn.so.
0
${
CMAKE_BINARY_DIR
}
/third_party/install/Paddle/third_party/install/mkldnn/lib/libmkldnn.so.
1
DESTINATION
${
PADDLE_SERVING_INSTALL_DIR
}
/elastic_ctr/serving/bin
)
endif
()
elastic-ctr/serving/op/elastic_ctr_prediction_op.cpp
浏览文件 @
2872e68a
...
...
@@ -15,6 +15,7 @@
#include "elastic-ctr/serving/op/elastic_ctr_prediction_op.h"
#include <algorithm>
#include <string>
#include <iomanip>
#include "cube/cube-api/include/cube_api.h"
#include "predictor/framework/infer.h"
#include "predictor/framework/kv_manager.h"
...
...
@@ -70,17 +71,65 @@ int ElasticCTRPredictionOp::inference() {
return
0
;
}
Samples
samples
;
samples
.
resize
(
req
->
instances_size
());
for
(
int
i
=
0
;
i
<
req
->
instances_size
();
++
i
)
{
const
ReqInstance
&
req_instance
=
req
->
instances
(
i
);
for
(
int
j
=
0
;
j
<
req_instance
.
slots_size
();
++
j
)
{
const
Slot
&
slot
=
req_instance
.
slots
(
j
);
for
(
int
k
=
0
;
k
<
slot
.
feasigns
().
size
();
++
k
)
{
int
slot_id
=
strtol
(
slot
.
slot_name
().
c_str
(),
NULL
,
10
);
samples
[
i
][
slot_id
].
push_back
(
slot
.
feasigns
(
k
));
}
}
}
// Verify all request instances have same slots
int
slot_num
=
req
->
instances
(
0
).
slots_size
();
#if 1
LOG
(
INFO
)
<<
"slot_num ="
<<
slot_num
;
#endif
for
(
int
i
=
1
;
i
<
req
->
instances_size
();
++
i
)
{
if
(
req
->
instances
(
i
).
slots_size
()
!=
slot_num
)
{
std
::
vector
<
int
>
slot_ids
;
for
(
auto
x
:
samples
[
0
])
{
slot_ids
.
push_back
(
x
.
first
);
}
std
::
sort
(
slot_ids
.
begin
(),
slot_ids
.
end
());
// use of slot_map:
//
// Example:
// slot_ids: 1, 20, 50, 100
//
// Then
// slot_map[1] = 0
// slot_map[20] = 1
// slot_map[50] = 2
// slot_map[100] = 3
//
// Later we use slot_map to index into lod_tenor array
//
std
::
map
<
int
,
int
>
slot_map
;
int
index
=
0
;
for
(
auto
slot_id
:
slot_ids
)
{
slot_map
[
slot_id
]
=
index
;
++
index
;
}
for
(
size_t
i
=
1
;
i
<
samples
.
size
();
++
i
)
{
if
(
samples
[
i
].
size
()
!=
slot_ids
.
size
())
{
LOG
(
WARNING
)
<<
"Req "
<<
i
<<
" has different slot num with that of req 0"
;
fill_response_with_message
(
res
,
-
1
,
"Req intance has varying slot numbers"
);
return
0
;
}
for
(
auto
slot
:
samples
[
i
])
{
int
id
=
slot
.
first
;
auto
x
=
std
::
find
(
slot_ids
.
begin
(),
slot_ids
.
end
(),
id
);
if
(
x
==
slot_ids
.
end
())
{
std
::
ostringstream
oss
;
oss
<<
"Req instance "
<<
i
<<
" has an outlier slot id: "
<<
id
;
fill_response_with_message
(
res
,
-
1
,
oss
.
str
().
c_str
());
return
0
;
}
}
}
...
...
@@ -115,30 +164,27 @@ int ElasticCTRPredictionOp::inference() {
// Level of details of each feature slot
std
::
vector
<
std
::
vector
<
size_t
>>
feature_slot_lods
;
feature_slot_lods
.
resize
(
slot_
num
);
feature_slot_lods
.
resize
(
slot_
ids
.
size
()
);
// Number of feature signs in each slot
std
::
vector
<
int
>
feature_slot_sizes
;
feature_slot_sizes
.
resize
(
slot_
num
);
feature_slot_sizes
.
resize
(
slot_
ids
.
size
()
);
// Iterate over each feature slot
for
(
int
i
=
0
;
i
<
slot_num
;
++
i
)
{
feature_slot_lods
[
i
].
push_back
(
0
);
feature_slot_sizes
[
i
]
=
0
;
for
(
auto
slot_id
:
slot_ids
)
{
feature_slot_lods
[
slot_map
[
slot_id
]
].
push_back
(
0
);
feature_slot_sizes
[
slot_map
[
slot_id
]
]
=
0
;
// Extract feature i values from each instance si
for
(
int
si
=
0
;
si
<
sample_size
;
++
si
)
{
#if 1
LOG
(
INFO
)
<<
"slot "
<<
i
<<
" sample "
<<
si
;
#endif
const
ReqInstance
&
req_instance
=
req
->
instances
(
si
);
const
Slot
&
slot
=
req_instance
.
slots
(
i
);
feature_slot_lods
[
i
].
push_back
(
feature_slot_lods
[
i
].
back
()
+
slot
.
feasigns_size
());
feature_slot_sizes
[
i
]
+=
slot
.
feasigns_size
();
for
(
int
j
=
0
;
j
<
slot
.
feasigns_size
();
++
j
)
{
keys
.
push_back
(
slot
.
feasigns
(
j
));
for
(
size_t
si
=
0
;
si
<
samples
.
size
();
++
si
)
{
Sample
&
sample
=
samples
[
si
];
std
::
vector
<
int64_t
>
&
slot
=
sample
[
slot_id
];
feature_slot_lods
[
slot_map
[
slot_id
]].
push_back
(
feature_slot_lods
[
slot_map
[
slot_id
]].
back
()
+
slot
.
size
());
feature_slot_sizes
[
slot_map
[
slot_id
]]
+=
slot
.
size
();
for
(
size_t
j
=
0
;
j
<
slot
.
size
();
++
j
)
{
keys
.
push_back
(
slot
[
j
]);
}
}
}
...
...
@@ -234,10 +280,9 @@ int ElasticCTRPredictionOp::inference() {
return
0
;
}
for
(
in
t
i
=
0
;
i
<
keys
.
size
();
++
i
)
{
for
(
size_
t
i
=
0
;
i
<
keys
.
size
();
++
i
)
{
std
::
ostringstream
oss
;
oss
<<
keys
[
i
]
<<
": "
;
const
char
*
value
=
(
values
[
i
].
buff
.
data
());
if
(
values
[
i
].
buff
.
size
()
!=
sizeof
(
float
)
*
CTR_PREDICTION_EMBEDDING_SIZE
)
{
LOG
(
WARNING
)
<<
"Key "
<<
keys
[
i
]
<<
" has values less than "
...
...
@@ -256,21 +301,20 @@ int ElasticCTRPredictionOp::inference() {
// Fill feature embedding into feed tensors
std
::
vector
<
paddle
::
PaddleTensor
>
lod_tensors
;
lod_tensors
.
resize
(
slot_
num
);
lod_tensors
.
resize
(
slot_
ids
.
size
()
);
const
ReqInstance
&
instance
=
req
->
instances
(
0
);
for
(
int
i
=
0
;
i
<
slot_num
;
++
i
)
{
paddle
::
PaddleTensor
&
lod_tensor
=
lod_tensors
[
i
];
for
(
auto
slot_id
:
slot_ids
)
{
paddle
::
PaddleTensor
&
lod_tensor
=
lod_tensors
[
slot_map
[
slot_id
]];
char
name
[
VARIABLE_NAME_LEN
];
snprintf
(
name
,
VARIABLE_NAME_LEN
,
"embedding_%
s
.tmp_0"
,
instance
.
slots
(
i
).
slot_name
().
c_str
()
);
"embedding_%
d
.tmp_0"
,
slot_id
);
lod_tensor
.
name
=
std
::
string
(
name
);
lod_tensor
s
[
i
]
.
dtype
=
paddle
::
PaddleDType
::
FLOAT32
;
std
::
vector
<
std
::
vector
<
size_t
>>
&
lod
=
lod_tensor
s
[
i
]
.
lod
;
lod_tensor
.
dtype
=
paddle
::
PaddleDType
::
FLOAT32
;
std
::
vector
<
std
::
vector
<
size_t
>>
&
lod
=
lod_tensor
.
lod
;
lod
.
resize
(
1
);
lod
[
0
].
push_back
(
0
);
}
...
...
@@ -278,11 +322,11 @@ int ElasticCTRPredictionOp::inference() {
int
base
=
0
;
// Iterate over all slots
for
(
int
i
=
0
;
i
<
slot_num
;
++
i
)
{
paddle
::
PaddleTensor
&
lod_tensor
=
lod_tensors
[
i
];
for
(
auto
slot_id
:
slot_ids
)
{
paddle
::
PaddleTensor
&
lod_tensor
=
lod_tensors
[
slot_map
[
slot_id
]
];
std
::
vector
<
std
::
vector
<
size_t
>>
&
lod
=
lod_tensor
.
lod
;
lod
[
0
]
=
feature_slot_lods
[
i
];
lod
[
0
]
=
feature_slot_lods
[
slot_map
[
slot_id
]
];
lod_tensor
.
shape
=
{
lod
[
0
].
back
(),
CTR_PREDICTION_EMBEDDING_SIZE
};
lod_tensor
.
data
.
Resize
(
lod
[
0
].
back
()
*
sizeof
(
float
)
*
...
...
@@ -290,7 +334,7 @@ int ElasticCTRPredictionOp::inference() {
int
offset
=
0
;
// Copy all slot i feature embeddings to lod_tensor[i]
for
(
uint32_t
j
=
0
;
j
<
feature_slot_sizes
[
i
];
++
j
)
{
for
(
uint32_t
j
=
0
;
j
<
feature_slot_sizes
[
slot_map
[
slot_id
]
];
++
j
)
{
float
*
data_ptr
=
static_cast
<
float
*>
(
lod_tensor
.
data
.
data
())
+
offset
;
int
idx
=
base
+
j
;
...
...
@@ -303,19 +347,24 @@ int ElasticCTRPredictionOp::inference() {
return 0;
#else
// sizeof(float) * CTR_PREDICTION_EMBEDDING_SIZE = 36
#if 1
LOG
(
INFO
)
<<
"values["
<<
idx
<<
"].buff.size != 36"
;
#endif
values
[
idx
].
buff
.
append
(
36
,
'0'
);
#endif
}
memcpy
(
data_ptr
,
values
[
idx
].
buff
.
data
(),
values
[
idx
].
buff
.
size
());
offset
+=
CTR_PREDICTION_EMBEDDING_SIZE
;
}
in
->
push_back
(
lod_tensor
);
// Bump base counter
base
+=
feature_slot_sizes
[
i
];
base
+=
feature_slot_sizes
[
slot_map
[
slot_id
]
];
}
#else
// Fill all tensors
...
...
elastic-ctr/serving/op/elastic_ctr_prediction_op.h
浏览文件 @
2872e68a
...
...
@@ -41,6 +41,8 @@ class ElasticCTRPredictionOp
baidu
::
paddle_serving
::
predictor
::
elastic_ctr
::
Response
>
{
public:
typedef
std
::
vector
<
paddle
::
PaddleTensor
>
TensorVector
;
typedef
std
::
map
<
int
,
std
::
vector
<
int64_t
>>
Sample
;
typedef
std
::
vector
<
Sample
>
Samples
;
DECLARE_OP
(
ElasticCTRPredictionOp
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录