MCPcopy Create free account
hub / github.com/PaddlePaddle/Serving / inference

Method inference

tools/cpp_examples/demo-serving/op/ctr_prediction_op.cpp:70–370  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

68}
69
70int CTRPredictionOp::inference() {
71 const Request *req = dynamic_cast<const Request *>(get_request_message());
72
73 TensorVector *in = butil::get_object<TensorVector>();
74 Response *res = mutable_data<Response>();
75
76 uint32_t sample_size = req->instances_size();
77 if (sample_size <= 0) {
78 LOG(WARNING) << "No instances need to inference!";
79 fill_response_with_message(res, -1, "Sample size invalid");
80 return 0;
81 }
82
83 paddle::PaddleTensor lod_tensors[CTR_PREDICTION_INPUT_SLOTS];
84 for (int i = 0; i < CTR_PREDICTION_INPUT_SLOTS; ++i) {
85 lod_tensors[i].dtype = paddle::PaddleDType::FLOAT32;
86 std::vector<std::vector<size_t>> &lod = lod_tensors[i].lod;
87 lod.resize(1);
88 lod[0].push_back(0);
89 }
90
91 // Query cube API for sparse embeddings
92 std::vector<uint64_t> keys;
93 std::vector<rec::mcube::CubeValue> values;
94
95 for (uint32_t si = 0; si < sample_size; ++si) {
96 const CTRReqInstance &req_instance = req->instances(si);
97 if (req_instance.sparse_ids_size() != CTR_PREDICTION_SPARSE_SLOTS) {
98 std::ostringstream iss;
99 iss << "Sparse input size != " << CTR_PREDICTION_SPARSE_SLOTS;
100 fill_response_with_message(res, -1, iss.str());
101 return 0;
102 }
103
104 for (int i = 0; i < req_instance.sparse_ids_size(); ++i) {
105 keys.push_back(req_instance.sparse_ids(i));
106 }
107 }
108
109 rec::mcube::CubeAPI *cube = rec::mcube::CubeAPI::instance();
110 predictor::KVManager &kv_manager = predictor::KVManager::instance();
111 const predictor::KVInfo *kvinfo =
112 kv_manager.get_kv_info(CTR_PREDICTION_MODEL_NAME);
113 if (kvinfo == NULL) {
114 LOG(ERROR) << "Sparse param service info not found for model "
115 << CTR_PREDICTION_MODEL_NAME
116 << ". Maybe forgot to specify sparse_param_service_type and "
117 << "sparse_param_service_table_name in "
118 << "conf/model_toolkit.prototxt";
119 fill_response_with_message(res, -1, "Sparse param service info not found");
120 return 0;
121 }
122
123 std::string table_name;
124 if (kvinfo->sparse_param_service_type != configure::EngineDesc::NONE) {
125 table_name = kvinfo->sparse_param_service_table_name;
126 if (table_name.empty()) {
127 LOG(ERROR) << "sparse_param_service_table_name not specified. "

Callers

nothing calls this directly

Calls 13

push_backMethod · 0.80
get_kv_infoMethod · 0.80
emptyMethod · 0.80
lockMethod · 0.80
ResizeMethod · 0.80
resizeMethod · 0.45
seekMethod · 0.45
sizeMethod · 0.45
unlockMethod · 0.45
dataMethod · 0.45
inferMethod · 0.45

Tested by

no test coverage detected