Skip to content

Commit 1f580e5

Browse files
authored
Merge pull request #580 from xiaoxiao-luomu/master
on-offline test ok
2 parents 66f3f5b + f0ad4d1 commit 1f580e5

3 files changed

Lines changed: 20 additions & 15 deletions

File tree

tools/inference/cpp/include/infer.h

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// you may not use this file except in compliance with the License.
55
// You may obtain a copy of the License at
66
//
7-
// http://www.apache.org/licenses/LICENSE-2.0
7+
// http://www.apache.org/licenses/LICENSE-2.0
88
//
99
// Unless required by applicable law or agreed to in writing, software
1010
// distributed under the License is distributed on an "AS IS" BASIS,
@@ -84,6 +84,7 @@ class PaddleInferModel {
8484
{
8585
USE_GPU = 0;
8686
EMBEDDING_SIZE = 9;
87+
SLOT_NUMBER = 301;
8788
place = paddle::PaddlePlace::kCPU;
8889
}
8990

@@ -109,6 +110,7 @@ class PaddleInferModel {
109110
public:
110111
int USE_GPU;
111112
int EMBEDDING_SIZE;
113+
int SLOT_NUMBER;
112114
paddle::PaddlePlace place;
113115
std::shared_ptr<paddle_infer::Predictor> predictor;
114116
};
@@ -151,16 +153,17 @@ class PaddleInferThread {
151153
for (size_t i = 1; i < ele.size(); i++) {
152154
std::vector<std::string> feature = SplitStr(ele[i], ':');
153155
// feasign -> embedding index
154-
if (feasignMap.find(feature[0]) == feasignMap.end()) {
155-
feasignMap[feature[0]] = feasignMap.size() + 1;
156-
}
157-
int64_t feasign = feasignMap[feature[0]];
156+
//if (feasignMap.find(feature[0]) == feasignMap.end()) {
157+
// feasignMap[feature[0]] = feasignMap.size() + 1;
158+
//}
159+
//int64_t feasign = feasignMap[feature[0]];
160+
uint64_t feasign = std::stoull(feature[0]);
158161
if (FLAGS_withCube) {
159162
samples.feasignIds.insert(feasign);
160163
}
161164
uint32_t slotId = std::stoul(feature[1]);
162-
oneSample[slotId].push_back(feasign);
163-
oneSampleFeasign[slotId].push_back(std::stoul(feature[0]));
165+
oneSample[slotId].push_back(std::stoll(feature[0]));
166+
oneSampleFeasign[slotId].push_back(feasign);
164167
}
165168
for (auto it = slotId2name.begin(); it != slotId2name.end(); it++) { // 全量 slot
166169
int slotId = it->first;
@@ -175,6 +178,7 @@ class PaddleInferThread {
175178
}
176179
}
177180
oneSample.clear();
181+
oneSampleFeasign.clear()
178182
if (lineCnt == FLAGS_batchSize) {
179183
lineCnt = 0;
180184
samples.batchIdx = batchIdx;
@@ -196,7 +200,7 @@ class PaddleInferThread {
196200
if (inputVarNames.empty()) {
197201
GetInputVarNames();
198202
}
199-
for (uint i = 2; i <= 409; i++) {
203+
for (uint i = 2; i <= piModel->SLOT_NUMBER; i++) {
200204
//slotId2name[std::stoul(name)] = name;
201205
slotId2name[i] = std::to_string(i);
202206
}
@@ -296,6 +300,7 @@ class PaddleInferThread {
296300
void FillLodTensorWithEmbdingVec(BatchSample<TypeIn>& batchSample, std::unordered_map<uint64_t, std::vector<float>>& queryResult)
297301
{
298302
//LOG(INFO) << "enter FillLodTensorWithEmbdingVec ...";
303+
queryResult[0] = std::vector<float>(piModel->EMBEDDING_SIZE, 0.0);
299304
std::vector<std::vector<size_t>> lod(1, std::vector<size_t>(FLAGS_batchSize + 1));
300305
uint feasignCnt = 0;
301306
uint feasignNum = batchSample.feasignIds.size();
@@ -309,8 +314,8 @@ class PaddleInferThread {
309314
int width = 0;
310315
for (int sampleIdx = 0; sampleIdx < FLAGS_batchSize; ++sampleIdx) {
311316
int len = batchSample.featureCnts[slotId][sampleIdx];
312-
lod0.push_back(lod0.back() + len * piModel->EMBEDDING_SIZE);
313-
width += (batchSample.featureCnts[slotId][sampleIdx]);
317+
lod0.push_back(lod0.back() + len);
318+
width += len;
314319
}
315320
memcpy(lod[0].data(), lod0.data(), sizeof(size_t) * lod0.size()); // low performance
316321
lodTensor->SetLoD(lod);
@@ -321,8 +326,8 @@ class PaddleInferThread {
321326
int offset = 0;
322327
for (int sampleIdx = 0; sampleIdx < FLAGS_batchSize; ++sampleIdx) {
323328
for (uint k = 0; k < batchSample.features[slotId][sampleIdx].size(); k++) {
324-
//uint64_t feasign = batchSample.feasigns[slotId][sampleIdx][k];
325-
uint64_t feasign = globalKeys[feasignCnt % feasignNum];
329+
uint64_t feasign = batchSample.feasigns[slotId][sampleIdx][k];
330+
//uint64_t feasign = globalKeys[feasignCnt % feasignNum];
326331
feasignCnt++;
327332
TypeIn *data_ptr = lodTensor->mutable_data<TypeIn>(piModel->place) + offset;
328333
memcpy(data_ptr,

tools/inference/java/src/main/java/ParserInputData.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ public ParserInputData() {}
3333
public static int BATCH_SIZE = 2;
3434
public static final int BUFFER_MAX = 20480;
3535
public static int BATCH_NUM;
36-
public static final int SLOT_NUM = 408;
36+
public static final int SLOT_NUM = 300;
3737
public static BatchSample[] batchSamples = new BatchSample[BUFFER_MAX];
3838
public static TreeMap<String, Integer> feasignMap = new TreeMap<String, Integer>();
3939

4040
public static void ReadInputData() {
4141
Integer[] slotIds = new Integer[SLOT_NUM];
4242
String[] inputVarnames = new String[SLOT_NUM];
43-
for (int i = 2; i <= 409; i++) {
43+
for (int i = 2; i <= 301; i++) {
4444
inputVarnames[i - 2] = String.valueOf(i);
4545
slotIds[i - 2] = i;
4646
}

tools/inference/python/slot_dnn_infer_dataloader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def init(self, args):
5656
self.visit[slot] = False
5757

5858
def slot_reader(self):
59-
slot_num = 408
59+
slot_num = 300
6060
slots = []
6161
if slot_num > 0:
6262
for i in range(2, slot_num + 2):

0 commit comments

Comments
 (0)