提交 a35114c5 编写于 作者: W wangjiawei04

fix conversation of PR296

上级 85b099b1
...@@ -99,6 +99,13 @@ class CubeAPI { ...@@ -99,6 +99,13 @@ class CubeAPI {
std::function<void(DictValue*, size_t)> parse, std::function<void(DictValue*, size_t)> parse,
std::string* version); std::string* version);
/**
* @brief: get all table names from cube server, thread safe.
* @param [out] vals: vector of table names
*
*/
std::vector<std::string> get_table_names();
public: public:
static const char* error_msg(int error_code); static const char* error_msg(int error_code);
......
...@@ -682,5 +682,13 @@ int CubeAPI::opt_seek(const std::string& dict_name, ...@@ -682,5 +682,13 @@ int CubeAPI::opt_seek(const std::string& dict_name,
return ret; return ret;
} }
std::vector<std::string> CubeAPI::get_table_names() {
const std::vector<const MetaInfo*> metas = _meta->metas();
std::vector<std::string> table_names;
for (auto itr = metas.begin(); itr != metas.end(); ++itr) {
table_names.push_back((*itr)->dict_name);
}
return table_names;
}
} // namespace mcube } // namespace mcube
} // namespace rec } // namespace rec
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "core/predictor/framework/memory.h" #include "core/predictor/framework/memory.h"
#include "core/predictor/framework/resource.h" #include "core/predictor/framework/resource.h"
#include "core/util/include/timer.h" #include "core/util/include/timer.h"
#include <utility>
namespace baidu { namespace baidu {
namespace paddle_serving { namespace paddle_serving {
...@@ -55,6 +56,8 @@ int GeneralDistKVInferOp::inference() { ...@@ -55,6 +56,8 @@ int GeneralDistKVInferOp::inference() {
std::vector<rec::mcube::CubeValue> values; std::vector<rec::mcube::CubeValue> values;
int sparse_count = 0; int sparse_count = 0;
int dense_count = 0; int dense_count = 0;
std::vector<std::pair<int64_t*, size_t>> dataptr_size_pairs;
size_t key_len = 0;
for (size_t i = 0; i < in->size(); ++i) { for (size_t i = 0; i < in->size(); ++i) {
if (in->at(i).dtype != paddle::PaddleDType::INT64) { if (in->at(i).dtype != paddle::PaddleDType::INT64) {
++dense_count; ++dense_count;
...@@ -65,22 +68,29 @@ int GeneralDistKVInferOp::inference() { ...@@ -65,22 +68,29 @@ int GeneralDistKVInferOp::inference() {
for (size_t s = 0; s < in->at(i).shape.size(); ++s) { for (size_t s = 0; s < in->at(i).shape.size(); ++s) {
elem_num *= in->at(i).shape[s]; elem_num *= in->at(i).shape[s];
} }
key_len += elem_num;
int64_t *data_ptr = static_cast<int64_t *>(in->at(i).data.data()); int64_t *data_ptr = static_cast<int64_t *>(in->at(i).data.data());
for (size_t j = 0; j < elem_num; ++j) { dataptr_size_pairs.push_back(std::make_pair(data_ptr, elem_num));
keys.push_back(data_ptr[j]);
} }
keys.resize(key_len);
int key_idx = 0;
for (size_t i = 0; i < dataptr_size_pairs.size(); ++i) {
std::copy(dataptr_size_pairs[i].first, dataptr_size_pairs[i].first + dataptr_size_pairs[i].second, keys.begin() + key_idx);
key_idx += dataptr_size_pairs[i].second;
} }
// TODO: Add Seek CubeValues Here, and replace EMBEDDING_SIZE with variable.
rec::mcube::CubeAPI *cube = rec::mcube::CubeAPI::instance(); rec::mcube::CubeAPI *cube = rec::mcube::CubeAPI::instance();
// TODO: temp hard code "test_dict" here, fix this with next commit // TODO: temp hard code "test_dict" here, fix this with next commit
// related to cube conf // related to cube conf
std::string table_name = "test_dict"; std::vector<std::string> table_names = cube->get_table_names();
int ret = cube->seek(table_name, keys, &values); if (table_names.size() == 0) {
LOG(ERROR) << "cube init error or cube config not given.";
}
int ret = cube->seek(table_names[0], keys, &values);
if (values.size() != keys.size() || values[0].buff.size() == 0) { if (values.size() != keys.size() || values[0].buff.size() == 0) {
LOG(ERROR) << "cube value return null"; LOG(ERROR) << "cube value return null";
} }
size_t EMBEDDING_SIZE = values[0].buff.size() / 4; size_t EMBEDDING_SIZE = values[0].buff.size() / sizeof(float);
TensorVector sparse_out; TensorVector sparse_out;
sparse_out.resize(sparse_count); sparse_out.resize(sparse_count);
TensorVector dense_out; TensorVector dense_out;
......
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. // Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
......
...@@ -3,7 +3,7 @@ include(common/CMakeLists.txt) ...@@ -3,7 +3,7 @@ include(common/CMakeLists.txt)
include(op/CMakeLists.txt) include(op/CMakeLists.txt)
include(mempool/CMakeLists.txt) include(mempool/CMakeLists.txt)
include(framework/CMakeLists.txt) include(framework/CMakeLists.txt)
#include(plugin/CMakeLists.txt) include(tools/CMakeLists.txt)
include(src/CMakeLists.txt) include(src/CMakeLists.txt)
include_directories(SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../kvdb/include) include_directories(SYSTEM ${CMAKE_CURRENT_LIST_DIR}/../kvdb/include)
......
FILE(GLOB common_srcs ${CMAKE_CURRENT_LIST_DIR}/constant.cpp) FILE(GLOB common_srcs ${CMAKE_CURRENT_LIST_DIR}/constant.cpp)
LIST(APPEND pdserving_srcs ${common_srcs}) LIST(APPEND pdserving_srcs ${common_srcs})
set(seq_gen_src ${CMAKE_CURRENT_LIST_DIR}/seq_generator.cpp ${CMAKE_CURRENT_LIST_DIR}/seq_file.cpp)
LIST(APPEND seq_gen_src ${PROTO_SRCS})
add_executable(seq_generator ${seq_gen_src})
target_link_libraries(seq_generator protobuf -lpthread)
...@@ -170,7 +170,11 @@ int Resource::general_model_initialize(const std::string& path, ...@@ -170,7 +170,11 @@ int Resource::general_model_initialize(const std::string& path,
if (this->cube_config_fullpath.size() != 0) { if (this->cube_config_fullpath.size() != 0) {
LOG(INFO) << "init cube by config file : " << this->cube_config_fullpath; LOG(INFO) << "init cube by config file : " << this->cube_config_fullpath;
rec::mcube::CubeAPI* cube = rec::mcube::CubeAPI::instance(); rec::mcube::CubeAPI* cube = rec::mcube::CubeAPI::instance();
cube->init(this->cube_config_fullpath.c_str()); int ret = cube->init(this->cube_config_fullpath.c_str());
if (ret != 0) {
LOG(ERROR) << "cube init error";
return -1;
}
} }
VLOG(2) << "general model path: " << path; VLOG(2) << "general model path: " << path;
VLOG(2) << "general model file: " << file; VLOG(2) << "general model file: " << file;
......
set(seq_gen_src ${CMAKE_CURRENT_LIST_DIR}/seq_generator.cpp ${CMAKE_CURRENT_LIST_DIR}/seq_file.cpp)
LIST(APPEND seq_gen_src ${PROTO_SRCS})
add_executable(seq_generator ${seq_gen_src})
target_link_libraries(seq_generator protobuf -lpthread)
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. // Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
......
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. // Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
......
// Copyright (c) 2019 PaddlePaddle Authors. All Rights Reserved. // Copyright (c) 2020 PaddlePaddle Authors. All Rights Reserved.
// //
// Licensed under the Apache License, Version 2.0 (the "License"); // Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. // you may not use this file except in compliance with the License.
......
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
文件模式从 100644 更改为 100755
[default]
dict_name: test_dict
mode: base_only
download_mode: http
wget_port: 8098
buildtool_local: /Serving/python/examples/criteo_ctr/cube/cube-builder
donefile_address: http://127.0.0.1:8080/output/ctr_cube/donefile
output_address: /Serving/python/examples/criteo_ctr/cube/output
tmp_address: /Serving/python/examples/criteo_ctr/cube/output
shard_num: 1
copy_num: 1
deploy_path: /Serving/python/examples/criteo_ctr/cube/test_dict
transfer_address: 127.0.0.1
[cube_agent]
agent0_0: 127.0.0.1:8001
cube0_0: 127.0.0.1:8027:/Serving/python/examples/criteo_ctr/cube
文件模式从 100644 更改为 100755
...@@ -2,6 +2,6 @@ ...@@ -2,6 +2,6 @@
mkdir -p cube_model mkdir -p cube_model
mkdir -p cube/data mkdir -p cube/data
./seq_generator ctr_serving_model/SparseFeatFactors ./cube_model/feature ./seq_generator ctr_serving_model/SparseFeatFactors ./cube_model/feature
/Serving/python/examples/criteo_ctr/cube/cube-builder -dict_name=test_dict -job_mode=base -last_version=0 -cur_version=0 -depend_version=0 -input_path=/Serving/python/examples/criteo_ctr/cube_model -output_path=/Serving/python/examples/criteo_ctr/cube/data -shard_num=1 -only_build=false ./cube/cube-builder -dict_name=test_dict -job_mode=base -last_version=0 -cur_version=0 -depend_version=0 -input_path=./cube_model -output_path=./cube/data -shard_num=1 -only_build=false
mv /Serving/python/examples/criteo_ctr/cube/data/0_0/test_dict_part0/* /Serving/python/examples/criteo_ctr/cube/data/ mv ./cube/data/0_0/test_dict_part0/* ./cube/data/
cd cube && ./cube cd cube && ./cube
文件模式从 100644 更改为 100755
...@@ -66,7 +66,7 @@ def train(): ...@@ -66,7 +66,7 @@ def train():
] ]
print(whole_filelist) print(whole_filelist)
dataset.set_filelist(whole_filelist[:thread_num]) dataset.set_filelist(whole_filelist[:100])
dataset.load_into_memory() dataset.load_into_memory()
fluid.layers.Print(auc_var) fluid.layers.Print(auc_var)
epochs = 1 epochs = 1
......
文件模式从 100644 更改为 100755
...@@ -29,15 +29,14 @@ buf_size = 100 ...@@ -29,15 +29,14 @@ buf_size = 100
dataset = criteo.CriteoDataset() dataset = criteo.CriteoDataset()
dataset.setup(1000001) dataset.setup(1000001)
test_filelists = [ test_filelists = [
"{}/part-%d".format(sys.argv[2]) % x "{}/part-test".format(sys.argv[2])
for x in range(len(os.listdir(sys.argv[2])))
] ]
reader = dataset.infer_reader(test_filelists[len(test_filelists) - 40:], batch, reader = dataset.infer_reader(test_filelists, batch,
buf_size) buf_size)
label_list = [] label_list = []
prob_list = [] prob_list = []
start = time.time() start = time.time()
for ei in range(1000): for ei in range(10000):
data = reader().next() data = reader().next()
feed_dict = {} feed_dict = {}
feed_dict['dense_input'] = data[0][0] feed_dict['dense_input'] = data[0][0]
......
文件模式从 100644 更改为 100755
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册