MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / _shared_insert

Method _shared_insert

src/common/AutoModel/automodel.cpp:147–209  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

145}
146
147bool AutoModel::_shared_insert(chat_meta_info_t& meta_info, std::vector<int>& tokens, std::function<bool()> is_cancelled, void* payload, int first_len_run) {
148
149 // print token history
150 // header_print("DEBUG", "Current token history: ");
151 // for (size_t i = 0; i < this->token_history.size(); i++) {
152 // std::cout << this->token_history[i] << " ";
153 // }
154 // std::cout << std::endl;
155 // // print tokens to insert
156 // header_print("DEBUG", "Tokens to insert: ");
157 // for (size_t i = 0; i < tokens.size(); i++) {
158 // std::cout << tokens[i] << " ";
159 // }
160 // std::cout << std::endl;
161
162 // prefix check for tokens and token history to see if we can skip some tokens
163 const size_t idx = this->token_history.size();
164 size_t skip_count = 0;
165 for (size_t i = 0; i < idx; i++) {
166 if (tokens[i] == this->token_history[i]) {
167 skip_count++;
168 }
169 else {
170 break;
171 }
172 }
173 if (skip_count != idx) {
174 clear_context();
175 skip_count = 0;
176 }
177 tokens.erase(tokens.begin(), tokens.begin() + skip_count);
178
179
180 if (this->total_tokens + tokens.size() >= this->MAX_L){
181 header_print("WARNING", "Max length reached, stopping prefilling...");
182 return false;
183 }
184 for (int token : tokens){
185 this->token_history.push_back(token);
186 }
187 buffer<bf16> y;
188
189 auto prefill_start_time = this->profiler_list[PREFILL_TIME].start();
190
191 y = _chunked_insert(meta_info, tokens, is_cancelled, payload, first_len_run);
192
193 auto prefill_end_time = this->profiler_list[PREFILL_TIME].stop(tokens.size());
194 meta_info.prefill_duration = (uint64_t)time_utils::duration_ns(prefill_start_time, prefill_end_time).first;
195 meta_info.prompt_tokens = tokens.size();
196
197 if (meta_info.stop_reason == CANCEL_DETECTED) {
198 return false;
199 }
200
201 this->total_tokens += tokens.size();
202 if (this->total_tokens >= this->MAX_L){
203 header_print("WARNING", "Max length reached, stopping prefilling...");
204 }

Callers 13

insertMethod · 0.80
insertMethod · 0.80
insertMethod · 0.80
insertMethod · 0.80
insertMethod · 0.80
insertMethod · 0.80
insertMethod · 0.80
insertMethod · 0.80
insertMethod · 0.80
insertMethod · 0.80
insertMethod · 0.80
insertMethod · 0.80

Calls 8

duration_nsFunction · 0.85
eraseMethod · 0.80
push_backMethod · 0.80
sampleMethod · 0.80
sizeMethod · 0.45
beginMethod · 0.45
startMethod · 0.45
stopMethod · 0.45

Tested by

no test coverage detected