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

Function create_req

tools/cpp_examples/demo-client/src/bert_service.cpp:61–98  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

59}
60
61int create_req(Request* req,
62 const std::vector<std::string>& data_list,
63 int data_index,
64 int batch_size) {
65 for (int i = 0; i < batch_size; ++i) {
66 BertReqInstance* ins = req->add_instances();
67 if (!ins) {
68 LOG(ERROR) << "Failed create req instance";
69 return -1;
70 }
71 // add data
72 // avoid out of boundary
73 int cur_index = data_index + i;
74 if (cur_index >= data_list.size()) {
75 cur_index = cur_index % data_list.size();
76 }
77
78 std::vector<std::string> feature_list = split(data_list[cur_index], ";");
79 std::vector<std::string> token_list = split(feature_list[0], " ");
80 std::vector<std::string> seg_list = split(feature_list[1], " ");
81 std::vector<std::string> pos_list = split(feature_list[2], " ");
82 for (int fi = 0; fi < max_seq_len; fi++) {
83 if (std::stoi(token_list[fi]) != 0) {
84 ins->add_token_ids(std::stoi(token_list[fi]));
85 ins->add_sentence_type_ids(std::stoi(seg_list[fi]));
86 ins->add_position_ids(std::stoi(pos_list[fi]));
87 ins->add_input_masks(1.0);
88 } else {
89 ins->add_token_ids(0);
90 ins->add_sentence_type_ids(0);
91 ins->add_position_ids(0);
92 ins->add_input_masks(0.0);
93 }
94 }
95 }
96 req->set_max_seq_len(max_seq_len);
97 return 0;
98}
99
100void print_res(const Request& req,
101 const Response& res,

Callers 1

thread_workerFunction · 0.70

Calls 2

splitFunction · 0.70
sizeMethod · 0.45

Tested by

no test coverage detected