Skip to content

Commit

Permalink
Merge pull request #580 from xiaoxiao-luomu/master
Browse files Browse the repository at this point in the history
on-offline test ok
  • Loading branch information
frankwhzhang authored Nov 18, 2021
2 parents 66f3f5b + f0ad4d1 commit 1f580e5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
29 changes: 17 additions & 12 deletions tools/inference/cpp/include/infer.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// 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
// 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,
Expand Down Expand Up @@ -84,6 +84,7 @@ class PaddleInferModel {
{
USE_GPU = 0;
EMBEDDING_SIZE = 9;
SLOT_NUMBER = 301;
place = paddle::PaddlePlace::kCPU;
}

Expand All @@ -109,6 +110,7 @@ class PaddleInferModel {
public:
int USE_GPU;
int EMBEDDING_SIZE;
int SLOT_NUMBER;
paddle::PaddlePlace place;
std::shared_ptr<paddle_infer::Predictor> predictor;
};
Expand Down Expand Up @@ -151,16 +153,17 @@ class PaddleInferThread {
for (size_t i = 1; i < ele.size(); i++) {
std::vector<std::string> feature = SplitStr(ele[i], ':');
// feasign -> embedding index
if (feasignMap.find(feature[0]) == feasignMap.end()) {
feasignMap[feature[0]] = feasignMap.size() + 1;
}
int64_t feasign = feasignMap[feature[0]];
//if (feasignMap.find(feature[0]) == feasignMap.end()) {
// feasignMap[feature[0]] = feasignMap.size() + 1;
//}
//int64_t feasign = feasignMap[feature[0]];
uint64_t feasign = std::stoull(feature[0]);
if (FLAGS_withCube) {
samples.feasignIds.insert(feasign);
}
uint32_t slotId = std::stoul(feature[1]);
oneSample[slotId].push_back(feasign);
oneSampleFeasign[slotId].push_back(std::stoul(feature[0]));
oneSample[slotId].push_back(std::stoll(feature[0]));
oneSampleFeasign[slotId].push_back(feasign);
}
for (auto it = slotId2name.begin(); it != slotId2name.end(); it++) { // 全量 slot
int slotId = it->first;
Expand All @@ -175,6 +178,7 @@ class PaddleInferThread {
}
}
oneSample.clear();
oneSampleFeasign.clear()
if (lineCnt == FLAGS_batchSize) {
lineCnt = 0;
samples.batchIdx = batchIdx;
Expand All @@ -196,7 +200,7 @@ class PaddleInferThread {
if (inputVarNames.empty()) {
GetInputVarNames();
}
for (uint i = 2; i <= 409; i++) {
for (uint i = 2; i <= piModel->SLOT_NUMBER; i++) {
//slotId2name[std::stoul(name)] = name;
slotId2name[i] = std::to_string(i);
}
Expand Down Expand Up @@ -296,6 +300,7 @@ class PaddleInferThread {
void FillLodTensorWithEmbdingVec(BatchSample<TypeIn>& batchSample, std::unordered_map<uint64_t, std::vector<float>>& queryResult)
{
//LOG(INFO) << "enter FillLodTensorWithEmbdingVec ...";
queryResult[0] = std::vector<float>(piModel->EMBEDDING_SIZE, 0.0);
std::vector<std::vector<size_t>> lod(1, std::vector<size_t>(FLAGS_batchSize + 1));
uint feasignCnt = 0;
uint feasignNum = batchSample.feasignIds.size();
Expand All @@ -309,8 +314,8 @@ class PaddleInferThread {
int width = 0;
for (int sampleIdx = 0; sampleIdx < FLAGS_batchSize; ++sampleIdx) {
int len = batchSample.featureCnts[slotId][sampleIdx];
lod0.push_back(lod0.back() + len * piModel->EMBEDDING_SIZE);
width += (batchSample.featureCnts[slotId][sampleIdx]);
lod0.push_back(lod0.back() + len);
width += len;
}
memcpy(lod[0].data(), lod0.data(), sizeof(size_t) * lod0.size()); // low performance
lodTensor->SetLoD(lod);
Expand All @@ -321,8 +326,8 @@ class PaddleInferThread {
int offset = 0;
for (int sampleIdx = 0; sampleIdx < FLAGS_batchSize; ++sampleIdx) {
for (uint k = 0; k < batchSample.features[slotId][sampleIdx].size(); k++) {
//uint64_t feasign = batchSample.feasigns[slotId][sampleIdx][k];
uint64_t feasign = globalKeys[feasignCnt % feasignNum];
uint64_t feasign = batchSample.feasigns[slotId][sampleIdx][k];
//uint64_t feasign = globalKeys[feasignCnt % feasignNum];
feasignCnt++;
TypeIn *data_ptr = lodTensor->mutable_data<TypeIn>(piModel->place) + offset;
memcpy(data_ptr,
Expand Down
4 changes: 2 additions & 2 deletions tools/inference/java/src/main/java/ParserInputData.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public ParserInputData() {}
public static int BATCH_SIZE = 2;
public static final int BUFFER_MAX = 20480;
public static int BATCH_NUM;
public static final int SLOT_NUM = 408;
public static final int SLOT_NUM = 300;
public static BatchSample[] batchSamples = new BatchSample[BUFFER_MAX];
public static TreeMap<String, Integer> feasignMap = new TreeMap<String, Integer>();

public static void ReadInputData() {
Integer[] slotIds = new Integer[SLOT_NUM];
String[] inputVarnames = new String[SLOT_NUM];
for (int i = 2; i <= 409; i++) {
for (int i = 2; i <= 301; i++) {
inputVarnames[i - 2] = String.valueOf(i);
slotIds[i - 2] = i;
}
Expand Down
2 changes: 1 addition & 1 deletion tools/inference/python/slot_dnn_infer_dataloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def init(self, args):
self.visit[slot] = False

def slot_reader(self):
slot_num = 408
slot_num = 300
slots = []
if slot_num > 0:
for i in range(2, slot_num + 2):
Expand Down

0 comments on commit 1f580e5

Please sign in to comment.