Skip to content

Commit 89d84ae

Browse files
committed
on-offline test ok
1 parent 99d5d74 commit 89d84ae

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

tools/inference/cpp/include/infer.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ class PaddleInferModel {
8484
{
8585
USE_GPU = 0;
8686
EMBEDDING_SIZE = 9;
87+
SLOT_NUMBER = 409;
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,

0 commit comments

Comments
 (0)