MCPcopy Create free account
hub / github.com/NVIDIA/FasterTransformer / read_start_ids

Function read_start_ids

examples/cpp/gpt/gpt_example.cc:73–139  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71}
72
73int read_start_ids(int batch_size,
74 std::vector<int>* v_start_lengths,
75 std::vector<int>* v_start_ids,
76 int& max_input_len,
77 const int end_id,
78 const int beam_width)
79{
80 std::vector<std::vector<int>> tmp_start_ids;
81 std::vector<int> tmp_start_lengths;
82
83 std::string file_name = "../examples/cpp/gpt/start_ids.csv";
84 std::ifstream start_id_file(file_name, std::ios::in);
85 if (start_id_file.is_open()) {
86 std::string line;
87 int i0 = 0;
88 while (std::getline(start_id_file, line)) {
89 std::stringstream lineStream(line);
90 std::string vals;
91 int i1 = 0;
92 std::vector<int> tmp_vec;
93 while (std::getline(lineStream, vals, ',')) {
94 tmp_vec.push_back(std::stoi(vals));
95 i1++;
96 }
97 tmp_start_ids.push_back(tmp_vec);
98 tmp_start_lengths.push_back(i1);
99 i0++;
100 }
101 }
102 else {
103 printf("[WARNING] Cannot open the file '%s'. \n", file_name.c_str());
104 max_input_len = 0;
105 return 0;
106 }
107
108 max_input_len = tmp_start_lengths.data()[0];
109 for (uint i = 1; i < (uint)tmp_start_lengths.size(); i++) {
110 max_input_len = max_input_len > tmp_start_lengths.data()[i] ? max_input_len : tmp_start_lengths.data()[i];
111 }
112
113 while ((int)tmp_start_lengths.size() < batch_size) {
114 std::vector<int> padding_ids;
115 for (int i = 0; i < max_input_len; i++) {
116 padding_ids.push_back(end_id);
117 }
118 tmp_start_ids.push_back(padding_ids);
119 tmp_start_lengths.push_back(max_input_len);
120 }
121
122 // Add padding
123 for (int i = 0; i < (int)tmp_start_ids.size(); i++) {
124 for (int j = (int)tmp_start_ids[i].size(); j < max_input_len; j++) {
125 tmp_start_ids[i].push_back(end_id);
126 }
127 }
128
129 for (int i = 0; i < (int)tmp_start_ids.size(); i++) {
130 for (int b = 0; b < beam_width; b++) {

Callers 5

gpt_exampleFunction · 0.70
prepareRequestFunction · 0.50
gptneox_exampleFunction · 0.50
prepareRequestFunction · 0.50
gptj_exampleFunction · 0.50

Calls 2

dataMethod · 0.80
sizeMethod · 0.45

Tested by

no test coverage detected